Why I Don't Use Else When Programming

Web Dev Simplified · 1.3M views · 2021 · 10:18

Open on YouTube

Software practice, open source & careersSoftware architecture & designWeb developmentexplainer

Why Stack Overflow recommends it

Stack Overflow users link it when explaining or defending else-less coding style, such as guard clauses and early returns, in comments on code that avoids else.

Recommended by 2 people across 2 different months, 2022 to 2023.

What it is

A 10-minute video from Web Dev Simplified arguing that avoiding the else keyword leads to cleaner code. It covers guard clauses, why a single return statement per function is not always good, and extracting logic into separate functions, with JavaScript examples.

What people said

Recommends Austin France · 2022-02 · Stack Overflow · on “Please do I interprete this ternary operator?”

@Stef I would encourage anyone reading to consider this programming style. Our company has adopted it and it makes code much simpler and easier to understand. [this video]

Recommends ruvim · 2023-10 · Stack Overflow · on “A weird problem in Forth when printing out the data stack and floating-point stack”

The reason of divergent behavior in your code is as follows. In the case of the data stack: i depth 1 - < i places a number on the data stack, and this number is counted in the result of depth . And 1 - eliminates this contribution of i . In the case of the floating-point stack: i fdepth 1 - < \ creates the error in the formatting i places a number on the data stack, and this number is not counted in the result of fdepth (since it counts the items on the floating-point stack only). To make behavior in the second case as in the first case you have to remove 1 - , as: i fdepth < Or you can change both variant as follows: depth i > fdepth i > (I.e., place the depth on the stack before placing o

Cites Barmar · 2022-06 · Stack Overflow · on “Bot responding multiple times to a message based on the amount of trigger words discord.py”

@Benjin Yes, although some believe that else-less programming is a feature, e.g. [this video] I'm not a total convert, but since the code in the OP was written in this style, I maintained it to solve the problem.