Bummer! You must be logged in to access this page.

Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

Do you copy code?

I wanted to get some feedback and start a discussion about cut/paste coding.

I just want to hear what people's feelings and thoughts are on their approach to reusing code, specifically code that they haven't learned or learned well.

My basic thoughts on this are that I try not to use anything I don't understand in a cut/paste method but instead rewrite it, even if I'm copying it so that I can think through the syntax and concepts as I do so. I also feel strongly that you remember how to do things better if you personally type them out over and over.

What do you guys think?

3 Answers

In my opinion that's a good way to learn, If you rewrite it you start to notice what it is really doing. As you say it also helps to remember how to do things better.

Agreed. To be clear, I've avoided copying anything that I didn't at least mostly grasp already, and in the processed made sure I learned how it really worked. This is actually how I started to learn Jquery, and now regularly reference the API specs.

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

While learning, definitely type everything out. Yes, it takes longer; yes, you'll make typos and mistakes, but you'll pick up the syntax and quirks of the language much faster than you will copy/pasting the code into your editor and then reading it over. Even better, due to those mistakes, you'll also learn to debug the language.

Once you know the language fairly well, though, I still don't recommend copy/paste :). If the language supports it, this is the best time to learn to re-use as much of the code as you can. Make re-usable classes or mixins or functions or whatever that particular language supports so you only have to write a given bit of functionality once.

Kenneth, I'm right with you. I have been learning how to identify the cause of bugs in my code a lot more quickly due to typing stuff out. For example, if I make a CSS change and suddenly something goes completely haywire, I probably just forgot a semicolon.

I also took the approach of making my code modular as you described, while working on my toggle switch for the recent contest on Treehouse. I wanted to write it in a way that I could easily recreate toggle switches and then only reskin them to create an entirely different button, then only have to position them on the page by moving a single div around.

Specially during my 9-5 job, I do copy and paste a lot to meet the deadline and to make the software run as they intended. But with my pet projects I always try to understand what I'am doing. Even when you copy paste, after some time, you will get a grasp of why you are copying and pasting (but it takes months of copy and paste :P)