TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Structured programming: how to write proper if statements

4 pointsby harporoederover 4 years ago

2 comments

redwolf22over 4 years ago
I disagree. Using this technique will lead to more cyclomatic complexity. I aim to write small methods and readable code. In small methods, there is no problem using early returns. Early returns will also help in the readability, because you can stop reading as soon as you realise, that the method returns here, whereas you have to read the whole method in order to know if some other code is executed.
评论 #25789480 未加载
Kim_Bruningover 4 years ago
Lots of extra comments here:<p><a href="https:&#x2F;&#x2F;lobste.rs&#x2F;s&#x2F;z17zyg&#x2F;structured_programming_how_write_proper" rel="nofollow">https:&#x2F;&#x2F;lobste.rs&#x2F;s&#x2F;z17zyg&#x2F;structured_programming_how_write_...</a><p>Like several of the commenters there, I also think that early returns are actually a good pattern. (I also happen to think that throw and yield are perfectly fine. )<p>If you know that your method is never going to work out anyway today, abort immediately. Don&#x27;t hang around!