Looking for a new constraint to use at our local Coding Dojo Vienna (Twitter: #CodingDojoVie) I took a constraint I heard about and gave it an extra spin. Due to further circumstances, I ended up coding under it myself.
The basic constraint is simple: To enforce giving names that express their intent, every identifier shall have at least X characters. With X in the range of possibly 40. This leads to noise in some names, but forces people to let go of things like "num" or "x1" and "x2". I wanted to try this one at the next dojo.
Since I knew the registered participants had a high proficiency level and are using meaningful names anyway, I wanted to add another constraint - one that is working against the first. Without thinking too much into detail (nor trying it out) I wrote this:
Identifier: Minimum 20 characters
Lines: Maximum 80 characters
When presenting it, I then added that I wouldn't allow breaking up code lines - i.e. the "statement" must use at most 80 characters. "Statement" is also not the best thing as I also meant to include the indentation characters and things like method signatures. This last bit wasn't communicated, so not everyone adhered to this.
Due to extra circumstances another participant wanted to be the moderator and I was able to work under this constraint. Like I wrote, I didn't properly think it through and meant it to be a crazy, funny and essentially silly constraint - it was the last session of the year before the holidays.
And fun we had.
The first realization my partner and I had was that with identifier even a bit longer than 20 characters, it was tricky to stay within the limit of 80 just for simple statements like "X x = new X();". We needed to think out of the box for various simple things: Fields instead of variables, extracting methods, refactoring names several times and the like.
The builder pattern was one thing we went for in the end, something another team also did. But apart from that, we didn't come far - we didn't even complete one unit test.
My impression was that this is a great constraint: You need to search for alternatives for the simplest things and it requires you to try out a lot. I was then even more surprised that the other participants also liked the constraint.
We shared our experiences during the retrospective and also discussed how the constraint could be refined - or whether it should be modified at all. What I'd like to communicate better is the max limit, so that it contains things like indentation but prohibits breaking a statement into multiple lines.
One team settled for a variant: Allow only up to three identifiers per statement, which has to be in one line. This tackles one of the negative points we discussed: Long names sometimes contain noise just to comply.
To me this sounds like a separate constraint, to be used/tried on its own, because to me it presents you with a solution of the "original" constraint and doesn't force you into haggling of characters.
Either way, tell me what you think of this constraint - or whether it is genuine at all. I also invite to use it at your next dojos - just be sure to tell me your experiences! Leave a comment below...