“Any fool can write code…

“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.”

I found this guy while researching the use of var following a spirited debate with co-workers. (In case you’re wondering, I’m pro-var. Viva la var!)


Author: Adam Prescott

I'm enthusiastic and passionate about creating intuitive, great-looking software. I strive to find the simplest solutions to complex problems, and I embrace agile principles and test-driven development.

3 thoughts on ““Any fool can write code…”

  1. Hi Adam! Long time 🙂

    I always thought using var hindered readability, at least for someone new to the project. Example –

    var myVar = SomeNewMethod();

    A fresh developer doesn’t know what type myVar is, because they don’t know what type SomeNewMethod() returns. They have to swing into that function and now keep another ‘layer’ of the code in their head as they try to understand it.

    Of course there’s two sides to it – if the reader is experienced with the project and knows what type the method returns, then var would be more readable.

  2. Hey, Dan! 🙂

    I walked into the debate-in-progress, and a developer was saying, “Using var is just lazy.” I agree with this, but I don’t think it’s a bad thing–why write redundant info, like in the case of List names = new List()? I think var names = new List() is equally readable/maintainable, and it was quicker to write.

    So, I’m willing to forgive the “lazy” part, but then he said this: “Well, I shouldn’t say ‘lazy,’ they just don’t want to do it the right way.” That’s the part that set me off.

    I agree with your comment that “var x = DoSomething()” is horribly unreadable, but in my opinion, the problem here is the method named “DoSomething.”

    Look at a more reasonable example:
    var people = GetPeople()

    Okay, it’s a collection of people. Is it a List, IEnumerable, People[], Collection, ObservableCollection, IList? It doesn’t matter; it’s some kind of people container. In most scenarios, I’d say that’s probably readable enough.

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: