DEV Community

Discussion on: Why I Prefer Simple Code Over "Smart" Code

Collapse
 
dariomannu profile image
Dario Mannu • Edited

It's hard to completely agree, unfortunately, and this is why:

First off, there's no definition of "simple" we can all agree on.
I've met people who'd rather call a repetitive piece of code "simple" over a for loop!

BTW: I'd use map/reduce instead of your for loop, and still call it both "clever" and "simple" and "maintainable".

total = cart.items
  .filter(i => i.available)
  .map(i => i.price *i.qty)
  .reduce((a, b) => a+b, 0)
Enter fullscreen mode Exit fullscreen mode

"Understandable"? Everyhing can be understandable... but some people may need to learn an extra thing or two. Today, we still have many who struggle with Futures and others who believe Observables are "unnecessarily complicated".

I (who spent a lot of time on them), say that using Observables is much "simpler" than NOT using them. So? Where's the truth? I say "simpler" because I know exactly what real-life complexities do Observables solve and how much repetition (=error risk) comes with alternative patterns. Someone who's not aware of those aspects will say Observables are overkill, or stuff like that.

Also, what's the definition of "clever"? Putting everything in one line? When C was born, we used to have fun creating all sorts of a[b++] += ++c *(d=10) and call that clever (or rather call ourselves clever for being able to read and write things of the like.

Then functional programming came along and we learnt that the worst part of code like this is side effects. We also learnt separation of concerns, architecture, etc, so we know exactly why that code was in fact not clever at all.
We may now call clever a different type of code. We could go on explaining why, and those who know the patterns we do would probably agree, whilst others would not.

And... you'd think is simple as that? Try comparing different paradigms. What is simple and clever in one, turns out terribly complicated (to imitate, replicate, etc) in another. Two typical paradigms that fight all the time are imperative and functional...

So.... this comment is growing too long, so I'll conclude with a "simple" goodbye! 👋

Collapse
 
sareena_rahim profile image
Sareena Rahim • Edited

Thank you for your time and for sharing such a thoughtful perspective.

I agree that “simple” and “clever” are highly contextual and depend a lot on experience, paradigms, and the problems we’ve learned to solve. Your map / filter / reduce example is a good case where abstraction can actually reduce repetition and error risk, and I can see why that feels both simple and maintainable to someone comfortable with that style.

For me, especially at my current stage, “simple” mostly means immediately readable and easy to reason about when I come back later. It’s less about the number of lines and more about lowering cognitive load for my future self. That’s why I tend to prefer explicit loops while I’m still building confidence and intuition.

I think that’s what makes this discussion interesting,what feels simple evolves as our understanding deepens. Your comment adds valuable nuance, and I appreciate you taking the time to explain your viewpoint