- 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
This: http://www.artima.com/weblogs/viewpost.jsp?thread=128338
God damnit akismet! This isn't spam you robotic whore!
Admin
And I could care less whether or not extension methods are "pure". Just imagine how terse my code is when I have extension methods like this:
static bool ForEach(this SqlConnection connection, string sqlExpression, bool isStoredProcedure, ForEachDataRowDelegate method, <snip exception logging optional parameter>)
Which lets you run a lambda statement against every DataRow in a SELECT statement. Very nice, one-line O-R mapping is the result (if you are creating objects in the lambda).
I also have these:
public static string CE64Serialized<T>(this T unserializedObject, byte[] encryptionKey, byte[] initializationVector)
public static T CE64Deserialized<T>(this string serializedObject, byte[] encryptionKey, byte[] initializationVector)
for de/serializing, de/compressing, de/encrypting, and then base64 de/encoding any serializable object. In one line of code.
Extension methods are the shit.
Admin
You're right, I have several sprinkled through my code base as well.
I try to avoid it if I can by putting common logic in my base classes. For example I have a two protected overloaded methods called Exec, one takes a Func<T1, TResult> and the other just an Action (no return) and wraps them in a try/catch with the catch closing the DB connection and throwing the ex. I could have easily put this in a common extension, but to be honest it isn't used outside of any class that inherits from it.
OTOH, I have an extension method for a custom enum type which is decorated with custom attributes to support localization: ToDescription(this MyType type){ // get the desc }. I did this because it's used everywhere in the app and because I can't stick it in the enum itself...
I do like them, I guess I'm just a little resistant to throw them at everything... And probably because I'm moderately retarded. :)
Admin
Sometimes the old ways really are best.
Admin
Admin
Thank you for the first real answer. I wasn't trying to troll, I was just curious as to why one would use the enum type in java.
Admin
I can think of a few differences between java's enums and regular classes:
Admin
All right, this is just being bloody minded. Yes there are homonyms for capital. They are still different words and it is clear from the context which version of capital the poster is using (i.e. the one that means exactly the same thing as "upper case" - e.g. A,B,C,D...).
Admin
TRWTF is that he uses the majuscule for H and O and the minuscule all the other letters. Am I right?
Admin
FTFY
Admin
waits for someone to fix his example of the code, wondering if they'll spot the nasty little change
Admin
Clever.
+4 plus an extra 2 for rail fan geekery.
Admin
Don't eat this Biryani crap. All bicycles are brown.
Admin
Except that isn't really what he said, is it?
Admin
So you want to use enums instead of classes/object? By allowing additional data and functionality you seem to be getting rid of the concept of enums in favour of classes.
Ironically, isn't this sort of over-engineering to make something availbale that is already available through other means exactly what todays WTF is about?
I'm guessing it depends on what you wnat an enum to be and what you want it to do
Admin
Which side were you arguing again?
Admin
I'm with boog on this one.
If we all wanted exactly the same functionality, we'd all agree that teh same language was best. We always see the old c(c++,c#) vs Java on here, with spatterings of python, haskell, lisp etc... (I won;t mention VB - I think every realises that is the absolute root of all evil).
And I think your clutching at straws claiming that people who dislike (or don't see the point of) features you like must be imbecile programmers...
Admin
Upper Case! Oh such wit!
Admin
Yah - I think you take word 'need' to a bit of extreme. If we ignore things we don't need, we'd still paper processing in most industries - and I don;t think that was even remotely boog's point...
Admin
Here comes the orchestra!
Admin
What you talkin' about? Capital would be used in both of the cases Steve mentions. Capitol (as far as I know) is a yankee word for where parliament sits (or congress, or something), thus Capitol City is the (fictional?) city where the Capitol is (there is apparently a Capitol City in kentucky, but Im guessing this is something else again).
Capital Ships are some sort of warships Capital Cities are the 'heads' of a state or country...
capitol is definitely very different to capital (as you point out) but there hasn;t been anuy confusion in mr The Cynics post...
Admin
Right.... So Java introduced these (fully fledged, apparently) enums in the last 7 or so years, but people who don;t understand what these things are or how powerful and fun they are couldn't possibly know the first thing about programming.
Hum. Wonder how much software has been written without such functionality (often, I dare say, by people who still wouldn;t understand the need for it). I'll give you a clue: A lot of software was written more than 7 years ago, and relatively loads of software is written using technologies other than Java.
No wonder there's so much crap software around. Let's all vote for Java and insist that people use as much of these fully fledged [strikeout]unicorns[/strikeout] Geiger-good enums as possible. This will guarantee that only the best people create only the best sodtware!
Admin
Admin
Now he just needs to start writing in C, where it's not a problem to do that.
Admin
Makes sense. He is talking about enumerating different strings after all.
Admin
All this talk of using enums in OOD is giving me agita.
Admin
FTFY. You forgot the 'n'.
Admin
I myself wrote plenty of s/w before about 7 years ago, and (as that was what the co. I worked for was paying me for) I wrote a lot of that in java. When enums came along I was delighted because it allowed me to achieve the effects I wanted in a lot more streamlined and maintainable manner.
I understand that as it was written in java it is by your definition substandard, but that's what I was paid to do. But it's facile to opine that because a program was written in a particular language it stands to reason it is rubbish. It's the sort of statement that causes one to come very close to blows. Even outside of the obvious trollery of a forum like this, this attitude is widespread in industry. It's one of the reasons I quit my last job: one of the DBAs refused to take on his responsibility on a project task because one of the sections that I wrote was done in PL/SQL. He told me it was rubbish code without even bothering to read it. It took six months and managerial intervention for him finally to even read the bloody thing. And when he did he had to sheepishly agree that it wasn't a bad implementation of what was indeed a fiendishly complicated requirement.
So, apologies for coming down on the side of "enums in java are good" but they certainly have their advantages. You don't choose to use them? Good for you. Now FOAD.
Admin
Enums should be compile-time shortcuts treated as primitive types in closed sets typed by the enum name. Functionality for enums should come from the same place that functionality comes from for all primitive types.
Since Java uses hey-I'm-really-a-class primitive methods, the implementation of enum (a class with a bit less typing in the start) is passable.
Similarly, since C doesn't associate machine types with machine instructions, its implementation is also sound.
Personally, since I prefer coding in C, I prefer C enums, although if I could add one thing to the standard it'd be compile-time strict enum typechecking (automatically disqualifying the ugly to-int mappings).
Admin
FTFY
Has anyone else noticed how astute / apt / ironic the Captcha Test has become. On this occasion, "damnum"; being the cod-Latin explecitve that boog would undoubtably have chosen when he realised he'd been had, lost...
Admin
Basically, Java enums are just syntactic sugar for the pre-Java-5 "typesafe enum pattern", with all the tricky parts (especially serialization) automatically implemented correctly and hidden from view.
Admin
Admin
On top of that, Java enums give you a lot more very useful features. But how does that mean "getting rid of the concept of enums"? The core property is still there. How is that "over-engineering" when the basic syntax is just as dead simple as in C and only gets a little more complicated if you actually use the additional features?
I stand firm in my conviction that the kneejerk rejection of the concept I was originally responding to can only be born out of ignorance and an unwillingness to even consider that implementing a concept differently from what you're used to can be any good.
Admin
Admin
I agree with every word, pal. My experience of java enums is fully positive.
They're easy to misuse by those who don't understand the concept and haven't bothered to learn the useful features (e.g. I've seen static helper classes written to convert the enum value to a descriptive string, e.g. "if (myEnum == MyEnum.BROKEN) return "Broken" else if ..." and full-on iteration through the instances instead of using valueOf etc.) but such things are amenable to maintenance improvements.
I believe a lot of the trouble here is that there is a perception of what an enum "ought to be" and anything which enhances the programmer experience of such enums is viewed as "a bad thing".
Admin
Yep, defining variables instead of constants would have made things much more interesting.
Also note G is missing.
Admin
I thought it stood for "Shift", as in "Shift Lock" which was provided on typewriters. It's always been a mystery to me why it changes the behavior of all of the character keys, not just the letters. Perhaps there really are capital digits and punctuation marks.
Must be an Elbonian spelling.
Admin
A better response from you would have questioned the accuracy of their concerns (Ex: do Java enums lead to the problems they fear?), rather than dismiss their concerns entirely and call them bad programmers.
Admin
If he's not, I will. How can anyone decide they don't need features if they don't know how to use them ? Not knowing how to use a fundamental language feature makes you a bad programmer, because when the time comes for you to use it, you won't realize it, and instead use buggy hacks that will land your code on TDWTF with a sarcastic comment about how you should have read a Java Programming For Dummies handbook.
Admin
I suppose I could make a fort out of sofa cushions and luggage. If I were to put one suitcase on top of the other to form a roof, then it would be true in both senses that it would be the upper case (by which I mean capital) and the capital (by which I mean upper case) of FT.WTF. Any way you look at it, sofa cushion forts are good places to commit eros.
CAPTCHA: populus. Man, I loved that game.
Admin
Do these really sound like well-considered worries about maintenance to you?
Admin
Admin
It's actually not so weird to do this in C. (Well, it's a little weird in this post though not a full WTF.)
Often stuff like device protocols involve ASCII character codes, so you can do this
typedef enum { Foo = 'f', Bar = 'b', Baz = 'z', Bat = 't' } ControlCode;
int sendControlCommand(ControlCode code, int value);
The whole point of an enum is to use a nice descriptive symbolic name ("Foo") for an abritrary value ('f'). I.e. as an improvement in clarity. No reason those values can't be chars (in C at least). The whole a, b, c thing in this post is either neccesary in VB or the programmer was uninformed about using character constants in the language (I don't know I don't know VB).
Admin
So yes, their comments (though sardonic) seem to indicate a concern over maintainability to me.
Admin
FTFY
Admin
Actually, you can do something like
Enum SomeEnumName SomeValue = Asc('a'c) SomeOtherValue = Asc('b'c) End Enum
This has the advantage that the enum value is easily converted to a char if that's what you need to write out to a file and you can tell what character it is without memorizing ASCII codes. The compiler realizes that Asc('a'c) is really constant.
Admin
The differences are:
Admin
This code is still present in the ticket validation system at the science center where I used to work... I left after being told I would not be allowed time to document anything I did and that I "would be around to fix things anyway" :p (just one of the reasons :p)
Please excuse the horrible coding practice, it was meant as a quick test but stayed.... (it is a simple logging of values to database, just statistics so I didnt care if I lost the occasional value...)
Admin
There is a difference between capital and upper case letters, but all of you are about four hundred years too young to know or care: a capital letter is a large embellishment that begins a scribal paragraph or sentence (but smaller than what we'd call drop caps), and an upper case letter is one modeled after the old Roman cursive as it applies to typography. Printers (that is, human beings who operate printing presses) would have two boxes ("cases") of metal letters to draw from, and the majuscule letters (which is the actual term) were in the upper one.
Also, "capitol" is a noun. "Capital city" is correct. The only city that is "capitol city" is a city called Capitol. Like Metro City or something.
Out-pedanted, ohh yeaaaaah. B-|
Admin
Shit, I forgot what I was originally going to post about.
The random letters are in capitals because VB automatically corrects the capitalization of a declared variable throughout the project whenever it's re-declared, including in a function definition. If the variable isn't declared (and Option Explicit isn't enabled) then every use of the variable changes its case.
This means that the moron responsible is not only picking terrible variable names, but also re-declaring them for e.g. For counters.
My god, Alex, why can't we do inline code tags?