DEV Community

Once you start writing a lot of code you're surely doing it wrong

Akuma Isaac Akuma on January 05, 2021

On several occasions, I've had a moment when very few lines of code solved an issue I was trying to solve earlier with very complicated or confusin...
Collapse
 
cyrilcabo profile image
Cyril Cabo

Fair point, but I guess this may mislead beginners into thinking that writing a lot of code is wrong or bad practice. Surely, there are cases (like this one), where you can leverage the language's perks, and be able to solve it with a few lines of code, but it is not always the case. I'm not trying to criticize you though, I just want to give a fair warning to beginners reading this. It was a good read, nonetheless. Good work!

Collapse
 
akumzy profile image
Akuma Isaac Akuma

You're not wrong, This is more like encouragement to maybe take a few step back whenever things become complicated or confusing and challenge yourself to seek a simpler way.

Collapse
 
phantas0s profile image
Matthieu Cneude

This is highly depending on the context. Sometimes you'll need "a lot" of code, sometimes you won't. No silver bullet here.

It's hard to get it your code right the first time, so here's what we should really do:

  1. Writing some code.
  2. Refactoring when you have more knowledge about the business domain / your functionality / other.

When you write something a bit consequent, you often write a draft first. It's the same for programming.

Collapse
 
akumzy profile image
Akuma Isaac Akuma

I agree

Collapse
 
ksaaskil profile image
Kimmo Sääskilahti

Good job showing how to write more readable and robust code by using the right tools for the job 👍 The first version could also be made more readable by defining helper functions to remove all that nesting?

Collapse
 
akumzy profile image
Akuma Isaac Akuma

Yeah, but that's will come after the implementation is being figured out completely

Collapse
 
ksaaskil profile image
Kimmo Sääskilahti

I respectfully disagree, I think it's better to write short functions with single responsibilities from the beginning. That makes refactoring a lot simpler and easier to see if the composed function is doing what it should. But that's just my experience 🙂

Thread Thread
 
akumzy profile image
Akuma Isaac Akuma

That's okay

Collapse
 
epsi profile image
E.R. Nurwijayadi

This is why we have Haskell.

Collapse
 
akumzy profile image
Akuma Isaac Akuma

Hahaha! I don't know Haskell and I'm sure it'll be overkill for web

Collapse
 
epsi profile image
E.R. Nurwijayadi

For web, there is purescript that very similar with haskell.

Something like this one
🕷 dev.to/epsi/purescript-playing-wit...

Purescript: Playing with Record

Thread Thread
 
akumzy profile image
Akuma Isaac Akuma

That's interesting, thanks for sharing

Collapse
 
sirseanofloxley profile image
Sean Allin Newell

In this case, less code is indeed simpler; sometimes, more code is simpler. Looking at you bit twiddling over optimized one liners...

Collapse
 
burdier profile image
Burdier

It depends on what you are doing at the moment.

Collapse
 
akumzy profile image
Akuma Isaac Akuma

🤔️ I never thought of it as clickbait

Collapse
 
xseman profile image
Filip

I personally prefer more code, if it's more explicit and self explanatory with no needed for comments or documentation.