Archive for the ‘Open-Source’ tag
…From Musician to Software Developer…
Before start working as a software developer on 2002, I spent three years being a musician. I played drums in a handful of bands from pop to contemporary jazz, and of course, also a lot of rock and roll!
I had great time doing this, I met most of my friends during this period, and it taught me quite a few lessons that I can use in other areas than music, especially in software development.
Mastering music (drums), and software development require a lot of dedication, both on reading and practicing.
In music, the first thing I did when I decided to take it seriously was to look for a music school to learn how to read and interpret music. Then I read most of the books related to drum techniques and rhythms, attended workshops, spent nights and weekends practicing to improve my ability and velocity. Practicing is very important! It’s when you give yourself the chance to commit mistakes and to let all the ugliness to happen; after all, no one is watching you. The intention is not to sound good, but to stretch your limits, so that you can perform perfectly on the stage.
In software development, it’s pretty much the same, you have to read a lot (books, blogs, articles, magazines), learn programming languages (choose two or three to specialise, and get a higher overview of others), attend workshops, meet people, practice by trying and evaluating different technologies, creating a blog to post your experiences, joining open-source projects, registering for coding competitions, solving some of the CodeKata challenges, preferably pairing with someone else, in summary, stretch your limits!!!! (Have you seen this before? ☺) Doing so will give you more self-confidence for you to perform well during your show, at client site.
Benefits of supporting tools
One of the deliverables to our current client is a project template, containing tools to guide them to build better software, ensuring lower bug occurrence and system integrity.
One tool we are using is Findbugs. One day, when running it, we came across an interesting issue, Findbugs was complaining that a class in a project was exposing its internal state, subjecting it to unexpected modifications. The class contained a single constructor with parameters setting its initial state and a set of getter methods. Any Java developer used to getters and setters pattern would say that the code below is valid.
public class Person {
private String name;
private Date dateOfBirth;
public Person(String name, Date dateOfBirth) {
this.name = name;
this.dateOfBirth = dateOfBirth;
}
public Date getDateOfBirth() {
return dateOfBirth;
}
public String getName() {
return name;
}
}
What would happen if you create a Person instance passing as parameter, pre-defined name and dateOfBirth variables and then, perform operations over these variables, modifying its states? And what if you retrieve these attributes (through getter methods), assigning them to new variables and start performing operations over them? For the name attribute it wouldn’t be a problem, since String objects are immutable, but certainly both cases would affect the dateOfBirth attribute, corrupting the state of the object.
One of the solutions to this problem would be to make getter methods always return a new object, copy of the original one and during object construction, initialize instance variables with new objects, copy from the original ones passed as constructor parameters.
public class Person {
...
public Person(String name, Date dateOfBirth) {
this.name = name;
this.dateOfBirth = new Date(dateOfBirth.getTime());
}
public Date getDateOfBirth() {
return new Date(dateOfBirth.getTime());
}
...
}
So, unless the objects you are implementing are good citizens and contains side-effect-free functions, you should consider programming in a more defensive way, to avoid unexpected behaviors in your project and also make use of tools like Findbugs to turn the development easier. Checkstyle and Cobertura are a good start.