Pages

Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

2008-10-17

So, you're stuck with <insert not so cool technology here>

This is a work in progress. Don't be surprised if this post changes over the coming weeks. This post is about small things you can do, even if you're stuck with whatever uncool technology.

Do something cool while commuting

I personally have spent a almost all my commuting time the last twelve months programming symfony. First a billing system for small businesses and then a web app for organizing work parties. The last one was for a non profit. Not paid of course. But it helps a lot to to something cool for 45 minutes in the morning before you start wrestling obtrusive frameworks that don't even respect basic things like url's. I also believe, out of personal experience, that I arrive at work more fit for work after 45 minutes of doing something cool and relevant, than after sleeping for 45 minutes more.

Use test driven development to save time

When I arrive at work, I can just forget about the comfort of making changes, alt-tabbing to firefox and refreshing to see the changes. There are some smart ways of avoiding server restarts, but the most important trick I've learned so far is to do use tests as far as possible before I deploy to the server and do the final testing. This way I save time, and I avoid sitting and waiting for that server, just to loose the patience and start looking at dzone for something useful. Oh, and then you also have the usual benefits of having a test suite to help you when you find out that you have to refactor that stuff.
Update (2008-10-31): Learn mockito. It is wonderful to just write someComplicatedClass = mock(SomeComplicated.class) instead generating a mock manually.

Refactor that stuff

I've recently read Michael Feathers "Working Effectively with Legacy Code", and it contains a lot of useful hints about how to get your code testable and how to add features in a safe way, but it was first at Robert C. Martin's speech at JavaZone this year that I became really inspired to make existing code more readable. If you've time, watch that presentation. It is available here. He recently published the book "clean code". Guess I'm going to buy the book. Just watching his presentation about functions was enough to go back to work and turn a 1200 line monster class into a much more readable class of less than 500 LOC. And I'm not finished with it yet.

Find some uninterrupted time, any uninterrupted time

(I don't do this anymore. But it worked 2 years ago, before I got married.) Sometimes I've found it better to trade in a couple of hours of sleep for a couple of calm hours. If your day is filled with interruptions, and you don't have a family to take care of, try sleeping a couple of hours (not more) in the afternoon. By the time the interruptions are going to sleep, you are (hopefully) wide awake and ready to get some real work done. Uninterrupted. And since you're not paid for it, you decide what to prioritize. In the morning, you might find it useful to sleep a couple of hours again, just so you can stay awake the rest of the day.

Update: Learn The Pomodoro Technique

(2008-10-31)I have just started learning "The Pomodoro Technique" and, so far, it has been a very interesting experience. Basically it helps you staying focused and avoid internal and external distractions. Add to that that you could learn the basics in less than one hour, and that you don't have to convert your whole team to increase your own productivity.

Update: Get a headset

Headsets serve two purposes:
  • Inform coworkers that you're trying avoid beeing interrupted
  • "Mask" conversations to avoid beeing distracted.

You found out something useful? Blog about it

How many times have you searched for something just to find the answer at someones blog? If you've had a hard time finding out something, chances are that someone else on this planet is wondering about the same. An example: I recently had a lot of work to remove a trojan until I did a search on google for information updated last 30 days about tdsserv. It turned out to be a very new trojan, first observed around 15. of september, as far as I understood the information. I posted the solution to my blog, hoping that someone else might find it useful, too. Last time I checked, I had three results coming in from search engines, related to that post, so obviously, I was not alone. It won't get me rich, but at least I'm sharing back.

2008-09-21

About Java, closures and attracting new developers, part II

(Warning: A web developers perspective.) I've been thinking of this since I wrote the post: About Java, closures and attracting new developers, where I tried to prove that the problem with Java is not related to the lack of closures. At the risk of offending the rest of you, here comes my explanation of why I don't use Java for my spare time projects, even if I like it.
  • The web server (I mostly use tomcat 6 at work) takes to long time to restart, so long time that it quickly becomes painful, especially when you add to this that:
  • you have to restart it every time you've changed a class.
  • The recommended web framework, JSF (JavaServer Faces) doesn't care about URLs. By default it will show the URL from the last page you visited.
  • JSF has a really unnecessarily complicated template language. I mean, I can't see the reason for having to use <h:panelgrid> when what you wanted is just <table>. Not to mention that there is no <div> tag in the default component set. Of course, you can just use a component set that has one, (or make your own if you have a couple of hours to spend,) but I guess you see my point.
  • JSF messes around with my id's, even if I've not asked it to do that. To get around that limitation you once again has to use a different component set (tomahawk comes to mind).
  • You don't have access to the javascript that is used. Of course this is touted as a benefit of using JSF, but in my opinion it's just a horrible violation of the rule about separation of concerns. What happens is that you can't just include that standard well-tested javascript library you want, which means you have to use jsf components again. And guess what: Those components are broken, and it always ends up with a lot of extra work for the designer.
  • And of course: JSF isn't the only problem with Java. Take something as simple as how to print a line of text to the console: "System.out.println()", or think about trying to open a file for reading. With execuse to every swede who reads this, we have a childish joke here in Norway that goes like this "How many swedes do you need to change a light bulb?" The answer is 1000, one to hold the bulb, and 999 to turn the house around. Same goes for Java, - how many objects do you need to read a file line by line? Or to resize a picture? (Yes, I know Fabrizio Giudici has tried to defend it, but I do not agree. Often, the Java API's seems way to low level, and my feelig is that sometimes you have to use one factory class on top of another. Also see next point on why this is more of a problem than it could have been.)
  • The documentation is also painfully unbalanced: There is a lot of javadoc generated API documentation everywhere, but I can't think of a single place to find something like askeet, -a well thought out demonstration of how to use the api or framework your're providing. (OK. I can remember to have seen som interesting blog posts over at http://weblogs.java.net. Example.)
But yes, I still use Java at work. And I still think Java is a great language, and a great platform. It just lacks a good, full stack web framework with great documentation, running on a fast server that doesn't need to be restarted many times an hour. (Edited: 2008-09-30)

Updated 2008-12-14: Symfony has done it again! More documentation available here: http://www.symfony-project.org/jobeet/1_2/Propel/en/

2008-08-06

About Java, closures and attracting new developers

Background
Julian Exenberger has an interesting post where he states that of the top 10 languages on the Tiobe index, Java is the only one not to support closures in any way, either officially or by at least som kind of (planned) support. He goes on to state that Java is going to be perceived to be obsolete, and it's going to be a harder sell in the enterprise because of this.
Another possible explanation
It might be that the Java crowd is panicing about the wrong thing. Surely, Java.next, as Stuart Halloway describes in his article Java.next: Common Ground might turn out to increase productivity a lot, but I guess language features are not the reason why some1 developers are leaving Java for Ruby or less known languages. I guess the reason why Ruby got popular is because of Rails2. Sure, the Rails people argues that it's better because of things like "metaprogramming", dsl's etc., but then, why is it possible to make an equally good, if not better, web framework in PHP? And why is everyone still talking about Ruby, and not about Django, TurboGears, symfony?

Here is what I guess: It's because of the enthusiasm in the Ruby camp. They're not very many, but they have a good language, they innovate, and they make a lot of noise! What Java lacks most is enthusiasm. Innovation can be copied (it's mostly open source), and lack of language featueres can be programmed around3, but not without enthusiasm, that is not going to happen. 

Of course there used to be a couple of reasons for that lack of enthusiasm, but they're starting to really fade away. Here are some examples: 
Focus on strength

Java has some unique features that makes it stand out. If we want Java to succeed, advocates of the language should focus on things like:
  • Supported by multiple big companies.
  • Secure. Java is widely perceived as a very secure programming language.
  • A clean language.4
  • Very good ide and debugging support.
  • Both Ruby, python and PHP are available on top of the Java platform, together with some Java-only languages like clojure, scala and groovy.
I have left out the open source argument, and the multi platform argument, because both of these holds true for both Ruby, python and PHP.



Conclusion
Java isn't dead, and it doesn't need to die even if Sun doesn't add all those cool features people are asking for. Start beeing enthusiastic!



1: Yes, I'm not writing many. Most of us still use Java, and it even seems that more people are still searching for java programming than for ruby programming: http://www.google.com/trends?q=java+programming%2C+ruby+programming
2: I guess this is evidence enough: http://www.google.com/trends?q=ruby+programming&ctab=0&geo=all&date=all&sort=0

3:  Yes, I am talking about my favourite web framework, symfony. Programmed in php, which, in case you didn't know has no closures (yet), and is not elegant at all, but rather ugly. I mean, having to prefix variables with $, and using "->;" instead of "." is just ugly. But that doesn't prevent sensiolabs from creating a super effective web framework out of it, and it has not prevented yahoo from choosing it over rails for both the new delicious site and yahoo answers.
4: I sometimes spend some hours maintaining Delphi code, and there is a couple of features that I really dont like, like the "with" keyword, that saved the previous author from some typing at the cost of making that hundred lines function even more unreadable, and the possibility to mix two different classes in one unit, and even mix the implementations!