Archive for June, 2009

The Tale of Two Carpenters

Why is it a good thing to have personal frameworks and libraries, why don’t I just build a monolithic system, that does one thing and does it good. Let me tell you a story of two capenters.

Adrian the first capenter likes build things. He can build anything giving the proper amount of time and motivation.

Sean also loves building things, but he hates doing the same thing twice.

One day a company approached both Adrian and Sean to build a special kind of chair for them. They did this so that they could pick the best from both. Adrian was the first to turn in his prototype. He has it all well planned and thought out. They liked it and told him they will get back to him before long. They have to wait another two days before Sean could turn in his own prototype. They also liked it, It looked so much like that of Adrian, they have both followed the specifications well. When the time for choice came, they chose Adrian over Sean because he took less time in building his prototype.

Problems started when the have a new staff member who wouldn’t fit into the chair because he was….rather big. They need to modify the SEAT. They called in Adrian and he said no problem, he went ahead to modify the CHAIR, adding a new kind of seat. It took him as long as it took him to build the chair to modify the seat.

Over time, these modifications were becoming more and more frequent and Adrian has to build a new kind of chair almost every other week just because of a slight modification. It came to a time that the company weren’t happy and began complaining. They went on the lookout for Sean, just maybe he could help them.

They found Sean and told him their problems. He laughed and said that it wasn’t a problem at all, and then he told them why his prototype took a bit longer to produce.

Sean, unlike Adrian didn’t build a CHAIR. He built the components that make up the chair. He built the front legs, back legs, arm rests, back rests, seat etc. It took him as long as it took Adrian to complete the chair. After building the chair, he started assembling them and that was why it took him longer. But now the company suddenly saw the solution to their problem. Adrian built a chair and so each modification no matter how small will alter the chair. Sean built components therefore he will need to modify only the component parts that are affected.

I told this story to say that as a developer, I strongly believe that you try as much as possible to have a personal library. It will help you a lot in the long run. Those days when I was still naive, when I hear “library”, I don’t see it as a thing that I must build. My software are large and monolithic. A little change to one part of the software will make me pull down the whole bunch. Now I know better. Whenever I see a feature that I have used twice, either in the same project or different projects, It is going into a library. I am happier now than then.

Also when you have a large project, please and please MODULARIZE. You don’t want to know what trouble you will save yourself or the person maintaining that project in the future.

Leave a Comment

Java(TM) ME Platform 3.0 – Netbeans Platform based

There are so many cool things about the new j2me platform, but the coolest of them is that it is Netbeans Platform based. I am kinda used to the Netbeans Interface that when I saw it, I almost jumped from my seat with ecstasy(hummn that word!).

Anyway that is not all. The truth is that I am not very happy with the way netbeans generates codes for me when I am using it for j2me, I never did complain about this, but it seems the designers of this platform were reading my mind. The platform is really very stripped down.

Also, the emulators are far better than in 2.5.2(so we expected) but not on this scale. They were far far better than far far better could describe.

It also has support for javafx mobile(is that good news? you bet it is). It also has support for BD-J, LWUIT, and a whole lot more.

Setting up new emulators is also very easy, the whole netbeans platform base is a very very wise design decision.

I can also test directly on my pocket pc. This feature is also very cool.

The coolest feature however I think is the way it handles RecordStores. Most times when I am developing, and I need to store records. I find myself gooing to delete the created records after every run. This is not so with the 3.0 platform. when you run your app normally, and you shut down the emulator, it wipes all residual data left behind. To make data permanent, you will have to run via OTA(which makes a whole lot of sense).

You can call me a Netbeans fanatic, but I think most of these cool features are as a result of the decision to use the Netbeans Platform. Good things have a way of having “goodly spiral effects”.

Leave a Comment

Strict Rules

Dear All,

When in the office, please concentrate only on official assignments.

I repeat, I will be very upset with any member of staff who during office hours/uses company equipment/company resources for personal projects /assignments.

The time you spend in the office should be entirely for company tasks. I repeat, this is totally unacceptable to me and I will be extremely angry if I find this being contravened.

I see this as a sign of disrespect and dishonesty to prosper oneself against the collective good.

The company will do all it can to keep its side of the bargain in its responsibilities to you and the company expects that you will do same.

Thank you

Leave a Comment

Not necessarily necessary

When I started learning java, I was coming from a world of pascal, delphi and vb, so I believed there are a lot of things in java that are not necessary. As my experience with the language grows, I started seeing things in a different light. I will name some of the things I thought were not neccesary then, and then I will try and explain why I now think they are.

getters and setters. Why use getters and setters. I could make all my members public and just read them like that instead of using getters and setters. And for as long as I can remember this is how I do my things. Then one day, as part of a bigger API, I needed to write a user class. The illumination started when I found out that the requirements are these: The user of the API will supply the password in string and we will store the hash value. Also when he requests the password, we should reset the one in the db, generate a new one, store the hash and return the string to him.

As usual I wrote a helper class that does that. The problem is when you want to create a new user, you give the String password and call a save method. Then in the save method I convert the string to md5 and store it (and that works fine), but when you say user.getPassword(), it should return a new password hash and all that. I was momentarily trapped. That was when I remembered getters and setters. The final user class looks like this

public class User {

String password;

String username;

public User(String username, String password) {

this.setUsername(username);

this.setPassword(password);

}

.

.

public void setPassword(String password) {

this.password = md5hash(password);

}

public String getPassword() {

return newPasswordMd5Hashed();

}

}

Getters and Setters were introduced so as to overcome this kind of problem I believe. When you want to do something special at the point of accessing a variable. It is like overloading the = operator in c++.

Access Modifiers: Some days ago, I posted a joke on my facebook page. This is it.

A php programmer walked up to a java programmer and said “java is full of crap. The chief of these being what u guys call access modifiers…public, private, protected..etc. why have all that crap”. The java programmer looked up and said “lets assume for a second that I am God, and I make your wife public” End of Discussion.

The joke however is on java programmers. Thats talk for another day. I used to be like that php guy. Why all these access modifiers. All my members and methods are public, so I really dont need them(This is where I prefer scala, the default is public, unlike java where the default is private). But my User class above also taught me the need for access modifiers. The user class is actually a base class for some other classes, We have the ManagedUser, TimedUser etc. If I make the password field public, then the programmer that is using the API can as well just use the = to assign value to it. This will have very un-desirable effects. If I make it private the programmer wont, but neither will ManagedUser and TiimedUser. I need them to also be able to modify this field because we store the passwords differently for a managedUser and timedUser. I need to make the field protected.

When developing API’s that will be used by other people, access modifiers are your friend my friend.

Wrapper classes: why have int and Integer, boolean and Boolean, double and Double. Who needs wrapper classes anyway. But that is a lie, sometimes you will need them. One day you will need to write a method that takes an object as an arguement or that returns an object. primitives like int,boolean,double are not objects. You will need to have wrapper classes. What I wanted to do when this dawned on me was simple. Pass an Object to a method. This Object could either be an Object or a primitive. What do I do? Simple, use wrapper classes.

public void done(Object i) {

if(i instanceof Integer) {

.

.

.

} else if(i instance of Double) {

.

.

.

} else {

.

.

.

}

}

Abstract Classes: Now this one I didn’t get until very later in my java journey. Abstract classes, Interfaces etc. But let me explain it to you in simple terms. You will need these features if you want classes to fufil a particular contract. For example, I was writing a class Store as part of a J2ME Database Management API. Now any POJO that must be persisted must have two methods toByteArray() and fromByteArray(). If I were doing J2Se, I could have used reflections, I didnt have this luck with J2ME CLDC. So I rememebered Abstract classes and interfaces. So I make sure every persistable class must extend and abstract class I called StoreBase. The class itself contains methods toByArray() and fromByteArray() without any body definition. Any class that extends StoreBase can be persisted, but it must have definition for those methods, else your code wont even compile. EOD.

EDIT: The default access modifier for java is packaged and not private as erroneously stated above.  Thanks to Jose Ayerdis

public class User {
String password;
String username;
public User(String username, String password) {
this.setUsername(username);
this.setPassword(password);
}
.
.
.
.
public void setPassword(String password) {
this.password = md5hash(password);
}
public String getPassword() {
return newPasswordMd5Hashed();
}
}

Comments (4)

Programmers or Comedians?

I read this somewhere

There’s something weird about software development, some mystical quality, that makes all kinds of people think they know how to do it. I’ve worked at dotcom-type companies full of liberal arts majors with no software experience or training who nevertheless were convinced that they knew how to manage software teams and design user interfaces.

This is weird, because nobody thinks they know how to remove a burst appendix, or rebuild a car engine, unless they actually know how to do it, but for some reason there are all these people floating around who think they know everything there is to know about software development.

Its pathetic because you see a lot of them tout certifications as if it’s ever a yard stick to measure how good they are? I wonder if I will be glad to allow a Doctor perform a brain surgery on me just because he knows how to treat malaria, or because he just graduated from medical school. They boast and brag about things they know nothing about. My boss will say they are name droppers. Myself and my friends have a name for them, we call ’em comedians. What else they could be? I interviewed one of them for a programming post in my company. Since he said he does Java Programming as a hobby and that he even has a mobile game he wrote in java that talks to a JSF back-end. The back-end itself relies heavily on hibernate as persistence layer(now isn’t that wonderful?). He has about three certifications..if not four. (CCNP, MCST and SCSA), I asked what IDE he is conversant with(expecting to hear Netbeans so that I could add a +1 to nigerians that use netbeans poll I am secretly compiling), his reply was “Websphere, JBoss, etc”..now isn’t that what a comedian will say?

Comments (7)