6 ms·
"They don’t tell you that a lot of programming skill is about developing a knack for asking the right questions on Google and knowing which code is best to copy
by retrogradeorbit 12y ago
"They don’t tell you that a lot of programming skill is about developing a knack for asking the right questions on Google and knowing which code is best to copy-paste."
No, no, no! This always frustrates me. This is not 'coding' (maybe it is, and we should be doing less of it, and more programming). This is gluing together pre-coded snippets and trying to make it work. Continuing to do this is an impediment to getting better. Thinking that somehow this is what 'coding' is, is missing the point.
I will read a stack overflow page perhaps in a search for some direction, look at all the 'solutions' like surveying a landscape of others approaches to the problem. Then I'll throw them all away and code my own. Possibly it will share a lot with one of the answers, what I would consider a good approach. But a literal copy and paste just doesn't happen. I would consider a copy and paste a recipe for inviting trouble, because you haven't really reasoned through the problem yourself, and thus don't really understand the solution intimately.
Programming is a process of mental reasoning around your problem with an eye on the form of reasoning computers use, so you can express that reasoning to the computer in the language you're using. Because computers don't reason like humans 'reason' (ie. humans don't really 'reason'...), knowing how a computer reasons and behaves is alien and takes time to understand and learn and it takes time to become quicker at comprehending this. This is the path of becoming a better programmer. Gaining that experience so the process is less alien and you more easily can fathom how a computer will respond and behave with a certain approach of laying out of the logic you are trying to express.
Copy and paste doesn't help you at all with this. In some cases it may prevent you learning essential lessons and hinder your improvement.
- bra-ket 12y agocopy and paste helps to get the job done
- jwdunne 12y agoI don't think so. A program is an infinite stream of jobs and is never quite 'done'. The less time you spend on keeping things nice and clean, the more frequent the jobs will be. After all, it still needs to be maintained. Unless you are using a library, it's gonna be better long-term going for complete understanding. Even then, it's usually a great idea to understand what a lib does under the hood.
- goblin89 12y agoI guess it depends. A freelancer hired through oDesk by default has a clearly defined job and zero incentive to care about ‘nice and clean’. Sometimes I just can't help thinking that the code I maintain has been optimized, foremost, for someone's job security—even when I know that the author is actually just of ‘get-shit-done’ type, and has been paid hourly.
- chrismorgan 12y agoI read that as tongue-in-cheek.
- soup10 12y agoI copy and paste code all the time. I'm in the business of getting shit done, not learning everything ever, I don't need to learn the ins and outs of some obscure algorithm I'm only going to use once. I also don't need to memorize Apis and boilerplate for technologies I rarely use. Of course once i'm settled into a domain I don't need google anymore. But it's invaluable for quickly diving into new stuff.
- Swizec 12y agoPlease never stop doing this. I get paid $$$++ to swoop in after people like you are done and whole teams grind to a halt productivity-wise because the codebase is so bad. You are doing god's work, son. Thank you.
- nomedeplume 12y agoplease define $$$++?
- Strom 12y agoIt means 'lots of money'.
- nomedeplume 12y ago...."lots of money" varies from community to community.
- dkersten 12y agoWhich is why saying lots of money if more useful than specifying an amount, because that amount may or may not be a lot of money where the reader is from, but might be a huge amount where the person who posted it is from.
- Swizec 12y agoWell, you take a dollar amount. Then you increase it. Then you increase it some more. Because companies who can afford it will pay you pretty much anything if you can make their whole engineering team even just a few percent more productive by improving the codebase. Or can figure out very hairy issues caused by Daily WTF style situations. For example, I have a friend who sometimes fixes bugs in compiled software running banking systems with no access to the original code and woefully out of date documentation. He gets paid some 300eur an hour in a country where the median developer salary is only about 30k eur per year (about 14eur/h) Sure, that particular type of problem likely/hopefully isn't caused by copy-paste programming, but it is caused by the sort of endemic issues copy-paste programmers to produce.
- baddox 12y ago> This is not 'coding' (maybe it is, and we should be doing less of it, and more programming). This is gluing together pre-coded snippets and trying to make it work. Continuing to do this is an impediment to getting better. Thinking that somehow this is what 'coding' is, is missing the point. That's not fair at all. Off the top of my head, three topics I have searched StackOverflow for a lot are Android development, MongoDB, and MySQL. Each time, I would consider the task I was doing to be programming, despite the fact that I was not building a mobile phone operating system or database myself from scratch.
- nhebb 12y ago> Copy and paste doesn't help you at all with this. Generally I agree with this, but there is a way to use copy-pasta as a learning tool. If I find a code sample that does what I want but don't understand it, here is what I do: 1. Add a comment with a link to the source for reference. 2. Rename the variables. 3. Comment the parts that I understand. 4. Flag the parts I don't understand with a simple // ? comment. 5. Research the parts of #4 until I understand them, and then update each comment accordingly. #2 is incredibly important to me. I've been doing some walk-through tutorials lately (e.g., http://learn.knockoutjs.com http://learn.knockoutjs.com), and if I use the same variable names as the tutorials suggest, then I'm just transcribing. The code doesn't stick in my head, and I'm not really learning as much. But once I start changing the variable names, then it sticks. #3 might seem like a waste of time, but I've found with conceptually difficult code, having the #3 comments helps keep me grounded if my brain gets too muddled.
- userbinator 12y agoThere should be one more step: 6. Make changes to it so that it does the same thing, but in a better way -- faster, smaller/more concise, etc. I think that being able to do this (correctly) is to truly understand, since then you are "thinking beyond the code" and can see the problem that it solves, not just an implementation that solves it.
- cliveowen 12y agoI completely agree with you and frankly I'm shocked to see most of the responses here purporting copy-pasting someone else's code to be a legitimate practice. I also imagine that most if not all of these people are into web developed where there's a long history of copy-pasting snippets of code and no one knows what he's really doing. I've seen many people write a jQuery script for their website and calling themselves developers. You're not a developer, you're mashing together tools you don't really know how to use in the hope that everything works out. On the browser you're working with a single thread, in the real world you're always dealing with multi-process/multi-thread programs that inevitably lead to race conditions and deadlock. I doubt anyone involved in systems programming thinks is normal to copy and paste code to "get things done", it's just not gonna work.
- ktran03 12y agoSame. I'm actually a little shocked HNers think regularly coping and pasting code snippets off the web is ok. That's, kind of crazy. This is bad especially for young developers (such as myself). Not to mention jeopardizing the security and integrity of your software project. I hear 'don't reinvent the wheel' often written in blogs etc. That is not good. The lazy developer would read that and go, 'oh, I dont need to know how these things work, it's already been done for me. I'll just slap A to B, no need to reinvent anything' Imo how it should read instead is, 'keep reinventing the dam wheel till you understand how it was made, only then you're free from reinventing it'.
- mattgreenrocks 12y ago> I'm actually a little shocked HNers think regularly coping and pasting code snippets off the web is ok I'm not surprised. Ever observe threads about software engineering? They're profoundly anti-intellectual. HN is not the place to get any sort of engineering advice, I'm afraid. It's tailored towards self-promotion via programming. The difference may seem small, but the motives are quite different: mastery (as a developer) vs getting it done.
- chrissyb 12y agoIMO it should be "You can't reinvent the wheel, but you can study physics to understand how the wheel functions."
- jesusmichael 12y agowow... You must be from the school of re-inventing the wheel... most things that need to be coded have been done before by someone else and quite well... No one chops down their own tress when they want to build a deck. They take lumber that someone else preformed and make it fit their project. If you are writing all your own code every time on every project... You must get nothing done...
- Shivetya 12y agoI will disagree with your copy and paste assessment. While it will hinder a junior programmer its a godsend to the senior developer. Someone who can quickly recognize what the code is doing and integrate it into the final solution. There are more than enough APIs just on the platform I work with daily that I can imagine how much fun it must be sorting through all those available to Windows developers must not be a joy. Well Google lets me search quickly for established solutions and combined with my knowledge I can quickly identify which if any will do what I want to do and adapt if not drop into my coding style. TL;DR Copy/Paste might not be good for new programmers, but time savings for experienced programmers warrants its use
- Kiro 12y ago> Then I'll throw them all away and code my own. Possibly it will share a lot with one of the answers, what I would consider a good approach So basically you're in the business of reinventing the wheel all the time. I feel sorry for your employer.
- userbinator 12y agoIt could be said that he is reinventing the wheel and trying to make it rounder, which is definitely a good thing.
- delian66 12y agoAlthough rarely, it is worth it sometimes to reinvent the wheel https://www.youtube.com/watch?v=h7Tq3Gsj6lY https://www.youtube.com/watch?v=h7Tq3Gsj6lY :-)
- lazyjones 12y ago> Copy and paste doesn't help you at all with this. In some cases it may prevent you learning essential lessons and hinder your improvement. It annoys the heck out of me too when people apply for a programming job and cannot implement even trivial CS methods (like integer => string conversion with base N), then point out that they would just Google for a solution if they needed something like this. But to be honest, a lot of programming wisdom is buried somewhere on the web as well as inside libraries that do not warrant reimplementation. Much of this googling and copy-pasting simply represents the fact that our traditional programming library approach isn't sufficient anymore for distributing correct implementations of particular functionality - probably too much overhead. SO is much like a large library with mediocre code, imprecise interface specification and without working imports, but it also contains many solutions to trivial problems that competent engineers should be able to implement straighforwardly...
- mattmanser 12y agoI have been programming professionally for 10 years, 5 years more as a hobby. I have been paid 100s of thousands of dollars, my code is used daily by 10s of thousands of people, I have built large, complex systems from scratch, worked in teams and by myself. The things I make do what they're supposed to, they don't break often[1], tend to be fast and usually my client is a happy bunny. I can fix anyone's code, even when I've never used the language before [2] and it was written by an outsourced programmer who quite obviously only read "how to write SatanScript in 28 days" and then was locked in a room for 2 years until his program kinda worked if you held it upside down while reciting the words to Annie. I am confident I am a good coder at this point in my career, and much better than many of the programmers I have met. There are a handful I have met that I know are better than me. I would only have a vague idea of how to do a integer => string conversion with base N without googling it. So am I shit? Am I suddenly a useless programmer because lazyjones only likes people who studied CS? Even though I can understand that code in a glance and rewrite it, often better or clearer than the SO example? You have picked an arbitrary, and extremely rare in the programming world, standard. No-one needs to write their own string handling routines any more. Programming is hard and there are many different flavours. And yours is an old fashioned favour from the early 00s. Stop judging people by it. [1] Apart from my very bad habit of making a minor last minute tweak or bug fix, not testing it, and introducing an easily fixed bug [2] They're all pretty much the same after you've used 3 or 4.
- ronaldx 12y agoAbsolutely disagree. I personally learned (as I think many people did) by copying code out of books. Whenever something went wrong, I had to figure out whether it was my typo or the book's typo or my conceptual error or the book's conceptual error. That process helped me to learn a lot, and quickly. If everything went perfect, I got to play some creative game which I loved and gave me a sense of acheivement that helped me to progress. I no longer do this, because it's not relevant to me at this stage of my learning, but I view that as an important part of my early learning process. If you reflect on your own early learning process, I would be extremely surprised if you didn't copy and paste code. Frankly, you are surely still dependent on other people's code now, you just might call it a 'library' instead. I agree if you're saying professional developers should avoid copy-paste (there are also legal consequences), but new learners can make great progress by using copy-paste. I would say it's an essential part of studying what other people have done.
- FreeFull 12y agoDo note that there can be a difference between copying code from a book (where you have to read each bit of the code and write it down) and simply hitting ctrl-c ctrl-v, in terms of what you learn.
- redshirtrob 12y agoI think there's a large difference between copy-paste and what you're describing (which I'll dub 'manual transcription'). I have no formal training in learning or cognition, but I do have quite a bit of personal, anecdotal evidence to suggest that manual transcription is far more useful, from a pedagogical standpoint, than straight copy-paste. Rather than take a boring example from my programming career I'd rather draw from my brief mathematical studies in college. In undergrad I was taking a course on Real Analysis. The course redefined, much more rigorously, certain concepts that I had understood at a much higher level--think the limit, derivatives and the Riemann Integral. Suffice it to say that these new concepts challenged my understanding of introductory Calculus, and when I was tasked with writing proofs based on the underlying concepts (e.g. neighborhoods), I struggled. In what can only be described as frustration I decided I was going to start copying the proofs over and over. I repeatedly transcribed half a doze proofs for a few days straight (I did each one a few times each night). A strange thing happened. I began to understand the proofs. By that I mean I started to understand the intuition required to make the transition between each step of the proofs. At that point I found the material much more accessible. Reading the book was easier, the lectures made more sense, I could do homework, and consequently I could complete the exams. I like this example because there is no copy-paste alternative. I had to engage with the material, but I chose to engage at a very mechanical level. Still, there was something about the process of reading and writing that aided in understanding the material. I don't believe you can get that with copy-paste unless you find some other way to engage with the code.
- increment_i 12y agoI can appreciate your opinion on this but it strikes me as a bit of a 'high horse' statement to declare that copy and paste is the wrong way to learn or advance the process of mental reasoning. At some level, we're all copying someone who came before us, unless you're working at the absolute bleeding edge. Everybody has their own style of learning, and not everyone is at a point in their journey where poring over API docs or dropping down into a lower level makes sense for them.
- Confusion 12y agoAgreed, but doesn't that mean the main premise is almost correct? It indeed seems like the skill of 'programming' depends on the development of a knack for Googling for the right terms. I think it is actually the other way around: once you develop the skill of 'programming', you will know what to search for when you have a problem and you will understand enough of the puzzle to construct the last piece from the various results to your search query. If you don't know how to search for an answer to your problem, you do not sufficiently understand your problem.
- riveralabs 12y agoCopy/Paste is OK as long as you understand the code. If the code is elegant and you know what's happening there's no need to change it. I would argue that the problem is not the copy/pasting but where to paste the code. As an iOS developer I download a lot of code samples from the Apple Development Website. In many cases on these samples the developers put a lot of code in Controllers to show how things are done. Beginner developers will usually copy/paste the code as is in the controller and believe what it does by faith. An experience developer should understand that the code was put in the controller for educational purposes and place the code where it belongs. A Model, Singleton, or leave it in the controller if it makes sense.
- orkoden 12y agoI have seen many sample projects included in full in final products. "It's from Apple, it must be good!"