Live data from Hacker News

One Way to Improve Your Coding

changelog.com

81–90 of 121 posts

Re: One Way to Improve Your Coding

#81
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…

Reading code becomes beneficial at the moment your biggest concern is no longer "does the application work?" but "how does the application work?" I ceased to be a beginner when I became confidant that I could make something work. My concerns ceased to be "can I make this work?" and became "is there a better way to make this work?" Confidence to answer the former question is gained through writing code. Understanding to answer the latter question is gained through reading code.

Re: One Way to Improve Your Coding

#82
post #57
post #39

Earlier quoted context omitted.

> The point of reading code is to understand it. There are varying levels of understanding (or desires to understand something). I use Python a lot. For a lot of the language and libraries my understanding is superficial; dicts have key/values, lists are ordered and mutable. As I use it more I'll dig more into specific parts as needed; how do lookups happen for a dict, how are lists allocated? If I downloaded cPython…

[deliberately responding out of order] > Your argument here sounds like it would be against having syntax highlighting No, but syntax highlighting is just something that helps parsing a single page. I'm talking about "show documentation for function/var/whatever under cursor", "jump to definition", etc... > There are varying levels of understanding (or desires to understand something). I use Python a lot. For a lot o…

I still think I have different (lighter) needs when skimming code online. I do think an IDE would be the ideal solution. What I saw the parent looking for is a middle-ground, maybe you have something like VSCode, but cull out compilation, editing, and debugging to it loads more quickly.

> That "digging" is what I am talking about.

Those are examples I gave are where I don't need to navigate the codebase. The answer is in a single file. So far I manage with the current web interfaces. Locally, I'd use grep and vi. GitHub works ok, but it's hard (but possible) to compare versions or jump between files. Using Google Code or SourceForge I have trouble finding the "Browse" button to even find the code.

Re: One Way to Improve Your Coding

#83
I agree that reading code is extremely important for improving as a programmer, but the code has to be read analytically. That’s hard work, because it means understanding the problems and subproblems that the code is solving. For example, you may have seen the longest identical subsequence algorithm used by diff, but analyzing the implementation in V7 Unix is a different learning experience. Or if you’ve studied interpreters, you could look at the awk sources maintained by Kernighan to see how a fairly complex interpreter fits together.

Re: One Way to Improve Your Coding

#84

A lot of people will recommend reading great code -- well known open-source libraries etc. That's good, but one thing I think is useful is to read your dependencies. Then you can get a better picture of what "regular" code is like. Most popular libraries are not great to read because they are often very abstract, or they use so much helper code that it's hard to see what's actually going on. But fairly small librarie…

As a (mostly) front-end developer, I agree that reading some of the code in your node_modules can be enlightening. Sometimes in a good way, sometimes in a bad way.

There have been times when I've dug into a module when something wasn't behaving properly, and was shocked at how bad the code was. It's not as if I included it intentionally - it's usually a dependency of a dependency of a dependency. All the same, it was garbage that I'd been shipping as part of my application.

Your point still stands, though. Having the code where it's easy to find and read is helpful. And reading bad code can be as helpful as reading good code. Sometimes, the trauma caused by seeing some atrocious code can improve your habits more quickly than reading beautiful code. :)

Re: One Way to Improve Your Coding

#86
I've been doing literate programming for my own projects lately, and I'd really like if more programs were written in this way: creating a complete narrative for a reader to understand the problem and the solution is certainly better than trying to piece together a story from uncommented pieces of code.

Re: One Way to Improve Your Coding

#87

A lot of people will recommend reading great code -- well known open-source libraries etc. That's good, but one thing I think is useful is to read your dependencies. Then you can get a better picture of what "regular" code is like. Most popular libraries are not great to read because they are often very abstract, or they use so much helper code that it's hard to see what's actually going on. But fairly small librarie…

Great suggestion. It's great because you have context (you know what the input/output is) so the learning curve is flatter. Anytime I've done it, it's been a confidence booster. I always feel like the dependencies I use are built by genius coders who are much better than me. When I inspect the source I am reminded that it's just the same ole' code as I would write, but of course better documented and tested :)

Re: One Way to Improve Your Coding

#88
To save anyone the trouble: the way is supposedly to read code.

Here's a counterpoint I find pretty convincing: http://www.gigamonkeys.com/code-reading/

Here's a brief excerpt:

> Seibel: I’m still curious about this split between what people say and what they actually do. Everyone says, “People should read code” but few people seem to actually do it. I’d be surprised if I interviewed a novelist and asked them what the last novel they had read was, and they said, “Oh, I haven’t really read a novel since I was in grad school.” Writers actually read other writers but it doesn’t seem that programmers really do, even though we say we should.

> Abelson: Yeah. You’re right. But remember, a lot of times you crud up a program to make it finally work and do all of the things that you need it to do, so there’s a lot of extraneous stuff around there that isn’t the core idea.

> Seibel: So basically you’re saying that in the end, most code isn’t worth reading?

> Abelson: Or it’s built from an initial plan or some kind of pseudocode. A lot of the code in books, they have some very cleaned-up version that doesn’t do all the stuff it needs to make it work.

>Seibel: I’m thinking of the preface to SICP, where it says, “programs must be written for people to read and only incidentally for machines to execute.” But it seems the reality you just described is that in fact, most programs are written for machines to execute and only incidentally, if at all, for people to read.

> Abelson: Well, I think they start out for people to read, because there’s some idea there. You explain stuff. That’s a little bit of what we have in the book. There are some fairly significant programs in the book, like the compiler. And that’s partly because we think the easiest way to explain what it’s doing is to express that in code.

Re: One Way to Improve Your Coding

#89

A lot of people will recommend reading great code -- well known open-source libraries etc. That's good, but one thing I think is useful is to read your dependencies. Then you can get a better picture of what "regular" code is like. Most popular libraries are not great to read because they are often very abstract, or they use so much helper code that it's hard to see what's actually going on. But fairly small librarie…

Also, at the OS level, there are entire projects built around just understanding the dependencies in the Operating System and applying minimalism to try and get to a state of (relatively) simple, known dependencies.

One of my favorites is Rob Landley's Aboriginal Linux:

http://landley.net/aboriginal/about.html

I highly recommend his blogs if you're interested.

Re: One Way to Improve Your Coding

#90

Earlier quoted context omitted.

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 rig…

However, it's not really a story you can read through end to end so often as a choose your own adventure with thousands of routes to move through. Though there are smaller projects you can work through and better, or less organized structures... it depends.
Post reply on HN