`
| |
|
Archive for August, 2008
Sunday, August 31st, 2008
During a pairing session with Michael Feathers, he told me why he does not like to override toString(), equals() and hashCode() methods in Java.
If you look around, different people use toString() method to return random pieces of text. The guidelines says that the toString() method should
Returns a string representation of the object. In general, the toString method returns a string that “textually represents” this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.
What does string representation of the object really mean? Does it mean all the values of all the instance variables? Does it mean just a selected values? Usually developers decide on some selected value which uniquely identifies the object. But there is no clear guideline.
Similarly when we talk about the equals() method, different developers look at object equality differently. Depending on the state of the object and the context, one might have to think about equality differently. So instead of overriding equals() method, Michael prefers to create methods like matchesId() or matchesName() which are very explicit in terms of what they are matching to.
So the next time you override one of these methods think about them.
Posted in Agile, Java | 1 Comment »
Sunday, August 31st, 2008
I just spend the last 3 hours pairing with Michael Feathers, who is on this way to the airport. Michael spent the last 2 weeks in India. During this stay in India he presented a tutorial on Working Effectively with Legacy Code in Delhi, Bangalore and Mumbai. He presented some simple yet powerful techniques of dealing with various issues in Legacy OO code.
Posted in Agile, Community | No Comments »
Wednesday, August 20th, 2008
Mr. Feathers is in India for 2 weeks. He is doing a TDD training for a company in Bangalore.
Flashback: I was really happy when he dropped me an email saying he is coming to India and would like to meet up with Agile enthusiasts in the area. After exchanging a few emails, we settled on running 3 free workshops in Delhi, Bangalore and Mumbai. Yes, that’s right, its your opportunity to meet him in person and spend 3 hrs talking about Working Effectively with Legacy Code.
As usual we are using the Position Paper’s concept to filter in the really interested folks. Over a period of time, the quality of the position papers are improving. Also position papers helps in setting expectations on both sides, the presenter and the participants. The present can adapt their workshop based on the position papers and the participants can gauge what the workshop will feel like based on other people’s position paper.
I really looking forward to pair with him on my Avatars of TDD experiment.
Posted in Agile, Community | No Comments »
Wednesday, August 20th, 2008
Unfortunately most people still measure size of code in number of Lines of Code (LoC). We all know LoC is a professional malpractice. Now, how do you objectively identify a long method? If we are not supposed to count LoC, then how can we define a long method?
Some people say, if the code does not fit in one screen and if you have to hit page down, then the method is long. How many times have you looked at code that fits in one screen, but still felt that code was long? Happens to me all the time.
Joshua Kerievsky says “If one cannot quickly and easily understand what a method does and how the method does it, it is a long method”. I really like this definition. But is a little wage to me and I don’t quite understand the theory behind why and when can something be hard to easily understand.
Recently I stumbled upon ”The Magical Number Seven, Plus or Minus Two: Some Limits on Our Capacity for Processing Information“, a 1956 paper by the cognitive psychologist George A. Miller of Princeton University’s Department of Psychology.
In this paper, Miller showed a number of remarkable coincidences between the channel capacity of a number of human cognitive and perceptual tasks. In each case, the effective channel capacity is equivalent to between 5 and 9 equally-weighted error-less choices: on average, about 2.5 bits of information. - Source WikiPedia
What does this mean? In a layman’s world, this means that 7+/-2 is the number of things (concepts) we can hold in our brain. So when I look at a piece of code and if it has more than 9 things in there, it exceeds my brain capacity to hold it in my memory and actually understand what is going on. I often notice that 7 or less things in the code is easy to manage. Once it starts cross that number, its gets exponentially difficult to hold it in my mind and to understand what is going on.
So if you are thinking of deleting elements from an array if they match a set of to-be-deleted elements, then that’s a good method for me. Why? Coz : I have an array, a set, an iterator, a loop, current values, a comparator and a delete operation. Around 7 things. That’s the max I can hold in my brain. But now if all of a sudden you throw thread synchronization into this, I may end up taking the loop, matching the current elements and the deletion out into another method.
So size has nothing to do with LoC, its a measure of related concepts that you need to hold in your brain.
Cyclomatic Complexity can also give some interesting data points to under/measure when a piece of code is long. Usually large methods have a higher CC.
Posted in Agile, Design | 1 Comment »
Tuesday, August 19th, 2008
RFC1925 - The Twelve Networking Truths, a master piece. Must read for all software craftsmen .
Posted in Agile, Design | No Comments »
Monday, August 18th, 2008
Being out of touch with Java coding and moving between Java 5 and 6 can be a great way to assume yourself. Couple of days back I stumbled upon a fairly well know Java 5 feature, @Override annotation. Annotations were introduced in Java 5. According to the JavaDoc
public @interface Override
Indicates that a method declaration is intended to override a method declaration in a superclass. If a method is annotated with this annotation type but does not override a superclass method, compilers are required to generate an error message.
One would read this and think the following code should work perfectly fine:
interface I {
void m1();
}
class C implements I {
@Override
public void m1() {
}
}
But guess what? In Java 5, the compiler gives the following error: “The method m1() of type C must override a superclass method”
The same exact code works perfectly fine on Java 6. You go back and read the Javadocs again and you can’t seem to find a fault. But it turns out that in Java 5, @Override annotation only applied to methods overridden from a superclass and not from Interfaces. (So if you implement a method from an Interface, @Override annotation cannot be applied in Java 5).
This is great, but there is no mention on public JDK 6 JavaDocs nor in the release notes.
Eclipse IDE 3.3.1.1 recognizes the new feature and add the @Override annotation auto-magically every time I override a method or implement an interface method. Pretty cool! Unfortunately for all you Intelij fans, there is an open bug still waiting to be fixed.
Posted in Java | No Comments »
Thursday, August 14th, 2008
And yes, finally I made it home this morning. After wasting 5 days in Canada, I finally reached home this morning. BTW if you are wondering what I was doing in Canada after my bad experience last time, I was visiting Toronto to participate in Agile 2008 conf. The conference got over on Friday and then I wanted to get back home as soon as possible.
Due to unavailability of seats, I was booked on Sunday flight. Which got cancelled due to bad weather in New York. Then I was put on the Monday flight. Which again got cancelled and they put me on the Tuesday flight. Delta Airline apparently has a policy that if the flight is cancelled due to weather problem, then they can treat the passengers like crap. No accommodation, no expenses, no change of flights, etc. Basically “you are on your own”. It turns out the best option is to cancel your tickets and run to another airline.
Big thanks to Deborah Hartmann for hosting me at her place and for taking care of me when I was down with a fever and cold. Deb, you rock!
Posted in Random Thoughts | No Comments »
Thursday, August 14th, 2008
Of late, most of my talks have been challenging the dogmatism that exists in the Agile community. I hate the whole “Our way or Highway (no-way)” attitude. Do it by the book or you are not Agile. Do X, Y & Z else you are not Agile.
Who’d believe with the way things are here
We’d be going everywhere telling people how to live?
Who’d believe we’d spend more
Shippin’ products with broken builds
Than to educate our minds?
Sorry but that’s what most do
I can’t help but think,
Someone’s foresaken you and me
By far what I see Agile today is, its “Process OVER People”. I could be completely wrong, but this is what I see happening in a lot (not every single) company. Because I think this way, some folks think I’m “Post Agile”. If challenging what some people are trying to push in the community is becoming “Post that community”. Then I guess I’m “Post Dogmatism”, I’m “Post Silverbulletism”.
I have always been of the opinion that Agile is just a means and not an end in itself. So is technology and so are companies and software they build.
If there is a new way, I’ll be first in line.
Posted in Agile, Community | No Comments »
Tuesday, August 12th, 2008
Here I’m still stuck in Toronto, after 2 days of trying to get to Mumbai via New York. Bad weather in NY and heavy travel season in North America has left me with no option but to be stranded in Toronto for 2 days on my own expenses. Is this some kind of a coincidence or what? Last time I was in Canada, I was stuck in Montreal for 2 days due to technical issues on the flight and then worker strike in Paris. This time I’m stuck in Toronto due to bad weather.
It appears to me that the airline industry really does not care for its customers. esp. if you are not a “high miles person”. In this position one is not really left with any option other than to live at their mercy. I’m so DONE DONE! with international travel.
Posted in Random Thoughts | 2 Comments »
Sunday, August 10th, 2008
My second visit to Canada and is as eventful as the first one. On the way to Canada, our flight was canceled. Had to wait with my wife and daughter (infant) on the airport without any help. Finally they put us on a flight next day. When we showed up next day, they told us my wife could not travel, because she did not have a US Visa. We told them we were traveling to Toronto, Canada and not US. But unfortunately we had a 2 hr layover in New York and we had to have a VISA. US, the only country in this universe which needs a transit visa. Our travel agent never told us about it. Very very frustrating. I almost made up my mind not to go. But my wife convenienced me to go.
Finally I land in Toronto on Tuesday afternoon just in time for my my workshop on “Styles of TDD” with William Wake. I missed the kick off of the Muzik Masti stage and Conference Retrospective, which was on Monday. After I landed it was a marathon for me. Back to back sessions. I had 4 sessions, 1 conference retrospective and 2 stages to manage. Everyone stepped up to help me, but it was crazy 4 days for me.
After all that, when I was finally really looking forward to go back home, I realized the flight was canceled. Due to bad weather in New York, all flights were canceled and I have to stay in Toronto for one more day. Worst thing is they don’t even provide me any accommodation. Thankfully Deb stepped up to help me.
I really think I’ve had enough. If I ever get back to India, I’m very sure I’ll never come back to Canada.
Posted in Random Thoughts | No Comments »
|