Sign in
Log inSign up
Douglas Parsons

86 likes

·

3.4K reads

13 comments

Jack
Jack
Nov 11, 2020

Quite ironic of you to mention the Line of Sight rule and then present the code examples in one line.

3
·
·1 reply
Douglas Parsons
Douglas Parsons
Author
·Nov 11, 2020

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!

1
·
Maxi Contieri⭐⭐⭐
Maxi Contieri⭐⭐⭐
Nov 16, 2020

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!

2
·
Rodion Borisov
Rodion Borisov
Nov 10, 2020

"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.

1
·
·1 reply
Douglas Parsons
Douglas Parsons
Author
·Nov 11, 2020

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.

1
·
Dany Tulumidis
Dany Tulumidis
Nov 11, 2020

Very interesting! I also dont like it to use else statements except in ternary expressions.

1
·
·1 reply
Douglas Parsons
Douglas Parsons
Author
·Nov 11, 2020

Hey. Thanks for taking the time to read the article. I'm glad you enjoyed it - and glad you feel the same way :)

1
·
Paweł Świątkowski
Paweł Świątkowski
Nov 13, 2020

Things become a little trickier with languages that do not have early return, such as Elixir ;)

1
·
·1 reply
Douglas Parsons
Douglas Parsons
Author
·Nov 13, 2020

Absolutely. I've no experience with Elixir, but I had to caveat it for Scala (which has early returns, but they are discouraged).

1
·
Bojan Nišević
Bojan Nišević
Nov 11, 2020

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.

·
·2 replies
Douglas Parsons
Douglas Parsons
Author
·Nov 11, 2020

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.

1
·
Bojan Nišević
Bojan Nišević
Nov 11, 2020

Douglas Parsons That's the sad part. ;)

·