Comment On ArticleTypeCodeSOD

Code generation can be an effective tool for strongly-typing your custom domains if the given domain is constrained to a specific set of values. Acceptable examples would include color names, statuses, and U.S. states, among several others. [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: ArticleTypeCodeSOD

2010-05-26 09:01 • by a care-bear (unregistered)
care-bear obliterates the competition by care-bear-staring into frist

Re: ArticleTypeCodeSOD

2010-05-26 09:04 • by Ocson (unregistered)
WTFCommentA

Re: ArticleTypeCodeSOD

2010-05-26 09:05 • by Chester (unregistered)
WTFCommentB

Re: ArticleTypeCodeSOD

2010-05-26 09:05 • by highphilosopher (unregistered)
Was this WTF generated via a WTF Generator, or did this really happen?

Re: ArticleTypeCodeSOD

2010-05-26 09:06 • by Airhead
This is pure brilliant because...uh, never mind.

Re: ArticleTypeCodeSOD

2010-05-26 09:07 • by MyKey_
Gotta be fun to try this with unicode.

Re: ArticleTypeCodeSOD

2010-05-26 09:08 • by Jan (unregistered)
This is best practice on embedded devices!

Re: ArticleTypeCodeSOD

2010-05-26 09:11 • by Barry (unregistered)
309657 in reply to 309656
Jan:
This is best practice on embedded devices!


I would take a photo of the alphabet on a wooden table...

Re: ArticleTypeCodeSOD

2010-05-26 09:11 • by Befton John (unregistered)
This would've been even more brillant if written in VB.

Re: ArticleTypeCodeSOD

2010-05-26 09:13 • by Knux2 (unregistered)
(Java)

System.out.println(ClassTypeW + ClassTypeO + ClassTypeW
+ ", " + ClassTypei + ClassTypet + " " + ClassTypes
+ ClassTypeu + ClassTyper + ClassTypee + " " + ClassTypet
+ ClassTypea + ClassTypek + ClassTypee + ClassTypes + " "
+ ClassTypea + " " + ClassTypel + ClassTypeo + ClassTypen
+ ClassTypeg + " " + ClassTypet + ClassTypei + ClassTypem
+ ClassTypee + " " + ClassTypet + ClassTypeo + " "
+ ClassTypet + ClassTypey + ClassTypep + ClassTypee + " "
+ ClassTypea + " " + ClassTypes + ClassTypee + ClassTypen
+ ClassTypet + ClassTypee + ClassTypen + ClassTypec
+ ClassTypee + " " + ClassTypet + ClassTypeh + ClassTypei
+ ClassTypes + " " + ClassTypew + ClassTypea + ClassTypey
+ "!");

Re: ArticleTypeCodeSOD

2010-05-26 09:13 • by Elmo (unregistered)
This is very handy.

Just in case the alphabet changes, in that case you are prepared!

Re: ArticleTypeCodeSOD

2010-05-26 09:17 • by pointyhairedpeon (unregistered)
That's actually pretty clever, in this way one can use inheritance to, I don't know, change the string associated to each letter. But it'd be better to dynamically generate this code through a SQL query, and embed the query into a PHP script. Then I'd write a small VB script piloting the cursor and the keyboard buffer in order to open Access, write the SQL query and launch it automatically.

CAPTCHA: dolor - how oddly appropriate.

Re: ArticleTypeCodeSOD

2010-05-26 09:25 • by apaq11
This solution is clearly not correct. There's no support for lower case letters...

Re: ArticleTypeCodeSOD

2010-05-26 09:25 • by ClutchDude (unregistered)
Wait....

Let me get this straight.

Everything in string the class is private and there are no other classes or methods?

I'm going to say it's the lack of sleep, but is there a point to this class if it's all private w/o getters?

Re: ArticleTypeCodeSOD

2010-05-26 09:25 • by toth
This is ridiculous. It's utterly useless; how do you do lowercase letters? And punctuation?

Re: ArticleTypeCodeSOD

2010-05-26 09:26 • by grizz (unregistered)
309665 in reply to 309661
pointyhairedpeon:
That's actually pretty clever, in this way one can use inheritance to, I don't know, change the string associated to each letter. But it'd be better to dynamically generate this code through a SQL query, and embed the query into a PHP script. Then I'd write a small VB script piloting the cursor and the keyboard buffer in order to open Access, write the SQL query and launch it automatically.


-1: Where's the XML?

Re: ArticleTypeCodeSOD

2010-05-26 09:26 • by Vladimir (unregistered)
Генерация кода может быть эффективным инструментом для сильно вводе пользовательских доменов, если данный домен ограничена определенным набором ценностей. Приемлемые примеров можно назвать имена цветов, статусов, и штаты США, среди ряда других.

В некоторых случаях это полностью избыточными для этого, например, если вы сильно набрав алфавиту:

ClassTypeLetters общественного класса
(
частных пд ClassTypeA = "";
частных пд ClassTypeB = "B";
частных пд ClassTypeC = "C";
частных строку сопзЬ ClassTypeD = "D";
частных ClassTypeE строку сопзЬ = "E";
частных пд ClassTypeF = "F";
частных ClassTypeG строку сопзЬ = "G";
/ / H-W ...
частных пд ClassTypeX = "X";
частных ClassTypeY строку сопзЬ = "Y";
частных пд ClassTypeZ = "Z";
)

Re: ArticleTypeCodeSOD

2010-05-26 09:28 • by Mister Zimbu (unregistered)
309667 in reply to 309664
toth:
This is ridiculous. It's utterly useless; how do you do lowercase letters? And punctuation?


ClassTypeLetters.CreateLetterTransformationFactory<ClassTypeA>(this).TransformLetter(LetterTransformationFactoryTypes.LowerCaseInvariant);

Re: ArticleTypeCodeSOD

2010-05-26 09:29 • by KeithJM (unregistered)
I'm going to say it's the lack of sleep, but is there a point to this class if it's all private w/o getters?


Are you implying that there WOULD be a point to this class if it was public and had getters?

Re: ArticleTypeCodeSOD

2010-05-26 09:30 • by lupo
309669 in reply to 309651
private const string ClassTypeComment = "Comment";

Re: ArticleTypeCodeSOD

2010-05-26 09:31 • by James Michael Hare (unregistered)
Hah, love it. Actually I remember some legacy code I worked on right out of college that had the following C #defines:

#define ZERO 0
#define ONE 1

Glad we're isolated in case zero or one change their numeric values...

Re: ArticleTypeCodeSOD

2010-05-26 09:33 • by @Deprecated
TRWTF is that the strings aren't marked static and final.
(Yes.... that will do.)

Re: ArticleTypeCodeSOD

2010-05-26 09:38 • by SR (unregistered)
309673 in reply to 309659
Knux2:
(Java)

System.out.println(ClassTypeW + ClassTypeO + ClassTypeW
+ ", " + ClassTypei + ClassTypet + " " + ClassTypes
+ ClassTypeu + ClassTyper + ClassTypee + " " + ClassTypet
+ ClassTypea + ClassTypek + ClassTypee + ClassTypes + " "
+ ClassTypea + " " + ClassTypel + ClassTypeo + ClassTypen
+ ClassTypeg + " " + ClassTypet + ClassTypei + ClassTypem
+ ClassTypee + " " + ClassTypet + ClassTypeo + " "
+ ClassTypet + ClassTypey + ClassTypep + ClassTypee + " "
+ ClassTypea + " " + ClassTypes + ClassTypee + ClassTypen
+ ClassTypet + ClassTypee + ClassTypen + ClassTypec
+ ClassTypee + " " + ClassTypet + ClassTypeh + ClassTypei
+ ClassTypes + " " + ClassTypew + ClassTypea + ClassTypey
+ "!");


Code review: add classTypeComma, classTypeSpace and classTypeExclamationMark and you're onto a winner (a space and 2 punctuation marks ought to be enough for anyone).

Re: ArticleTypeCodeSOD

2010-05-26 09:40 • by Steven (unregistered)
#include <stdio.h>

#define LETTER_TABLE \
X(A, "A") \
X(B, "B") \
X(C, "C") \
X(D, "D") \
X(E, "E") \
X(F, "F") \
X(G, "G") \
X(X, "X") \
X(Y, "Y") \
X(Z, "Z")

#define X(a, b) a,
enum LETTER {
LETTER_TABLE
};
#undef X

#define X(a, b) b,
char *letter_name[] = {
LETTER_TABLE
};
#undef X

int main() {
enum LETTER x = A;
printf("x=%s\n", letter_name[x]);
return 0;
}

Re: ArticleTypeCodeSOD

2010-05-26 09:40 • by pointyhairedpeon (unregistered)
309675 in reply to 309665
Bah, XML is for sissies: much better to use RSS for adding comments to the sourcecode, giving for each line of the code a different URL containing the documentation associated to it.

Re: ArticleTypeCodeSOD

2010-05-26 09:42 • by @SuppressWarnings (unregistered)
309676 in reply to 309672
What language has both const and final keywords?

Re: ArticleTypeCodeSOD

2010-05-26 09:42 • by ubersoldat
309677 in reply to 309666
Vladimir:
Генерация кода может быть эффективным инструментом для сильно вводе пользовательских доменов, если данный домен ограничена определенным набором ценностей. Приемлемые примеров можно назвать имена цветов, статусов, и штаты США, среди ряда других.

В некоторых случаях это полностью избыточными для этого, например, если вы сильно набрав алфавиту:

ClassTypeLetters общественного класса
(
частных пд ClassTypeA = "";
частных пд ClassTypeB = "B";
частных пд ClassTypeC = "C";
частных строку сопзЬ ClassTypeD = "D";
частных ClassTypeE строку сопзЬ = "E";
частных пд ClassTypeF = "F";
частных ClassTypeG строку сопзЬ = "G";
/ / H-W ...
частных пд ClassTypeX = "X";
частных ClassTypeY строку сопзЬ = "Y";
частных пд ClassTypeZ = "Z";
)


I couldn't said it better.

Re: ArticleTypeCodeSOD

2010-05-26 09:44 • by ubersoldat
309678 in reply to 309675
pointyhairedpeon:
Bah, XML is for sissies: much better to use RSS for adding comments to the sourcecode, giving for each line of the code a different URL containing the documentation associated to it.


Actually, with the right approach, this could be a great idea.

Re: ArticleTypeCodeSOD

2010-05-26 09:58 • by Keith Brawner (unregistered)
309679 in reply to 309678
Doxygen?

Re: ArticleTypeCodeSOD

2010-05-26 09:59 • by @Deprecated
309680 in reply to 309676
@SuppressWarnings:
What language has both const and final keywords?


Oh, sure, get all technical on me...

All I can say is someone mentioned Java and then I blanked on the const....

Re: ArticleTypeCodeSOD

2010-05-26 10:03 • by frits
309681 in reply to 309662
apaq11:
This solution is clearly not correct. There's no support for lower case letters...


Duh, just call .ToLower() to get lowercase. There's no need to reimplement functionality that's already provided.

Re: ArticleTypeCodeSOD

2010-05-26 10:09 • by Jim (unregistered)
309682 in reply to 309681
frits:
apaq11:
This solution is clearly not correct. There's no support for lower case letters...


Duh, just call .ToLower() to get lowercase. There's no need to reimplement functionality that's already provided.


You genius. How do comments get 'featured'?

Re: ArticleTypeCodeSOD

2010-05-26 10:15 • by Mr Smiþ (unregistered)
309683 in reply to 309660
Elmo:
This is very handy.

Just in case the alphabet changes, in that case you are prepared!


Þat is a good point. Just add on:

private const string ClassTypeÞ = "Þ";

and þe code will be ready!

(I sure hope the Daily WTF comment software accepts thorns or this post will look stupid. Well, more stupid than it is inherently.)

Re: ArticleTypeCodeSOD

2010-05-26 10:15 • by RHuckster
309684 in reply to 309667
Mister Zimbu:
toth:
This is ridiculous. It's utterly useless; how do you do lowercase letters? And punctuation?


ClassTypeLetters.CreateLetterTransformationFactory<ClassTypeA>(this).TransformLetter(LetterTransformationFactoryTypes.LowerCaseInvariant);


I just threw up a little in my mouth.

Re: ArticleTypeCodeSOD

2010-05-26 10:34 • by Buddy (unregistered)
It could have a purpose as part of a character classification algorithm or converting UNICODE/LATIN-1 to ASCII 7-bit say in e-mail or news readers.

E.g.

A a À Á Â Ã Ä Å Æ à á â ã ä å æ => ClassTypeA

Thinking really way out there, ClassType* could be redefined later on as Morse code or something and then it would be almost a logical way to do things.

ClassTypeA = DOT DASH;
ClassTypeB = DASH DOT DOT DOT;
...

During development would set it first as "A", "B", etc. to make it easier.

Re: ArticleTypeCodeSOD

2010-05-26 10:37 • by -anon for this (unregistered)
Off-topic, I've come across code where the multiplication factors for k (as in kilo), c (as in centi), m (as in milli), ..., were defined in an XML file. This file was then parsed by the framework, whence a factory pattern was used to provide the required real multiplying factor to the end application.

This might have been an acceptable solution had the XML file been stored in a database table [n.b. the previous sentence is intended to be an ironical remark]. However, the XML was instead stored in the flash RAM of the embedded device, making it way too "hands-on" to be "enterprisey".

Needless to say, this "solution" was soonish returned to the designers for re-consideration.

Re: ArticleTypeCodeSOD

2010-05-26 10:44 • by Kempeth (unregistered)
309689 in reply to 309665
grizz:
-1: Where's the XML?

I totally agree! As it is you have to change the source code every time the alphabet changes.

Re: ArticleTypeCodeSOD

2010-05-26 10:44 • by Markp
309690 in reply to 309676
@SuppressWarnings:
What language has both const and final keywords?

Java does.

Re: ArticleTypeCodeSOD

2010-05-26 10:47 • by Anon (unregistered)
I've seen something similar but with numeric constants. It was because corporate policy involved running a code style checker, and it complained about "magic numbers." Which really translated to "any numeric constant that was greater than 3."

Solution?

public class Numbers {
public static int NUMBER_4 = 4;
public static int NUMBER_5 = 5;
....
}

Re: ArticleTypeCodeSOD

2010-05-26 10:51 • by Salvatore (unregistered)
309692 in reply to 309670
Lucky you it was "college code"

I saw the following C defines in code at WORK, that runs on a embedded system which manage the communication module of a TRAIN.

#define THOUSAND 1000
#define THIRTY 30

and a few others.

I'm not kidding.

Re: ArticleTypeCodeSOD

2010-05-26 10:52 • by Salvatore (unregistered)
309693 in reply to 309670
James Michael Hare:
Hah, love it. Actually I remember some legacy code I worked on right out of college that had the following C #defines:

#define ZERO 0
#define ONE 1

Glad we're isolated in case zero or one change their numeric values...


Lucky you it was "college code"

I saw the following C defines in code at WORK, that runs on a embedded system which manage the communication module of a TRAIN.

#define THOUSAND 1000
#define THIRTY 30

and a few others.

I'm not kidding.

Re: ArticleTypeCodeSOD

2010-05-26 11:05 • by Zylon
Someone please explain to me how "Code generation" has anything to do with this particular WTF.

Re: ArticleTypeCodeSOD

2010-05-26 11:07 • by Hatterson (unregistered)
309695 in reply to 309670
James Michael Hare:
Hah, love it. Actually I remember some legacy code I worked on right out of college that had the following C #defines:

#define ZERO 0
#define ONE 1

Glad we're isolated in case zero or one change their numeric values...


Well it *could* be worse.

#define ZERO 1
#define ONE 0

Re: ArticleTypeCodeSOD

2010-05-26 11:15 • by ContraCorners
309696 in reply to 309682
Jim:
frits:
apaq11:
This solution is clearly not correct. There's no support for lower case letters...


Duh, just call .ToLower() to get lowercase. There's no need to reimplement functionality that's already provided.


You genius. How do comments get 'featured'?

+ ClassType1

Re: ArticleTypeCodeSOD

2010-05-26 11:24 • by AnOldRelic (unregistered)
309698 in reply to 309686
Buddy:
Thinking really way out there, ClassType* could be redefined later on as Morse code or something and then it would be almost a logical way to do things.

ClassTypeA = DOT DASH;
ClassTypeB = DASH DOT DOT DOT;
...

This kind of thing needs to broadcast DOT DOT DOT DASH DASH DASH DOT DOT DOT.

Re: ArticleTypeCodeSOD

2010-05-26 11:40 • by toshir0
309700 in reply to 309677
ubersoldat:
Vladimir:
Генерация кода может быть эффективным инструментом для сильно вводе пользовательских доменов, если данный домен ограничена определенным набором ценностей. Приемлемые примеров можно назвать имена цветов, статусов, и штаты США, среди ряда других.

В некоторых случаях это полностью избыточными для этого, например, если вы сильно набрав алфавиту:

ClassTypeLetters общественного класса
(
частных пд ClassTypeA = "";
частных пд ClassTypeB = "B";
частных пд ClassTypeC = "C";
частных строку сопзЬ ClassTypeD = "D";
частных ClassTypeE строку сопзЬ = "E";
частных пд ClassTypeF = "F";
частных ClassTypeG строку сопзЬ = "G";
/ / H-W ...
частных пд ClassTypeX = "X";
частных ClassTypeY строку сопзЬ = "Y";
частных пд ClassTypeZ = "Z";
)


I couldn't said it better.
Agreed. You obviously couldn't do that...

Re: ArticleTypeCodeSOD

2010-05-26 11:44 • by tragomaskhalos (unregistered)
309701 in reply to 309693
Salvatore:
James Michael Hare:
Hah, love it. Actually I remember some legacy code I worked on right out of college that had the following C #defines:

#define ZERO 0
#define ONE 1

Glad we're isolated in case zero or one change their numeric values...


Lucky you it was "college code"

I saw the following C defines in code at WORK, that runs on a embedded system which manage the communication module of a TRAIN.

#define THOUSAND 1000
#define THIRTY 30

and a few others.

I'm not kidding.


This sort of thing is not uncommon. The usual culprit is a "no magic numbers" clause in a coding standard (along with an implicit "no common sense either") of course ....

Re: ArticleTypeCodeSOD

2010-05-26 11:46 • by Anonymous Coward (unregistered)
309702 in reply to 309691
Anon:
I've seen something similar but with numeric constants. It was because corporate policy involved running a code style checker, and it complained about "magic numbers." Which really translated to "any numeric constant that was greater than 3."

Solution?

public class Numbers {
public static int NUMBER_4 = 4;
public static int NUMBER_5 = 5;
....
}

Obviously you were the person they needed that code style checker for. Why 4? 5? 7?

When you have a loop stating

for (i=0;i<7;i++) { /* do something */ }

you'll be guessing what 7 means and why the number 7 was used. Whereas if the same code would (depending on the language you use) would say something like

const DAYSPERWEEK=7;

then the loop would be

for (i=0; i<DAYSPERWEEK; i++) { /* do something */ }

...and this would make it instantly clear that the loop iterates each weekday (rather than the seven dwarfs in "Snow White").

Note also that your NUMBER_4, NUMBER_5, NUMBER_6 etc. do not add anything useful to the readability of the code.

Re: ArticleTypeCodeSOD

2010-05-26 11:48 • by getofmymetriclawn (unregistered)
309703 in reply to 309686
Buddy:
It could have a purpose as part of a character classification algorithm or converting UNICODE/LATIN-1 to ASCII 7-bit say in e-mail or news readers.

E.g.

A a À Á Â Ã Ä Å Æ à á â ã ä å æ => ClassTypeA


Please, avoid any job that has a remote connection to localization or international communications. This algorithm is already used much to often. Under no conceiveable circumstances is "A" a good representation for an "Ä" or "Æ". If you really have to use 7-bit ASCII, Ä and Æ can be represented as AE. Not that there is a good reason for using anything other than a proper unicode encoding like UTF-8 anyways.

Re: ArticleTypeCodeSOD

2010-05-26 12:09 • by SR (unregistered)
I'm all for strong typing. I make good use of YesNoUnknown (though had I rolled my own it would have been YesNoUnknownFileNotFound)
« PrevPage 1 | Page 2 | Page 3Next »

Add Comment