Live data from Hacker News

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

shockoe.com

161–170 of 184 posts

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

#161
A corollary, a comment on method, and an anecdote:

Related, this approach also reveals syntactic errors in printed books. This re-enforces the principle, since it shows that even published authors make mistakes. It also means that, even following the text verbatim, I have to account for code errors and the standard bugs (as others note here).

Somewhat related to other comments here regarding closing the book and trying to recreate the code or underlying logic, I often think of REPL iterations in relation to industrial-scale engineering (rocket launches, bridge-building, etc.). If the cost of the test-iterate cycle is not seconds or minutes, but months and millions of dollars, we'd think very carefully about the logic and edge-cases. Granted, I like that fast iteration is possible, but in cases where that's not an option, you'd just have to use other approaches. Mostly, that would mean truly, deeply understanding what you're asking the machine to do.

Despite being a fan of Gonzo Journalism, I've never heard the anecdote about transcribing entire Hemingway novels. Re-typing code examples verbatim seems sort of obvious, but re-typing narrative fiction, not so much. So it's sort fascinating to hear that anyone in fact did that (and for exactly the same reason).

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

#162

I totally agree with the title of this post and often times I have pledged to myself to never copy and paste even though I always get the idea first what is this piece of code is doing but still most of time I end up making mistakes with copy + paste. At the end, the time spent to rectify the errors resulting from copy + paste is much more than I thought I would save.

I agree. This happens to me alot even when I copy paste my OWN code and intend to change it slightly.

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

#164
This is something I really just learned through experience. I'll frequently just look at the example, type it out, and then immediately start fiddling with it.

I learn coding through doing it myself, not from simply seeing someone else's work.

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

#165

I also agree strongly with this statement. When I was in school, I found that the most important part of the notetaking process was manually writing the notes during lectures. Reading them afterwards rarely helped me remember or learn more. Reading notes written by someone else was next to useless.

Cognitively speaking handwriting and typing are different tasks and thus have different results on the learning process, which may or may not vary individually.

I think the best method to learn coding highly depends on the learning style of the person.

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

#166
post #161

A corollary, a comment on method, and an anecdote: Related, this approach also reveals syntactic errors in printed books. This re-enforces the principle, since it shows that even published authors make mistakes. It also means that, even following the text verbatim, I have to account for code errors and the standard bugs (as others note here). Somewhat related to other comments here regarding closing the book and tryi…

Iv'e been researching these kind of educational and cognitive topics for some time and it's quite obvious that writing code and writing fiction or non-fiction narratives are cognitively different tasks. However, further scientific research is necessary to obtain evidence whether or not retyping narrative (or even code, I might argue) is a good method.

This is the only article I know of someone using this method in narrative: http://www.publicationcoach.com/how-to-use-deliberate-practi... .

It's unfortunate the article is scientifically suspicious.

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

#167
post #69

Earlier quoted context omitted.

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

COuld you elaborate a bit on what the benefit of the other representations in your example. I don't get it.

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

#168
it probably helps more to type out the program in a logical order - in the order of execution, like a pre-order traversal of the (module-dependency) tree.

say, in c, you could type the main, and when there is a function call, go there and type it, understand, come back.. that way you get the flow of it and you'll understand the whole code in one go.

Yes, it helps to type.

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

#169
post #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 u…

This is really a nice trick!! Thank you for sharing!

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

#170
post #69

Earlier quoted context omitted.

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

I think it is important to learn enum's but it is a bad example. You really should use the built-in types when they're available. Color is a particular example (in both .Net and Java) where you should never re-invent the wheel.

In general teaching enum's is very important and something I've not really seen schools do (although their "learn to program" programs are typically 101 to newbie, I've never seen a program that really builds on the basics).

Post reply on HN