• (cs) in reply to Mister Zimbu
    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);

    Brillant! Very enterprisey, and it adheres to "best practices" (like the Factory pattern).

    Although this wonderful solution is still lacking punctuation. If it weren't for that, I would immediately adopt it into my own code.

  • dan (unregistered) in reply to Hatterson
    Hatterson:
    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

    Even this can sometimes (rarely) be justified.

    If you are driving a GPIO as an output, the physical level you are driving on the line and the logical value that it represents don't always match up. So you might need to set the output to 1 in order to actually send a ZERO.

    The often-mentioned embedded systems are where you would be most likely to run into this sort of thing.

  • Foobar (unregistered) in reply to ClutchDude
    ClutchDude:
    I'm going to say it's the lack of sleep

    No, sleep is there, but not in the String class. Try java.lang.Thread.

  • mike (unregistered)

    If you think this is a WTF, your code is probably strewn with string literals, and because of this, bug-ridden.

    These are apparently business objects that happen to 1 character in length. Would you use string literals everywhere if the strings were 2 characters long? What about 5? Why is it different because they are 1 character long?

  • Steve Buchok (unregistered) in reply to Vladimir

    Exactly what I was thinking.

  • Dan (unregistered)

    He should have stored those values in a database table.

  • (cs) in reply to pointyhairedpeon

    This design would never hold up at the Enterprise level. Two major failings:

    1. If results are meant for screen, there definitely has to be some Ajax.
    2. And I don't even see XML anywhere. You should be suing XML between the SQL and PHP, as well as between the keyboard buffer and Access.

    EDIT: wrong button... meant to quote this: "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. "

  • Ocson (unregistered) in reply to somedude
    2) And I don't even see XML anywhere. You should be suing XML between the SQL and PHP, as well as between the keyboard buffer and Access.

    I agree. XML deserves to pay for everyone's pain and suffering.

  • NorgTheFat (unregistered) in reply to dan
    dan:
    Hatterson:
    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

    Even this can sometimes (rarely) be justified.

    If you are driving a GPIO as an output, the physical level you are driving on the line and the logical value that it represents don't always match up. So you might need to set the output to 1 in order to actually send a ZERO.

    The often-mentioned embedded systems are where you would be most likely to run into this sort of thing.

    Yes it can be much worse:

    Public class Class extends EnterpriseRulesEngine { enum Letter { A, B, C, D... }; enum Number {1,2,3,4,5...}; } ...

  • (cs) in reply to James Michael Hare
    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...

    For the love of all that has any meaning... please tell me this insanity stopped at 9...

    In case the grenade hasn't gone off yet, that is to say that ,for example, 105 would be represented by ONE ZERO FIVE and not ONEHUNDREDFIVE.

  • Axl (unregistered)

    Perfect just in case the alphabet evolves!

    http://i.imgur.com/MMlkg.gif

  • facilisis (unregistered) in reply to somedude
    somedude:
    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...

    For the love of all that has any meaning... please tell me this insanity stopped at 9...

    In case the grenade hasn't gone off yet, that is to say that ,for example, 105 would be represented by ONE ZERO FIVE and not ONEHUNDREDFIVE.

    No, that would be TENFIVE.

  • jordanwb (unregistered)

    So that's what a brain hemorrhage feels like.

  • Jeremy Friesner (unregistered) in reply to James Michael Hare

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

    You know the rule... no magic numbers in the code! We'll be damned if were going to let this mysterious '0' and '1' slip through when we can just as easily use semantically descriptive constants.

  • (cs) in reply to James Michael Hare
    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...

    That's a very clever way to get around the problem of "I can't tell whether this is supposed to be a zero or an uppercase oh, and whether that's a one or a lowercase ell".

  • anon (unregistered) in reply to da Doctah

    A more clever way would be to use a font that doesn't suck.

  • Matt (unregistered) in reply to Mr Smiþ
    Mr Smiþ:
    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.)

    Don't you want eth (not thorn) in "that" and "the"? I guess this might vary by language, I'm only familiar with Icelandic.

    (Disclaimer: I'm not familiar with Icelandic.)

  • (cs) in reply to Vladimir
    Vladimir:
    Генерация кода может быть эффективным инструментом для сильно вводе пользовательских доменов, если данный домен ограничена определенным набором ценностей. Приемлемые примеров можно назвать имена цветов, статусов, и штаты США, среди ряда других.

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

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

    Machine translation fail.

    Настоящие программисты не используют Prompt!

  • (cs)
    for (TYPE_UNSIGNED_INTEGER i = ARRAY_FIRST_MEMBER_OFFSET; i < n; i += ARRAY_MEMBER_OFFSET_DIFFERENCE) {
      // ...
    }
  • (cs) in reply to @Deprecated
    @Deprecated:
    TRWTF is that the strings aren't marked static and final. (Yes.... that will do.)
    Umm... const in C# is the equivalent to Java's static/final modifiers. (I know Microsoft just complicated something super simple. For a final (non-static) value
    public string finalString{ get{ return "A Final String"; } }

    I think the naming convention is wrong here but I don't do C# much.

  • airdrik (unregistered) in reply to Anon
    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; .... }

    Better solution: 22 // 4 3(3+2)(32+1) // 105 Now, no magic numbers greater than 3!

  • blah (unregistered) in reply to codeReign
    codeReign:
    I think the naming convention is wrong here but I don't do C# much.

    Your wrongness isn't limited to naming conventions.

    Here are the rest of your mistakes: -everything in your post

  • (cs) in reply to ClutchDude
    ClutchDude:
    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?

    You have to use the classes in System.Reflection to extract the constants. That way, your snooping competitors can't get at them!

  • np (unregistered) in reply to James Michael Hare

    At my work, we have definitions like #define TRUE 0 #define FALSE 1

    Just to confuse everyone.

  • (cs) in reply to Salvatore
    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.

    I am going to start taking the bus from now on :-s

  • Doc (unregistered) in reply to Knux2

    Fail! Punctuation marks obviously weren't on that guy's priority list.

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

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

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

    Hey, if you're gonna translate the code, you might as well translate the alphabet (at least halfway):

    ClassTypeA = 'А'; ClassTypeB = 'Б'; ClassTypeC = 'С'; ClassTypeD = 'Д'; ClassTypeE = 'И'; ClassTypeF = 'Ф'; ClassTypeG = 'ДЖ'; ...

  • purpleshadow100 (unregistered) in reply to codeReign
    codeReign:
    @Deprecated:
    TRWTF is that the strings aren't marked static and final. (Yes.... that will do.)
    Umm... const in C# is the equivalent to Java's static/final modifiers. (I know Microsoft just complicated something super simple. For a final (non-static) value
    public string finalString{ get{ return "A Final String"; } }

    I think the naming convention is wrong here but I don't do C# much.

    Actually, C# has a readonly keyword which is the equivalent of java's final keyword. (static is the same in both cases) The const keyword is different from static readonly: it's handled at compile time, not run time. As a result, changing a const value means you have to recompile every file that uses it. private const is generally fine, but public const should generally be static readonly instead, unless you're sure the value won't change.

  • Paula (unregistered)
    1.) FILE_NOT_FOUND
    2.) ???
    3.) ClassTypeP + ClassTypeR + ClassTypeO + ClassTypeF + ClassTypeI + ClassTypeT + "!"
  • mabinogi (unregistered) in reply to Anonymous Coward
    Anonymous Coward:
    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.

    Nice lecture, but the reason Anon posted the code was because they already knew all that. Read the first sentence again: "I've seen something similar"

  • ABCD (unregistered)

    Can you use this to write alphabet spaghetti code?

  • (cs) in reply to alegr
    alegr:
    Vladimir:
    Генерация кода может быть эффективным инструментом для сильно вводе пользовательских доменов, если данный домен ограничена определенным набором ценностей. Приемлемые примеров можно назвать имена цветов, статусов, и штаты США, среди ряда других.

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

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

    Machine translation fail.

    Настоящие программисты не используют Promt!

    FTFY.

  • £ (unregistered) in reply to getofmymetriclawn
    getofmymetriclawn:
    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.

    Credit cards and passports require names to be encoded in exactly that subset of the alphabet. Maybe there's no good reason for credit cards and passports to prohibit UTF-8, but there's a good reason for programs to conform to the requirements.

  • ChipUni (unregistered)

    That's true. You never know when people will add another letter to the alphabet.

  • Murphy (unregistered)

    Really? This is the only WTF in that code?

    Surely this is just a precursor to a truly worthy WTF. All joking aside, what sort of bastard codebase has the need of this class hierarchy?

    Or is this just lifted from sample code from the GOF's Flyweight pattern?

  • Gary Olson (unregistered) in reply to Steven
    Steven:
    #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; }

    Excellent. Every enterprise system needs redundancy.

  • Paula Bean (unregistered)

    Happy Blogiversery!

    TDWTF = Brilliant!

    By the way, would you please stop discrediting my company's name!

    Thankyou.

    Paula Bean CTO Innotech Corp.

  • neveralull (unregistered) in reply to dan
    dan:
    Hatterson:
    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

    Even this can sometimes (rarely) be justified.

    If you are driving a GPIO as an output, the physical level you are driving on the line and the logical value that it represents don't always match up. So you might need to set the output to 1 in order to actually send a ZERO.

    The often-mentioned embedded systems are where you would be most likely to run into this sort of thing.

    In this case, I would prefer to see: #define PHYSICAL_0 1 #define PHYSICAL_1 0
  • (cs)

    CommentTypeWTF

  • (cs) in reply to anon
    anon:
    A more clever way would be to use a font that doesn't suck.
    I don't think I want to live in a world where someone else controls what font my users have on their workstations.
  • lokey (unregistered) in reply to Hatterson
    Hatterson:
    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

    what about

    #define File_Not_Found NaN

  • PotatoEngineer (unregistered) in reply to da Doctah
    da Doctah:
    anon:
    A more clever way would be to use a font that doesn't suck.
    I don't think I want to live in a world where someone else controls what font my users have on their workstations.
    I don't think I want to work with anyone who views (and critiques!) code in a font that can't differentiate 1/l and 0/O. Apply the cluebat to whoever really has this problem.
  • (cs) in reply to a care-bear

    care-bear, you made my day!

  • JoJo (unregistered) in reply to toth
    toth:
    This is ridiculous. It's utterly useless; how do you do lowercase letters? And punctuation?

    I DONT SEE ANY PROBLEM WITH THIS IT DOESNT NEED LOWER CASE AS NOBODY USES THEM AND PUNCTUATION IS ONLY FOR PEOPLE WHO NEED TO BREATHE WHEN TALKING

    LOUD HOWARD

  • (cs)

    At least this is NOT common practice on embedded devices with no filesystem...or is it? :-S

  • getofmymetriclawn (unregistered) in reply to £
    £:
    getofmymetriclawn:
    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.
    Credit cards and passports require names to be encoded in exactly that subset of the alphabet. Maybe there's no good reason for credit cards and passports to prohibit UTF-8, but there's a good reason for programs to conform to the requirements.
    You are right that credit cards require 7-bit ASCII. However Ä should be represented as AE on credit cards. Passports can have larger charsets. Here in germany the charset "LA8 Passport" is used, which basically comprises of all latin characters and diacritcs, so all of A a À Á Â Ã Ä Å Æ à á â ã ä å æ are allowed.
  • Vicky (unregistered) in reply to Steven
    Steven:
    #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; }

    No no no. Use the stringification operator, just define your macros as X(A) X(B) etc, then:

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

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

    MUCH better.

  • (cs)

    This piece of code would make perfect sense if the USA decided to change all abbreviations of US states to single upper-case letters.

    Obviously, there is the small issue that there are 50 US states (and then some oddities like the District of Columbia), and only 26 upper-case letters, but this could be solved by using accents, or special Icelandic characters.

    "A man from Houston, Ǽ, was interviewed by the police in connection with the investigation into bad coding practices."

    Makes perfect sense.

  • (cs) in reply to getofmymetriclawn
    getofmymetriclawn:
    £:
    getofmymetriclawn:
    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.
    Credit cards and passports require names to be encoded in exactly that subset of the alphabet. Maybe there's no good reason for credit cards and passports to prohibit UTF-8, but there's a good reason for programs to conform to the requirements.
    You are right that credit cards require 7-bit ASCII. However Ä should be represented as AE on credit cards. Passports can have larger charsets. Here in germany the charset "LA8 Passport" is used, which basically comprises of all latin characters and diacritcs, so all of A a À Á Â Ã Ä Å Æ à á â ã ä å æ are allowed.
    One reason that credit cards have a restricted character set is that the embossing machine has a limited number of physical dies to do the imprinting with.
  • Quirkafleeg (unregistered) in reply to Severity One
    Severity One:
    This piece of code would make perfect sense if the USA decided to change all abbreviations of US states to single upper-case letters.

    Obviously, there is the small issue that there are 50 US states (and then some oddities like the District of Columbia), and only 26 upper-case letters, but this could be solved by using accents, or special Icelandic characters.

    "A man from Houston, Ǽ, was interviewed by the police in connection with the investigation into bad coding practices."

    Makes perfect sense.

    What was he doing? Writing fragile, buggy dæmons?

Leave a comment on “ArticleTypeCodeSOD”

Log In or post as a guest

Replying to comment #:

« Return to Article