Early Return Is Not Great
Early return is actually not great Early return is probably the most underrated practice, even among experienced developers. // Instead of this func Do() { if cond_1 { // do stuff if cond_2 { // do more stuff if cond_3 { // do even more stuff } } } } // Do this func Do() { if cond_1 { return } // do stuff if !cond_2 { return } // do more stuff if !cond_3 { return } // do even more stuff }
A programming meme contrasts deeply nested conditional logic with an early-return style. The joke is that early returns are often praised as a best practice, but the post humorously argues that they are actually not great in this example, especially when the conditions are written negatively. EN: A programming meme contrasts deeply nested conditional logic with an early-return style. The joke is that early returns are often praised as a best practice, but the post humorously argues that they are actually not great in this example, especially when the conditions are written negatively.
social media post / публикация в соцсетиcode screenshot / скриншот кодаnested conditionals / вложенные условияearly return statements / ранние операторы возвратаcomputer programming / компьютерное программированиеdeveloper text / текст разработчикаblack interface / чёрный интерфейсwhite code panels / белые панели с кодомgreen comments / зелёные комментарии
- @gentoomemes / 14295 2024-10-26
- Type
- image
- Size
- 589×492 · 31.4 KiB
- Mood
- sarcastic, absurd
- Language
- en
- Added