No, you are not allowed to write generic code
I had a discussion with a dev on my team today:
Him: I don't want to write the code to fit just this particular scenario, I want it to be generic.
Me: This is in the controller for this particular use case, there isn't any other scenario that it will ever handle.
Comments
1) you might be limiting your developers, if the code still did what it needed to do, and there wasn't any significant performance hit, or amount of code to be written, I don't see why not let developers apply some techniques to write generic code
2) I'm sure this is a cultural thing, but in America I'm sure a lot of people would find this kind of post a bit rude
@Eber,
1/ The issue was dead code, stuff that handled a lot more stuff than was ever going to happen, and could be significantly simplified by dropping the unneeded stuff.
2/ There is a big cultural difference, but I also talk a bit differently than I write.
@Eber
I'm almost sure Ayende made the remark because it looked like the code took the developer extra time. But I could be wrong.
And yeah, I think it's a cultural thing :) I like clearness more than politeness (Europe).
@Grimace,
No idea if it took him extra time to write it, it took me extra time to read it. That is a capital offense on the part of the code.
I agree too, in a use case make no sense to have generic code. A use case by definition uses instances and no types, so in most of cases i think be useless to write generic code.
I think that one can write code in the way that I like, there is only one way for a beginer dev to learn this lesson and is to watch it by self.
i.e. if you said a good developer that don must write generic code, maybe him understand it, but other developers can think that they "NEVER" must wirte generic code and this cause more harm than good.
I think that the way is to left the developer to make the mistake and show it the problems at time, if the feature is simple sure it will work some extra hours to make it simply again, but he sure learn the leason =)
If I was in the situacion of a boss telling me that I dont must write generic code, sure I will begin to think in other work when I can express myself =)
Just my point of view.
Cheers
... one more thing =)
My boss some time ago when I was writing code for intersystem comunication with flat files tell me that I cant write something generic, and later I begin to write the FileHelpers ( http://www.filehelpers.com ) at home and later any new interface between our system is written in much less time and the impact of change is greatly reduced.
Cheers
Marcos
Comment preview