Saturday, February 27, 2010

Selfdocumenting code vs generic names

Some people like their generic names. Every method is named like update() or handleEvent() or init() etc. These names are not very much selfdocumenting. Therefore these methods come with comments very often. The comments explain, what the method does. However, comments are evil, as we all know.

The ideal method does one thing and has a name, which clearly identifies this thing. A proper name helps the reader to understand what it does, without having to read the code. Or at least it gives him a hint about your intentions.

Actually that's another good point. Expressing the intention of the method gives the maintainer the possibility to change the code while keeping the intended functionality.

Sometimes the methodnames are declared by a interface though. In that case you have to use the more generic names. However, inside the method you can call your nicely named methods again. So you still get the benefit from properly naming them.

And don't be afraid of long methodnames. However, try to avoid to use "and" and "or" or something similar to connect disparate things. This is a hint, that the method does more than one thing and probably should be refactored.

Friday, February 26, 2010

Refactoring vs business

In our current project the business officially hates the word refactoring. And right so.
Today every attempt to "improve" the code is called refactoring. However, the original term, as introduced by Martin Fowler's book "Refactoring", ment something different. It ment something much more narrowed than just improving the code.

Refactoring means improving the code in tiny and clearly defined steps, while always keeping the original functionality.

First of all, most of the projects i have seen so far, do not have enough test coverage. So you can't really be sure, if the functionality remains intact. Secondly, a lot of people don't even bother to add new tests while they refactor. Which means they don't even know, what functionality is there after the refactoring. And last but not least, the approach of tiny little steps, hasn't really made it into the devs mind at all.

The outcome of this adhoc "refactoring" doesn't come unexpected. Most likely you will see many things breaking or even missing after the refactoring. And this makes the business crazy. They don't like to pay somebody for breaking existung features.

So what can we do about it? First of all, don't use the word refactoring if you mean a plain rewrite. Secondly, avoid the word refactoring when talking to the business. They don't really understand what quality of code can buy them. This way you don't have to use the word refactoring when you talk to the business.
Imho we should be refactoring all the time, if we see some smell in the code. However, newcomers might see smells where oldtimers don't. So, before you refactor, talk with your fellow developers about it. Last but not least, if you refactor, make sure you do it right. Don't leave out the tests. They might not cover everything, but they should give you a good baseline of confidence in your code.

I promise, if we all follow these practices, one day, we will see the business beeing happy about refactoring :) At the latest, if they ask you for new features and you can build and integrate them easily without breaking things.

More than 10 years in Flash. Great time!

Wohoo. When i woke up this morning i realized, that i'm doing Flash related work for more than 10 years now. What a journey. It was great fun and the time just flew by. However, I wonder, what the future brings? Will there be a Flash player in ten years from now?

Thursday, February 4, 2010

Hellfire -> multicore flash compilation

I've been playing with Hellfire lately. It is a interesting project, which uses a compilation server to achieve faster Flash/Flex compilation. Have a look for yourself at Clement is very responsive, if you need help.

One particular interesting configuration, which is made possible by Hellfire, is to run FlashBuilder on your laptop and delegate the compilation to some other, maybe more powerful machine under your desk or somewhere else in the world :)

Tuesday, February 2, 2010

Downloading from Flex

In you case you didn't know as i did, it is simple to create a download link in Flex using request );