loading...

Discussion on: Keeping your code clean by sweeping out "if" statements

thomasjunkos profile image
Thomas Junkツ

I think we share a lot. Mostly avoidance of nasty convoluted code. That said it follows that when we both would encounter "a more complex situation" we would do our best to deconstruct it into much more digestible parts.

But I do not share your implicit bias that an if-free version were implicitly clean. Especially when I read

I think that the cleaner way has a huge benefit

Which anticipates which solution is cleaner 😉

Good code is code which does what it should nothing more.

Thread Thread
tomazlemos profile image
Tomaz Lemos Author

I do think we share a lot, and it seems like this “if” matter is sooner or later part of the journey of developers who want to get better at writing good quality code.

I think that perhaps the main lesson here is that we should be able to choose how we’re going to write a particular piece of code, and this anti-if crusade is a way of discovering patterns that can be really useful, when many developers never question the “if” status quo and hence could have less tools to address good code requirements.

That said, the post is completely biased in that the if-less examples are cleaner, so it should really come at no surprise that I anticipated which solution I think is cleaner...

And last but not least, I do question your last phrase. I think most developers are really focused in making code do what they want, when the focus should be in writing code that tells you “what” it does.

So many times I have wasted precious time deciphering code only to realize it wasn’t the right place to work in.

I don’t really want to understand how the code works, unless I have to. I just want to take a look at it, understand what business rules it addresses, and see whether it’s the right piece of code to work with or not... If it is, then I’ll spend the necessary time understanding “how” it does it.

And I think the dictionary examples do make a better job at communicating the business rules.

I appreciate a lot being able to discuss this topic here, thanks 🙏🏼

Thread Thread
thomasjunkos profile image
Thomas Junkツ

I appreciate a lot being able to discuss this topic here

Yes. This discussion is good. And I find it is so on different levels. What I find mostly valuable is that it shows to others not being for so long in the industry that we aren't dealing with truths: We do things for reasons; and taking one or the other way has its own right. And that we both agree to disagree helps others to form their opinion on this topic.