July 18th 2013

select a.Name, b.Status from a
inner join b
on b.ID = a.StatusID

Do you write readable code? Are you sure? The chances are, unless you're me, you don't.

Take a gander over to this admittedly old Stack Overflow question.

The original poster wanted to know whether the order of the fields referenced in the ON clause of a JOIN matter. The answer, quite simply, is that it doesn't. But read through all the actual answers. What theme do you notice?

I count 4 replies that talk about readability, directly or indirectly. And, what I find funny, is that several of those readability replies contradict each other. One person says "it makes better sense to reference the variable in the same order they were declared" and another person says the exact opposite and doesn't even give a reason beyond "readability". One person gives a reason that makes no sense and a final person talks not only about the readability of ordering your ON clause correctly, but also the importance of adding tabs and line breaks.

The truth is, there's no such thing as readability. I write my code my way. You write it your way. I find it easier to read my code than your code, so of course my way is more readable than your way. Your way is unreadable to me, so it must be wrong. And that's something we can all agree on.

(PS: I'm not against standards agreed upon with the people you work with. If you work with someone whose code you read a lot, it's nicer if you follow the same conventions.)

Go back...

Visitor Comments

Post Your Own Comment

Note that comments may not appear immediately on this site.

Commenting is not available in this channel entry.