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 ) {



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.

File system navigation program

February 6, 2010 § Leave a comment

Today I started to set up a serious development environment on my mac, and the first thing I needed is a good file navigation program, at work I use a windows XP machine and for me their navigation system sucks, it is slow, inefficient and you waste a lot of time doing ordinary stuff like copying a file from one directory to another, deleting files, etc.

Don’t get me wrong, for a normal user it may be enough, but for a programmer things change, so I set a ranking system based on the following:

1. Can you look at two directories at the same time?
2. Can you navigate through directories very fast, and without using the mouse?
3. Can you do everything using keyboard shortcuts? with no need to right click on icons? such as copying files, getting their information, sending them by email, compressing them?
4. Can you compare two files, or two directories? for example you have two versions of the same file, that you want to compare on the fly to see what is difference between them.
5. Can you map network drivers, and FTP folders and navigate through them as normal drives?
6. Can you compress files/folders on the fly?
7. Can you see hidden files?
8. Can you run commands from the command prompt/terminal through the program?

In a windows environment the best application in my opinion is Total Commander, I get used to it, and now I can’t use a windows computer without it, and it meets all the points mentioned above, so I searched the internet for a Total Commander program for Mac, and found this great application named Disk Order 3.0 its exactly the same as Total Commander, it just does whatever I want as I want 🙂 I LOVE IT.

Simple Things Should be Simple, Complex Things Should be Possible

October 4, 2009 § Leave a comment

Assuming you are a software developer, let me ask you a question, what do you do at work (except drinking coffee)? do you modify code written by others? or do you develop projects from scratch? either way this post is for you. For me Its almost 2 years that I adjust and modify pieces of code written by others (if I just could know where they live), anyway here is the story:

Your boss comes to your office holding a cup of coffee in his hand, and tells you about a new modification, we have to read some information from a .csv file and parse it (YEAAH finally something new to do), this is something that happens everyday, there is a problem and we have to solve it, but lets dig to see how this problem is solved by different programmers?

John, a programmer who is not a programmer (but sadly thinks he is), will consider reading a .csv file the end of the world (I don’t even know what the hell is a csv by the way), he will start spamming all the office asking how he could do it, he will get 10 different ways to solve it, and after wasting 20 days, and interrupting other coworkers during this period, its done… YES YOU CAN JOHN!!. We put John’s modification in a production environment, and we get a big fat NullPointerException, Why? on my PC worked… John its because you considered that the file should be in the directory:

C:\Documents and Settings\Users\Dump John\Desktop\file.csv

And guess what, that path is written in the source code file, and to change it we need to checkout the project from the repository, change it, recompile it and deploy it again. JOHN take this advise, go find a job in McDonald, and leave programming for real programmers.

Fred, the second programmer is one who knows everything, he has a 10+ programming experience, he read 15 books about design patterns, he collects certifications as collecting flowers, he used almost all java MVC and web development frameworks, he knows about good programming habits, ok ok you are good Fred, what is your solution?

  • Create an IDataReader interface that will have a readData() and processData() methods (you have to program  for interfaces).
  • Create a class AbstractDataReader that implements IDataReader and adds many common methods, that will be used by our subclasses.
  • Heey now the file is .csv but in the future may change so lets create those classes CSVDataReaderTSVDataReader,XMLDataReaderDBDataReaderSocketDataReaderFTPDataReaderHTMLDataReader, that will handle almost every kind of file, and lets group text ones alone, and DB alone, so lets make them descendants of AbstractTextDataReader andDBAbstractDataReader.
  • We have DataReader’s for almost any type, but we have to be sure which one to use, so lets create a DataReaderFactory, that will determine the correct file reader and return a proxy to the correct IDataReader object (object factory & proxy pattern).
  • Yeeeeah I like the idea, go on Fred…
  • The way files are processed may change and its not good to put it in a source code file, lets create a proprietary workflow language that can be expressed in plain XML, and use a parser that will parse these commands, and transform them to java code.
  • Lets adapt the delegation design pattern too, I don’t know for what, but it sounds cool I want to use it.
  • Many DataReaders can be operating at the same time, so lets create a pool of IDataReader objects, and lets use Dependency Injection to inject those objects in the classes that will use them.
  • Should we use our own Dependency Injection framework? NO (we are reinventing the wheel) Spring framework provides it, lets integrate Spring in our solution.
  • Since threads are playing we need to put synchronization stuff, and having racing conditions is the last thing we want, this is a serious framework, its Fred’s framework.
  • Everything should be configurable, so lets put everything in .properties files, no wait lets store them in a database, so we can change them without the need to restart the application.
  • Lets log all operations, and lets also provide a GUI application to manage the threads pool, logs, and configuration parameters.
  • We should do everything with Aspect Oriented Programming (AOP) in mind, so we can add and remove layers of code without interference.
  • Ok shut up Fred we got your point.

This is a perfect and nice solution Fred you are really a great programmer, I love your idea. I am not done please keep reading…

Finally Steve a duct tape programmer (as Joel Spolsky describes him in his post)  comes, Steve is just as the previous programmer Fred, but with one additional thing, HE USES THAT THING ON HIS SHOULDERS (yes the head), before even starting to work he asks one or more questions to his boss, to better understand the situation, and after talking with his boss. It is cut clear that those coming information will be only from a .csv file, and they will almost never change. So he decides to go simply with a simple class that reads a file and parse it and thats it. (of course he would make it a bit more flexible to small changes) and everything is done in, lets say… 4 hours? It could be even done in 2 hours.

Got it? No? ok lets continue… after two years both Fred & Steve changed companies (John was shoot by Steve, I told him to find a job in McDonald…), and you can’t reach them anymore, and guess what… a modification is needed. A new piece of information should be passed to the system, so the .csv file has some extra information now, and one additional step should be done when processing the file. And we need someone to do this modification… guess who?? Steve? No. Fred? No.

Got it? No? ok lets continue… after two years both Fred & Steve changed companies (John was shoot by Steve, I told him to find a job in McDonald…), and you can’t reach them anymore, and guess what… a modification is needed. A new piece of information should be passed to the system, so the .csv file has some extra information now, and one additional step should be done when processing the file. And we need someone to do this modification… guess who?? Steve? No. Fred? No.

I am the one who will do the modification.

In the first case I should waste my time navigating Fred’s framework, moving from one class to another, going up and down in the inheritance tree (Geeez Fred how many classes did you put there). Guys I just need to read a fucking .csv file and process it.

Finally I get to the point where I can add the new parameter, now what? Oooh yes I have to add the new processing step, yes its easy I just have to validate the new parameter, but please give me one day to learn how the hell can I do it using Fred’s XML workflow language, that its not even working well.

Lets go back, what is the modification? add a parameter and process it. Why for something so easy I should spend so much time? because someone (Fred) who read design patterns thought its cool to do it in that way. Wrong Fred wrong, don’t complicate your life (and mine please) if its not necessary, your boss didn’t ask you to design a general DataReader module that will read everything, even what is written on your dirty pants, he just asked you to extract and process 4 parameters from a .csv file for God sake!! (just give me Fred’s new address).

The bottom line is simple, if you have to read a file just read it as Steve did, but if you need to develop a general data reader module then go Fred’s way, be intelligent, use your head, small things should remain small and simple, its not logical to create a 50 class framework to read a file that can be read in 10 lines of code.

For me, the best solution was Steve solution, easy, simple, and fast. Have a nice day and remember what Alan Kay said:

Simple things should be simple, complex things should be possible

Worst 5 Code Snippets Till Now

September 7, 2009 § 1 Comment

Last week I changed my Job, and started working in Rockwell Automation, after spending the last two years working in web development using Java. In this post I would like to share the worst moments in those years. Do you know all the theory we learnt in universities about Object Oriented, code reuse, encapsulation, cohesion, robust systems that don’t break because of a small change? I didn’t see anything of that, projects where started by unexperienced programmers who just heard that Java is Object Oriented without knowing what the hell does that mean.

Working on those spaghetti projects was very frustrating, but in the same time very challenging, it was amazing how some people managed to write indigestible code that makes you through up. This is my top 5 worst codes till now:

1. Do You Call This Validation?
Try to guess what this programmer is trying to do using this piece of code? exactly he is trying to validate the number of days in a month as a part of a bigger date validation method, if the month is 4,6,9,11 it should be 30 days, while if its 1,3,5,7,8,10,12 it should have 31 days, with a special consideration of month 2 and leap years.

Yes maybe the code is working, but can you read it easily? are you sure its bug free? in your opinion how many people out there needed to validate a date string? maybe something around 1000000 programmers right? Good, So don’t you think that there should be some magical method that will do this for you? What about trying to parse it with a DateFormat instance and catch an exception if something goes wrong?

Whenever you are up to start coding something just stop and do this conversation with your self:

yourself: Hi you.
you: Hi yourself.
yourself: do you think this operation is very common?
you: Yes, I Think Date validation is done by many people…
yourself: do you know something that will do it for you?
you: No.
yourself: ok, so ask master Google about “Java Date Validation”.
you: oooh here is a ready solution, thanks yourself.
yourself: you are welcome you, see you the next time, bye.
you: bye yourself.

2. Is This a Constructor?
Here a programmer wrote this constructor (I took the image using my iPhone), some of you may think yes its a big constructor but he used eclipse automatic code generation tools, NOO, in this constructor there was a tiny bug that I discovered, which made me conclude that this constructor was written by hand. (by the way this is only the top part of the constructor, its not complete).

For the programmer who wrote this constructor I have two questions, one, why the hell did you write this constructor by hand? two, do you think there is someone much crazier than you that will call a constructor with all that parameters? ok maybe there will be a 0.001% chance that this constructor is needed in that class. But writing it by hand? if I was a manager I would fire him, I don’t need programmers that waste 30 minutes for something that could be done in 1 second (and yet do it wrong).

3. The Power of Encryption
This one is really great, its clear that someone is trying disparately to encode a string. The problem is that this is not encoding, this is starting to become encryption somehow WTF!!. what about performance? how many times is the String parsed and parsed again? never heard about a StringBuilder or StringBuffer? couldn’t you read a bit about encoding before starting your own encoding solutions? guys all this makes our life difficult 😦

4. Ever Heard About Data Integrity?
During my work I was located for 3 months on a project which was using a postgres database and till now everything was wonderful, the problem was that the people who created the database schema never heard about Data Integrity, Primary Keys, Foreign keys …etc, working with that DB was like putting your data in a trash (it just accepts anything you put in it!!), come on man at least put primary keys for God sake!!

The nice excuse of not forcing data integrity was … “we don’t need it, all DB access is done through Hibernate”, oooh really? so you are saying that Hibernate doesn’t need constraints? and you are so sure that there will be no other application in the future that will access the database directly? How the hell could you be so sure that you don’t have corrupted data if you don’t have constraints?

After working on that project I soon realized that there was a lot of trash in the DB, orphan tuples, missing data …etc. Take this advice, if you see someone using a database without forcing data integrity, and you have the power, just fire him and send him home, there are so many dump ass programmers in this field that we have to get rid of.

5. Best Comments Ever
Everybody should place comments in their code, its good to comment your code. YES!! but if your comments are not useful just don’t write them down and waste my time, how many times did you see something like this:

//print the value of x if its bigger than 10
if( x > 10 ) {

Is this comment useful? I can already see that if x is greater than 10 it will be printed, I am a programmer who reads Java code faster than your comments, writing a comment like this one is an insult for programmers (Yes we know what is an IF statement), I don’t want to see those stupid comments in the code, its even a maintenance nightmare, later when the specification changes, and x should be printed when its greater than 9 instead of 10, I will have to change the code and the stupid comment too. What about this one:

//the constructor
public Person( ) {
//some code

Ok now lets talk seriously, we are Java developers, we are working on a serious project, do you think that someone needs your help, to tell him that, that was a constructor? if your answer is yes, fire him and you will save time and money. If you find comments like this do two things:

1. Delete them.
2. Try to locate the person who wrote them and shoot him.

These where the worst codes I ever seen, have you seen codes worst than those? please post them and lets all have fun 🙂

The Road To Java Certification 2

August 28, 2009 § Leave a comment

After getting 90% in the SCJP certificate, I was more hungry for Java certifications, so I decided to take both the SCWCD and SCBCD exams, yes I prepared for both exams in parallel. Why? because my company offered to pay for the SCWCD, and I wanted to get certified as fast as possible and it seemed a bit strange to ask for the SCBCD in the same time, so I decided to buy it by my own, and ask for a refund later (which I didn’t have because I changed company after one week of my certification).

Since I work in the web development field, preparing for the SCWCD was not from zero, I already worked intensively with Servlets, JSPs, JSTL, and other stuff. For the SCBCD I already had a good experience with Hibernate and ORM technologies which helped a bit, but almost zero experience in EJB3 session beans, so preparing for the SCBCD required more time and attention.

Again the first thing to do before starting your study is to know what is the exam about by reading the exam objectives, for both the SCWCD and SCBCD. Pay attention to the business component objectives because there is no complete book that will cover the whole exam material, so you will need to know what stuff to learn, from different sources.

Books to Read
The best book for the SCWCD exam is Head First Servlets & JSP known as HFSJ by Brayan Bashman, Kathy Sierra and Bert Bates. This book is really amazing, it introduces the material in a unique and entertaining way that will make you very enthusiast to read and learn more and more (In this book, Servlets talk with Application Servers, very funny and interesting conversations). There is a mock exam at the end of the book DON’T DO IT before reading the book once or twice, this mock exam is very close to the real one.

For the SCBCD the situation is different, When I did it there was no book dedicated for the exam, so I had to check more carefully the exam objectives and select appropriate chapters from different books, the books I studied for the exam are:

1. Enterprise JavaBeans 3.0.
2. Manning: EJB3 in Action.
3. Pro EJB3.

The first two books would be enough (I just skimmed the Pro EJB3), in addition to these books its highly recommended to read the Mikalai Zaikin study notes, read them after you finished reading at least one book.

Mockup questions
For the SCWCD the mock questions at the end of the HFSJ book are enough, but to get more confidence here are some links:

1. JavaRanch Mock Exam
2. JDiscuss
3. Marcus Green Exam

for the SCBCD exam, I bought the EnthuWare exam simulator, I bought it because there was no complete book that covered the whole material (like the HFSJ for the SCWCD), so I wanted to be more confident. This simulator have something around 400 questions, do them all and you will pass the exam without problems.

Finally as the Java Programmer certification, if you have any question or any doubt just post it on the JavaRanch, there are dedicated forums for each exam.

What You Learned?
After getting certified what changed? the nice thing is that now I better know how to use the technology. But something more important is that now I know how it works from the inside, I know how the Application Server works with those J2EE components. In addition I got stronger web development architecting skills, I can build better and robust architectures for web applications, in addition to portable and distributable applications.

And finally as I mentioned they are other two lines in your CV that will help making you pass recruiters quality filter.

Whats Next?
I didn’t decided yet, but I was thinking of one or two Oracle certifications, but not right now. For now I just want to relax and have fun, no more certifications for 6 months 🙂

Next: Worst 5 Code Snippets Till Now

The Snow Leopard is Coming…

August 24, 2009 § Leave a comment

In the latest Apple WWDC 2009 they mentioned that Snow Leopard will be shipping in September, but here it is shipping in the 28th of August as mentioned on the Apple official web site. did they plan for this from the beginning? Is it a marketing plan? is shipping snow leopard before Windows 7 another marketing plan?

I don’t know, but believe me there is nothing greater than shipping a product before its actual date, which is something very difficult in our field (Software Developers), and apple did a great job.