Lazy Developers?

When I was out with my new dog (I Chihuahua, wonderful dog), I was thinking about Defensive Programming and Design by Contract. I like to do some refactoring and help other people to write cleaner code etc,  not that I’m an expert in the area but I think most of developers can see stuff that blinds other developers during development. I remember a scenario that made me kind of mad, I often notice that some developers doesn’t even care to validate arguments on public API or other methods, they assume the caller pass in the right values. When I started to develop apps, I didn’t validate arguments (In know I was a noob ;)). But since I started to do validation, it reduces the number of bugs in my code, and the difference was big. But that isn’t the only reason I like to do validation. Another  reason is because the caller of the method should know if they have passed a wrong value, there are of course some other reasons also, but the main reason is make sure the caller or the method pass in the correct value, and if they do, they will get what they want.

I notice that several developers today don’t care about validation, I ask them why and they all gave me the same argument “Why should I, it will only make me add more code and it’s boring to write code that checks values”. Can this be summarized that some developers are lazy?

Maybe I’m stupid because I get mad when I hear that kind of argument, but I’m special ;)

8 Comments

  • You are not stupid, that kind of 'argument' not only reflects a lazy attitude, but also is disregarding the fact that adding appropriate validation will in the long run result in developers having to write less code; as validation is often a good defense against introducing bugs that inevitably will have to be fixed.

  • I think one big reason for this lazy thing is that most people learn from reading other peoples code and if validation is missing from most of the code samples it will not get through to the readers...

  • A former boss me told me that the reason I was better programmer then most she knew was that I where lazy, and tried to get the best code as fast as possible. I didn't agree with her, because I use a lot of time on refactoring my code until I have a certain degree of satisfaction.

    I believe that the reason that people tend to jump over the validation stuff is because the tools don't support validation out of the box.

  • I may be lazy, but I am also impatient. Which is why I'm a huge advocate of fail-fast programming, including always checking your parameters before you bother doing anything else.

  • Some developers are lazy, no doubt about it (I can be that too sometimes). What bothers me is how the laziness is often excused with arguments like "there was not enough time".

    For argument validation I usually use a utility class, for example:
    Guard.ArgumentNotNull("type", type);

  • Its not lazyness that makes the dev implement validation, its stupidity/ignorance/lack of competence.
    Its like not paying the bills, its very boring but the consequenses of not doing it is pretty bad.

  • I am certainly validating arguments on public methods. Do you validate on each and every method you add to your code? even the mst inner private methods?


  • Shahar:
    The most important part is the public methods which someone can call; most of my private methods will be created during refactoring. When a private methods is called from another method. The method which call the private method may already have done the validation of the arguments, so in that case the private method don’t need to do the validation.
    To use validation on every single method including private methods etc can affect performance, so it’s not good to overuse validations.

Comments have been disabled for this content.