Live data from Hacker News

One Way to Improve Your Coding

changelog.com

71–80 of 121 posts

Re: One Way to Improve Your Coding

#71
post #35

Earlier quoted context omitted.

Keep in mind that part of what makes reading code beneficial is that it's not necessarily easy - in fact, it's often rather hard! The benefit is developing a set of "mental heuristics" to figure out what parts of a codebase are useful, so that when you have to dig through someone else's code you can figure it out just a little bit faster. That said, here are a couple suggestions. I'm not sure what you use other than…

Thank you! I'll have to look at these later on! Still feels like stealing, but that's my problem :)

Stolen knowledge is best knowledge. Then dazzle everyone with how smart you are!

Oh, and don't be afraid to do git blame on some particularly hairy piece of code and see how it came to be. Often commit messages has a lot of information. If you are using Emacs, vc-region-history is pure gold, I don't know how to produce that view from the command line.

Re: One Way to Improve Your Coding

#72

Can anyone recommend good tools for reading code? I find github.com to be very klunky for this purpose, and even emacs/vim make the task much more troublesome than it could be. Is there such a thing as a "read-only IDE" anywhere out there? (Ideally features would include click-to-definition, navigate back and forth, add bookmarks and annotations.)

this chrome extension, octotree https://goo.gl/BZRqop , is very helpful for reading code on github. Reading github is how I started learning how repos are structured and how to read other people's code when I was early in my cs degree.

This is awesome, thanks

Re: One Way to Improve Your Coding

#73
It doesn't look like a good approach to me. There are a lot of bad code out there and the only thing you can learn from it is how to write bad code.

The important things are the right mindset, the ability to reason about code quality, and good set of more concrete skills: algorithms and data-structures, beginner level understanding of different programming paradigms and their applications (class-based OOP, prototype based OOP, FP, you'll get a deeper understanding of one or several of these approaches when you start using some specific language), particular language features, idioms and libraries which can help you solve real problems.

Most of these things can't be deducted from reading code. Some of them can but again you have to read good code. The suggestion to just read a code of the thing you use is bad. You have to find a mentor who can direct you to the idiomatic and effective code.

The best thing you can do after getting used to the right way is to solve some problems and then improve your own code until it shines. Then you can read a code of the libraries you use and maybe improve it.

Re: One Way to Improve Your Coding

#74
post #62

When I was teaching at General Assembly, I always tried to encourage students to read more code. Could you imagine someone studying writing in college without reading a TON of books, analyzing, and critiquing the writing other others? Where all they did was simply write, but never read anything from great writers? No, clearly not. Yet, that's what I see most new programmers doing. There's an urge to do it all on thei…

It isn't necessarily analogous to compare the study of writing in college to that of learning to program. For one, by the time you are in college, you have been speaking, reading, and analyzing (via communication) your native language for ~15 years. Because we already have such a vast foundation to work from, we can venture into deeper parts of the language and meaning and interpreting how authors use it to create me…

I think programming is more analogous to learning a new language.

I think your analogy is spot on, and yet reinforces the OP's point - one of the best ways to learn a new language is to read a lot of good writing in that language - you absorb idioms, subtle points of grammar, and vocabulary, all of which would be a struggle if you just try to focus on the basics or use a grammar textbook to help. Immersion in the right environment is by far the best way to learn.

The current situation with most people programming is that they spend years looking at code written by other beginners (stackoverflow, tutorial articles), and very little time studying real production code written by people who have been doing it for a long time. That is as the OP points out a huge mistake and one it takes many people decades to remedy if they ever do. It's like trying to learn a language by putting 30 beginners in a room with a textbook and making them speak to each other.

I'd honestly recommend absolute beginners to spend at least some time reading simple code by someone they admire, if only to demistify the process, and make them realise it is not as complex as they fear. Beginners almost never do this though.

Re: One Way to Improve Your Coding

#76
I completely agree but in many cases, as opposed to a book, I don't know where to start. And in many cases you do need some domain knowledge or at least understand the requirements and mentally map code to what it's supposed to do. Reading code with its unit test I guess is the best way.

Is there a good list of "must read" code that someone is curating that you recommend?

Re: One Way to Improve Your Coding

#77

I'm going to be "that guy" in the comments section this time, largely because I feel like I've been seeing this more recently and I've had to fix it myself: I don't really get why it seems to be a "thing" recently for websites to have low-contrast text colors. This is at least the second time in a week I've seen light gray text on white background, and to not strain my eyes I went into the CSS for the website and fix…

I'll bet $100 that in this instance, it was just an impromptu design decision. He liked the way it looked, it contrasted nicely with the headings and that's it.

Re: One Way to Improve Your Coding

#78
By reading other people's code you start to get a feel for how many ways you can slice an apple. Many ways.

I find even choosing the degree of formality is often difficult. If you have a gander at Oracle/Sun's JavaFX implementation, you'll see just how much code, how much complexity goes into making a large and comprehensive API - and also who the architecture is about 4x more complicated due to their will to try to build rendering pipelines, which is ultimately an optimization of sorts.

And then of course the quick, dense, poorly commented code on some node.js implementations that seem to be novel and smart, but nevertheless threadbare.

Finally - it seems that there is quite a lot of variety in common practices particularly in Javascript.

Re: One Way to Improve Your Coding

#79
post #62

When I was teaching at General Assembly, I always tried to encourage students to read more code. Could you imagine someone studying writing in college without reading a TON of books, analyzing, and critiquing the writing other others? Where all they did was simply write, but never read anything from great writers? No, clearly not. Yet, that's what I see most new programmers doing. There's an urge to do it all on thei…

I'm not sure this is a fair comparison, because books are written to be read, but code is (usually) written to be executed. As much as we all agree that code readability is important, the simple fact of the matter is that executability matters a helluva lot more. We're paid to write code that executes, and many people stop there.

The result is that there is a lot of code out there that executes just fine but is completely terrible to read, and I wouldn't advise learning from. And the problem is, especially for beginners, it's difficult to determine which is which.

Add to this the fact that code changes over time, in more ways than one.

1. It physically changes, i.e. we commit changes to it, so a codebase that is well written today may be dramatically changed tomorrow.

2. The context changes, i.e. the circumstances that make one tradeoff better than another change all the time, and if the context isn't captured effectively, it's difficult to understand when good decisions change to bad ones.

3. The language changes, i.e. new versions or even entirely new languages come out which fix mistakes in old versions or languages, so good code today may be difficult to learn from in the future if the language is no longer well understood.

We need more collections of repositories that are agreed upon as "good quality" that everybody agrees are worth reading and learning from.

Re: One Way to Improve Your Coding

#80

It doesn't look like a good approach to me. There are a lot of bad code out there and the only thing you can learn from it is how to write bad code. The important things are the right mindset, the ability to reason about code quality, and good set of more concrete skills: algorithms and data-structures, beginner level understanding of different programming paradigms and their applications (class-based OOP, prototype…

"There are a lot of bad code out there and the only thing you can learn from it is how to write bad code."

Oh, I dunno. I've done it a bit and found value in it.

I spend big chunks of time writing customizations or extensions for WordPress plugins. It's not exactly a fun way to make a buck but it is easy to be better than most folks writing for WP and I work remote from a tourist town... but my point is that I have read a shit ton of really bad code. If you think that all it's done has made me able to write bad code, fair enough... I'm not exactly solving difficult problems.

But I still feel that it's good advice to read other peoples' code.

The benefits of knowing that you can do better than some folks aside, being frustrated by some poorly documented code that is difficult to reason about is a really great way to understand why you shouldn't write stuff like that, and the various ways in which things can get messy.

It's not the best thing in the world, and I suppose that on some level its struggling against rather than reading this code which is the real benefit.

But I agree with Stephen King when he writes in _on Writing_ that there is value to writers in reading some bad novels.

If you've been working for a while and want an easy way to improve your practice, and your general impulse when working with other folks code isn't to follow down to that code from your IDE, there is a lot of worse advice than to just go ahead and look at underlying code other folks have written.

Post reply on HN