How to Build Good Software? MS Press Code Complete says Measure twice, cut once

I am starting a series of posts about software construction, based on good and bad experiences while working for my many employers.

“Software construction (a.k.a. architecture), is the only activity that’s guaranteed to happen on every project”. It is not rare that projects or new features are abandoned either because they are too costly, or because they are not needed anymore, or because they are other more important priorities.

In the same vein: “Measure twice, cut once”. “Measure twice, cut once” is highly relevant to the construction part of software development, which can account for as much as 65 percent of the total project costs. The worst software projects end up doing construction two or three times or more. Doing the most expensive part of the project twice is as bad an idea in software as it is in any other line of work.

When you see Software that change versions (major versions) while not really having been used much, this is a sign there is something wrong in the construction part.

Java Concurrency In Practice Book Review

My reference book on Java concurrency is Doug Lea's Concurrent Programming in Java: Design Principles and Patterns. He is one of the authors of this new book, Java Concurrency In Practice. There is also Joshua Bloch, author of Effective Java, that many people love (but I am less a fan of it, even if I would recommend it to Java newbies), and author of Java Puzzlers, that I found more fun.

With such authors, I had relatively high expectations. I was surprised that there is not much material in common between Doug Lea's book and this one, which is a good thing. It's a different presentation, that focuses on different problems.

There is some very interesting material, I especially enjoyed chapter 16 on the Java Memory Model. There are not many  books with information on it. I did not know that initializing a final member in the constructor was providing thread safety for the accessor method of the corresponding field if there is no other modifying method, no synchronization needed. And not having the member declared as final was breaking the safety.

I also had not heard of Amdahl's law before. It seems quite intuitive, but then the example in the book about processing parallel tasks using a synchronized LinkedList (improvement up to 3 threads, no more later due to time spent on synchronization) shows that the reality is not that intuitive.

I enjoyed how the book is written, and how information is presented. There is for example their concept of publication and escape (in chapter 3) which tells you important things, like not starting a Thread in a constructor (and if you still want to do it they present a nice way to do it).

I think this book is a simpler read that Doug Lea original book, and probably a better introduction (that still goes very deep) to Java concurrency programming.

Why are you not using Entity EJB 1.1?

I am currently quite busy learning about Websphere Commerce. I was surprised to notice that they still use Entity EJBs 1.1. My experience was that many companies turned away from Entity EJBs, sometimes from the beginning, preferring TopLink or Hibernate (later).

I know that Entity EJBs are more heavy to use than Hibernate, but with the proper tooling support, it’s not really a big issue. Are there more fundamental reasons? There are probably some mapping limitations, but IBM implementation is apparently quite good in term of features.

I will write a complete post about my own analysis of EJB 1.1 vs IBM EJB 1.1 vs EJB 3.0 vs Hibernate, but I was wondering first what was your feedback on EJB 1.1.

Switching to Windows

That’s it, I have done it, the unthinkable. I have switched from MacOs X to Windows XP. My idea was first to install Ubuntu on the Mac Mini, but if you want to keep the Mac Os X install, the methods I have read on the web required to use bootcamp. At around the same time I was annoyed by problems I had with bluetooth and Skype in MacOs.

So, with bootcamp installed I decided to give a try to Windows. And it works quite well on the Mac. As I use it mostly as a media box (movies, photos, jukebox, browser and tablature reader) and not really as a developer, I find Windows quite convenient. I have always preferred Picasa to iPhoto. And moving back to Picasa for my photos is a joy. I can’t believe the speed difference between the two apps, and it’s not a matter of memory, I have 2gb. The crappy ways iPhotos deals with my folders is over. I am also happy to use again foobar2000 instead of bloated (and limited (only MP3s and MP4s)) iTunes. In my quest to look for a convenient setup, I discovered ProjectM visualisation, also available for MacOs X (with iTunes) and Linux. I am quite impressed with the animations. I have the impression that graphics are much faster under Windows than under MacOs, it’s probably due to much better optimized drivers.

Today I gave a try to Netbeans 6.0. It’s not a dev machine, but I find convenient to sometimes be able modify quickly an existing program, or test some java stuff. It’s still in beta, and it shows, I found it so slow! Plus functionality is really not on par with Eclipse when it comes to code analysis. It reports some errors way too long after I corrected them, and it does not report other important errors, for example when a library requires another library. With Netbeans, you see the library problem only at runtime. Under Eclipse, you have an alert in your project, before running it.

What’s not working very well is the broken Apple keyboard, I really don’t understand why they changed all the non alphanumeric keys in the French keyboard layout. But it’s broken in MacOs as well, Another thing is the bluetooth headset. Apple bluetooth drivers don’t do that. Anyway Apple bluetooth range in the Mac Mini is a joke. My thinkpad offers a much wider bluetooth range. Overall I am quite happy with the current setup, being able to use Picasa, foobar2000, Open Office,.and latest software like Skype 3 or Photoshop 9. And I don’t have to lose any more time with the freaking Finder backward interface.

Social (Web) Revelation: Tags Are Lame

I had a revelation yesterday while thinking about del.icio.us, the most well known social bookmarks site. I find out that I almost never use my tags, and I am often not satisfied by results when I search using tags. What use can you make of 100s of tags? in the end only less than 10 are usable to classify very different stuff. And even then compared to a search it’s not a much useful classification.

If del.icio.us search engine was decent then I am sure I would never use tags. But their search engine is slow, and does not search much (it sometimes fails to find results on words in titles).

What is needed is really a social search engine, where you could look things up by user as criteria, and possibly by dates. I googled for it and immediately saw that my “revelation” was quite common. There are several social search engines. There is cranky, where you can see eventual reviews by some users, added to search results. There is eurekster, where you can search in any user bookmarks, but you can’t search everybody (how silly). There is Yahoo MyWeb, quite decent if you ignore the presentation and if they added descriptions on results.

A friend of mine told me that furl, another social bookmarks site, is more search oriented, but unfortunately a bit slower to use since it keeps a copy of the page you bookmark.

But still I feel like none of the sites do the right thing, some have too many features, others bad presentation, focusing on useless crap. I actually think that google should have that feature integrated with the common search. I am sure it will in the future, but they seem to be late on the social side of the web.

1 year of mac mini - the deception point

I am less enthusiastic about the Apple experience than I was one year ago. I am quite enthusiastic with the hardware in general, except the keyboard. The computer is small and quiet, and there are not many competitors at this price on the market.

Experience as a developer

I feel frustrated with MacOs X as a development environment, when compared with Ubuntu Linux. I always miss the multiple desktop, despite expose magnificient look. The standard behaviour for the terminal, bash, vim, etc. are more convenient in Linux. Installing software and updates is much more convenient on Linux thanks to the open source repositories. The key bindings for special characters is awful for a programmer on the Apple keyboard, because non standard, and not even written on the keyboard. Installing linux on a mac mini intel is not trivial, but I am considering it seriously.

Experience as audio/web user

No particular complaint about the web, but I use Firefox instead of Safari, because of Firefox Adblock extension. Chat works well, Skype is ok. There are sometimes problems with bluetooth audio for Skype that, I think, are related to MacOs.

Audio is good too, I end up finding iTunes ok to use, it is fast enough to manipulate 100GB of songs. But I don’t use any fancy feature, except cd-burning. It makes a good jukebox, and the remote is handy, but not terrific (any wireless keyboard would do in the PC world, for 90% of the cases).

Photo is not great, I don’t like iPhoto that much (especially when compared to Picasa). iPhoto is quite slow for me (and I have 2gb of RAM). I found it a pain to install TheGimp on MacOs, not knowing which X server to use. Photoshop is still not compiled for intel, and dog slow on my mac mini.

Page is not great either. It does render beautiful letters, but overall I don’t find it very usable compared to more standard software like OpenOffice, and it’s time limited!

Conclusion

Overall I think I would not buy a Mac again if comparable PC hardware exists. MacOs is not a bad OS, but I prefer Ubuntu Linux. If you don’t use or like Linux then is really Vista worse? I don’t think so.

Tired Of Bad Singletons

While looking through some code for a project, I saw that:

  public static final ProductYP instance = new ProductYP();
 
  public ProductYP()
  {
    if (instance != null)
      throw new RuntimeException("Only one instance allowed");

    prods = new HashMap();
  }

  public static ProductYP getInstance()
  {
    return instance;
  }

And I don't think it was done by a newbie... It's actually not far from being correct, it's just that the guy obviously does not know about private constructors. I have seen several broken singleton implementations in previous projects and had several debates on the double-checked locking pattern (it works since JDK1.5 with volatiles but is useless). I am upset to see another half broken implementation. Everybody should have read at least this.

What have you seen as broken singletons?

Declaring Your Logger - No Problem

I used to like the java specialists newsletter, most news used to be a bit challenging. Nowadays however the quality is lower. In the latest news, the author proposes to use the StackTrace to get the class name, in order to declare a Logger independently of any explicit reference to the class name.

While this is a clever hack, it still requires some code to be duplicated in every class, compared to Aspect/IoC approach. But was there really a problem with declaring loggers the usual way in the first place?

With modern IDEs, most people just create a template for the logger declaration line. Also, renaming MyClass to MyClass2 will rename MyClass.class to MyClass2.class automatically. Here is my template for Eclipse to which I assigned the short name log4j:

private static final Logger LOG = Logger.getLogger(${enclosing_type}.class);

Very Quick Django Trial -> Bye Bye Django

I tried a bit django for one very simple thing, where django is not of much use, but it was a way to try it with something else than examples on the site.

Even if django templates features seem very good and very convenient when reading the docs (for example the extends keyword), I found out that the template system is very annoying. Firstly one has to learn another templating system. Secondly, and much more importantly, the debug facilities for templates are close to non existent. I have a better memory using ruby on rails templates (which are not the best either).

Java templates, based on Velocity, JSPs or JSF are much nicer to debug. PHP (which I consider an ugly language that can unfortunately often gets the job done) used to be crap at debugging, but with eclipse plugin phpeclipse it is much better these days.

I think templates play a very important role in web application development, and I am surprised that a framework with so many good ideas fails in reality (at least for me) because debugging templates is a pain. Hopefully it will become better one day, but until then bye bye Django.

A Proof That JavaScript Sucks.

Google developed GWT.

Why would GWT be so well acclaimed if JavaScript was a good language. When you talk about GWT to someone (a developer preferably), the first reaction is often

great I don’t need to do any JavaScript

I recently discovered another similar open source project, ZK. The first thing you can read on the website is

ZK is an open source Ajax Web framework that enables rich user interface for web applications with no JavaScript and little programming.

If you compare that with how JRuby is (or Jython used to be) trendy, you will agree there must be a problem with JavaScript.

JavaScript is not bad at everything, for very simple scripting, it is quite decent, the recent inclusion of Rhino in the JDK 1.6 is useful anywhere you need simple dynamic behavior. But most developers obviously don’t want to deal with it.

Previous

Next