C++, Java, CGI

A big advantage Java has is its open source development tools. There are some truly excellent programmer’s editors, debuggers, and other tools available for free. Download Sun’s Java stuff, then go get Eclipse for a programming environment - all free.

Java is a great language for learning, in my opinion. It’s a relatively clean OOP implementation, it’s got a short learning curve, and it’s free.

An even easier way to learn basic concepts is to learn Javascript (nothing like Java, despite the similarity in name). The primary advantages of Javascript are: 1) it’s a marketable skill, 2) The only thing you need to program in it is notepad, 3) Making changes is lightning fast, speeding up the learning curve, and 4) Source code examples are everywhere. Just do a ‘view source’ on just about any web page and you’ll see tons of example code.

Having said all that… I’m rather down on Java as a serious programming tool for applications these days. Our company has invested in several large Java projects, and all of them have been a pain in the ass. Performance is a particular problem. Mind you, we’re trying to do some pretty high-falutin’ stuff with it.

In terms of what’s marketable, I think perhaps the best skill to learn right now is .Net. You can start with C# and a scripting language like ASP.NET. Once you’ve learned the .NET libraries with the simpler languages, you can move into C++ if you want. But .NET requires you to buy Microsoft Visual Studio.

As it happens, I bought Javascript: The definitive Guide when I started making web pages. Never needed it though. My pages are rather simple, and non-commercial. People who read my CJ2A page say they like it simple. (Of course, these are older guys who collect nearly-60-year-old Jeeps.)

I have copies of most of the Easytrieve Plus programs I’ve written, from the simple early ones to the more complex multi-“doo-loop” ones. I think it would be fun to choose a few of them and translate them into an OO language. First of all, the “what do you want to do with the data” question is already answered. I just have to mock up some data files to work with.

Can you clarify wnat “.Net” is?

Oh, one other thing - SQL skills are very useful, no matter what language you learn. Fortunately, there is an excellent free SQL database called mySQL which you can download and learn to program.

.NET is Microsoft’s new programming framework. Here’s Microsoft’s homepage for it: http://www.microsoft.com/net/

SQL is one of those other things I want to learn. I’ve used it a couple of times, several years ago. I kept asking the company for a class in it, but one was never offered.

Does Javascript have polymorphic variables? I honestly don’t know–my experience with the language is very limited.

Basic SQL is not hard to learn, so you should be good to go on that.

Another hard core Java developer here.

I used to work mostly in C, C++, and PL/SQL (Oracle’s in-database procedural language).
Although I am sure that C++ has made great strides since my last exposure to it in 1998, it is not a language for the timid or the beginner.

As stated before, Java cleans up a lot of the nastiness of C++ such as arcane syntax and memory leaks.

Now for my own theory on these things: the people who write languages learn from the pain they have experienced in older languages. Hence, the more modern ones should (in theory, of course) be more user friendly, flexible, foolproof, extensible, whatever than older ones.
When Java was conceived, C++ was in its prime and memory leaks were the common complaint. Likewise the weird syntax. Cross-platform portablility consisted of zillions of indecipherable precompiler macros that protected highly machine-dependent sections of code.
Java took care of these issues in a fairly elegant fashion, while bringing along some new things to trip up beginners (classpath anyone?)

I know zilch about C#, but I would assume that it is a more refined language than even Java since it has the advantage of being designed after Java.

(Of course, I mean in general, since anyone can pick apart any language if they desire)

Now, about what it means to learn a language…

I feel it is important to distinguish between learning a language and learning a framework or set of libraries.
It is fairly easy to get going in Java without too much pain, but you won’t really be doing much. At least you will be making proper OO programs, though.

The first bit of fun starts when you begin to learn the details of some of the standard libraries provided with Java – how to work with I/O, how to use arrays, how to build simple GUI’s, how to access databases.

The next leap, for any major league language, will be going from coding using libraries and such to coding using powerful frameworks.

One can spend quite a bit of time learning the Java Swing architecture for building GUI applications; likewise, one can spend a long time learning how to use the Microsoft Foundation Classes to write Windows GUI apps in C++.
If you want to do web applications, the Java Servlet architecture, and then fancier frameworks such as Struts begin to come up.

I guess my point is that you may wish to consider a strategy for getting some depth as well as bredth to your studies. There is no way even the most uber of geeks can understand all frameworks and libraries, so you must pick and choose the ones you need. Get the basic language skills (bredth) down well – understand events, I/O, collections, standard idoms, and so forth. Then go deep with a project that dips into some of the specialized libraries: do a GUI application that uses database libraries. Do a web app that hooks into the same DB. Lots of interesting places to go.

Any language you choose will likely have the same challenges: the language basics first, the libraries, and then the frameworks. Consider the latter two categories well as you make your decision.

I learned C++ first, then Java. Though I like C++ better, I work mostly in Java now, so my C++ is very rusty. However, Java annoys me for reasons big and small.

Big Things (some of these have already been mentioned):

No multiple inheritance
It is not used that often, but is still occassionally useful.

No operator overloading
This makes the language much uglier, in my opinion. Especially annoying is having to call equals() for comparisons. Most of the time, when people want to compare two objects, they want to compare their values, not their pointers. They should have done the same thing with == that they did with the concatentation operator +, and made equals another operator (like instanceof) that compares pointers. If they did indeed fix this in 1.5, why did they make it case insensitive?

No functors
I suppose functors may be even less common than multiple inheritance, but sometimes there is no way to share code without passing functions or function-like objects. Yes, it is possible to get around this with interfaces and classes that implement them containing one function. However, I would rather that it be supported natively in the language.

Small things:

At first, the way Java passes objects annoyed the hell out of me. Now, I think of them as C++ pointers with the syntax of C++ references. However, the way objects are passed combined with the lack of an overloaded == operator for Strings creates one of the most frequent sources of bugs (at least where I work). Frequently, people create functions with a String parameter that may be “blank”. Some people use the empty string “” for this; others use null. Of course, they are not equal, and this causes a lot of bugs. More often, someone will write code like this



void f(String x, String y)
{
  if (x.equals(y))
  {
    // do something
  }
}


Then, someone else will call this function and pass null for x, causing a NullPointerException. In C++, the common practice is to pass references to strings. The code below will never cause a null-pointer exception, because all references must refer to something; moreover, it forces people to pass an empty string.



void f(string& x, string& y)
{
  if (x == y)
  {
    // do something
  }
}


It seems that two features of Java were designed in such a way to inadvertently form a frequent source of errors.

Also, is it just me, or does Java seem to encourage people to use incredibly long function and variable names? I admit to have fallen into this habit myself. Longer is not always more descriptive. I once ran across a function named “doesPotentiallyMoreDataExist”. Wouldn’t “hasMoreData” be more succinct? What does “potentially more” mean anyway? (No, the Javadoc did not say.)

OK, I think I’ve done enough ranting for now.

C++ is C with object-oriented bits bolted on the side. It works, but it’s big and ugly and honkin’ annoying.

Java is a language built from the ground up to be object-oriented. It’s a far better programming experience than C++, but still has a hard time getting taken seriously by the decision makers.

I’m surprised the main gripe with java isn’t the stupid everything devolves to object thing that leads to code like:

int b = ((Integer)((ArrayList) foo.get(“key”)).get(4)).parsetInt();

I’m not even sure if that’s right, I’d have to run it through a compiler just to see if all the braces are matched. I think me record is 5 different castings in a single line just to get an element out of a data structure.

Obviously, I haven’t learned the syntax yet; so the examples are beyond me. I don’t know what “void f(String x, String y)” means, for example. But for the other part, this is how it would look in Easytrieve Plus:

IF X = Y

  • DO SOMETHING
    END-IF

“int b = ((Integer)((ArrayList) foo.get(“key”)).get(4)).parsetInt();” seems to be parsing a string and assigning the found value to “int b”. But it’s Greek to me.

I started reading the JavaScript book last night. It’s ©1996, and talks about Netscape 3.0. It hints about “fixes” in upcoming newer versions of JavaScript. Thinking in Java, the book I got in the company seminar a couple/three years ago, is ©1998.

About “null” versus “space”. Some of the data we received in my last job had nulls in it that would cause the program to fail. When editing the file (in TSO) the null would look like a space. When browsing the file (again, in TSO – that was our system) the null appeared as a decimal point. EZ+ numeric fields must be numeric in order to perform arithmetical operations on them, so nulls or spaces would cause the program to crash.

Here is an example of what I’m used to. It right-justifies an accounts receivable aging bucket by searching for spaces and decimals in ASCII and in Hex:


//*[programmer identifier]* JOB (*[account number]*,1),'                    ',   
//             MSGCLASS=A,TIME=1,   RESTART=       
//             NOTIFY=*[programmer identifier]*,PRTY=12              
/*ROUTE PRINT Q                                    
/*JOBPARM ROOM=5001,P=PROC14,L=9999                
//JOBLIB  DD DSN=*[job library name]*,DISP=SHR         
//        DD DSN=SYSP.PAN.LOADMOD,DISP=SHR         
//*                                                
//CLEANUP EXEC DELDS                               
//STEP01  EXEC  PGM=EZTPA00                        
//*TEP01  EXEC  PGM=EASYTREV                       
//SYSPRINT    DD SYSOUT=*                          
//EZTVFM   DD UNIT=SORTDA,SPACE=(CYL,(90,10),RLSE) 
//SORTWK01 DD UNIT=SORTDA,SPACE=(CYL,(90,10),RLSE) 
//SORTWK02 DD UNIT=SORTDA,SPACE=(CYL,(90,10),RLSE) 
//SORTWK03 DD UNIT=SORTDA,SPACE=(CYL,(90,10),RLSE) 
//SORTWK04 DD UNIT=SORTDA,SPACE=(CYL,(90,10),RLSE) 
//SORTWK05 DD UNIT=SORTDA,SPACE=(CYL,(90,10),RLSE) 
//SORTWK06 DD UNIT=SORTDA,SPACE=(CYL,(90,10),RLSE) 
//SYSOUT      DD SYSOUT=*                          
//FILEA   DD  DSN=*[input file name]*,DISP=OLD    
//FILEB   DD  DSN=*[output file name]*,DISP=(NEW,CATLG,CATLG),         
//            UNIT=SYSDA,SPACE=(CYL,(250,50),RLSE),                    
//            DCB=(RECFM=FB,LRECL=400,BLKSIZE=23200)                   
//SRTMSG      DD SYSOUT=*                                              
//SYSIN DD  *                                                          
*********************************************************************  
**  custno                                                         **  
**                                                                 **  
**  JOHNNY L.A.                                                    **  
**    /  /                                                         **  
*********************************************************************  
FILE FILEA                                                             
  INPUT-REC              1  400   A                                   
  AR-NUM                 12   17   A                                   
  FIELD-BYTE-IN1   AR-NUM      1   A INDEX SUB1                        
  AR-NUM-A-OUT            12   12   A                                   
                                                                       
FILE FILEB                                                             
  OUTPUT-RECORD         1  400   A                                     
                                                                       
********************************************************************** 
**  WORKING STORAGE RIGHT-JUSTIFYING FIRST AR-NUM FIELD             **
**********************************************************************
  WS-AR-NUM-A-IN       W   17  A                                      
    FIELD-BYTE-IN1B  WS-AR-NUM-A-IN 1 A INDEX SUB1B                   
  WS-AR-NUM-A          W   12  A                                      
                                                                      
JOB INPUT(FILEA)                                                      
   PERFORM RIGHT-JUST                                                 
   PUT FILEB FROM FILEA                                               
                                                                      
 RIGHT-JUST. PROC    
   WS-AR-NUM-A-IN = '000000000'
   SUB1        = 17                                                   
   SUB1B       = 11                                                   
   DO WHILE SUB1 GE 0                                                 
      IF FIELD-BYTE-IN1 = ' ' X'3F' X'00' '.'                         
         SUB1  = SUB1 - 1                                             
      ELSE                                                            
         FIELD-BYTE-IN1B   = FIELD-BYTE-IN1                           
         SUB1  = SUB1 - 1                                             
         SUB1B = SUB1B - 1                                            
      END-IF                                                          
   END-DO                        
   MOVE WS-AR-NUM-A-IN TO AR-NUM 
END-PROC                         


By making the logic a “proc” instead of writing it into a larger program, I could copy RIGHT-JUST. PROC into the bottom of a larger program and just call it with the PERFORM step and adding the appropriate variable-names to the Library (“definition”) section. I did that with most of my “generic” procs, and added them to programs as they were brought to my attention.

It’s a huge savings in time when the user doesn’t have to have the data contributor re-send corrected data – especially when the contributor often has no programming staff. (Often they’ll hire someone to get their AR program written, and will have to hire them again to fix problems.) I’ve saved millions of lines of data and untold hours and days with these little procs. (Well, some of them aren’t so little.)

The new VP of that department came from a different part of the company. In her previous department, data was required to be in the correct (industry standard) format. The part of the company I worked for was much smaller, and accepted data in any format the customer used because we wanted the lines of data for the database. I heard that the new VP is now insisting that my former department will no longer reformat customers’ data, and that they must give it to us in our format. No more new Easytrieves. (Not that she could have any more written, since she got rid of everyone who knew how to write them.) But data will still come in in different formats; so rather than have us – we, who knew the data intimately – use the new Ascential DataStage tool to reformat it the company hired the (ironically-named) Indian company Tata to write DataStage reformats. Weird. “All data must be in our format, or it will not be accepted. If the data is not in our format, it will be reformatted.” :confused:

Okay, I haven’t had enough coffee. Please excuse the rambling.



void f(String x, String y)
{
	// Do stuff
}

Is declaring a function (or method) called ‘f’ which takes two String parameters and returns nothing (void)

That’s what the b = (…) parseInt() is, the rest is retrieving the value out of an ArrayList (a fancy type of array).

What Shal is compaining about is having to tell the compiler what type of object each thing is. You do this by prefacing the object with the object type in brackets, this is called ‘casting’. Hence the (Integer) and (ArrayList) elements, they don’t actually do anything. The (ArrayList) cast is required so that the compiler knows what is allowed with what foo.get(“key”) gives you.

IIRC parsetInt() is a method that converts a string (“42”) into an int (42).

What I brought up and bitwise complained about is that in C/C++/C#/Java the comparison operator is ==. To compare integers do:


if( x == y )

. So how do you compare strings? (C is terrible with strings I won’t go there) The problem is that while


if( string1 == string2 )

is legal in Java and will compile and run fine, it will always be false because it is comparing pointers (or references, or something) NOT the characters in the string. You need to use the .equals() method, ugh.

I am fairly confident that all languages have traps such as the “string == string” trap mentioned here. Just pick a language that is not so difficult to use, worth a bit in the market, and appeals to you.

That said, while this particular trap (and others of its ilk) shouldn’t be there at all, it is a beginner’s mistake. Most experienced Java coders would never even try such a thing, having been bitten in the past – indeed, a Java coder would rarely use “==” for comparing anything that wasn’t a primitive type.

We accept these rough edges on our languages of choice because there are enough cool parts to compensate. Try writing fancy multithreaded code in any language… Few languages handle threading as easily as Java.

Want nasty? Check out how C or C++ precompiler macros can cause grief:

// (Not sure this is correct syntax since it has been ages)
#define SQUARE© = c * c

result = SQUARE(i++);

This would expand to “i++ * i++”, which is most certainly not what was intended.

Small Clanger: I’m not following you. How would it look in a structured language?

STRING_X = ‘’
STRING_Y = ‘’

Is that right? That is, you’re initializing String x and String y to blanks?

What about the double-equals? “Comparing”? Is that the same as a single-equals? I can understand if you’re comparing two multi-line datasets to see if they are the same, and to possibly write out extra lines or different lines in one. How would that look in structured language?

The double == is simply a syntax element from C that has worked its way through some other languages.

In C (and its descendents), “==” is the comparison operator and “=” is the assignment operator.

You only use “=” to set the thing on the left to be equal to the thing on the right.

x = y * 3.14;

You only use “==” in situations where a true/false answer is desired.

if(z == -1){

}

This is slightly confusing, and has been a source of many errors for C programmers since “x = -1” and “x == -1” are both proper things to put in an “if” statement, but the former is usually a tempting trap, while the latter is the desired one.

if(x = -1){
// Oops. X has now been given the value of -1. No good.
}

if(x == -1){
// That’s better.
}

Now for the OO part of it.

It’s fairly easy to understand equality of “primitive types” (integers, floats, bytes, booleans, and the like). When you start using slighty more complicated things like strings, equality is a little bit more complex. You want the computer to magically compare every character in the two strings and tell you if all of them are the same.
In fact, most languages do this for you when you use the standard comparison operator. C++ does.

C doesn’t, though. You need to use a special function to do this job since C is a more low-level language and strings aren’t really handled as special cases.

/* C code /
if(strcmp(string1, string2){
/
Great! */
}

This is needed because a string in C is simply an array of bytes with a null character (ASCII zero) at the end.

Java treats strings much better than C, but it still doesn’t provide magic to allow you to transparently compare them.

You need to do this:

// Java
if(string1.equals(string2)){
// My strings are equal!
}

This doesn’t seem so bad – it’s not much different from doing this in C – but once you consider that “string1” is really a reference (a number that says a memory location where the string is) and it can be “null”, you have to do some belt-and-suspenders code to avoid the dreaded null pointer exception.

In object-oriented languages, all custom objects need a special way of comparing them. If you make a “car” object, the computer has no way of knowing that you consider two cars alike if they have the same motor, model, year, and color; you have to write a special function for your object that answers the question “Am I equal to this other object?”

The string object I used as an example before has just this type of special function in some OO languages – the special function simply checks all of the bytes of the two strings.

Unfortunately, Java simply calls the function “equals” and expects you to code it as if it were any other function, hence the “if(string1.equals(string2))” syntax that small clanger pointed out. C++ has a similar “equals()” function, but they made the language in such a way that the programmer can replace the standard behavior of the “==” operator directly with the custom version. Hence, in C++ one can say:

if(car1 == car2){
// These cars must both have the same motor, model, year, and color.
}

There isn’t much more to OO comparison. It’s simply a matter of you writing a custom function that returns true or false when given two of your custom objects to compare.

In my professional programming background, I’ve used several languages, including Java (J2EE, Struts, and an in-house framework), C, C++, VB 6.0, and Delphi. I’ve also done SQL with both Sybase, DB2, and SQL Server databases.

Honestly, if I had to pick any beginning language, I’d probably go with Java. I remember struggling mightily with the whole OOP concept at first, spending hours and hours of frustration. Then, suddenly, it was like the light bulb went on in my head, and I just ‘got it’.

One of the worst things about OOP, for me, was declaring an instance of a class as a subclass. For example, consider a football team. A football team is made up of a bunch of football players, but not all football players have identical skills. All football players have a height and weight. I quarterback has a passing ability. An offensive lineman has a blocking ability. A tailback has a running ability. So you can create a class structure like this:



public class FootballPlayer {
  public  String height;
  public String weight;
}

public class Quarterback extends FootballPlayer {
  public String passerRating;
}

public class OffensiveLineman extends FootballPlayer {
  public String blockerRating;
}

Then, down in your FootballTeam class, you could have something like this:



public class FootballTeam {
  public void createTeam() {
     FootballPlayer  qb = new Quarterback();
     FootballPlayer  LT = new OffensiveLineman();
   }
}

Took me a long time to wrap my brain around how that could be considered vaild code.

Sorry, which particular bit of my rambling are you referring to here? Expand your query and we will try to explain. As it happens initializing strings to nothing/zero length is not something you’d be likely to do in any of the C-like languages, for varous reasons.

m7[sup]b[/sup]5 covered that.

Small Clanger: I was referring to “void f(String x, String y)” where you said “Is declaring a function (or method) called ‘f’ which takes two String parameters and returns nothing (void)”.

It sounds like you’re saying “Perform function f. Function f assigns ‘nothing’ to String x and String y.” So let’s say String x = ‘cat’ and String y = ‘dog’. You perform f and then print the results. String f assigns (nothing) to whatever is in the variables String x and String y, so it prints nothing.

Is f a function that “voids” variables? Or is “void” something that assigns (nothing) to any results that come from f?

This is what I meant earlier when I said that there seem to be “black boxes”. Unlike structured code, I can’t just look at something and say, “Oh. This is what’s happening”. Granted, I haven’t gotten into the books yet and it will probably become clear when I do. But when everyone else already knows what’s going on, it’s hard to go on from even the basics.

minor7flat5: I’ll have to get some caffeine into the system before I get into your post. Let me ask this, though: What’s the difference between these two lines?

IF X = Y * 3.14
PRINT X
ELSE PRINT ‘X IS FALSE’
END-IF

IF X == Y * 3.14
PRINT X
ELSE PRINT ‘X IS FALSE’
END-IF

(Obviously “==” is not legal in this language; just tyring to see the difference.)

Sorry about the confusion I think our examples have been too sparse, the void function was especially confusing.

Start with some code ( x = y + z; ) that needs no explanation. Lets say you want to put the ‘+’ operation into a function (let’s not ask why) I think a function is what you called a PROC.

In curly-brace languages you define a function like this, no black box here it’s all your own code:


int add_two_ints( int a, int b)
{
	return a + b;
}

We say that add_two_ints has a return type of ‘int’ and use it in the program like this, assume x y and z are already declared.



	y = 42;
	z = 777
	x = add_two_ints( y, z ); // run off to the add_two_ints() and assign the result (return value) to x;
	// x now equals 819 so the following if() evaluates to 'true'
	if( x == 819 )
	{
		// do stuff with x (equals 819)
	}
	// as **m7[sup]b[/sup]5** said trouble is this is also valid
	if( x = 666 )
	{
		// uh oh, x now equals 666
	}


A ‘void’ function is one that doesn’t return anything, it can’t be used as the right hand side of an assignment. A function called just “f()” is a terrible example because there is no clue as to what it does. A better one might be:



void swap_strings( String s1, String s2 )
{
	// some code to swap s1 and s2
}

It is a ‘void’ function because you aren’t interested in what it returns, only on what it does to s1 and s2.



	String str1 = "Cat",
	String srt2 = "Dog";
	
	swap_strings( str1, str2 );


One more:



String concatinate_strings( String s1, String s2 )
{
	return s1 + s2;
}

In use:



String petstr = concatinate_strings(  "Cat", "Dog" );


The reason I qualified ‘function’ with ‘method’ is that in OO all functions belong to a class and are properly called methods of that class.
Whew, that’s enough for now, maybe I’ll do some work.

BTW if anyone has critisims of this post because it simplifies the behaviour of strings or mixes up languages then feel free to explain in full. :slight_smile: