86 likes
·
3.4K reads
13 comments
Quite ironic of you to mention the Line of Sight rule and then present the code examples in one line.
Absolutely not intentional. Not sure why but something has removed all of the code formatting.
I've fixed this now - thanks for highlighting the problem!
Nice article!
I agree that else statements are problematics, hard to read as you mention. But I'd go one step further and remove IFs altogether!!
Without IFs there are no elses!
"Lack of context" is an important bit! I should be able to tell what the code does without all this branching that you have to read from the bare top.
Absolutely! It's a hard concept to explain in small snippets of code, as they are often really easy to read. I'm glad you agree though, and thanks for taking the time to read the article.
Very interesting! I also dont like it to use else statements except in ternary expressions.
Hey. Thanks for taking the time to read the article. I'm glad you enjoyed it - and glad you feel the same way :)
Things become a little trickier with languages that do not have early return, such as Elixir ;)
Absolutely. I've no experience with Elixir, but I had to caveat it for Scala (which has early returns, but they are discouraged).
This is not good approach. There is only one sufficient principle in the craft: Every tool has its purpose and do not use a tool for a wrong purpose.
Not using a tool at all protects you when you do not know its purpose and how to use it properly. Also not using a common tool just to be protected from ignorance tells about amount of ignorance.
Hi Bojan. I'm sorry to hear that this didn't strike a chord with you.
It's a dangerous argument you go down. I'm not saying that they have no purpose - they clearly do. Instead, i'm trying to illustrate that there are better alternatives for where they would normally be used.
I've not come across places where my code would benefit from else
statements.
Douglas Parsons That's the sad part. ;)