Is it normal for my code to be long?

Let me explain what I mean by “long”.

I’m currently working on the cash register project for the JavaScript certification. This project more than the others has me writing multiple functions to get small pieces to use for passing the challenges.

After I completed the Roman Numeral Converter, I looked at other solutions and they were/are so much more simple. I felt like my solution was messy and way too “complex”. Mine was maybe two times the lines of code than some of the others I looked at. I’d like to go back and try to simplify it at some point.

To be fair I’ve also solved some tasks in just a single line or two.

I guess I’m trying to ask if it’s normal to have longer code when starting out?

I guess I’m trying to ask if it’s normal to have longer code when starting out?

Absolutely. Don’t worry about it. Just come up with your solution and be proud of it. And then look at how other people solved it and see what you can learn from them.

And smaller isn’t always better. Sometimes developers get obsessed with showing off how they can solve a problem in the fewest lines possible. Often I’d rather have some extra lines and increased readability.

7 Likes

It takes a lot of knowledge and experience to handle a (complex) problem with a simple solution.

Sometimes you solve stuff manually, but battle-proven algorithms already exist you are not aware of.

2 Likes

You should be more concern if its working or not I also had the same experience when i was starting. Refactoring comes when you have already enough experience and every solution already makes sense to you. Make it work then clean it up.

2 Likes

I used to worry about this, with time and practice I learned to make my code shorter, in the beginning some of my fcc solutions were like 70 lines,I’d look at a solution to compare and it would be like 3 lines like dammmn ! I would just read those solutions and with time your code will get shorter

1 Like

Also, once you get things working, you can go back if you wish to make things more efficient/modular/cleaner/reuse code and stuff. They call this refactoring.

1 Like

Thanks that’s good to know about refactoring!

Okay I’m glad to know that I’m not alone. I’ve also been following the approach where I read the other solutions to try to learn how they work.

Okay thank you! I’m glad to know this is normal.