6 ms·
Yup. There's so many of these that are either irresponsible (Hiding code) or of limited usefulness (IsNullOrEmpty) or too limited to be truly useful (Named Para
by mendicant 15y ago
Yup. There's so many of these that are either irresponsible (Hiding code) or of limited usefulness (IsNullOrEmpty) or too limited to be truly useful (Named Parameters).
Hiding Code: I've got an idea. If you've got to hide code, maybe it _doesn't belong in that class_. Single responsibility people.
String.IsNullOrEmpty(): Wow! Thanks MS for saving me from writing one 4 line helper method. What would be useful is if you provided these helpers for the other 90 that I need every project. Seriously, any C# dev can provide you with their "utility" project that has them.
Named Parameters & Defaults: Awesome!..... unless you need something other than a primitive, in which case you can't set default values, since it's nothing but a fancy compiler trick.
I like C#, but really, there's not much they've added since Linq that's really crazy interesting. Not that there isn't, but most of it isn't listed in this article.
- varunsrin 15y agoHiding code is actually quite useful - its not meant to obscure code that doesn't belong, as you imply. Say for instance, I'm working on two methods that are expansive, but i'm trying to debug a small part of those methods. To make watching breakpoints and tracking flow easy I hide all but the necessary parts of the code. I use regions in pretty much the same way - once I have a certain region of functionality locked down and tested, I hide it so I can focus on the part that's still being developed / tested.
- kevinkemp 15y agoIf your method only has one responsibility, the chance that you need to "hide" any code is almost nonexistant.
- jasonlotito 15y agoOf course, if your methods are properly written, the chance you need to "see" all the code is almost nonexistent.
- mendicant 15y agoMy point is: If your class/code/file is so big that you need to hide code to be able to easily navigate (or worse, understand) it, you're doing something wrong. I understand this is a religious argument of the code world and you're likely to disagree with me. I'm fine with that.
- boyter 15y agoYou are missing the point. Lots of large applications I work on maintaining have large awful methods. This feature is excellent in these cases. You could argue that I should re-factor the whole thing to avoid this issue, but certain design decisions made by someone else make this a huge change, and in the world of risk adverse enterprise applications that is not going to happen.
- hkarthik 15y agoCan you not start writing tests against those monster methods so that you've got a refactoring safety net? I totally agree on being practical and not refactoring methods that work correctly. But if you find yourself in the monster methods making changes quite often, it seems irresponsible to not refactor and leave the camp ground cleaner for the next time you or someone else comes through it.
- boyter 15y agoIts a big ball of dependencies with no chance to mock due to someone deciding on being "clever". Its up there with being untestable. Generally I agree. If possible clean it up, but quite often its a small one line change, which needs to be fixed ASAP, so there is little chance to refactor.
- varunsrin 15y agoTo be honest, its like a matter of OCD to me - for instance, I like keeping my desktop completely free of icons (even though I don't need to). In a similar way, I like only looking at the code that's relevant - if the method I'm working on is larger than a single screen (which happens with comments and such included) I like collapsing parts I don't care about. I don't, strictly speaking, need to in order to work effectively but I like to - as you said, more of a religious argument than a quantifiable one.
- kevinkemp 15y agoI wouldn't lump named parameters and defaults together like that. They're completely separate concepts.
- mendicant 15y agotrue, but they kind of go hand in hand. The nice part about named params is that it can make your code more clear if you have a lot of parameters on a method... but you could do the same thing by introducing a parameter object and be as clear and more resistant to change.