3 ms·
I was quite comfortable with refactoring for a very long time before I started doing tests, and I think that colors my approach to the problem space. I write co
by hinkley 9y ago
I was quite comfortable with refactoring for a very long time before I started doing tests, and I think that colors my approach to the problem space. I write code until it misbehaves the first time, and then I start writing tests, comfortable in the knowledge that in another half hour this code will be unit testable and look better than what everyone else is turning in, and that I'll spend 20 minutes at the end cleaning it up even more.
But I am not everybody, and trying to set team policy on my comfort levels is quite likely a bit dangerous.
I've paired with a few smart people this month and was horrified by how they refactor. Most trust their hands more than the tools. They do a LOT of transcription instead of copy and paste, and don't use the IDE's refactoring tools at all. That's not just inviting human error to the table, that's giving it the seat of honor.
For most processes there are ways to do it that are worse than nothing at all, and unfortunately many of us seem drawn to them almost instinctively. I try not to think about it because it just makes me angry that the distance between what we collectively know and what we individually do is so wide.
- thaumasiotes 9y ago> They do a LOT of transcription instead of copy and paste Transcription makes you think about what you're typing in and avoids the whole class of errors that arise from copy-and-paste. Transcribing code rather than pasting it is not a red flag.
- hinkley 9y agoTranscription can lead to the same conditional in two blocks of similar code instead of the two intended. It can lead to fencepost errors due to changing or inverting an inequality. And in some languages it can lead to code that looks up data that doesn't exist (misspell a property name outside the happy path). The big problem is that you're chewing up short term memory slots that used to hold the next thing you planned to do. For me I generally use only a couple slots for a single refactor because it's all muscle memory. Additionally, it just takes a hell of a long time, which means you go from virtually no chance of interruption to a measurable one. When I was young I had an exceptional short term memory and could pull off some crazy big refactor without introducing errors. But now it's normal at best, and also I rely far less on those sorts of feats, in part because I put a higher value on commit history readability.
- thaumasiotes 9y ago> Transcription can lead to the same conditional in two blocks of similar code instead of the two intended. It can lead to fencepost errors due to changing or inverting an inequality. And in some languages it can lead to code that looks up data that doesn't exist (misspell a property name outside the happy path). Funnily enough, all of those are also problems with copy-and-paste. But they're much more likely to occur through copy-and-paste, because it's easy to do that without reviewing the code.
- hinkley 9y agoYou're saying you should do extract method or rename variable by typing the code out again long form instead of cut and paste or using the IDE?
- reitanqild 9y agoWhat language?
- hinkley 9y agoIn this case a bunch of former Java devs touching Java for the first time in a while. There could be something to that. Could be they've forgotten how, but this isn't the first experience like this. I am doing fine with the tools even though they don't do everything when the language is not statically typed).
- reitanqild 9y agoI'm afraid it is common. Java isn't perfect and when people also treat their IDE as a glorified text editor I think it is no wonder they dislike it. (If you go with Java, embrace it. This is probably the thing I disliked most about the way programming was taught in school: they used Java, but without the tooling that makes it awesome. Supposedly so we should learn it well. If anyone here teaches Java: by all mean have your students use javac in the first assignmemt but teach them maven the very next thing you do. Learn them to use an IDE - it's not harmful as long as you don't accept autogenerated code.)
- poikniok 9y agoWhat is wrong with autogenerated code?
- reitanqild 9y agoNothing. There is nothing wrong with code generation in a production setting with "grown up" engineers who uses version control and knows the pitfalls. The part in parenthesis is just a rant about education and how teachers use notepad and javac to teach Java. So my point is the only thing students shouldn't use in an IDE is code generation.
- copperx 9y ago
- ericgunnerson 9y agoAuthor here... I have the same issue you have. I luckily work in a language with great refactoring tools, but it's like pulling teeth to get people to use them rather than cut and paste.