« [Video] Coding Session #12: Reusable Workflow Considerations | Main | [Video] Coding Session #13: AJAX with Servoy »

December 23, 2011

[Commentary] Does being tired make us better coders?

I did a team programming session the other day that started late with my brain already fried. My cohort wasn't in much better shape either but we felt we needed to at least grind something out.

At one point I got really annoyed because my tired brain was stumbling over finding and implementing an API call. And not someone else's API call—one of our own creations. Creations that we expect other people to use as they are in a released product.

If I'm having a hard time, how the hell is anyone else going to figure it out?!? Grrr....

Piling a stupid moment on top of tired and cranky is one way to critique your own code. In my frustration I wrote a bunch of un-PC comments about how we weren't paying attention to details and documentation and whatnot—at the top of our next day's todo list. Highlighted in red to make sure everyone started their day with what I deemed in the moment was the correct sense of urgency.

Fast forward to the next day. My brain has had some time to get over frustration and start working on some solutions. This leads to an all-day session of team coding that results in a reorganized API that is much cleaner and Troy figuring out a neat trick for getting Servoy's code completion to work with functions attached to our own objects. A very productive day.

As we're winding things down I quip in our all-hands meeting, "Hey, maybe brain-dead programming has some benefits after all." My way of apologizing for yelling on the master todo list. Because, you know, I've never gone through the 12-step program for apologizing correctly.

To which one of the team links us to this:

Why programmers work at night

A very interesting read. One of the author's premises is: "Because being tired makes us better coders".

I'm not sure I agree with that part entirely but I will say that being tired is one hell of an honest way to look at your own code.

| Posted by David Workman on December 23, 2011 at 07:26 PM in Commentary | Permalink

Comments

Hey, good insight there. It usually really helps :).

But, do you care to show that "neat trick" to get code completion working? Have been toying around with that some time.

Patrick

Posted by: Patrick | Jan 5, 2012 11:21:03 AM

Wrap functions in an object declared as a global variable of media type. Use inline JSDOCs for the parameters. Example:

var CMS = {
markup : {
	getErrorPage : function(/**JSRecord*/ siteRec) {
			return globals.WEBc_markup_link_error(siteRec)},
	getHomePage : function(/**JSRecord*/ siteRec) {
			return globals.WEBc_markup_link_home(siteRec)}},
session : {
	clearData : function() {
			return globals.WEBc_session_deleteData(/**String*/ sessionID, /**String*/ dataKey)},
	getData : function() {
			return globals.WEBc_session_getData(/**String*/ sessionID, /**String*/ dataKey)},
	getSession : function(/**String*/ sessionID) {
			return globals.WEBc_session_getSession(sessionID)},
	setData : function() {
			return globals.WEBc_session_setData(/**String*/ sessionID, /**String*/ dataKey, /**Object*/ dataValue)}},
ui : {
	getData : function(/**JSForm*/ formName) {
			return globals.WEBc_block_getData(formName)},
	setData : function(/**JSEvent*/ event, /**String*/ key, /**String*/ value, /**JSForm*/ formName) {
			return globals.WEBc_block_setData(event,key,value,formName)}}
}
Then as you type for example:
globals.CMS.session.getSession...

...you get code completion along with parameter suggestions each node you get to.

Example taken from the CMS global variable in the Sutra CMS resources module (more extensive there). Allows us to have a server-side API that mimics client-side Javascript libraries in terms of format. Trying to make things as familiar as possible for web coders.

The other big advantage that will kick in down the line is that we can gracefully enhance/deprecate. Just check for the Sutra CMS version in our function wrappers and run the appropriate method call. API stays the same.

Posted by: David Workman | Jan 5, 2012 11:52:25 AM

Post a comment