Contents tagged with style

  • Returning to multiple exit points

    My blog post on multiple returns and why they are actually quite useful has a small but enduring popularity (some of it negative) among those who obsess over minutia. Yes, that includes me sometimes.

    For instance this blog post, which argues for single returns, with an example where a single return is better.

    Continue reading...

  • Deep indentation is still bad and wrong

    I wrote a while back about how indenting trailing lines of code to match some semantic element of the line above was bad and wrong - it's inconsistent and hard to maintain, not to mention hard to get right initially and generally makes code harder to read unless you have a very wide screen. Continue reading...

  • The single exit point law

    It is sometimes said that a method should have only one return statement (i.e. one exit point) and that to code using more than one return per method is bad practice. It is claimed to be a risk to readability or a source of error. Sometimes this is even given the title of the "single exit point law".  Actually, if you want to call something a law, I'd expect some evidence for it. I do not know of any formal study that back this "law" up, or of any study of the multiple-return pattern at all. This makes it a "preference" not a "law". And it's a preference that I do not hold for c# code. Or java, ruby or python code either. Continue reading...

  • Indentation of trailing lines of code

    I'd like to blog about a point of code indentation. I have a strong and unusual opinion on this topic, that the way that most people do it is ... less than best.

    I suspect that about half of the readers will not want to read further, since they already know the right way to indent code (the way that they do it already, whatever that may be) and the other half won't want to read further, for fear of getting involved in the religious wars, lest the nits that I pick infest them too. But anyway, though de gustibus non est disputandum (that's Latin for there's no accounting for taste), consider the following as an option.

    Continue reading...

  • 1