Best practices

Who do You write code for?

TL;DR: You should write code in a way that your colleagues would understand best. After all, they are the ones that will be reading it over and over again. No matter in how much of a hurry you are, you should always take the time to give things meaningful names.

Who do you write code for? It’s a simple question with an obvious answer.

As Martin Fowler bluntly states it:

Any fool can write code that a computer can understand. Good programmers write code that humans can understand.

The days of a programmer writing cryptic assembly code that only her computer understands have long gone by.  The question deserves attention however, as I seem to keep bumping into examples that prove not everyone shares this belief (or is too lazy to act upon it).

The example

Recently, I came across a bit of SQL code that looked like this:

DECLARE @nvcWFN_SQL NVARCHAR(MAX)
DECLARE @nvcWFN_SQL_1 NVARCHAR(MAX)
DECLARE @nvcWFN_SQL_2 NVARCHAR(MAX)
DECLARE @nvcWFN_SQL_2Bis NVARCHAR(MAX)
DECLARE @nvcWFN_SQL_2Bis2 NVARCHAR(MAX)
DECLARE @nvcWFN_SQL_2Bis3 NVARCHAR(MAX)
DECLARE @nvcWFN_SQL_3 NVARCHAR(MAX)
DECLARE @nvcWFN_SQL_4 NVARCHAR(MAX)
DECLARE @nvcWFN_SQL_4Bis NVARCHAR(MAX)
DECLARE @nvcWFN_SQL_4Bis2 NVARCHAR(MAX)
DECLARE @nvcWFN_SQL_4Bis3 NVARCHAR(MAX)
DECLARE @nvcWFN_SQL_5 NVARCHAR(MAX)
DECLARE @nvcWFN_SQL_6 NVARCHAR(MAX)

--The code goes on by initializing these variables with parts of
--a SQL SELECT query

SET @nvcWFN_SQL =
        @nvcWFN_SQL_1 + @nvcWFN_SQL_2 + @nvcWFN_SQL_2Bis +
        @nvcWFN_SQL_2Bis2 + @nvcWFN_SQL_2Bis3 + @nvcWFN_SQL_3 +
        @nvcWFN_SQL_4 + @nvcWFN_SQL_4Bis + @nvcWFN_SQL_4Bis2 +
        @nvcWFN_SQL_4Bis3 + @nvcWFN_SQL_5 + @nvcWFN_SQL_6

--Execute the dynamically generated query
EXEC sp_executesql @nvcWFN_SQL

This is part of some code that generates a complex SQL query at runtime. Ignore the fact that this might not be the best idea ever, but just analyze the code itself.

Continue reading

Standard
Testing, Web Development

Creating cross-browser extensions with Crossrider

Last year I had the opportunity to work on the development of a browser extension for multiple browsers. As I wanted to minimize the amount of browser-specific code and wanted to avoid duplicating my extension for every browser, I used the Crossrider framework. This post provides an overview of my experiences with developing a cross-browser extension using the framework.

The requirements

The extension I had to create was meant to search through web pages as the user visited them and then add some extra functionality to certain keywords on the page. I won’t go into details here, but it’s something similar as Skype’s Click to Call, which does the same with phone numbers: Click to Call recognizes phone numbers and adds a button to the webpage to easily call this number through Skype:

Skype Click to Call in action - copyright www.skype.com

Skype Click to Call in action – copyright http://www.skype.com

Continue reading

Standard
Continuous Delivery

The Road to Continuous Delivery

In this post I will summarize some of the main principles of Jez Humble and David Farley’s great book on¬†Continuous Delivery¬†and¬†share my experiences of applying them on software projects I’ve been involved in.¬†

First, I’d like to share a story to give this discussion some context:

Meet Joe. Joe is a software developer. It’s a regular¬†Friday¬†afternoon, 15 PM. Before heading home, Joe has to start this thing called a “weekly¬†build”. Joe makes sure everyone on the team has checked in their changes to the source control system. Joe starts the fully-automated build at the click of a button. The current build process takes some time, so he grabs a coffee. Five minutes later Joe returns to his computer, only to be shocked by what his monitor is displaying:¬†build failed. Joe’s palms suddenly get sweaty, because he’s been in this situation before. It has been a week since the previous build was performed. He inspects the version control history: his team has committed tons of¬†changes this week, most of them having self-explanatory descriptions like “Fix for Bug 1421, should work now”. The operations team will be breathing down his neck waiting for the binaries, since the quality assurance department expects a version of the product containing the latest features to start testing Monday¬†morning.¬†Having no idea how long it will take him this time to fix the build, Joe grabs another coffee and calls his girlfriend: “Don’t wait up honey, I’ll be home late.”.

Have you ever been in a similar situation? I feel your pain. Please read on for some ideas that will make your life easier and your boss happier. Otherwise, your team may have picked up the practices of continuous integration (or to a further extent, continuous delivery). Good for you!

Continue reading

Standard
Self-Learning

Global day of coderetreat 2012

While everyone was sleeping out last saturday, groups of software developers worldwide assembled to participate in this cool event called global day of coderetreat. The concept of a coderetreat is simple: whereas the only way for other professions like musicians to get better is to train their skills by regular practice -just for the sake of practice-, software developers never seem to really “train” their skills. They get dropped in one deadline-prone project after another, but never really take the time to perfect their skills (or as Corey Haines likes to call this, get industry best practices¬†under their fingers).¬†Software developers can train their skills individually by performing code katas, or they can do so in group by attending a coderetreat.

Just as musicians get better by practicing scales and jamming with other people, developers can improve their skills by performing code katas and attending coderetreats.

Continue reading

Standard
Mobile

Experimenting with mobile application development

One of the key ideas I took with me from Devoxx a while ago was this: mobile app development is hot. I wanted to gain some experience in this field so I decided to create a pet app to mess around with: WhereIsMyCar. It does exactly what the name implies: the app lets you take a picture of your parked car and it stores this picture and your current coordinates so you can easily find it again after a long night of coding. The reason I went for this kind of app is twofold:

  • It’s limited in scope, so I wouldn’t be coding for months on end
  • It uses some of the newer device/HTML5 capabilities (taking pictures, geolocation, localstorage,…) so I could also gain a little experience with those.

After deciding on which app I was going to build, I hit the next bump in the road: should I go all-native, or should I create my app in a non-platform-specific way? Martin Fowler has an excellent infodeck on this topic here. Since I did not want to limit myself to the Android platform right off the bat, I went for the cross-platform option.

Cross-platform app development = HTML5 + javascript + device wrapper framework

Continue reading

Standard