Tuesday, May 29, 2012

Turning to the dark side

It's been over 15 years since I've tried switching to Linux for the first time. I distinctly remember the first experience I've had that day when "to install" really meant "to compile the kernel". It was awful, bad and completely not approachable by mare mortals. That's how I met Linux.

The astounding thing about it though was that it kept nagging me over and over again. The sole idea of having an operating system for free and be able to customize it to your liking (although excruciatingly painful) stayed with me since that day. I was sold to the idea of using free software and some years later to give back something in return.

Some years later I've learned that there's nothing like a good Linux server and bought into the idea that as far as I am concerned Linux is The Operating System for servers but as far as Desktop is concerned it just doesn't measure up to the competition.

It's years later now, the new millennium, and I can finally enjoy a Linux distro prepared truly in a way that can compete with what I've already knew. It's Ubuntu 12.04 LTS - the first Linux I feel is worth using at all on a desktop.

So here's what I value the most and why I think you should just switch to Ubuntu 12.04 and never look back again:

  • Unity: User Interface that rocks! The first ever successful attempt to create a good looking and usable alternative to Windows
  • Memory consumption that doesn't eat all you have for breakfast
  • Hardware support that blows your mind
  • It's Linux inside all this meaning you can do whatever you please to it

My advise to you is: If you have not tasted it yet go ahead and try it out! It'll blow your mind how much space you can get in almost every aspect of your PC, starting with hardware requirements and ending with available screen space. It is truly astonishing!

Have a nice day!

Wednesday, May 16, 2012

Making Groovy scripts maintainable

Writing Groovy code is cool. Fixing them some time later can be hard as they tend to grow out off control pretty soon. Finding an install.gsh that has 100+ lines is not hard. And since Groovy is a very expressive language those 100 lines are not making the compiler happy - it's actually stuff to be done.

I have a bad feeling about this

In Java we're pretty much used to either creation of big, ugly, monolithic classes or going the completely opposite direction with Spring or some other dependency injection framework. In scripts we tend to rather go the first way which makes them unmaintainable and hard to understand. Why? Because historically shell scripts were created this way and we tend to think in this way. It's a script, isn't it?

These are not the droids you're looking for...

In fact Groovy scripts are not scripts at all. They are classes, that will have a main method. The only difference is that they are automatically compiled when needed. This means we can use all the good Java stuff when writing Groovy scripts: classes, external libraries through @Grab annotation and so on.

Here's an example:

Configuration.groovy:
class Configuration {
    String path
}
install.gsh:
#!/usr/bin/groovy

println new Configuration(path: "/tmp")

Since all the classes are in the default package (inaccessible from pure Java!) you don't need to import them manually. Should it make sense to split them into folders you can always do that:

org/example/Configuration.groovy:
package org.example

class Configuration {
    String path
}
install.gsh:
#!/usr/bin/groovy

import org.example.Configuration

println new Configuration(path: "/tmp")

Further more you can write tests for your classes, make sure they always work even if some mad cow enters the arena and goes Hulk on your code :)

May all your scripts be maintainable forever and for always!

Why things are so damn complicated these days?

I've been going over some older projects these last few months. Partially because this is part of my job as an architect (to know what's in the box and to propose better solutions if the existing ones are reaching to the limit of their usefulness) but partially because I've gotten really passionate about The Legacy. And I don't mean it like "oh, this is the legacy code we hate" and all that but rather to see and understand what causes today's problems and how we can make the world a better place. Well.. at least for us, programmers...

The endless possibilities

If I gave 10 people a general purpose task, let's say describing a simple domain I fear that I'd get back 20 different designs. I get that kind of impression a lot recently when faced with the same problems solved in many different ways by the same person. It is just a matter of time before that happens. Quite frankly that is a good thing: it means that person is trying something new and most probably learning from mistakes they previously made. But what about the code we have already committed? Is it really there to pollute the air for ever and ever? Is this what we call "Legacy Code" today?

We're screwed! What should we do?

Tuck the tail and run like hell! That always solves the problem, doesn't it? You made a mess first trying to do the right thing, then because you were under constant time pressure and later on because things were already so damn bad you didn't really care about this piece of crap. The easiest way out is through the front door. Usually the justification is "because I can't really develop myself any further" or "I'd like to learn more about this and that but the current place I'm in sucks so bad my boss will not allow me to". All those crappy statements are in fact about one and the same: "I've made a mess and as sure as hell I ain't gonna clean this stuff up!". If you think about it, it kind of makes sense, doesn't it? Why should you even remotely care what will the new guy think about your capabilities? You ain't gonna be there to witness it anyway, right?

Are we there yet?

I predict that some time very soon a lot of big systems is going to undergo a series of major setbacks. Anybody wanna take that bet? Would you rather sink with the ship or go down swinging?

I know it is not going to be very popular what I'll say right now but I'll say it anyway: For God's sake! Write clean code! It's not so damn hard, really! If you ain't got the skills then stop complaining about your boss that he/her is not giving you the development opportunities you'd like. It's your job to do it right and it is your job to develop yourself. Nobody is going to do that for you, not in a million years! And if you'll ever find yourself sitting in an open space bitching about the quality of code then don't forget that you have hands, eyes and a biological CPU to clean that up if you think it is a mess. Don't run from it - fix it! If you don't know if it will work after you do fix it - then fix it anyways! Clean code lives shorter, is easier to replace than that old, shitty stuff that stinks like hell every time you touch it!

So why are those things complicated again?

It's easy: we made them that way. We make them that way every single day (despite the heroic efforts of Uncle Bob and others). Period. They didn't create themselves - we're not quite there yet with the AI to procreate on its own. At least it is not a common scenario in the web database front-ends :)


May the force be with you!