My Secret Life as a Spaghetti Coder
home | about | contact | privacy statement
Is your code littered with checks for types and nulls? Don't get me wrong, now - coding defensively is quite alright:

some_number = get_user_input()
if( is_numeric(some_number))
  some_number_plus_3 = some_number + 3

So is a bit of polymorphism:

def function(input)
  input = input.join("") if(input is an array)

With that you can treat arrays and string inputs the same. (This comes from an example where I actually wanted to do the opposite, in messing with Smith-Waterman.)

Maybe you have certain default parameters to your program and you'd like the ability to override some of them with a tag in an XML file, as I was doing recently. You get an XmlNode xnode by searching the XmlDocument for that tag. Then, if xnode is null, you use the default.

But if you are constantly checking types and asking if some_variable isNull? to the point at which the signal to noise ratio is so low as to be annoying, your code might be irrationally fearful, anxious to the point of delusion. You might even ask if the time has come for it to visit a professional trained in treating paranoia.

Is your code paranoid? Or am I just too liberal with mine? Thoughts below are encouraged.

Hey! Why don't you make your life easier and subscribe to the full post or short blurb RSS feed? I'm so confident you'll love my smelly pasta plate wisdom that I'm offering a no-strings-attached, lifetime money back guarantee!

Leave a comment

this is why you create a class and do all your checking an validating in the class itself so you don't have all this business logic all over the place. plus you look less paranoid and more geekish.

Posted by tony petruzzi on Oct 02, 2007 at 05:31 PM UTC - 5 hrs

I find that when i code "too" defensively I can end up covering up bugs that I'd rather be finding.

Posted by Joe Zack on Oct 02, 2007 at 06:31 PM UTC - 5 hrs

I tend to think a bit like Joe. I make an effort to distinguish the scenarios that really might happen from those that I think are highly unlikely. It's hardly scientific, I admit, but it keeps me from being ridiculous. And if I'm wrong - especially about the places where I don't think it's likely and it happens anyway, the fatal error tells me right away.

Even more ghastly...sometimes I intentionally avoid error handling for the same reason. There are just some places where, if there's a problem, I want to no about it immediately and in no uncertain terms.

Posted by Rob Wilkerson on Oct 02, 2007 at 07:03 PM UTC - 5 hrs

Tony - funny you mention that, I had written the same earlier that day!

Joe - Do you have a concrete example where that happened? Are you talking about something so paranoid as try/catching your entire program?

Rob - I think we're on the same page there.

Is there a place it turns from anti-paranoia to sloppiness though?

Posted by Sam on Oct 05, 2007 at 09:00 AM UTC - 5 hrs

Leave a comment

Leave this field empty
Your Name
Email (not displayed, more info?)


Subcribe to this comment thread
Remember my details

Picture of me

.NET (19)
AI/Machine Learning (14)
Answers To 100 Interview Questions (10)
Bioinformatics (2)
Business (1)
C and Cplusplus (6)
cfrails (22)
ColdFusion (78)
Customer Relations (15)
Databases (3)
DRY (18)
DSLs (11)
Future Tech (5)
Games (5)
Groovy/Grails (8)
Hardware (1)
IDEs (9)
Java (38)
JavaScript (4)
Linux (2)
Lisp (1)
Mac OS (4)
Management (15)
MediaServerX (1)
Miscellany (76)
OOAD (37)
Productivity (11)
Programming (168)
Programming Quotables (9)
Rails (31)
Ruby (67)
Save Your Job (58)
scriptaGulous (4)
Software Development Process (23)
TDD (41)
TDDing xorblog (6)
Tools (5)
Web Development (8)
Windows (1)
With (1)
YAGNI (10)

Agile Manifesto & Principles
Principles Of OOD
Ruby on Rails

RSS 2.0: Full Post | Short Blurb
Subscribe by email:

Delivered by FeedBurner