4 ms·
A Modest Proposal for the Copy and Paste School of Code Reuse
- patio11 18y agoIf there were only some way to give code snippets on the web some form of universal resource locator, you could skip the guid...
- varaon 18y agoThe existing problem (for Jeff) is that it is hard to find modified or improved versions of the same snippet. Whereas a URL points to an inidividual snippet, the GUID could point to different versions. The same GUID could also be used for the same snippet in a different language. Obviously you could also group related snippets on a site, but that formalizes it too much. Snippets are mean to be copy/pasted and passed around on forums, blogs and sites.
- mjs 18y agoBut ... you can still Google for the URL.
- deleted 18y ago[deleted]
- csomar 18y agoI think it needs a system, not simply developers do it like that. May be a new startup that takes care of snippets
- pavel_lishin 18y agoLike the ones he linked to?
- silentbicycle 18y agoFinding copy-pasted pieces of code that have been modified in place is actually a rather difficult problem. I've been working on a tool for this in my spare time over the last several months, and I hope to release it sometime this summer. Pinning down what's "similar enough" is subtle, and if you go too far, it complains that boilerplate-y code in e.g. Java is unnecessarily redundant. (While this is certainly true, it's not useful.) I look forward to the upcoming structured programming revolution. Some day, people will use subroutines!
- zacharydanger 18y agoJeff Atwood is essentially describing git/github.
- tumult 18y agoYou should copy and paste code so rarely that this shouldn't be a problem. The author of the article proves this point effectively with his snippet example; the correct way to fade out a window in Cocoa is with an NSAnimation and the NSViewAnimationFadeOutEffect on an NSWindow. His code blocks the thread directly and could cause problems, especially if called from a routine that responds to an IBAction (GUI event). There's a reason good developer documentation calls example code Listings or Illustrations: you're supposed to read and understand it, then write it yourself in your own application. Copying and pasting code verbatim is always a bad idea, even for simple things like short regexps. Don't copy and paste code that you don't understand or couldn't write yourself.
- teej 18y agoCopy, paste, and modify is one of the ways I managed to learn web development in the first place. Sometimes, understanding doesn't come from reading alone. You need to feel the clay in your hands to mold it into the pot you want to make.
- tumult 18y agoIf you learn better that way, sure, feel free to do what works best for you. I don't see how this applies to the article, which advocates inserting code with a GUID in a comment so that you can find it again later and copy/paste a new version in.
- teej 18y agoIt's a direct response to your comment, not the article. "Don't copy and paste code that you don't understand or couldn't write yourself."
- gnaritas 18y agoEver think that it actually slows your learning down? Honestly, you learn code much better if you actually type it yourself. Even if you have a working example, retype it manually, it'll make you appreciate doing proper reuse via function calls much better. Copy and paste is a bad habit, code is not clay, and treating it as such hurts you.
- biotech 18y agoIf one had a database of code snippets, then, given a specific code snippet it would be possible to find "similar" code in the database: code that had been changed or improved from some original version. One could even create an evolutionary tree for each snippet, if one were so inclined. The pertinent algorithms are already in heavy use in bioinformatics.
- vinutheraj 18y agoErr .. I am the only one with this view or did anyone else also think that the article wasn't provided any new insight or point of view. He just basically iterated everything that everyone knows about the pros and cons of copying code ?!
- silentbicycle 18y agoYeah. Many blog posts (and not just his!) consist of rehashed material from books like _The Pragrmatic Programmer_, _Code Complete_, _The Practice of Programming_, etc., with small amounts of commentary. Sometimes the author is doing it as a way to ruminate on the ideas, sometimes they're doing it for some kind of ad revenue, etc.
- anthonyrubin 18y agoThat is what Jeff does. I really don't understand how every one of his inane posts makes the front page of HN.
- pauldino 18y agoI thought this was new: "Attach a one line comment convention with a new GUID to any code snippet you publish on the web. This ties the snippet of code to its author and any subsequent clones. A trivial search for the code snippet GUID would identify every other copy of the snippet on the web."
- snprbob86 18y agoThere already is a globally unique identifier, although not necessarily a "GUID", on things you get from the web: It's called a URL.
- mannicken 18y agoOh my god, I can almost see some noir company disabling Ctrl-C/Ctrl-V on programmer's laptops.