4 ms·
You 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
by tumult 18y ago
You 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.
- teej 18y agoI'm not saying I do this today, I'm saying it was integral to my learning process when I started, years ago. Typing it out doesn't help solve the issues of learning the subtleties of syntax. You need to start with something that works and then start seeing the ways your poor typing breaks the code.
- lacker 18y agoBut sometimes I need to use code that I couldn't write myself. An example: you can send an XmlHttpRequest to a different port on the same domain in Firefox, but only if first you add the line document.domain = document.domain; Now, I wouldn't expect to be able to figure that out myself. So I just copy and paste, add a comment saying that this is a bit of magic that makes cross-port xhr's work in firefox, and add the url I got it from in the comment. Doesn't that seem reasonable?
- tumult 18y agoYes, it does. We don't need some GUID standard for stuff like this, as advocated by the article. Your example is fine.