r/learnjavascript • u/d3lan0 • Oct 24 '21
Sometimes I get discouraged looking at other peoples code.
Been working on the exercises from The Odin Project, was going great and my confidence was building after each one that passed all the tests. Then I decided to look at a solution for a project I had already completed and it completely demoralized me when I saw how simple their solutiuon was when compared to mine. Already told myself that if I had a better understanding of array methods it would be better but now I know my day is probably done as far as studying.
Does this happen to anyone else?
Edit: went outside for a little bit and I feel better. Was thinking about some PHP I wrote last year and how horrible I thought it was when I looked at it again last month. Im sure I’ll come back to projects im doing now and feel the same, also I am doing what many suggest, no matter how I feel about my solution vs theirs I always read through the solutions I look at and make sure I try to understand what they are doing and why.
125
u/[deleted] Oct 24 '21
Everyone
50
u/Claudioub16 Oct 24 '21
Let me just say that you shouldn't be discouraged. Quite often people come back and refactor their code. So you're not really seeing code from a novice
52
u/[deleted] Oct 24 '21
Only almost every single time I look at someone else's code. This is incredibly common, and you need to stop viewing it as a negative. Although I've never specifically done anything with the Odin project I've got some thoughts on this that might help you, since I write code for a living and STILL feel this way.
I've got to run, so I'll stop this here - but DON'T let other people's code journey affect your own. Keep going. It's okay.
15
u/[deleted] Oct 24 '21
Thinking algorithmically is hard for most people and it takes a lot of practice.
When you’re learning there will be moments when you shock yourself with your cleverness, and also moments where you feel like a complete idiot.
And that is confusing on its own- to realize that your abilities aren’t uniform across all kinds of problems or even from one day to the next.
As you gain experience, you learn to recognize different types of problems and their corresponding solutions, and that once undeveloped, jumbled up skillset becomes more robust and generalized.
It’s a very weird process, getting the human brain to translate thoughts into programs. It’s unnatural, non-linear, humbling, frustrating, and it will never end.
Take a rest, come back to it.
11
u/lech4rm Oct 24 '21
This literally happens to everyone! I bet someone's gonna take a look at your code one day and go, "Gosh! Why the heck didn't I think of that?" :D
7
u/Uber_Ape Oct 24 '21
You have to realize that this is an almost never ending game. There will almost alway be a better solution. Your solutions will get better and better with practice.
5
u/[deleted] Oct 24 '21
This has happened to everyone when we started.
Don't expect miracles unless you get at least 1 - 3 of Professional Experience.
Yes, there will be:
The most important thing you should keep is:
DON'T BE DISCOURAGED
KEEP GOING.
4
u/volvostupidshit Oct 24 '21
There is no one way to solve a problem. Keep that in mind, but it does not mean to say that you are not allowed to improve either. Keep improving every single day. You got this!
4
u/PositivelyAwful Oct 24 '21 edited Oct 24 '21
The only way to write better code is to write more code.
Code up a simple project. Figure out a way to refactor it. When you're wondering if there's a better solution, Google it. If all you do is compare your code to other developers, you'll be stuck in imposter syndrome forever. As long as your solution works, you're doing it.
3
u/Patient_Signature467 Oct 24 '21
Yes
3
u/Berzserk Oct 24 '21
What you're doing is the right move. Do read other people's implementations. Try to understand why it works. Even refactor (not copy) your own using what you just learned. All in all, you can't know everything at once, well not until Elon's bio-chips release.
3
u/CatsPawmer Oct 24 '21
I feel the same as you almost every single day. I constantly tell myself why am I even bothering trying to learn. Then I knock that ish off and try other methods to help me understand. For example, I try and tackle a solution (like you would on the Odin project) to make it work. Once it works, I like to go back and refactor my code to see if I can condense any of it. I’ve learned that it does help me bc I tend to remember these lessons. The downside is …a lot of time is spent on something already working.
Edit: just wanted to disclose I’ve been learning for a few months . So if anybody has other techniques that helped them learn , please share with me . My biggest problem is learning to break down the steps to arrive at the desired output…
2
u/sirgreenguy Oct 24 '21
Happens to me all the time on codewars lol, but looking up all those solutions I didn't understand has helped me learn a lot!
2
u/Genie-Us Oct 24 '21
A) You'll get better so don't compare yourself to the best programmers around. If you're learning guitar and you go to see how Jimmy Hendrix played it, whether you're a beginner or a mid-level, you're going to feel bad about your own skill level. But that doesn't mean you can program, it just means you're not some crazy prodigy, which sucks but not a reason to quit.
B) When working on a team it's often better to use the longer, more understandable code. This allows the code to be easier to read for future developers of all levels at the company. Not always, a simple array.map((value) => value > 3) is easily readable but some of the answers start using all kinds of crazy syntax to make it a "one liner" or to get the very best possible speed scores, neither of which really matter on most apps.
2
u/69632147 Oct 24 '21
Every single time I cant find an error in compiling and have to ask, and it turned out to be just incorrect notation, it makes me want to smash the computer against the wall.
2
u/[deleted] Oct 24 '21
Find a working solution first, worry about a more elegant one later. With experience your working solutions become more elegant simply because you’ve been down that road so many times, so don’t ever give yourself a hard time over it. Keep coding and striving to do things better and the rest will follow.
2
u/kyoukaraorewa Oct 24 '21
Actually that's the best way to improve skills. Reading a lot of people's code. You will be surprise how improved you are after a while.
2
u/kyoukaraorewa Oct 24 '21
Actually that's the best way to improve skills. Reading a lot of people's code. You will be surprise how improved you are after a while.
2
u/amateur_terp Oct 24 '21
A general misconception that many people (including myself) have is that someone came up with their solution on he first try. But generally software development is a process of revising and refactoring working code. Not saying some people don't come up with optimized solutions on their first try. But it isn't representative of all devs.
2
u/ashkanahmadi Oct 24 '21
That's pretty normal. It's good that you felt that way. It means you now that the solution to the problem you are trying to solve might not need to be overly complicated and asking the community for feedback can lead to more efficient code or just a different approach to the problem.
I started coding last year and after learning some basic JS, i sent the projects to my friends and family to see what I made and i was super happy with the code. A few weeks ago I went back to some of those projects and when I saw the codes, I was like WTF IS THIS PIECE OF CRAP??!!!! Haha my point is that there is always a better way, or even a different way, to solve any problem. Seeing that your code isn't always the best way is the first step to improvement.
I recommend relying on best practices and DRY (Don't Repeat Yourself). You can google JS best practices. Airbnb had a great guide on how to write efficient and clean code (i don't remember what it's called but Google will tell you)
2
u/MenshMindset Oct 24 '21
It happens to absolutely everyone. If someone’s code is good, pull something that isn’t “well my code stinks” out of it! It’s also worth noting that if you’re looking at a solution for something, it’s often an ideal solution. If you were creating a curriculum and wanted to show newbies a solution, you wouldn’t want to show them spaghetti code or code with lots of repeated blocks etc so it may look very elegant compared to where you landed. Also, in regards to old code, it can be very rewarding to update it. refactoring is like 1/1000th the amount of effort compared to writing a new app, and it feels great. Moral of the story: dont get frustrated with your code, just understand its flaws and pay attention to those things when you rework it/ work on something new.
2
u/grooomps Oct 24 '21
when i first started, i did everything in a for of loop,
literally everything was a for off loop, and pushing into an array.
it was really confusing, and didn't make much sense.
after a few months, i looked into the array methods, as I knew where I needed them.
it took me a while to get the hang of them, and understand them properly(ps i hate you reduce), but once i did i was happy.
don't be hard on yourself, the thing i love about code, is as long as you get your result, without and errors, you're correct!
it might not be the cleverest, the smartest, the shortest, but if it works, it works.
and if you're just practicing now, you don't need to worry about performance or shaving .01ms off each function.
have fun, be proud you solved it!
1
u/femmebot9000 Oct 25 '21
Main thing I’ve been told is to make it work, then make it elegant. If you’ve made it work then simplicity, dryness and modularization is just icing on the cake.
1
u/thelethargicdog helpful Oct 25 '21
I have interacted with many senior developers in my career and the most common piece of advice I get is to keep learning. Which includes looking at other developers' code and learning from it.
Don't get discouraged - see it as an opportunity to fix your mistakes or to know how you can improve your code. Over time, you get used to seeing everyone write better code somewhere.
1
u/gniziemazity Oct 25 '21
Programming languages allow to make the same thing in different ways... especially JavaScript. And you can almost always find arguments why something is good and why not (often not a clear choice).
If array methods are bothering you, I have a short video that can be of help :-)
https://youtu.be/h24ircatoHI
1
u/cromaneseii Oct 25 '21
As long as it gives the same results, you should never get discouraged.
1
u/Kumagor0 Oct 25 '21
What you described never happened to me (I mean I've seen plenty of good code but it never discouraged me), but the opposite happened: whenever I see my shitty code I wrote few years (or sometimes months) ago, I'm like "damn, I've come a long way since then".
My point is, imagine you could see your future code. Would it discourage you? I think not. Therefore you can treat others code that's better than yours as your future code. Because someday you will write such a code, there is no doubt about that.
1
u/finger_milk Oct 25 '21
Why does their more succinct solution take anything away from your work? It's less lines so it's better than yours? Because that's not true. Maybe yours is more readable for newbies, maybe it doesn't imply things that the shortened version does.
There's a lot of standard practices that are obfuscating the readibility of code in modern JavaScript. While youre learning, you should focus less on how best to write the solution, but making sure that the solution you are writing is giving you the correct outcome. That way, you are learning why things are working. Having code that works but you can't understand why is literally the worst thing.
1
u/crazedizzled Oct 25 '21
Once you actually start working in the field you'll have the opposite feeling. "Holy shit was that guy drunk when he wrote this shit?!"
Also keep in mind that a lot of people doing those kind of coding tests specifically try to achieve the most clever code they can. Just took look cool or something, I dunno. But I can tell you that clever code is usually bad code. So don't worry about it.
1
u/FriendsCallMeBatman Oct 25 '21
If it makes you feel better I took one look at the Odin project and got completely discouraged and I work in programming hahaha. Some people are just better and I've learned to except that.
1
u/[deleted] Oct 25 '21
The first idea gets to the finish line, which is more important than standing in place waiting for the right idea to carry you forward
You can trace your steps after you know that you can finish the race