TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

I hate cut-and-paste

120 点作者 emwa超过 13 年前

26 条评论

samlittlewood超过 13 年前
For bonus points - add robust code folding to this, especially when the folding persists across edit sessions.<p>I worked on a large embedded system where all the principal developers used such an editor (there was some occam heritage). One incautious copy and paste of 'a handful' of lines, and you had accidentally replicated a complete subsystem! It made debugging 'interesting'.<p>Every time I think 'Oooh - code folding - what a great idea', I retrieve those memories.<p>More generally, any time editor cleverness is interposed between the creative idea and the source code, I get a twitch. It should be possible to work on the source code without requiring anything more than a bare-bones editor - that is all I can assume about what my favourite editor shares with whatever future developers (incl. myself) happen to be using.
评论 #3149057 未加载
markokocic超过 13 年前
Actually cut-and-paste is ok, since the code is moved from one (wrong) place to another (better) place.<p>Problem is copy-and-paste, which litters codebase with duplication and lead to messy and hard to maintain code.
评论 #3150401 未加载
评论 #3150101 未加载
jrockway超过 13 年前
Great article. Code expands to fully use all available editing tools. If you can see 1000 lines of code on your screen at once, you'll work with 1000 line chunks of code. If you have great tab-completion, you'll make your APIs big enough to make the tab completion useful. If you get a million lines of boilerplate every time you create a file, every file will be more than a million lines long.<p>What's great about ed is that you keep most of the program in your mind. There is no tab completion. There is your brain. And when you keep the whole program in your brain, you write less code and the code you write is better thought out. I wish we could go back to the days of ed, but all we can do now is consciously resist the desire to work at our tools' maximum capacity.
评论 #3151103 未加载
swombat超过 13 年前
<i>Then came the full screen editors. They were a bliss compared to line editors. Really. If you don't believe me try 'edlin' for a day or so. We'll see how you like that. Then you'll be wondering how come any software got written at all for the first 2 decades of computing.</i><p>I have been wondering that, actually.<p>On the topic of the article, luckily, the Rails community (and python, and others) seem to have embraced this idea, under the heading "DRY principle" (Don't Repeat Yourself). There might be a connection between that embrace of DRY and the fact that Ruby/Python afficionados tend to prefer "simpler" text editors (Textmate, Vim, Emacs, Sublime) rather than IDEs.
评论 #3149458 未加载
评论 #3149017 未加载
TelmoMenezes超过 13 年前
Although I'm not from the punch card era, I overall agree with the sentiment of this article. I learned to code has a hobby when I was a kid and then took a CS degree. During the CS degree I was indoctrinated out of "bad habits" that I developed as a self-taught programmer. One of these bad habits was being terse. I took my degree during the golden age of createFactoryOfServerProcessGenerators() type things. Now, with more experience and wisdom, I realize I was right all along. A development environment that comfortably fits in your brain makes programming more effective and fun. And maybe I'm too idealistic, but I strongly believe the two are related.
david927超过 13 年前
Copy-and-paste is bad, I agree, but on the other hand, I hate it. And by 'it' I mean <i>all of it</i>. I have never seen a large system that could, for more than a moment in time, be seen as anything else than elephantiasis.<p>It's shameful and I'm sick of it. I want out. Right now, I'm paid quite well as a contractor to make some enhancements to a project developed by a hundred underpaid developers in a distant land, who did a remarkable job, considering. But it's rat's nest -- they didn't stand a chance. And I can't look myself in the mirror anymore and say this is what I do. It's grotesque. I'd rather run a coffee shop (and indeed I've been talking about it) because at least I could go home at the end of the day having seen a little beauty here and there, instead spending all day staring into the face of the Elephant Man.
评论 #3149043 未加载
评论 #3149225 未加载
ssp超过 13 年前
As usual, there is merit to the opposite side too. Don't create some huge abstraction with class hierarchies and virtual methods and stuff, just to avoid cutting and pasting a ten-line function somewhere.<p>Often it's a good idea to start by cutting and pasting, and then afterwards figure out what ended up being sharable.
评论 #3149187 未加载
评论 #3151210 未加载
staktrace超过 13 年前
I hate people who say cut-and-paste when they mean copy-and-paste. Pet peeve of mine, I guess.
评论 #3149428 未加载
skrebbel超过 13 年前
I really disagree with the premise of the article that IDEs encourage copy&#38;paste. Full screen editors do. IDEs do the <i>opposite</i>, by making it super-easy to reuse existing code through code completion and docblock tooltips. In a decent IDE, copy&#38;paste is often <i>more</i> work than finding the right method and calling it.
评论 #3149216 未加载
praptak超过 13 年前
My first programs ran on a programmable calculator. I wish I could have kept the habits I had back then. Drawing block schemata on paper before coding seemed tedious but it was in fact valuable. Damn you lord Sinclair and your ZX Spectrum for providing a full screen "editor" which let me skip the design phase. And it didn't really have cut'n'paste in the modern sense.<p>(Edited) Also: <a href="http://clonedigger.sourceforge.net/" rel="nofollow">http://clonedigger.sourceforge.net/</a> Use it for great good.
评论 #3150315 未加载
mjschultz超过 13 年前
Does anyone know if there are tools out there that look at a code base and find "similar" snippets of code?<p>I would expect such a tool to parse the language into AST form and find branches that are the same except some identifiers and a few other details. It is probably intractable in general, but I think it is feasible for most code bases.
ErrantX超过 13 年前
Yep; we've just had exactly this problem with a contractor. Some functionality needed tweaking, which was done on one page - but on testing we found the exact same functionality hadn't been tweaked on all the other pages.<p>Huh?<p>Turned out it was a copy/paste job... which in turn became only the start of the rabbit hole. :)
mebassett超过 13 年前
It's gratifying to get something up and running quickly. I do a lot of "copy and paste programming" to get a functional prototype doing stuff. it's helpful when I need to show a non-technical person (e.g. my boss) in a convincing way. ctrl-c + ctrl-v is my best friend<p>Most of it is throw-away code: just playing with ideas and different implementations. Exploratory programming is cheap these days, and I really think it's for the better.<p>If it looks like I'm narrowing down on something I'm actually gonna use, I refactor, rewrite, simplify, and delete a lot of code. ctrl-x becomes my new best friend. (I write in natural languages much the same way.)
chaosfox超过 13 年前
And I hate guns. No wait.. actually I hate people who use guns to kill other people.
评论 #3148930 未加载
klklklk超过 13 年前
There are some greate advice however its impractical in the real world. (I am not defending copy and paste, the DRY principle should be your number one rule.) Most (good) contractors work in this way however its impossible to lay out your solution to its entirety and build a beautiful solution. Without specs being changed on you or you realizing that what you are building is not something the clint wants.
rayhano超过 13 年前
But, but... surely what you are suggesting is people be intelligent... why would they do that when they can be bone idle lazy???
becomevocal超过 13 年前
Right on.<p>To get code shipped I usually copy and paste if it really saves me time, but make a checklist of optimizations I can do at a later date.<p>When that time comes, find/replace does the dirty work.
kleiba超过 13 年前
This is reminiscent of a classic Yegge blogpost: <a href="http://steve-yegge.blogspot.com/2007/12/codes-worst-enemy.html" rel="nofollow">http://steve-yegge.blogspot.com/2007/12/codes-worst-enemy.ht...</a>
sylvanaar超过 13 年前
Good IDE's will help you find code duplication.
wccrawford超过 13 年前
It's poor carpenter who blames his tools.<p>What he really hates is his lack of willpower when it comes to doing things the wrong way. Cut-and-paste enabled him to be lazy, but it certainly didn't force him to be.
评论 #3149054 未加载
djKianoosh超过 13 年前
copy/paste is one of the cancers of our profession
评论 #3151429 未加载
drivebyacct2超过 13 年前
I'm confused. Isn't this just a discussion of code duplication, that most try to avoid in programming because it means it should probably be re-factored into something reusable? Isn't it more about copy/paste then than cut/past?
davewicket超过 13 年前
cut-and-paste != copy-and-paste.
skeptical超过 13 年前
This article is just wrong.<p>Thanks to eclipse I go days without copy-pasting. May I suggest that if you're copy pasting too much you're doing it wrong?<p>If we take it to the extreme, why would you need to have the same code in two different places?
评论 #3149161 未加载
eliben超过 13 年前
&#62; I blame the IDE's<p>Please, <i>please</i> learn to write correctly. "IDEs", not "IDE's"
45656565超过 13 年前
So I make a tool to make my work easy, then I go and misuse the tool to make my work shitty. Then I go around blaming the tool for my shitty code since it does not hinder me writing shitty code. I never thought a editor was supposed to hinder writing of shitty code.