Creating code and sharing it with the world is ALMOST always a good thing. I'm not trying to make it sound as though I have never written bad code, in fact far from it, there's very few pieces of code in my past that I'm proud to say I've written. And sure, there was a time when I probably thought my lousy code was really really good. So don't think that this is a personal attack on the author of the following code, although I am presenting his work as a cautionary example of what NOT to unleash upon the world.
A little back story. I've been working on a simple website for a friend of mine for, oh, say, 6 months or so. He's a photographer so the emphasis of the site is on the photo galleries, and I've gone through countless iterations (self-produced galleries, pre-built galleries in javascript and flash), and really haven't been totally happy with any of them. Then I found a gallery that looked just beautiful. It was written using the jQuery javascript framework and the creator made it look very slick using a reflection library that made the displayed image appear to be floating above a lake or a mirror. Classy.
So I downloaded this gallery-that-shall-not be named, followed the minimal instructions that were provided on the home page as far as setting it up... and of course it didn't work. I spent a little time fiddling with the options set on the page itself and when nothing worked (no image displayed, no thumbnails displayed, no list of galleries displayed) I decided to dig into the code and figure it out.
Step 1: Get the list of 'galleries', or groups of images. I figured if I could get this to display, maybe I could get to some thumbnails and who knows, even get an image to display?
init_menu = function(g) {
var currNav = null, currSubnav = null;
$('div#mainNav li.nav').each(function() {
var nav = this;
nav.subnav = $(nav).find('ul');
$(nav).click(function() {
// hide previous subnav, if any
if(currNav && currNav != nav) {
$(currNav.subnav).BlindUp(300);
}
// show subnav, if any
if($(nav.subnav).css('display') != 'block') {
$(nav.subnav).BlindDown(300);
}
$(nav.subnav).find('li a').click(function() {
if(this != currSubnav) {
try {
var imgs = images[nav.title][this.title];
if(imgs.length > 0) {
g.init_gallery(imgs);
}
if(currSubnav) {
$(currSubnav).removeClass('active');
}
$(this).addClass('active');
// get rid of annoying dotted border on focus
// for hyperlinks
this.onfocus = function() {
this.hideFocus = true;
}
currSubnav = this;
return false;
}
catch(e) {
alert(e.message);
//alert('SYSTEM ERROR: The selected category (' + nav.title + ' | ' + this.title + ') contains to images!');
}
}
});
currNav = nav;
return false;
});
});
}
What you see above comprises the entire contents of the menu.js file. This file's job is apparently to create a series of menus / submenus and allow you to select and initialize a photo gallery. However, the example HTML document that came with this project didn't actually achieve this , in fact it didn't do much of anything. Clearly in a situation like this some comments would be nice. As you'll notice, there are exactly 3 comment lines (lines starting with '//'). The first two are:
// hide previous subnav, if any
// show subnav, if any
The last one is apparently just to hide some unwanted code. The previous two however, are almost as useless in informing an unacquainted user with how to use this code. First question: 'What does subnav mean?' A: A sub-menu, probably. The programmer uses the variable names he came up with in the comments, rather than what data / objects those variables represent. And it only gets stickier because, as you see in this block of code:
var currNav = null, currSubnav = null;
$('div#mainNav li.nav').each(function() {
var nav = this;
nav.subnav = $(nav).find('ul');
'Nav' is apparently this programmer's favorite word. currNav, currSubnav, mainNav, nav, nav.subnav... yikes! Either this file should have been renamed 'nav.js', or every instance of 'nav' should have been replaced with the word 'menu', I think.
Trying to parse the meaning of all these variables (and page elements as well) with very similar names is tricky enough, but trying to do so with only two programmer comments (both of which make reference to 'subnavs') is downright obnoxious.
Here's the lesson. As someone much smarter than me once said, "Real programmers don't write documentation, the code should be obvious". I concur with this statement, if you write code and have the forethought to make it legible and understandable, it shouldn't really need any documentation. However, if you write code where the variable names and context are as vague as this, and you intend to distribute it for others to use, do us all a favor and put in some comments.
Thursday, August 14, 2008
Monday, July 21, 2008
Furthering the cause.... oh yeah!
After a truly inspired computing weekend, I have this to show for it (see above). To the untrained eye, it probably looks kind of confusing. But to a dedicated computationalist, that's truly a beautiful sight. What you see there is a record of my first commit to an open source project! That's right, after years of taking advantage of the code that others provide, gratis, for the betterment of geeks and ordinary folk everywhere, I've now thrown a wee bit of my own code in the pot.
So what's it all about? Well, as you can see above, the project is called 'ruby-hl7'. No, it's not an incredible coincidence that it has the name 'Ruby' in the title. The project is written in a computer language called 'Ruby' that I've been becoming a fan of (but you can imagine why I started looking into said language to begin with). Anyway, it's a project to make it easier to parse HL7 interface messages (like the ones that carried your medical record from Dr. Johns office to the hospital, the last time you decided to pet a cute-and-innocent-looking dog over the picket fence which was really designed to protect you from it and not vice-versa) using the Ruby programming language. Exciting stuff, eh? And I found this project to be lacking in one or two small ways so I fixed it up and sent the code off to be included in the project, which it now is!
Anyway, contributing to an open source project is fun, and much less intimidating than I thought, and I plan to be doing more of it soon.
On a totally different note, but also part of my weekend geekout, I have made some serious progress on Tim's photography website, and once I include his latest round of changes I'll get it up so that y'all can get a look at it.
Anyway, please read my prior post as well, and get on Twitter!
Binary
Thursday, July 17, 2008
"Got damn Summer" said the bitter old man, "this ain't a damn freeway."
Summer is just flying by, fortunately I've been able to grab a little bit as it fell of that big grimy truck called 2008. A trip to South Carolina, skydiving, wakeboarding in Virginia, a beautiful 4th of July, numerous moped and bike rides and a few good swims. Then there's the bad stuff: Moomin's funeral, weed wacking the yard, and the ever ominous gas prices making life a little bit more difficult for everybody.
That's right, I've gone and gotten me a twitter account! I just know that twitter is going to be the cement that fills in the gaps between the bricks in the windowless wall that I call "sharing myself with the world". And thus I will try to increase my communication with the people I know and love, and that communication will be at three different levels:

I started this blog with the intention of helping anyone interested in keeping up with my life, but as time goes by I find it harder and harder to do squeeze doing ANYTHING into my already busy summer schedule, least of all writing about the things I've already done or am planning to do! Not to mention I have a habit of procrastinating on the blog until I've already told just about everyone in my life about these things. At that point, I have the nagging compulsion to fill in my blog only because I feel bad for it, much as I feel bad for discarded stuffed animals on the side of the road. I know blogs don't have feelings, but I can't help feeling bad for my own poor neglected blog.
Well, I've decided to revamp my entire communications structure, and anyone who's anyone on the 'net these days know's exactly where I'm going with this:


That's right, I've gone and gotten me a twitter account! I just know that twitter is going to be the cement that fills in the gaps between the bricks in the windowless wall that I call "sharing myself with the world". And thus I will try to increase my communication with the people I know and love, and that communication will be at three different levels:
Level 1) "What's happening?" - Want to know "what's happening" with me? Just follow me on twitter and you'll see. Twitter, for the uninitiated, is a site where you can post short (less than 140 character) messages (called 'Tweets') about your day and about life. Others can follow your updates and thus, keep up with you in a much-closer-to-real-time way, almost like one-way mass instant messaging. My twitter account name is binary011010.
Level 2) "What'cha working on?" - That's what this blog will be used for, my computerized projects and other endeavors will be posted on here, a logical place for an avid technophile.
Level 3) "We need more" - Need more of me, well for that I'll be falling back on the old mainstays: Phone calls, email, visits and yes even snail mail. It's my intention to reenter the real world one of these days, and I'll use these means as a start.
So expect some changes in the coming days. In the meantime, here's a picture of me with a baby... awwww.
Level 2) "What'cha working on?" - That's what this blog will be used for, my computerized projects and other endeavors will be posted on here, a logical place for an avid technophile.
Level 3) "We need more" - Need more of me, well for that I'll be falling back on the old mainstays: Phone calls, email, visits and yes even snail mail. It's my intention to reenter the real world one of these days, and I'll use these means as a start.
So expect some changes in the coming days. In the meantime, here's a picture of me with a baby... awwww.
Friday, May 9, 2008
You can't just read the headlines
An iGoogle or Pageflakes account is a great thing to help keep up with the ever changing world of the web. I use my iGoogle to keep track of my todo's, the news, and to make frequently accessed net services less of a chore to access. But as with any news service, you can't just read the headlines. If I had this morning I could have been left seriously misinformed...

Anyways, stay tuned, I know I've been neglectful but I've got plenty of new stuff to write about... my recent trip down to Pawtucket, skateboarding season returns, new forms, and plenty of that sweet programming goodness that everyone has been begging me to write more about. I promise a real update is coming very soon.
Anyways, stay tuned, I know I've been neglectful but I've got plenty of new stuff to write about... my recent trip down to Pawtucket, skateboarding season returns, new forms, and plenty of that sweet programming goodness that everyone has been begging me to write more about. I promise a real update is coming very soon.
Friday, April 18, 2008
The saga continues...
Just a little post to make your afternoon a little more interesting.
![]() | The Legend of Zelda: The Lampshade of no real significance - Get the lamp to the temple |
Wednesday, April 2, 2008
A good week to be a girl named Ruby.
Beep beep! My baby's got it going on!In case word hasn't made it all the way around the blog-o-sphere yet, this little lady finally got her long awaited acceptance letter! She is now mere inches away from fulfilling her dreams.... and let's face it, the fantasies of every little boy in need of a tonsilectomy or routine physical! That's right, this little bit of trouble is going to be a nursie. Go darling!
And of course this kind of life change is gonna require a smoking set of wheels. Ahhhh, the 2005 Yamaha Zuma. 49cc of raw, highly fuel efficient and quiet, horsepower. Hot Damn! Well we are both going to miss trying to cruise around on the Puch Magnum, but it really was time for a bike with slightly lower odds of dying mid-intersection.
And with all the present excitement, it's hard to conceive what good fortune appears set to arrive in the near future! Come this June, Ruby, myself, Mother Melissa and Little Shea will all be heading down to visit their kinfolk in South Carolina. Surely a great family reunion will be had, not to mention that I will be experiencing a place (the South, yes the real South) and most likely a lifestyle that I really haven't seen before. Now I know what you're thinking: 'Binary, you bag on the South all the time.' Yes, it's true, I do and I won't deny it; however I'm willing to keep an open mind and I think that maybe, just maybe, a few Cicadas, Crocodiles and Confederate flags might do this Yankee elitist a little good.
Oh, and speaking of foreign lands, it appears that my sweetie is going to get the opportunity to travel to the land of her forbears after all. We are
now in the planning stages of her trip to Vietnam! She is in final preparation for starting to get her passport application under way, and has kicked off what will surely be remembered as the most successful and lucrative spare changing operation in human history. We are also developing plans for an arts and crafts auction, and with any luck will not have a repeat of the horrors of the tour fundraising summer from Hell. I'm sorry to even have to bring that up, but I do have good reason to. No one wants to see a sequel to that Three Stooges Without The Laughs episode; so if anyone out there has any great ideas that don't involve, you know, sacrificing our dignity or selling our souls, please please share 'em.Dreaming of a Christmas in Ho Chi Minh City. A place where the N is presumed to come before the H (and not the other way 'round). Ahhh, it's a good week to be a girl named Ruby!
Live long and prosper,
Binary
Thursday, March 27, 2008
Anatomy of a DCS Release
I've been doing these DCS software releases for a while. Now that I have a blog, I thought it might be interesting for people to know what I mean when I say I'm doing 'a release'.
Thursday, March 27th 2008:
9am - 6pm : Finish cleaning up a few last minute issues. Phone conference to make sure we are 'go for launch'. We are. Do the final builds on the development and beta machines, and pull down the beta code which will be moved to the production server. Dump all data from development to be moved to production. Drop everything up on the production server. Just another day in the life...
6pm - 8pm : It's Ruby's late night at school, so it's my night to make dinner. First, clean the dishes. Check the supplies and we don't have any pizza stuff, so I take a walk down to Market Basket and get the necessary goods. No time for Kung Fu class tonight. Make pizza. Do a load of Laundry. Gotta love a productive evening anyway.
8pm - 9pm : An hour to kill before the release really starts. Go outside and run through Tai Chi and Kung Fu forms a few times. Watch a half hour of Ashton Kutcher's new show. Not impressed. Make cup of coffee #1 for the night.
9pm : The release really begins. Users are still on production server. Disable logins so no more go on. Do backup of Demo server. Do code import on Demo, update Demo website, then run database conversion code. Done in no time at all. Demo's done, beta's done, dev's done. Only production remains.
9:45pm : Everyone's off of production. Do a backup of production and stop the website. Backup completes by 10:00. Estimated Bed Time: ~12:00. Overly optimistic? Probably.
10pm : Break out the new code for production and begin the import. This is the longest part of the night. Update the production websites and play a game of Backgammon on the Nabisco SnackWells website. Backgammon is MY new game. I house the computer player, obviously.
11pm : Notice in the production import log that the integrity checks found some errors. Nothing to worry about, I've seen errors in there before and the system always cleans them up. Play around with some AJAX stuff in my ongoing project. Killing time.
12am : What the hell? The pre-import integrity check is still running? How can that be? Oh god, after the system cleaned up the errors it ran the integrity check again. It's going to be a long night.... Make cup of coffee #2. Estimated Bed Time: ~1:30. It's possible.
2am : Import is almost done.... c'mon baby. Two more games of backgammon down. 1 went to Nabisco, the other to me.
2:20am : And the import is done! Wow, that must have been the longest to date. Now to take care of survey setup and other configuration business.
3:40am : Finally wrapping it all up. Basically took about an hour to do all the remaining setup after the import was done. Probably could have taken about half the time but I'm tired. Better luck next time!
Thursday, March 27th 2008:
9am - 6pm : Finish cleaning up a few last minute issues. Phone conference to make sure we are 'go for launch'. We are. Do the final builds on the development and beta machines, and pull down the beta code which will be moved to the production server. Dump all data from development to be moved to production. Drop everything up on the production server. Just another day in the life...
6pm - 8pm : It's Ruby's late night at school, so it's my night to make dinner. First, clean the dishes. Check the supplies and we don't have any pizza stuff, so I take a walk down to Market Basket and get the necessary goods. No time for Kung Fu class tonight. Make pizza. Do a load of Laundry. Gotta love a productive evening anyway.
8pm - 9pm : An hour to kill before the release really starts. Go outside and run through Tai Chi and Kung Fu forms a few times. Watch a half hour of Ashton Kutcher's new show. Not impressed. Make cup of coffee #1 for the night.
9pm : The release really begins. Users are still on production server. Disable logins so no more go on. Do backup of Demo server. Do code import on Demo, update Demo website, then run database conversion code. Done in no time at all. Demo's done, beta's done, dev's done. Only production remains.
9:45pm : Everyone's off of production. Do a backup of production and stop the website. Backup completes by 10:00. Estimated Bed Time: ~12:00. Overly optimistic? Probably.
10pm : Break out the new code for production and begin the import. This is the longest part of the night. Update the production websites and play a game of Backgammon on the Nabisco SnackWells website. Backgammon is MY new game. I house the computer player, obviously.
11pm : Notice in the production import log that the integrity checks found some errors. Nothing to worry about, I've seen errors in there before and the system always cleans them up. Play around with some AJAX stuff in my ongoing project. Killing time.
12am : What the hell? The pre-import integrity check is still running? How can that be? Oh god, after the system cleaned up the errors it ran the integrity check again. It's going to be a long night.... Make cup of coffee #2. Estimated Bed Time: ~1:30. It's possible.
2am : Import is almost done.... c'mon baby. Two more games of backgammon down. 1 went to Nabisco, the other to me.
2:20am : And the import is done! Wow, that must have been the longest to date. Now to take care of survey setup and other configuration business.
3:40am : Finally wrapping it all up. Basically took about an hour to do all the remaining setup after the import was done. Probably could have taken about half the time but I'm tired. Better luck next time!
Subscribe to:
Posts (Atom)

