" /> kasia in a nutshell: April 2005 Archives

« March 2005 | Main | May 2005 »

April 30, 2005

Variable length redux

When I posted this entry I never expected it to turn into a long discussion. It was really more of a rant born out of frustration when trying to read someone's code. I don't have much to add other than what is posted in the previous entry, but I thought Burt's (who is a former co-worker, a good friend and an excellent programmer anyone would wish to have on their project) comment deserves to be in an entry all on its own. He explains much better than I why this is even an issue. For context, read the previous entry and all the comments first.

Golly.

This is not a religious war - this is clearly a difference of opinion between people who have different ideas of what clarity is.

There's several key aspects of clear programming that some of the people here are missing:

1. Methods should NOT be 10 miles long. If you need a long variable because you don't reference it until 50 lines later or you don't know what type 'rval' is because the method declaration is 5 pages back in your editor, the problem is with your method, *not* with the choice of name. And in fact, something like rval *is* very clear. After looking at 50 methods all where rval is returned, it becomes pretty damn clear that when you set 'rval', you're setting what is returned. If some uniquely named thing is returned from every method, there is an order of magnitude more effort identifying what is returned.

2. Formatting *is* important. As Mats mentioned, the human brain is great at pattern recognition. If this causes you a bit more effort when you modify code, too bad. Code is read MANY more times than it is edited - Paul, are you suggesting that we should the tradeoff of legibility vs. ease of writing should be made in favor of ease of writing? Shame on you!

I'd say that formatting is even more relevant than the length of the variable name. The clear organization of her example was more important than the length of the variable names - but the shorter length of the variable names enables such clear organization more than variable names such as preparedStatement, jdbcDatabaseConnection, queryResultSet and objLongAss. In addition, your brain's time to process will be proportional to the length of the name, as will the effort to match the pattern. Which is quicker? Finding 'rval' in ( ps, rval, conn, rs ) or finding 'customerObject' in ( customerQuery, customerObject, connection, customerQueryResults )? Furthermore, there is an inherent loss of clarity when you have to break a single statement into multiple lines because you are doing something like

PreparedStatement selectCustomerPreparedStatement = c customerDatabaseConnection.prepareStatement(selectCustomerSQLString); ResultSet selectedCustomersResultSet = selectCustomerPreparedStatement.executeQuery();

3. The aptly-named Aristotle there was 100% spot on. If I'm writing a loop, give me an actual reason to use a giant variable name as a loop index. Since the loop should fit on the screen, i.e. be no more than 5-10 lines, it should be pretty damn clear that i is the loop index - I really don't need something like intLoopIndex to tell me that. If you're finding yourself scrolling back and forth to check variable names and types, you've gone past the point where it's time to refactor a chunk of code into another function/method.

5. Don't knock the C programmers. There's a lot to be said for typing efficiency, and there's a reason why many unix commands are 2 characters or so. Frankly, I am less concerned about there being a slightly longer learning curve for people than I am about treating senior developers as fools, and I am greatly concerned about the effect of 'point-and-click' programming on the capabilities of developers.

6. WHAT THE HELL HAPPENED TO COMMENTING YOUR CODE?! Yes, the code should be clear. But it is your responsibility as a developer to write clear comments! The clearest variable name in the world will still not tell you WHY something was done. I (fruitlessly in many cases) look to the comments for purpose, not to the variable names.

Anyways, I agree with Kasia 100% on this, though I fear it's a losing battle given the vast preponderance of 'helpful' IDEs these day - observe pbw's comments about the editor 'fixing' the code formatting. Great, just what I need, yet another tool that thinks it's smarter than I am.

April 26, 2005

A completely and utterly irrelevant coding practice that drives me nuts

Long variable names. Hm, not quite.. unnecessarily-long variable names (there are very legitimate reasons why someone would sometimes use a long variable name.. that is not what I'm bitching about).

An example of that would be.. say, this completely-fictional-but-reality-based code snippet:

Connection connection = getConnection();
ResultSet resultSet = null;
PreparedStatement preparedStatement =
connection.prepareStatement(some_query);
SomeLongAssObject someLongAssObject = new LongAssObject();

//blah blah blah

return someLongAssObject;

I see code like that and my blood boils over. Yes, I know I'm anal and there is nothing really wrong with writing code like this.. except.. well.. it's hard to read! It's sloppy and, let's not forget, badly formatted.

Same code as above as refactored by the queen of anal code:

Connection        conn = getConnection();
ResultSet         rs   = null;
PreparedStatement ps   = conn.prepareStatement(some_query);
SomeLongAssObject rval = new LongAssObject();
//blah blah blah
return rval;


Now isn't that better?

Who is onevoice.org?

I got spammed today by some website called onevoice.org. Now on surface, that would appear to be some well-meaning grass-rooty type of place trying to help the little guys be heard.. What makes me suspect it's more like astroturf is well, the whole spamming me thing. The email came from a residential Road Runner IP in Texas.. (spam warning right there) using Eudora Internet Mail server the demo version of all things.. Unless that last bit of info was spoofed. It's easy enough to do.

I decided to do a little bit of google investigating just to see what this is all about. Surprisingly, there is actually very little to be found on google about these guys. The current "about us" page lists a Edie Littlefield as "Executive Director". Not much on google about her either.. I decided to call the phone number listed on the domain. It's in San Diego and manned by an answering machine professing to belong to a Dale Sundby. Google produced quite a bit more information for this person .. and if it's the same guy (San Diego bit matches at any rate) so did Forbes. At some point, he appears to have been the Chairman and considering he paid someone to design the website, he mostly likely funded it as well.

None of this says much of anything.. but when a "grass roots" website starts to spam people and usenet it's a little suspicious. Particularly if they're fronted by someone who is obviously net-savvy.

Curious.

April 24, 2005

The California trip round up

  1. Delta left my suitcase in Atlanta. For no reason, my co-worker's (who was on the same flights) bag made it to San Jose just fine. So I got to use crappy "complimentary" Delta toiletries and do laundry my first day of the trip. They did deliver it the next day, so it worked out okay. I'm just glad I didn't put the laptop I needed for the class in the suitcase... as I was seriously thinking of doing.
  2. I can now write bpel processes in my sleep. Literally. Had a whole nice, long dream about doing just that. Is that a sign of good training?
  3. Oracle classes had no Internet access so I actually had to pay attention and find ways to break the software (at least 3 found!)
  4. Hotels would make more money on in-room Internet access if their free lobby wireless didn't work on the 5th floor. Suckers.
  5. I met a drunken guy in the hotel lobby who claimed to be the Oracle VP of training from Virginia and talked much about...
    • Processors that run at 30ghz and are hotter than the surface of the sun and have to be water cooled.
    • His Datacenter receiving the "most green datacenter" award because they produce more energy than they use (those hot cpus above)
    • Machines will soon rise against us, since we're the only thing keeping them from never being broken. They self-fix.
    No, I didn't ask if he ever passed high school physics, he was buying us drinks and providing free entertainment after all.
  6. I can now say I have seen the most useless device ever. A laser pointer that plugs in your ipod. I can totally visualize the meeting that culminated in this fine product:
    - yo man.. I have this cool idea...
    - ...
    - Get this man.. a laser pointer that plugs into the ipod!
    - ...
    - .. and a flashlight!!
    - dude..
    - yah.. I know man.. pass the bong.
  7. The only fun part of the "MySQL Quiz" at the MySQL conference was heckling them from the (very small) audience.
    "What does B in MySQL AB stand for?"
    "Boring!"
    Maybe if they had better questions.. or prizes.. (see above).
  8. Someone on the plane was using Milton from "office space" as a ring tone. "Excuse me.. I think you have my stapler..". Half the plane burst out laughing.. speaks well of them.
  9. After using my work windows laptop for a week.. I really appreciate my powerbook.

A nice "welcome home"

I got home about an hour ago from my California trip to discover my mail server has been working overtime. Quick glance through the logs revealed tons of rejected messages to random email addresses.. reminiscent of a dictionary attack. But that wasn't it.. it's something much, much more annoying. See, dictionary attacks can be easily blocked. They normally come from infected machines in a limited address range and a counter-measure can easily be scripted.

This is something that essentially amounts to a DDOS attack against my mail server. A spammer used my domain as a return address on a lot of spam. Looking at the graph above, I would say this will only get worse before it gets better.

I guess time to setup SPF... although I doubt it'll help much here.

April 17, 2005

Packing my bags

I'm off to California tomorrow for a week to do some Oracle Training.. and no, unfortunately I do not have time to visit the MySQL conference, but I will probably drop by the O'Reilly party to hang out with some geeks.

April 10, 2005

Murphy's Law: the running edition

It was a beautiful spring day today in the bowels of Connecticut, which of course calls for an outdoor run in the park! I've only been running in the more-populated, asphalted and non-muddy lower reservoir up to now since it's been, well, too muddy to run in the less-populated, asphalt-lacking and much-more-fun-to-run-in upper reservoir. But today.. a beautiful spring day, been sort of dry for a while, snow has melted.. time to hit the upper reservoir! The "haven't been there since last fall" part becomes relevant soon.

Since I haven't been doing much running lately[0] I decided on one of my shorter routes [1].. say no more than 40 minutes or so. It was such a beautiful day though, that halfway through my run I decided to do an additional little loop and head towards the center of the park to circle a lake. That's where I ran into a scared little old lady. She had a hiking stick, a hat and looked close to tears. She hiked all the way from the lower reservoir (some 3-4 miles at a guess) and was lost[2]. I tried to explain to her how she can get back to the main (blue) trail.. but it was confusing even me, so decided to walk her there. It wasn't too far off my route and I felt bad for her. After she was well on her way back to her car and much more cheerful I went back to my running.. except at this point I've been out much longer than planned, with no water on a very sunny day and was a little scared I'd run out of steam before getting back to my car.. so decided to take a short cut.

Yes, you guessed it! About 15 minutes after helping someone else find their way out I was hopelessly lost myself! Well, that's a bit of an exaggeration... but it wasn't until I hit the pipeline trail that I realized that instead of heading closer to my car I managed to head in the exact opposite direction.. So instead of running for 40 or so minutes.. I ended up running & hiking for well over 2 hours.. my legs hurt!

[0]I really cannot stand dreadmill running and am too chicken to run among cars on the street.. hence I only run in the park which is hard in winter. The park isn't plowed.. so in winter it's mostly non-usable for running. Unless someone is really a masochist and can pick out trails without seeing any signs of them.

[1] Upper reservoir is where I tend to do my longer runs, since the shortest commitment is at least 3 miles.. well, unless one turns around.

[2] It is really easy to get lost in that park.. it has some 50 miles of trails and most look the same. There are only trailblazers on the mail loopy trail.

April 09, 2005

Point to ponder

As you travel through space faster your travel through time decreases.. and vice versa, right? Wouldn't that mean a body in freefall (therefore not traveling through space) is traveling through time at fullest possible speed.. therefore should age faster?

Code Coverage: so that's what I've been missing!

I know, I know.. every single comment I'll get to this post is "what? You've never used a code coverage tool before?".. but it's true.. I've never actually used a code coverage tool before.. It just never came up on any of my projects and none of my previous co-workers ever mentioned even the possibility of using such a tool... but.. well..

This so completely and utterly rocks. I've been using clover on our project at work and it's really very, very cool. I can tell exactly what's been tested properly, what hasn't and what unit tests I still need to write. The reports clover generates are quite easy to read and go down to source code level, so you can easily tell what's not tested yet (or what is just error checking).

Another tool I've looked at before we settled on clover is Emma. It's not as nice as clover (the reports are harder to read) but it works well and, best of all, it's open source.

Both tools work just fine as ant-tasks.

(I'm averaging at around 80% coverage on my unit tests for those curious).

April 07, 2005

Leave a voice message?

Why would anyone want to have the world at large (or just the Internet users) leave them a voicemail message? Why? Why? Why?

I keep seeing these "Skype me" buttons on blogs.. that's like hanging a sign on your door "ring and run, it's fun!"

You'd have to be either

(a) so enamored with anything new, scripty and techy that you don't even notice how asinine and useless it really is.

or

(b) Desperate for human contact, any human contact.. even a stranger's heavy breathing while he does god-knows-what on his end.

What's next, instant, virtual kick-me signs?

April 05, 2005

Note to self

1. It is far too easy to accidentally open every highlighted email in a separate little window using Apple Mail.

2. Quitting the app seems like a good idea to get rid of the 100s of windows (34 to be exact) but it doesn't work, they just open back up when going back to Mail (eating up CPU cycles and filling up RAM).

3. There appears to be no way to close all windows (or I just can't find it) or an option to not remember which bloody windows were opened when Apple Mail is quit.

grrrr

*click* *click* *click* x 34

April 04, 2005

Upgrades

Since the rest of the world has been running blogging software that is less than 3 years old I thought it may be time for me to catch up to 2004. So here I am, running (test testing testing 1,2,3) a new MT 3.15 installation. Really, not a hard upgrade, except for the one part where I tried to follow instructions.. I should have known better.. (I never read README files, I don't know why I tried it this time around).

Instructions say...


If you are upgrading from version 2.6, 2.61, 2.62, 2.63, 2.64, 2.65, 2.66 or 2.661
Run mt-upgrade30.cgi, then mt-upgrade31.cgi.

.. and script says...

It's a 2s perl hack to fix it.. but really.. (change 3.0 to 2.6 on line 47 in mt_upgrade30.cgi.. then again in mt_upgrade31.cgi)

So now that I'm running this spiffy new version of MT (and it is spiffy) it's probably high time I should redo my templates... and that ugly css file.. and those hideous category archives.. and.. er.. the whole site really.

You may also notice my blogroll is gone.. I've been using blogrolling (mostly out of laziness) and since I liked it, I made a donation a while ago, well it seems they've gone pay service and chose to bombard me with daily "upgrade now! expiring! mayday! mayday!" messages.. That's annoying, so I'll have to work on something all by my scripty self.

Time switch (again)

I like daylight saving time.. it saves daylight! Well, I like the longer days anyway. At least it raises the possibility of going for a run in the park after work (naturally, not the actuality of it). What I don't like is the switch -- it throws my inner clock out of whack, and frankly, I'm not a morning person.

If daylight saving time gives us more hours of daylight in the 'live-able' hours of the day therefore saving electricity, sanity and calories.. why the bloody hell don't we just stay on it? Why switch (by which I mean switch-back to non-DST)? Let Arizona and those other backwater states stay in their timewarp and the rest of us can enjoy nice evenings full of sunlight.

April 01, 2005

Tired of Yahoo News ads?

Not that I really ever notice them, but discovered just today that adding any special character (: ; ^ etc) at an end of any yahoo news url gets rid of all ads on the page. Neat.

Observe a normal url:
The Pride of CT Goes to Prison

Same url wtih a ; at the end:
The Price of CT Goes to Prison

Probably won't last.. but good to know for copy-pasting news items for now.