Dot Net Fluke: Getting by on C# for iSeries RPG Developers

Useful tutorials on C# and .NET for RPG iSeries AS/400 developers. Brought to you from the folks at AranRock Consulting

6/17/08

C# -'The worst bloody language in the world'

My brother-in-law, a Phd wielding university prof.who has a penchant for the complex and abstruse called around yesterday to declare the whole .Net  bouquet and the languages contained therein 'the worst bloody language in the world'.  He came to me asking some very simple questions such as how to read a customer file, display it in a windows form, process it etc and was soon bogged down in connection strings, data binding, data sets etc. "But I just want to display the data and read it!" he exclaimed. He was astounded that the columns in a table aren't easily directly accessible when using SQL which isn't checked until run-time (LINQ I suggest? " Yeah but you still have to go thru hoops!"). 
Coming from procedural languages like RPG, I can sympathize. If I want to process a table in RPG  to check spending limits of a customer and update the table I do this

F CustomerFile IF   K DISK

C Read CustomerFile;
C DOW not %eof;
C If AmountSpent > CreditLimit;
C AllowSpending =False;
C Update CustomerFileR;
C Endif;


C  Read CustomerFile;
C EndDO;



The equivalent in C# is much more complicated and includes connection strings, command text and a data reader which all have to be set up.

Note that for the ONE 'F' declaration in RPG there are 3 in C#.  To even do a read needs to be setup - you need to create a data reader first. Imagine having to 'create' a read statement in RPG! The code doesn't even include the update functionality!  But the biggest problem is that column names are not typed directly in C# meaning you can't refer to the column name directly. The column 'AmountSpent' is not known to the C# program.   Linq alleviates this situation but you still have to do the setup work first.  I understand the frustration.



using System;
using IBM.Data.DB2.iSeries;

namespace iSeriesADOexample
{
class Program
{
static void Main(string[] args)
{
iDB2Connection connection =
new iDB2Connection("DataSource=PUB1.RZKH.DE; UserID=XXX; Password=xxx; DefaultCollection=COLMBYRNE1; LibraryList=COLMBYRNE1, *USRLIBL");
iDB2Command cmd = connection.CreateCommand();
connection.Open();

cmd.CommandText = "Select * from COLMBYRNE1.CUSTOMERFILE";

try
{
iDB2DataReader dataReader = cmd.ExecuteReader();
while (dataReader.Read() == true)
{

Double AmountSpent = dataReader.GetDouble(3);
Double CreditLimit = dataReader.GetDouble(4);

if (AmountSpent > CreditLimit)
{
DoUpdate();
}

}
}
catch (iDB2SQLErrorException e)
{Console.WriteLine("Error:" + e.MessageDetails);
}
Console.Read();
cmd.Dispose();
}
}

}



Programming is the art of bringing ideas to life. That's what my brother-in-law came to me for. He had an idea for a program and wanted to make it real. Unfortunately the initial  hurdle to create his simple program was far too great. The wizard functionality in Visual Studio only highlights how difficult it is to do basic actions like read a table, display the contents, process the results and update the table. This is one of the most common programs that every programmer creates yet in .NET it is difficult for a beginner.

It is clear Microsoft have 5-10 years to go before .NET is really mature and allows both beginner and seasoned developer to easily bring their ideas into the world. We program to make things better, faster, more fun, more interesting - not harder.  The tools we use then should also be better, faster - not harder. The effort to use a tool must never be greater than the effort it takes to solve the problem logically.  (Byrne's first hypothesis*) If you want to add 2 and 5 , C# should do that as easily as it does to solve it- and it does  int sum = 2+ 5;    E.g. if a client says that some of his customers are over their credit limit and needs to halt their spending then the logical solution which is to flag those spenders. The effort to implement that in C# should be that easy.  This is the benchmark which Microsoft must follow - just to keep up.

Labels: , , ,

10 Comments:

At August 5, 2008 at 10:29 AM , Anonymous Anonymous said...

Have you tried C++?
That is the worst bloody language in the world!

 
At August 5, 2008 at 10:30 AM , Anonymous Anonymous said...

mmm... What exactly is the criteria for the worst bloody language in the world?
RPG can be pretty darn funky when it wants to be. Any RPG program over a 1000 lines long becomes an unmangeable expensive nightmare.

 
At August 5, 2008 at 12:30 PM , Anonymous Anonymous said...

I think you are missing the point. C# was designed to be expressive meaning that it can solve a wide variety of programming issues.
The cost of being expressive is complexity. That means C# can be hard to read and hard to write. There are plenty of languages out there that are easy to write and easy to understand - RPG being one of them - but the cost of that is a limited ability to solve issues coherently.

 
At August 5, 2008 at 12:41 PM , Anonymous Anonymous said...

The thing that kills a
language is powerful syntax and abstractions.

I work in C# (worst language EVER!) and I had to write some loops to
accumulate some values in some collections. I spent a good deal of
time looking for some standard accumulate function. Nothing. So I
decided to roll my own using generics and anonymous functions. My
manager looked at the code and asked "Who's going to maintain this?
How will they understand it?"
That's not the first time I've encountered these questions. I heard
it when I used function pointers in C. I heard it when I used
templates in C++. I heard it when I used Lisp for ANYTHING. :)


I can certainly understand concerns about over engineering a
solution. I've been the victim of many over complicated class
structures. I think there's a difference between complicating a
design and using the language syntax. When I simplified the
implementation from six independent functions to one that gets an
anonymous function, I thought I was making it easier. I didn't worry
that future developers would have to know ALL the syntax of the
language instead of just the set that intersects with C++.


I'm finding that regardless of the language used, many
"professional" developers have a serious issue with the more powerful
abstractions available to them. A language like Lisp that supports
the abstractions so naturally (as opposed to the syntactic mutilation
that happens in C#) is doomed.


Sorry about the rant. I am incredibly frustrated. How is C#'s poor
readability my fault? I didn't design or select the doggone language.


I hope our product's translators understand the languages they
translate. Maybe they figure knowing a few major words is enough, and
they can wing the rest! :)

 
At August 5, 2008 at 12:51 PM , Anonymous Anonymous said...

As far as I'm concerned, C# is now going the way of C++: it's got syntax that I will never, ever use and is well on its way to complexifying its way out of my life

 
At August 5, 2008 at 12:54 PM , Anonymous Anonymous said...

C# is too complex already. Most people that write .NET blogs are not average developers, they are geeks that spend their whole day reading C# books and other blogs. The average guy is dying on all this new C# and VB feature load.

 
At August 5, 2008 at 12:56 PM , Anonymous Anonymous said...

C# and the .NET framework has to be able to service the profesional programmer/developer/project. It can't be picthing to the lowest common denominator. The working programmer whether .NET, Java or C++ can reasonably be expected to keep abreast of new features at a reasonable pace. If the average chap can't, I'm genuinely sorry to say, that's tough.... this isn't about being a geek, it's about being a working developer.

 
At August 31, 2008 at 9:38 PM , Blogger DeeJay said...

I agree that C# by itself can be very complex but in my line of work, we make good use of several additional programs to not only improve our speed but make programs easier to write. The biggest help, was an O/R Mapper, which takes all of the guesswork out of setting up a connection, creating the commands, etc. I'm hoping LINQ and the Entity Framework can make this more of a built-in feature.

 
At October 16, 2008 at 4:34 PM , Blogger Dalcyon said...

Hi,

Sorry but why don't you just use SQL to filter and update your anwsers ?

You should try in SQL

cmd.CommandText = "UPDATE CustomerFile SET AllowSpending = CASE WHEN AmountSpent > CreditLimit THEN 0 ELSE 1 END;"

cmd.ExecuteNonQuery();
cmd.Dispose();

Regards,

Dalcyon

 
At June 27, 2017 at 4:34 AM , Blogger kingrani said...

Flipkart is one of the biggest world wide eCommerce Site flipkart cashback offersso

Flipkart is one of the biggest world wide eCommerce Site Flipkart hdfc offersso


Flipkart is Offering Cashback Offers Flipkart YES Cashback Offer You will get upto 75% Discount

Flipkart is Offering Cashback Offers Flipkart Phonepe Cashback Offer You will get upto 75% Discount

Flipkart is Offering Cashback Offers Flipkart Cashback Offer You will get upto 75% Discount

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home