26
The moment I realized I was nesting if statements all wrong
Working on a simple login script for my first project. Took me like 4 hours. Had 12 layers of if else nesting. My buddy glanced over my shoulder and asked why I didn't just use early returns. Didn't even know what that was. Showed me how to flip my logic and exit early. Cut my code in half right there. Anyone else have a basic concept that clicked way later than it should have?
2 comments
Log in to join the discussion
Log In2 Comments
ruby_sanchez459d ago
You saw a buddy go through this too? My friend was working on a user registration form and he had the same problem. He had like 10 if statements all nested. I showed him how to check for the bad stuff first and just return. He stared at his screen for a minute then deleted half his code. Felt pretty good watching him realize how much simpler clean code is.
8
umaprice4d ago
Stared at his screen for a minute then deleted half his code" - that's the best feeling, right?
5