Archive for August, 2009

Myths, Myths, Myths!

J2EE Myths.

I have met a number of java developers who don’t do J2EE. So many of them have so many reasons why they don’t do it. This post is a view at some of these reasons. I call them myths because most of them are actually not true, or not entirely a correct view.

1.J2EE is hard: This is one of the most popular of these myths. The question is J2EE is hard; compared to what? We quickly forget that programming is anything but easy. I started writing Java in 2002/2003. Then I have a number of friends, most of us were VB experts(or addicts depending on who is doing the evaluation). When I deflected and I started learning Java, most of my friends have this same view of J2EE today to Java then. Java is HARD. But today, these guys are .NET/C# Experts, Some have even successfully picked up Functional Languages like erlang. So the thing is, nothing is hard, or difficult. It is our capabilities to handle them that are shallow. The first time I picked up scala, I wrote this post  Scala after one week. Today I know better. So J2EE is not hard. It’s the programmer’s capability to handle it that is not top notch. There are several J2EE projects flying around, the guys that built them are neither aliens, nor programmers on steroids.
2.J2EE is not necessary: This is another myth popular among most especially non-java programmers. Never say something is not necessary until you try it out. J2EE was built to solve a particular problem(I will get to that soon), so unless you say that problem no longer exists, then I can agree with you that J2EE is not necessary.
3.J2EE is too verbose: And so is java. The verbosity of java is not news anymore. I laugh when I see guys compare writing the famous “Hello World” in java to some other languages. The truth is J2EE was not designed to write programs like “Hello World”. It was designed for building multi-tier applications. If what you want to write is “Hello World”, nobody forces you to use J2EE. Some other languages are more suited for that. But to build scalable n-tier applications, then you need J2EE.
4.J2EE is an overkill: Compared to what? Again this is the question I normally ask. Some will say compared to php. It’s pathetic because comparing J2EE to PHP is the best example of Apples and Oranges. I once had a project in PHP (I am almost through converting it to J2EE). After a while, I have to discontinue the project in order to keep my sanity. You can call me a bad PHP programmer, but the truth is in design, PHP was designed so that you can easily write un-maintainable code. It requires extra effort on the part of the developer to write maintainable code. J2EE on the other hand was designed so that it is difficult for you as a programmer to write un-maintainable code. It requires extra effort on the part of the developers to write un-maintainable code. This extra is not an overkill. I write PHP from time to time when all I need is to put together some piece code. But I am sure a very very low percentage of php programmers can be able to build something on the scale of facebook and yahoo using php without running into maintenance issues.
5.J2EE is slow: Your J2EE servers were designed to run on multicore, high end CPUs and not your low end systems. Trying to run Glassfish, for example on a P3 512Mb RAM is suicide. Because what the servers handle are not trivial, so the hardware requirements for them can also not be trivial. For the fact that they can run on low end systems did not mean they should be run on low end systems. If M$ had allowed Vista to run on a P3 512Mb RAM System, imagine what a world this would be!

There are several other reasons people give for not venturing into J2EE, the only valid reason I have gotten over time is I DONT NEED IT NOW. That was the same reason I gave several times over until the need arises. For everyday web-applications, I believe php will just get you by, but you will need J2EE if you are particular about scalability, security, inter-operability, maintainability, and all the other goodies that J2EE have to offer.

Comments (7)

Die early, Die Fast, Die Loudly

During my years of programming, I have met so many programmers with different ways of doing things, for example some believe in documentation, some don’t. This is however one of the many little things that programmers do differently. Some of these little things degenerate into big flame wars.

One of these concepts is what I call the DIE concept. Some programmers believe your program should run as long as possible, other believe the program should die as soon as possible before corrupting other data. I am going to explain the DIE paradigm, because….well I want to write something.

 

Die Early: We believe your programs should die as early as something bad happens. This concept flows down to compiled languages. If a dot, a jot of your incantation is wrong, the code won’t even compile! This I believe is the way things should work. Never allow your exceptions to be swallowed up. PHP is the only culprit that came to mind here. I believe errors and warnings are/should be a core part of programming. When a language turns off errors and warning by default, then I have a problem. There are several/countless hours wasted by programmers debugging php code that wont have been spent if the language just spit out some errors. I give kudos to java in this case. When something goes wrong, just blow up, or at least log a COMPLETE STACK TRACE of what happened and also TELL SOMEONE THAT SOMETHING BAD HAPPENED.

 

Die Fast: If you are going to die, please just do so. It makes no sense trying to do house cleaning while you are dying, you won’t need it anyway. The longer it takes an application to die, the more prone the whole system is to a complete disaster. When a part of the system experiences big enough turbulence to make it die, let it just die, or make it stop recieving input from other parts of the system, and it should never send out any message except for the next rule.

 

Die Loudly: When a module/application is dying, let it do so as loudly as possible. Print all the stack trace, or log it. If there are other modules sending message to it or reading message from it, let them know that the module is dead and can no longer recieve data. So many times, it is bad to let these guys find out for themselves that there server or client is dead. Let is be as loud as it can be. In a scenario where you have monitors and/or supervisors, they should make sure that all applications that require this dead module are paused at least. The best is to KILL THEM TOO.

 

This is how I have learnt to program, and sincerely, it’s always worked for me. I could have named this post “I love Exceptions”. They are a part of the application development process as well as a way to know what is happening to your application even at runtime.


Comments (3)

That is not my name, please!

I have cause to meet some java newbies over the past week. And one thing 90% of them have in common is that they all had exposure to some other languages. PHP and Python in the majority. Another thing is that most are confused on the java naming convention. One of them even think naming conventions add to the terseness of the language. This post is to clear some of those misconceptions.

The reason for a convention, is so that everyone will be on the same page. Naming conventions in java allows developers to work together without much problem. When you use the convention properly, merely looking at your code, I know which is a class, which is a method, which is an object or variable, which is a constant. In fact if you follow some general programming naming conventions, I can know which class declares what object, what type a variable is and so on. I will highlight these naming conventions here and how I think they should be used.

  1. Classes: All classes should start with a capital letter. If your class’ name comprise more than one word, subsequent words should also start with capital letter. Every other character should be small letters. If your class has an abbreviation (e.g SQL, URL etc), they should be ALL CAPS no matter where they appear. Examples of good class names are TextDirectionChanger, InvalidOption, Controller, URLManager, NewSQLConnector
  2. Variables and Objects: All variables and objects should start with small letter. If your variable or object has more than one word, what do you do? yes, you capitalize subsequent words just like we did for classes. So valid objects or variables will be something like counter, classIntegrator, messageObject. But good programming practice should make us want to different between objects and normal variables of inbuilt classes. So this is what I normally do, when declaring variables, I use any name, but when declaring objects, I do something like this InvalidOption invalidOption, JOptionPane jOptionPane, etc. Also I put the name of the built-in type as part of the variable name when it is appropriate, e.g int intID, String strName, Double dblPrice. This later part are my own conventions, different programmers have different ways of doing this sort of things.
  3. Methods: Your methods take the same format as your objects/variables. The only difference is that methods have parameters list. Even if your method don’t have any parameters, you MUST put an opening and close parenthesis. One example that comes to mind is this getContentPane(), although this method returns an Object, it still follows normal method naming convention and although the method take no arguments, we still put the argument list delimiter ().
  4. Constants: All Constants should be ALL UPPER CASE. examples are EXIT_ON_CLOSE, HIDE_ON_CLOSE, etc. From those examples, you will see that the rule are a little different for constants. If your constant name has more than one word, separate the words with an UNDERSCORE.

There are other conventions, like proper use of interfaces, proper naming of methods, documentations etc. These are usually left to the programmers discretion. It is however good practice to follow popular conventions.

Comments (3)

Open Letter to Facebook

I remember the first time we met. It was like you were made for me. I was in love with your friend, hi5, and the relationship was not strained. But you came along and I saw what I have been missing. You were smarter, and knows how to satisfy me more. I tried to make your friend see reasons why she should start getting smart, like you, tried to make her see that her ways were old, we are not in the 90’s anymore. At least she should change her clothes, and maybe her scent. But she was too rigid, she wouldn’t listen.

So like they say in my country, and I think in every other civilized world, “its bros before hos”. My bros(friends) pressured me and I finally left her for you, and since then, the relationship has been sweet, flowers and paradise, until recently.

You have a sister called called twitter, and although I didn’t see anything wrong with you, you always think she is more beautiful than you do. When you decided to have your first plastic surgery, you told me about it, said it’s nothing serious and I went through it with you. And truthfully, it was a success, I loved you more after than before. Maybe you thought it was cool, so you decided to have other surgeries without consulting me. And yes you did have other surgeries, you’ve definitely been there done that: face lift, tummy tuck, breast enlargement, and some other ones that are too sexually explicit to mention. Funny enough, all my friends, or at least a higher percentage thought you were doing well with these surgeries, but for me, you were beginning to look like crap. The more you want to look like your sister, twitter, the more bogus you become. The more bogus you become, the less I found you interesting. It’s true that your sister, twitter is beautiful, I have seen her and wow, she is really beautiful, but her beauty is not in her voluminosity, its rather in her simplicity.

I guess she learnt a lot from your distant cousins, google and youtube. She knew she must be simple and easy to understand, if she is to attract men like me. She knew with time, other people will come to love her simplicity, just like they love your cousins. She knew what simplicity could make her achieve, and she makes herself easily understandable. That is what you were, that is the facebook I loved. But this facebook I am seeing now, to quote a popular Nigerian musician “….is not the girl I used to know, she’s a shadow of herself.”.

The most interesting thing is, my friends who pushed me away from hi5, all seems not to see that you have changed. They all seem to love the new you, and I am like an island. The only few that ventured to even visit your sister with me, got glued and understood me better, but the higher percentage won’t even stop to catch a breadth while all they do is sing your love songs.

And just like your friend hi5, you seem not to miss me. Not immediately I left her anyway. And right now, you seem not to miss me too. I disappear sometimes for a whole week, and when I come back, nothing seems to have changed. Its still the same old you, changing your looks faster than Michael Jackson, and the same old friends singing your boring love songs. Now to me you seems like a movie playing at 1-frame per day. I could be gone for a week and still not miss anything.

Anyway, I don’t want to cheat on you, so I am writing you this letter. This song says it all.

Dear facebook
How I hate to write
Dear facebook
I must let you know tonight
That my love for you has died away
Like grass upon the lawn
And tonight I wed another, twitter.

Comments (9)

I’m in love with my Stereo. No My Netbeans

If there is one trait common to all developers that I have met, it is their love for art. Topmost is the love for music, good music. Ranging from pop to rock to r&b, most programmers love music. The question is when shall we have an IDE that integrates playing music files by default? at least mp3. I was really hoping netbeans will be the first to take this initiative, but till date no one is talking about it. If you really support me on this, lets make a lot of noise about it. Lets twitter it, blog about it, post questions about it, and maybe someone will just listen and give us native support for playing music in Netbeans. I know you can write a plugin, but I think I prefer if it comes bundled with the IDE itself. I have a few things I will love to see.

1. Support for Streaming from sites like last.fm

2. Support for downloading and playing podcasts

3. Support for playing popular(ogg) and less popular(wma) file formats. 🙂 lol, at least you get the picture.

4. Support for online radio. and more

I have just tweeted about this, you can join me by retweeting, or simply make your own tweet. Maybe in 6.8 or 6.9, our wish shall be granted.

Comments (10)

Please Service My Requests.

I had a conversation with a friend about the unscrupulous use of http request methods. There are four major ones I use and this is how I think they should be used(or how I learnt over time to use them).

POST: This should be used when sending a message to the server, especially if that message is intended to be stored on the server. Examples are creating a new user, or inserting a new record generally into any particular table in the db. Also if you are storing a file on the server, use POST.

PUT: I use this method when I am updating a record on the server. Basically for db UPDATE instructions. I also found a way to use it to post files to the server when such files already exists, for example changing a profile picture.

DELETE: I use this method when I am removing something from the server or from a db on the server. It is almost self explanatory

GET: I use this sparingly, and following w3c specs, I make sure that whenever I use GET, there is no side effect on the server or db AT ALL. I use it only for retrieval of files and records from the server.

There are four more, HEAD, OPTIONS, CONNECT and TRACE. I really don’t use these ones.

I see some codes and I feel like cursing the developer. Especially PHP Codes. They use $_REQUEST for everything, regardless of what method they use on the form. I also saw a particular project where everything was POST(This is as unacceptable as having 500 lines of code under a single button click). This I think should not be, these methods are there to put some sanity in your code, and help the maintainer, so please use them. Best Practises are the Best

Comments (3)