3 ms·
I, for one, don't blindly copy and paste code. Code collects entropy over time; if it's been around for a while, it almost invariably can be improved. Copying a
by barrkel 12y ago
I, for one, don't blindly copy and paste code. Code collects entropy over time; if it's been around for a while, it almost invariably can be improved. Copying and modifying is cargo-cult coding in the small and one of the fastest ways to create a codebase where you have no idea what the code is doing.
Adding process and standardization around this seems like a patch on a dysfunctional coding culture. Standardization frequently ends up on something that isn't the best way, and with web development in particular, is likely to be outdated in a few months. Requiring meetings to change standards to improve code has got to be a toxic working culture.
- cmpb 12y agoGood point, but how do you keep up code quality in the code base with standardization? Edit: without* standardization
- barrkel 12y agoI'm assuming you mean without standardization? Pair programming, code review, and actively refactoring code to use existing abstractions or build new abstractions when it appears that the same problem is cropping up in a situation that might warrant copy / paste / modify. It might be possible that a couple of different abstractions / patterns crop up that solve the same underlying problem. It usually isn't a problem for them to coexist for a while until one proves better. Sometimes they evolve in different directions; sometimes the people most responsible for the respective abstractions agree between them what synthesis should win going forward. I'm just worried about giving too much ammo to a certain type of code lawyer, who likes to quote chapter and verse and gets a kick out of being technically correct. You find these kinds of people everywhere, on Wikipedia, increasingly on StackOverflow, etc., and I think they can create a bit of a poisonous culture if they have too much law to enforce. There is a place for some low-level standards, don't get me wrong, but it can get out of hand.
- gutnor 12y agoI agree with you in the following scenario: small team (<20 dev), manageable codebase size (~ 200K line), and enough budget to keep the project running without too much specialization. If you cannot keep the project within those parameters, code nazi is unfortunately the way to go. For most people on HN that should be another day at work, for entreprise backoffice system developers like me, that's a rare sight. And in any case it all breaks down without great communication between team members and compatible code culture (i.e. there is some way for the whole team to agree on something and apply it without childish guerrilla resistance )
- 0xdeadbeefbabe 12y ago> I, for one, don't blindly copy and paste code Yes, but blind to what? The coder is blindly manipulating symbols[0]. What if the code produces the artifact you desire? I'm not sure anyone really blindly copies and pastes. On the flip side, if you forget what you wrote in a month or two, how is that outcome different than copying and pasting in the first place? [0] http://blog.airover.ca/2014/06/programming-blindly-manipulating.html http://blog.airover.ca/2014/06/programming-blindly-manipulat...
- barrkel 12y agoSomeone sees this code somewhere: // this code accomplishes x foo(); bar(); frob(42); They want to do x, and they copy the whole block, and perhaps modify the argument. They have only a surface understanding of what foo, bar and frob do, if any. They don't know if there is an order dependency; they don't know if the behaviour is specific to the situation where the code was copied from, or whether it applies (or not) to the place the code is copied to. This is blind copy and paste. It is blind because it is not seeing through the symbols to the workings underneath. Functions, classes etc. as abstractions are useful, but they're leaky, and to write good code, you need to understand things at a lower level. At the very least, you need to know about implicit dependencies, time and memory complexity, and have a vague idea of the heft - the constant factor - of what you're putting into motion. If it's a codebase undergoing continuous development, and foo / bar / frob are grouped together in more than one place, it's a smell. The code probably needs refactoring and restructuring, and all the calling points need adjusting. This is just a more concrete example to get across what I'm talking about, since it seemed to be unclear. I don't have time to watch a video before replying, sorry. Also the only way I forget what I wrote a month or two ago is if I've changed jobs, and then it's a willing forgetfulness. It takes many years for me to forget my code, for better or worse.