- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Sometimes you just get so slammed that it doesn't even occur to you to come to this site. It happens to me for a week or so at a time.
I hope he comes back, though, because boog is awesome. I would mourn his loss like I would mourn yours, frits.
Admin
Evidence is clearly steming from sixth sense that I develop after spending 1 year at camp for speshul gifted children.
Where is boog boy and what is sock pupet?
Admin
Admin
Admin
Admin
Admin
But this isn't the whole truth. The median number of parameters is two, and I have only 4 functions across perhaps 25 kloc that do take 5 parameters. Those functions could take a struct instead, but I really don't feel like changing them as they're written in assembly and all I'd be doing is loading stuff from the struct into the registers...
Admin
Admin
Admin
Admin
The reason I did the whole XML handling like this, was (again) because you had to be able to take out one web service and replace it with another. Since not all services use XML (I'm not even sure anymore if the second one did, or if it was an API they offered), I let the web service's class get the data and transfer it into the object, then the other web service's class'd get the object and transfer it into whatever form it required.
Add to that that it had to be possible to queue these (had to also happen during cron runs), I'd say storing a serialized object'd be simpler than storing an XML file with all the elements you'd be treating (data of 1 object vs. data of all objects in the database)
Of course, if there's a better way to do this, I'm all ears
Admin
But it makes no sense whatsoever to do this in machine code where you'd have to manage memory, and a struct has no methods anyway in machine code (so it could never be a visitor anwyay, unless you stashed a function pointer in the struct...). The end result of applying high-level concepts to low level languages is that you end up re-writing high level languages and doing a shittier job at it.
Admin
gasps for air PPPPEEEEEEEEEEENNNNNNNNNNNSISISISISISISISSSSSSS!!!!!!!!!
Admin
Where or when would you consider it acceptable to use static classes or static methods? I just don't follow the "OMG, you're a moron if you use static anything!" logic.
If you've ever stepped through .Net framework code, you'll see an abundance of static methods and classes like the Convert and Math classes, or int.Parse, int.TryParse, etc. etc., not to mention several "helper" classes I've come across in ASP.Net (like HttpUtility which should be static, but instead is sealed and filled with only static methods).
I really think a statement like "if I see static methods/classes, I'll need to teach the dev OOP" is very broad, and is wrong IMO...
I am, however, always open to other points of view, as long as it's backed up with a decent explanation.
Admin
Admin
Admin
I can top that. Not in LOC but, we have a 6,000 line C# file. Some highlights:
Admin
I haven't done enough PHP to know how thoroughly oop-ified it is, but my long-term design goal would be to develop a domain object model that generically describes:
Make the classes above abstract and then just provide concrete implementations when you need them. It's way more extensible than procedural-style static methods. It lets you share the code everywhere, optimize the hell out of the internals over time, and add new functionality to the natural growth points in your object model.
OOP is all about simultanously managing and encouraging the growth and improvement of your code base.
Admin
Addendum (2011-09-29 11:09): There was a 7.5 step process for adding new menu items that was only documented in comments across the code base. Why 7.5 steps you ask? Well there used to be 7, but the original programmer has to added a step between 2 and 3 (step 2.5). This is the high quality code you get when you pay $100 an hour to consultants. That rate applied to the time she spent in the bathroom crying after the department manager criticized her code/and or progress.
Admin
Admin
Holy shit! What could possibly excuse so much MFC code? Does she not want to use methods she's already used somewhere else because they're "used" and not brand new or something?
Admin
More WTFs:
This was for a measurement instrument that had two channels. Code related to channels had no less than 100 distinct checks for which channel we were on. ie.
The code was littered with checks like:
Where TRUE is macro defined as 1 and the result could be several non-zero return values.Several thousand line methods with multiple returns and gotos and inline comments that were 50 lines of justification for whatever crappy things they were doing that robbed screenspace and made things less clear than no comments at all. I wish I saved some of those comments because I remember some of them were pretty funny.
Admin
I prefer spaghetti-and-meatball code, where the spaghetti is bound to meatballs (data / state) and meatballs are connected to each other with spaghetti.
I disagree with Microsoft's use of Interlocked, Math, and Convert as static classes. They could have made them instance methods - which is ideal - or they could have made them extension methods if they found their intellisense member list getting too big, as they did with LINQ.
Every time I ever thought about writing a static class, it took no more than ten seconds for me to see how an object-oriented approach would be superior. If there is no conceivable state other than through types I don't own, I make them extension methods.
Admin
Admin
Admin
What does it take to get a ****ing article around here?
Admin
ducks
Admin
That's a good idea. Mention of Javascript always kills my sex drive. Along with my will to live.
Admin
Come on, guys, we're having a hard time since Alex's latest untimely passing. We're working on rebooting him, and then we'll have an article up for you.
Admin
Admin
MY EYES!!!!!
Admin
Admin
Admin
What you're arguing (extension methods) is a personal preference or style, which is valid, but nothing to do with whether or not you should use static methods or classes.
I do see the value in extension methods, but to me they're an extension of the developers personal style, which according to best practice and your very own words, should never exist in code. You should never be able to look at code and say "hoodaticus wrote this because there's fucking extension methods all over the place". Also, unless you wrote them yourself, they can waste other developers time because they're not defined in the same place/code-file as the type itself.
Also, other than the CLR doing this magic for you, what is different in your implementation than mine? At the end of the day all you have is a static class filled to the brim with static methods...
Admin
It's like those self-described guru's who see a nested IF block that's easy to read and maintain, but says "I can put this all on one line", the result being a ridiculous mess of OR's and parens, etc, stretching out to the right so far we have to scroll to see it, and nobody can really understand the actual purpose of what it's doing or how to make and adjustment if one is needed--regardless of how well someone thinks they've commented it.
Admin
Timmy, Pls don't make post again!
Thx, Nagesh.
Admin
Admin
Fake Nagesh, Chullu bhar paani mein doob jao!
Admin
With System.Math, OOP is not demonstrably better, so I don't mind it so much. But Active Directory is an object store of gargantuan proportions, with numerous methods and innumerable properties and nesting and yada yada. It's practially made for an OO solution.
Originally, all I needed was to look up a display name from a user name. I knew that Active Directory is a big topic and might need more functionality one day, so I resisted the urge to make a static class. I made a second class ActiveDirectoryUser to hold per-user data, with ActiveDirectory as the factory. Now when I need to authenticate a user, I just add a GetIsAuthenticated method to the user object. It grows over time.
Yeah, you can do all that with statics. Now add this wrinkle:
Make it work for a domain other than the one you're on.
Uhoh! Now I get to copy-pasta all my static methods to overload them with a domainName parameter.
Now data bind the list of all users to a ComboBox.
Okay, so now I need a GetUserStringList static method.
Now let someone select that user and reset that password from the ComboBox.
Gosh, this would be a whole lot easier if the ComboBox list items were bound to an actual object that has a ResetPassword method, wouldn't it? Instead of chaining a bunch of static method calls together?
It's not a matter of preference. If you start out with a static class, you will either throw it away when you need more out of it and replace it with a proper API, or you will add spaghetti, or you will simply leave the problem unsolved. Instance classes were invented to solve the latter problems.
With the amount of time required to start the OO solution not being significantly different from making a procedural solution, I go with OO every time. I really didn't think this would be even remotely controversial.
Since you and I usually agree on everything, I'm going to assume my lack of communication skills is at fault for our disagreement. I'm looking at this from the perspective of someone who has never written a static class and has seen them used as escape hatches by ALL BUT ONE of my developers so that they don't have to use OOP. The one good developer and I both sneer at Util classes because, to quote him, "they're not object oriented".
I don't know where you're coming from, which is probably where this conversation got derailed.
Addendum (2011-09-29 14:35): There are exceptions for everything. Nagesh brought up a good point about decoupling. If cross-namespace coupling bothered me, I would either put the coupling code in only one of the namespaces, merge the namespaces, or provide a static class to handle the conversion (if the conversion doesn't itself need OOP patterns for extensibility). So it is sometimes the answer - but I have never seen anyone do it, because most people just aren't that good.
+5 for Nagesh?
Admin
Admin
Plus your implication that anybody would need to teach me OOP pissed me right off. :)
My bad, we do agree.
Admin
Admin
Nope, that wasn't me (a) it said "unregistered" on the username, (b) I wouldn't use **** for fuck, and (c) most important, boyo, useless cunt I don't argue with, but I'm not a mick I'm a fucking taff, look you.
Admin
Yeah, come to think of it, what does it take to get a cunting article around here?
Admin
I told you my communications skills were to blame :). That would have pissed me off too! I apologize.
Like I said elsewhere, rules aren't for good developers - they're for bad ones. You are definitely in the "good" category. You're a rule maker - someone who should be listened to - not a follower.
For reasons why static classes are actually good and can increase the encapsulation of your non-static classes, see here. Although, he's only talking encapsualtion, while I'm taling about APIs in general.
Admin
Just today only I've had at least 3 head-desks because the person who I inherited the code from couldn't even spell OOP...
Admin
Admin
Abandon hope, all ye who hope for an article today.
This always happens at the worst times. Things are slow...I just spent the last 30 minutes cleaning out my inbox, and the only thing I have to come back to is C-Octothorpe and hoodaticus making out.
Admin
Admin
If you two are quite finished, there's still fifteen minutes before five o'clock. Nagesh isn't just going to bash himself, you know!