Java is Getting Old

March 13, 2010 § 1 Comment

For the last 6 months, I have been programming with both Java & Python. Python is new for me. Java is my whole time programming language, its almost 8 years that I do Java programing (since the first years of University). I love Java, I love its huge community which is very important for a programming language success, and finally its greatest IDE ever Eclipse.

However, there is a problem in Java, the language syntax is not evolving, I remember one of the last improvements of Java 1.6 was a new look & feel (Nimbus)! do we need another look & feel? do we need Java for desktop programming? come on Java is dead for this field, focus on your power, the web, backend applications, messaging systems, and what about an addition of some of the things I am proposing here?

I still remember the day Java introduced the for each loop in the Java 1.5 release (which by the way was available for years in other programming languages):

String[] myArray = new String[10];

for ( String str: myArray ) {

System.out.println(str);

}

This was a very welcomed change, it increased productivity when using collection classes (do you still use an Iterator)? productivity comes from writing less annoying/repetitive code, like getting the Iterator object, doing a while loop, iterating over the collection… bla bla bla.

These are the moments when your brain as programmer turns off, and your fingers does the work (there is no thinking, just annoying code). This was not a very big problem when everybody had to do it this way. but when I got used to the for each loop, I started working on a project developed in Java 1.4. Every time I came to iterate over a Collection frustration increased because I was feeling unproductive (I know that I can use eclipse templates). Steve McConnell in his book Code Complete 2, lists the ratio of high level language statements to equivalent C Code, which shows the weakness of Java productivity compared to Python.

This is exactly what is happening with me after using Python, there are some great syntaxes in Python that I really really really wish Java would introduce in their next release, they are trivial ones, and easy to introduce in the language, but they have a great impact on productivity, I report two of them:

1. Multi line Strings (Block strings)

These are strings that consist of multiple lines, Python supports them using three single ( ‘ ) or double ( ” ) quotations for example, an SQL query string could be written like this in python:

sql = “””

select *

from table1

where table1.col1 = 10

“””

However in Java it is usually done using a StringBuilder/StringBuffer like this (for those who do the same thing with a String don’t do it, they will slow down performance, remember Strings are immutable):

StringBuilder sql = new StringBuilder();

sql.append(“select *”);

sql.append(“from table1”);

sql.append(“where table1.col1 = 10”);

  1. I know you can write it in one line and its still readable, but assume the query is very big and can’t be contained in a line of 120 columns (code readability)
  2. I don’t want to put it in a .properties file, I just want this query string in my code, and I want it to look nice, don’t start with MVC.

2. Array & Collection Operations Using Operators Instead of Methods

A lot of our programming deals with arrays and collections, we get array values using indexes, we get subsets of an array (slicing), we swap items in arrays… etc, again Python beats Java in this too, for example in Java if you want to get the last character of a String you do:

String str = “ABCDEFG”;

char last = str.charAt(str.length() – 1);

Yes it is not rocket science but its frustrating, in python strings are lists of characters so what applies to lists applies to strings too, and getting the last character is like navigating the list backwards, making the code more readable, and faster to write (BTW, the Java code is 65 characters length, while the python one is 30 characters, the HALF):

str = “ABCDEFG”

last = str[-1]

Here are some other operations that can be done in python on any type of lists, which are not supported in Java, I used strings for simplicity:

str = “ABCDEFG”

str1 = str[1:3] #Substring from 1-3 (BC)

str2 = str[ :4] #substring from 0-4 (ABCD)

str3 = str[:-2] #substring up to length -2 (ABCDE)

str4 = str[0::2] #start from 0 and do steps of 2 (ACEG)

str5 = str[::-1] #start from 0 and do -1 steps, in other words invert the string (GFEDCBA)


These are a subset of the most important features that I wish Java will include in their next releases, its really annoying to do these stuff by calling class methods, I don’t care if Object Oriented allows this or not (a String is an object, and slicing should be done by a method) ok let there be a substring method, but I want to extract substrings like python too, its faster, easier, and more readable, and make it up to the programmer to choose between the bulky methods, or the intuitive operators.

One last thing, In this post I mentioned things that Python does in a great way, and that I wish Java will support them, but it doesn’t mean that Python is better than Java, there are many things I hate about python too, the most important one is the decision to use indentation instead of braces ( { ) for code blocks, which drives me crazy, there are many issues in Python too, Nothing is Perfect.

Problem of IT Universities

March 7, 2010 § Leave a comment

IT Companies all over the world face the same problem when it comes to recruiting new programmers, THEY ARE NOT EASY TO FIND! every year many programmers, computer engineers, and software developers graduate from universities, but where are they? where are the good ones? why some of them are amazing in programming, while others can’t reverse an array of characters?

The problem is that graduate programmers doesn’t work out of the box (they are not plug and work), they don’t have the needed expertise or knowledge to do what they are supposed to do (write nice working code), in the same time companies need people who can program, they don’t have time to teach them everything (they already studied 5 years, isn’t that enough?) These conditions make a programmer’s working path start with some kind of internship, software testing, more testing, new job, another new job, yet another job, and finally after 2 or 3 years they reach the point of doing what they are supposed to do, WRITE CODE. Don’t get me wrong, I know there are some graduates that could work in companies even before graduating, but these are a minority, and they don’t have anything to do with this post.

Yesterday I was arguing with a college about this problem, and we concluded that the problem is: The absence of a long term software project (and not a single course project), that starts from ground up to acceptance tests and maintenance.

A typical university course (e.g. graphics design) would last 4 months, with a project assignment (e.g. a painter) to deliver at the end of the semester, 95% of students will deliver broken projects that doesn’t work as they should, they get a bad mark, and thats it!, the project is closed and a new one is opened for the next course (object oriented programming). In this way students doesn’t learn how to build a good software architecture, refactor their code, track bugs and adjust them. They don’t feel the PAIN of bad software projects.

If I where a man of power I would force all IT universities to follow this plan, along with their already established plans, I don’t care if students doesn’t have time, they are students and they have only one job STUDY STUDY STUDY, the more you study now the faster you will find your chair in the market, here is the plan:

After learning the basic programming language ( ANSI C or Java ) which should be the first or second semester, students are presented a group of projects to choose from, these are long term projects that will span 3 semesters (1.5 years), students working in a team, shall deliver a piece of software. In this manner students will learn stuff about team working, software engineering, they will be assigned tasks to do, there will be schedules to respect, unit tests, usability tests, meetings … etc. and the nice thing, they will have to deliver something that WORKS.

After delivering the project, students role change, they will become project engineers (PE), with more responsibilities and more experience in their field (the project they worked for 1.5 years). They will be asked to re-start the same problem they solved as a team, but this time they will lead their own team of freshmen students, and they will be working on the project on all sides, requirements, architecture, design, creating schedules, assigning tasks to other students, specifying the architecture of the project, reviewing code etc.

This way students will work on a software project for almost 2.5 – 4 years depending on how much their studies last, which will allow them to see, and practice the same stuff they are going to do after graduation, which will make them mid-experienced programmers right after university, and for sure more demanded from companies, and somehow save at least two years of their life.

This was an idea we got while talking, its an abstract solution for a big problem, but it sounds great to me, if students could learn many real world problems during their university studies such as:

  1. Software versioning SVN or CVS.
  2. Working as a team.
  3. Working on timed tasks, (you have to code this module in one week).
  4. Tracking bugs and adjusting them.
  5. Refactoring code.
  6. Software testing.
  7. Deliver working programs.
  8. Leading a software development team.
  9. Writing requirements and technical specifications.
  10. Working on a long term project, and not a 4 months project.
  11. Deliver something that actually works, and being responsible of it.

Some companies already have their work arounds for this problem, for example Joel Spolsky founder of Fog Creek, offers internships for good university students, so he can prepare them to work for his company, they will work on his projects, learn his tools, and follow the path he is planning for them, so once they graduate THEY ARE READY to work in his company, and profit starts from day 0.

Where Am I?

You are currently viewing the archives for March, 2010 at Omar Al Kababji.