How to learn to code "well"?

How to learn to code "well"?
0.0 0

#1

One thing about self-studying code is that there is not really any great resources that teach you to code “beautifully”. Most books and courses throw a bunch of expressions and functions at you one at a time and then give you an exercise that requires you to put some of them together to accomplish a task. (Actually, a lot of books don’t even do that. They just keep moving on to the next function. They teach you to code, but they don’t teach you to code well.)

While FCC is awesome in many ways, this is one area where it too comes up short. Unless I missed something? Is there an area or part of the site where we can see elegantly coded algorithms and such?

I’ve always found this to be one of the biggest problems with self-study materials. There’s often more than one way to do something and while there are times that an alternate way might actually provide an advantage in certain cases and not other, there are also times where one way is the clear winner over another.

I can make my programs do what I want usually. But my problem is that I am constantly feeling like I’m writing crappy spaghetti code instead of tight elegant code. How can I get over this feeling and where can I go to learn some common “bad programming habits” that I might have to be careful for?


#2

Well, the wiki has solutions for the algorithms that can show you good ways to do it.

Do you just mean the methods you use to solve problems, or the writing style as well? For the latter, using a linter with decent rules in your editor of choice can help you get into good habits, too.

There’s also the opportunity to seek a code review here or on Gitter, although the majority of people that read it will be fellow students that don’t necessarily know best practice either :slight_smile:


#3

Learn jQuery’s Code Organization Concepts
Bunch of good videos on Modular JS
Other than that just google ‘JavaScript Design Patterns’.


#4

One thing I find is an advantage of Codewars is that when you complete challenges, it automatically shows you other solutions from other people, ranked by people’s feedback on them.
There you can see different ways of solving a problem and people’s reaction to them shows you if they are considered best practice or particularly “clever”.

I feel something like that would be a great improvement for FCC as well.

So it’s really about seeking feedback on your code. You’ll gain confidence in the quality of your code if you get positive feedback to it, or if you get suggestions on how to improve it and why.

Such code reviews are already a topic discussed here as well.


#5

Thanks for the replies everyone!


#6

I can tell you based on how I’ve learned thus far. I think it’s really important to have other people review your code and review other people’s code regularly. So many of the things we do when styling our code is about our human readers rather than our machines, so it’s hard to know when to use (or not use) some code convention if you’re learning by yourself. There’s plenty of opportunities for that here on the forum, but also browse GitHub sometime and see if you can figure out how one or another piece of code works.

Some of the best practice I have gotten is by refactoring old code using new techniques. I just went through my backend API projects and redid them with promises. After I did my backend APIs, I went through my frontend projects and abstracted some of the work they did into backend programs. I recently redid my calculator project using the module pattern. Lastly, there were a lot of “AH-HA!” moments when I took a detour to learn other languages - Python, Ruby, Objective-C, Swift, and C all forced me to learn different ways of organizing code, some of which more-or-less translated to JavaScript, but all of which rests on logic that is important to understand.


#7

I am currently taking Udacity’s course on Javascript Design Patterns. It covers the Control-View-Model pattern and makes you write bad code, and then refactor it to be good. Also gives you an exercise to refactor someone else’s bad code. It’s a really good course.
You can find it right here: https://www.udacity.com/course/javascript-design-patterns--ud989

I am curious to find other resources as well. I’ll be following this discussion.

But in general, practice and code reviews are the most important things.


#8

Don’t worry about spaghetti code. Learn to flowchart.
I have my own search engine that is 18 years old and very much spaghetti.
There is no way I can remember it all. I have no problem making changes…

Sometimes I just follow previous noodles to implement new features.

10,000 plus lines with oodles of noodles. I put my own line numbers in as well
So I can error trap at a common area. Check the line number and error to determine where and what to do.
Local error trapping for everything makes the code crap.


#9

This is helpful: https://github.com/ryanmcdermott/clean-code-javascript

This might interest you: https://standardjs.com/


#10

Back in the day when some idiot “yourdon” was pushing structured design…
He must have marketed it to HR because I didn’t know anyone that was good with it.

All you could do in an interview was say that “Yourdon”: was pretty smart.
Otherwise it would be like saying “I hated school” which I did.

Structured programming was just a convenient excuse for not being able to flowchart or understand anything but the simplest code.

Boo Structured cheers spaghetti