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.

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 Perfect Software Development Team

August 17, 2009 § Leave a comment

An important question that needs an answer. What is the perfect software development team? what is the perfect number of developers in a team? what kind of developers should they be? how should it be organized? of course this depends largely on the project size, in this post I target the perfect team for small or middle sized projects, so please don’t email me telling me that you can’t develop Windows XP with only 10 developers.

But why do we need a team? If I work alone I will prevent all the overhead of communication between my team members, I will not waste my time explaining things to others, and I will have control on the whole project. My answer is, if you can do everything alone then go ahead, you don’t need a team and you will save time and money. Unfortunately in the real world there are deadlines to respect, you need many and different skills that are impossible to find in only one developer, and finally most projects are too large to be developed and tested before their deadlines by a single developer.

Ok, so you decided that your project needs a team… Lets get started. The first ingredient for the perfect team is its structure, there are two common team structures as Mike Gunderloy suggests in his book Coder to Developercommunity of equals or hierarchal. In a hierarchal structure there will be a Manager that will guide the team, an experienced developer that controls a bunch of non-talented developers telling them what to do and how to do it, this structure is widely used because managers think (and I say managers not I) its more profitable, since they will extra-pay only the one talented developer, while the other developers will get low salaries. In my opinion this is the most stupid, unproductive, unpredictable, non robust, risky, and non profitable structure for the following reasons:

1. Although by this structure you have more man force in your team, but this doesn’t mean you will be more productive, yes we are building something but building programs is not like building houses. From the book The Mythical Man Month Frederick P. Brooks Says:

“In one of their studies, Sackman, Erikson, and Grant were measuring performances of a group of experienced developers. Within just this group the ratios between best and worst performances averaged about 10:1 on productivity measurements and an amazing 5:1 on program speed and space measurements! In short the $20,000/year programmer may well be 10 times as productive as the $10,000/year one”.

Note that this is due the lack of talent and the overhead needed for communicating and organizing the large number of programers, which is much smaller if your team consists of sharp developers. remember that its better to build the system with as few minds as possible.

2. Software quality. Unfortunately management quality measures are applied by looking at the software from the outside (the running application), but what about the quality of your code? what if you need to add a new feature? will it be easy? will it introduce new bugs?  if you modify one module will this change cascade to the other modules? This depends on how talented your developers are, great developers will write modular code, respecting Object Oriented principles, while non-talented developers will write Spaghetti Code, full of bugs, and difficult to maintain.

3. High Risk. The hierarchal structure is used to save money (as managers think), which leads to hiring low salary non talented developers, this introduces a high probability that they will dismiss as soon as they find a better job with a higher salary, which if happens, and it will happen. You will have to hire a new developer, re-explain everything to him and start all over again, and since the project code sucks is crappy; integration time will increase. What if it happens 10 days before your deadline?

These are the major reasons why I don’t advise the use of hierarchal structure, which sadly its the most adopted structure. The better choice (in my opinion & experience) is the community of equals which I prefer calling it a community of talents. In this structure you have a few number of talented, experienced great developers doing the job of 30-100 normal ones. In this structure its advisable to have different skills, for example a talented back-end developer, a talented front-end developer, a talented tester and so on. By this you can split your project to layers, with each developer working on his own layer. the benefits of this approach can be summarized as follows:

1. Talented developers will write better, robust, almost bug free code. Code will become Lasagna Code instead of  Spaghetti Code (Lasagna is structured in layers, Spaghetti is a mess, got it?).
2. Orthogonal code, where modifications in one layer will not effect other layers, your modules will be loosely coupled.
3. Versioning conflicts will decrease since there will be no two developers working on the same file, and this will save a lot of time.
4. Communication & organization time will decrease, meetings with the whole team participation will be possible.
5. Finally since its a community of equals work will be even more fun.

This was about the team structure, but what about the number? this depends on your deadlines, my suggestion is to identify the major layers of your project, for example a typical java web application project can have the following layers:

1. Persistence & Business layer, developed in EJB3
2. Presentation Layer, for example in HTML or Flex 3.
3. Control Layer, coordinating the communication between the presentation and business layers.
4. Reporting module, which generates .pdf reports, for example using Jasper Reports.

Then depending on the deadlines hire an adequate number of talented developers for each layer, having in my mind that performance will not be multiplied by the number of developers since as more developers you add for each layer, the more communication time you will need.

Yes! you are right, where the hell is testing? Testing is something that every developer will do alone. Every developer will be writing his own unit tests for the modules he develops, however integration testing and stress testing testers can be added to the perfect team. Finally a team manager with programming experience is needed to interface between his team and customers.

This is my opinion about how I would structure and choose my perfect team, In this post I avoided as much as possible the term experienced developer and I used talented developer because having a 10 years experience doesn’t mean that you are a great developer, great developers are rear and difficult to find, they are those who understood what a C pointer is the first their professor explained it, they are those that can solve whatever problem you assign them, they are those who can switch from C++ to Java in 3 days, and this can be achieved by talent not experience, even though experience is helpful, in the end you need developers who are ready to learn new stuff if needed not people who will solve every single problem using a PL/SQL procedure because they passed the last 10 years doing only that.

NextDo People Talk About You?

Efficient Software Development (2/2)

August 12, 2009 § Leave a comment

In my previous post I discussed how we could write code more efficiently, and focused on the importance of keyboard shortcuts, in this second part I will give additional tips to optimize the remaining steps I mentioned. Again the steps were:

1. Write Some Code.
2. Compile and deploy the source code to the application server.
3. Start the application server.
4. Open the browser and test the new modifications.
5. Its not working, I say bad words to my screen.
6. Stop the application server … and go back to step (1).

What’s next? what about automatic code generation? there are many pieces of code that can be generated automatically by the IDE, this saves a lot of time, and prevents the introduction of bugs (we are humans and we do mistakes). Every Java programmer knows what are Java beans, they are Java classes which adhere to certain coding conventions, one of these conventions is to provide a getter and a setter method for accessing it’s properties, Eclipse allows you to generate those methods automatically, another example is the implementation of equals() and hashCode() methods inherited from theObject class. why should we write them by hand when Eclipse can do it?

One final tip is the use of column editing, many programmers don’t know what is column editing, however now that it has been included in the final version of eclipse (Galileo) there is no more an excuse for not learning it, check this video.

Compile and deploy

For Java programmers it happens that you compile your code, create a .war or .ear archive containing your classes, place it in a deployment directory under your application server. This is a simple workflow that consists of compiling, generating a file, copying the file to a specific directory, can’t we automate it? of course, we can use an ANT script, if you don’t know ANT its time to for learning.

Sometimes you deploy the whole application just to check a small modification, my suggestion is to make as much modifications as possible before deploying, if you have a good project architecture that includes unit tests, things could become more efficient if you use out-of-container testing (I use it for testing EJB3 applications); you will write code and then lunch a bunch of unit tests to test your code without the need to deploy the application.

Start/Stop the application server

Many application servers can update deployed web apps with no need to restart them, (Hot deployment for JBoss user), however even in these application servers you encounter situations where you are forced for a restart, so its advisable to choose a light weight application server for development if possible, for example if you have a .war application and no EJB’s under JBoss in a production environment, you could use Tomcat instead of JBoss in your development environment, why? because to start JBoss you will need an average of 50 seconds, however if you use tomcat it’s something around 15 seconds, 30% faster. Repeat with me Time is money, Time is money, Time is money.

Open the browser and test the new modifications

So you deployed the new application, and you are ready to test if everything is working fine, which means you will do the following steps:

1. Switch to the browser window (please tell me it’s Safari).
2. Type the web application URL http://localhost:8080/MyKillerApp
3. Do some clicks to reach the intended page.
4. Start testing the modifications you did, and check your logs.

Even in these operations you are losing a lot of time caused by application switching (the browser and the IDE). The best solution is dual monitor mode, a programmer SHOULD have two monitors not one, they are so cheap those days that you can find a 19 inch screen with less than $120, by using two monitors you can open the browser on monitor A, and the IDE on monitor B, this will save window switching time, switching headaches, and save the keyboard buttons (alt + tab or cmd + tab). Remember that in a normal situation you will be switching between windows even for checking the generated logs (WHAT? you don’t use logging? are you crazy!? please read this). Finally I would advise to bookmark your main application URLs to prevent writing them every time.

Those where my tips for being more efficient, note that following Object Oriented paradigms such as, DRY (Don’t Repeat Yourself), Encapsulation, Polymorphism, and common design patterns will all lead to better code that needs less time to maintain and debug.

Next: The Power of Apple Multi-touch Trackpad

Efficient Software Development (1/2)

August 12, 2009 § Leave a comment

How much code do you write per day? do you introduce bugs when you are modifying a piece of code?  do you finish your tasks before their deadline? do you use a good IDE? are you EFFICIENT in doing your Job? a programmer is like a carpenter they both have talent, the programmer builds programs, while the carpenter builds wooden objects and structures, they both use a set of tools that help them do their job. If you choose a good set of tools and know how to use them proficiently, its more likely you will be doing a better job. In this post and the next one I will target this issue and try to provide several tips to become more productive.

To be more efficient in your work you have to do only one simple thing, SAVE TIME, which leads to extra hours to do other stuff (comment your code, write documentation, chat with your friend, or even to sleep). To save time the trick is simple, just detect things you keep repeating over time and try to optimize or automate them, its like optimizing a piece of code, just save 0.01 seconds (which is not an easy task) in an operation inside a loop of 1000 iterations, and you just saved 10 seconds. If you manage to optimize an operation from 60 seconds to 30 and you do this operation 100 times a day, Ta Daaa you just saved 3000 seconds or 50 minutes a day, 25 hours a month, 300 hours a year … Ok you got my point, right?

As a web application developer what are the things you keep repeating all the day (except saying bad words, and hitting the computer screen)? Well since I have been working in web application development for almost 2 years, my working cycle was something like this:

1. Write Some Code.
2. Compile and deploy the source code to the application server.
3. Start the application server.
4. Open the browser and test the new modifications.
5. Its not working, I say bad words to my screen.
6. Stop the application server … and go back to step (1).

This is a look from 1000 feet at what I did everyday, for sure there are some middle operations, for example between steps (2) and (3) there could be the step of writing a unit test for the new code. but to keep things simple I will stick to this primitive programming cycle. Lets dig into each step and try to optimize it as much as possible.

Writing Code
This is what we do, and what we are payed for, it consumes around 80% of our working time, which makes it a good candidate for optimization. we use IDE’s to write programs, however its amazing how many programmers use or know only 10% of what their IDE offers them, here is a little assignment, bring a piece of paper and write down all the keyboard shortcuts you use in your IDE while you are programming:

ctrl + z
ctrl + c
ctrl + v

… and then !!? ctrl + x … yesss? you use only these ones? and you call yourself a programmer? are you telling me that you navigate those strange menus File .. Edit ..? Amazing!!

Since I have been developing in Java for a long time I will be talking about my favorite IDE Eclipse, for sure other IDE’s will be almost the same, and provide almost identical functionality. I will provide some examples that could increase your efficiency, note that there are many shortcuts to do things in eclipse and its impossible to cover all of them, in a blog post, I will write about the ones I use in another post.

the idea is simple, avoid using the mouse as much as possible, moving your hands from the keyboard to hold the mouse wastes a lot of time (you have to glue your hands with your keyboard), I suggest finding a shortcut combination to do whatever thing you are trying to do using the mouse.

suppose you have a variable named sum1 and you decided to change its name to something more meaningful such asprofit you can either change it by hand all over the source code, and may be by mistake introduce new bugs if you didn’t pay attention to the correct scopes, this operation will take around 1 minute of your life (yes its a big source code, andsum1 is used everywhere), or you could place the cursor on the variable sum1 press ctrl + 1 and choose rename in fileand eclipse will do the rest, and you will be pretty sure that no new bugs where introduced. What did you say? …right, you could use a simple find and replace operation, do you think it will work? will it cause some mysterious bugs? think about it.

another simple but common example, suppose you have a code like this one:

doSomeStuff();“some logging information”);

and for some reason you decided that you have to log the information before calling the doSomeStuff() routine, in other words the source code should become like this:“some logging information”);

Piece of cake you:

1. select the line doSomeStuff() either by mouse or using the keyboard.
2. cut this line either by mouse, or using the command ctrl + x.
3. place the cursor below the line containing
4. paste either using the mouse, or using the command ctrl + v.

Yes you finally did it you slow turtle, however if you knew some shortcuts you could have easily placed the cursor on thedoSomeStuff() line (without highlighting anything) and pressed alt + arrow down and thats it. Right now you may be saying what the hell is he talking about!, to answer you, let us make some calculations on how many buttons you just pressed:

1. select the line doSomeStuff(). [move cursor to beginning of the line][shiftend]
2. cut this line. [ctrlx]
3. place the cursor below the line containing [arrow down]
4. paste the line. [ctrl + v]

Total number of buttons pressed is 7 however using the second method the total number of buttons pressed is 2 which makes us 28.5% faster, this could be a difference of half a second only, but as I said repeating the same thing all the day will really make a difference.

These are just two simple examples, there are hundreds of other situations that can be optimized, especially when you are doing re-factoring, such as extracting a code block to a new method, move a method from a child class to its super class, formatting source code, finding the closing curly bracket ( } ) of a big while loop, commenting and uncommenting a block of code, automatic code generation, and many others. My suggestion is to take a look at the preferences of your favorite IDE and try to memorize as much keyboard shortcuts as possible since they will increase your coding efficiency, and decrease the number of bugs you could introduce by mistake when writing things by hand. You don’t have to memorize everything at once, make it something incremental, every time you are up to do some operation think if you could find a shortcut to do it and learn it, after one or two months you will notice a big difference, when I started learning shortcuts I printed them on a piece of paper and attached it on the wall in front of me, so that I could find whatever shortcut I needed very quickly.

One last thing, these are things that can increase your speed, however before writing code programers have to think how they will solve a given problem, and this depends on your own way of thinking, and experience, and I am sorry but I can’t help on this one, just like a carpenter, he can have the best tools in the world, but if the talent is missing no matter how good your tools are you will not be that efficient, and this is what really distinguish pragmatic programmers from normal ones.

I suggest reading this book The Pragmatic Programmer by Andrew Hunt & David Thomas

Where Am I?

You are currently browsing the Software engineering category at Omar Al Kababji.