Live data from Hacker News

Want to learn to code? Don't copy and paste, type out other people's code

shockoe.com

151–160 of 184 posts

Re: Want to learn to code? Don't copy and paste, type out other people's code

#151

Earlier quoted context omitted.

One thing that has really sped up my my learning over the past few months on Code Academy -- complete a lesson, then in another tab open their scratch pad feature and try to retype the code not only from memory, but also while thinking through the logic. Has really been effective for me as I feel like I now have a pretty good (beginner) grasp on JS and Python

I have to try this. Could you code in other languages before doing this?

Not really, no -- it's been pleasantly surprising how quickly I've picked it up using the above method though. I highly recommend giving it a shot.

Re: Want to learn to code? Don't copy and paste, type out other people's code

#153

As someone who learned to code recently (last 3 years), this advice is good but dangerous in the long-term. I started by typing out other people's code from various books or tutorials, but found that it produced a feeling of "success" that made me lazy in taking the step to producing my own code from scratch. I had that feeling of progress, without actually making real progress. In my experience the best way to learn…

I disagree. I have always thought that one of the keys to being a good programmer is reading a lot of other peoples' code, and it's a process that doesn't stop just because you're more experienced. I've been programming for maybe 15 years now, and one of the ways I learn how for example a new algorithm works is still to type in an example and run it.

Integrating the manual activity of typing with the mental activity of thinking about what you're typing in and the visual activity of reading someone else's code just stimulates a lot of different neurons and helps you learn.

Re: Want to learn to code? Don't copy and paste, type out other people's code

#154

As someone who learned to code recently (last 3 years), this advice is good but dangerous in the long-term. I started by typing out other people's code from various books or tutorials, but found that it produced a feeling of "success" that made me lazy in taking the step to producing my own code from scratch. I had that feeling of progress, without actually making real progress. In my experience the best way to learn…

If I may add to this, I found it really helpful to comment out every line as I went. Even today, when I want to learn new languages or frameworks I pick a repo on github and copy the whole thing line for line, commenting as I go. I found that this helps a lot.

I work this way too, and for the last several years I have been looking for software that would let me mark up some code without actually changing the underlying source files (keeping the annotations on the side). Putting your own comments in screws up diffs and all sorts of things like that.

Re: Want to learn to code? Don't copy and paste, type out other people's code

#155

Earlier quoted context omitted.

If I may add to this, I found it really helpful to comment out every line as I went. Even today, when I want to learn new languages or frameworks I pick a repo on github and copy the whole thing line for line, commenting as I go. I found that this helps a lot.

I work this way too, and for the last several years I have been looking for software that would let me mark up some code without actually changing the underlying source files (keeping the annotations on the side). Putting your own comments in screws up diffs and all sorts of things like that.

you could try stripping comments before diff'ing. If you have single line comments you can use diff -I otherwise try this: http://freecode.com/projects/stripcmt

Re: Want to learn to code? Don't copy and paste, type out other people's code

#157

When learning code out of a book for a new language, one trick I found that worked really well was to read the code, then close the book and try to type as much of it from memory as I could. I would futz with it for several minutes exploring various ways of making it break, seeing if I could 1) predict how I was breaking it, and 2) use the error messages to fix my mistakes. Then I would open up the book again and com…

This is exactly how I handle learning languages/frameworks. I wrote a little something on it as well [0]. I value thorough comprehension over "how fast can I finish this book?". I try to get my hands as dirty as possible. I want to see the warts of this thing I plan on using to build projects. Trying to rebuild book examples from memory forces you to consider the requirements and the end goal. This was particularly useful when I first learned about linked lists and queues in C.

[0]: http://vertstudios.com/blog/how-to-read-programming-tutorial...

Re: Want to learn to code? Don't copy and paste, type out other people's code

#159
post #69

When learning code out of a book for a new language, one trick I found that worked really well was to read the code, then close the book and try to type as much of it from memory as I could. I would futz with it for several minutes exploring various ways of making it break, seeing if I could 1) predict how I was breaking it, and 2) use the error messages to fix my mistakes. Then I would open up the book again and com…

I'm a high school computer science teacher, and this is a WONDERFUL idea. I'm totally going to steal it and create a few assignments based on the concept.

Please do teach them the value of data representation. I don't think this is obvious but it can make the difference between having to write a mountain of code or finding a simple solution.

Super-simple silly example: You have to write a program to work with four colors: Red, Green, Blue, Black. Naive representation will use strings: "red", "green", "blue", "black". A little smarter would be an enum type where red=0, green=1, blue=2, black=4. And, depending on context, it might even make sense to use individual bits to identify each color: red=01h, green=02h, blue=04h, black=08h. And, if the goal is to extend to other colors, it might make sense to represent them as RGB vectors.

You get the idea. I find that a lot of newbie programmers are too focused on the mechanics of writing code. They forget (or don't know) that investing some time in optimizing the representation of the data or problem they are trying to solve could make a world of difference.

Re: Want to learn to code? Don't copy and paste, type out other people's code

#160

Regarding the Hunter S. Thompson anecdote: I've heard this story many times over the years and was always found it amusing but was skeptical that it did HST any good. I mean, what use is it to blindly just copy something letter by letter? I did Nanowrimo on a whim this year and it was a lot of fun (I doubt I'm actually any good at it, though). In doing it I found myself going to Gatsby and a Hemingway book (The Sun A…

See http://books.google.ca/books/about/Day.html?id=kKOefRuY954C The book, "Day," by Kenneth Goldsmith was created by typing out, word for word, an issue of the New York Times. It's considered a book of poetry. Typing out a novel word-for-word doesn't seem all that insane to me. And it likely isn't a useless exercise either: artists learning to draw and paint have often tried to reproduce the works of the masters in p…

Might also be worth noting that some of William Burroughs' writing (as he self-describes) were created by cutting a type-written page into quarters, rearranging various quarters, and then dealing with whatever came of that (i'm of course paraphrasing, from memory of reading his works years ago, so forgive any vagaries).
Post reply on HN