Seen in our codebase...



  • public class HerpDerp
    {
        private const string strDollarSign = "$";

        private int iTotal = 0;

        ... snip ~1000 lines ...

        private string GetTotal()
        {
            string total = strDollarSign + iTotal.ToString();

            return total;
        }
    }

    I know this is out of context, but I say no amount of context can make this less-than-WTF. 

     



  • I must be numb, this hardly registers as a wtf. An unneeded variable and hard coding the $ symbol two things that I don't really find wtfy anymore. Maybe context would help make it seem more wtfy.



  • @delta534 said:

    I must be numb, this hardly registers as a wtf. An unneeded variable and hard coding the $ symbol two things that I don't really find wtfy anymore. Maybe context would help make it seem more wtfy.

     

    I dunno, but "... snip ~1000 lines ..." seems like a WTF unto itself. 



  • I must be more numb to the wtf than I thought..



  • The WTF is presumably the potential localization problem, combined with the inferred lack of cohesion in a thousand-line class that includes this function.

    So yeah, I'm numb to it too.



  • @arotenbe said:

    The WTF is presumably the potential localization problem, combined with the inferred lack of cohesion in a thousand-line class that includes this function.

    So yeah, I'm numb to it too.

    It would be epic if the class was actually named HurpDerp.



  • @arotenbe said:

    The WTF is presumably the potential localization problem
     

    I have PHP code with a $dollar variable, but it could contain "$", "A$", "€" or "£", as set from the database (and in future it could potentially contain other symbols) so localisation is started. A better name might have been $currency_symbol or something, but what are you going to do?



  • @Zemm said:

    I have PHP code with a $dollar variable, but it could contain "$", "A$", "€" or "£", as set from the database (and in future it could potentially contain other symbols) so localisation is started. A better name might have been $currency_symbol or something, but what are you going to do?

    This code wasn't written to support localization. We deal in dollars only. I can't begin to imagine what this guy was thinking. Also, some of those snipped ~1000 lines included this total coming from the database as a DataRow, which is used to create some XML, from which a string representation of the total is extracted, converted to an int (with which no calculations are performed), and then back to a string in the method I posted earlier. If I never see another fucking XmlDocument (for the .NET devs among you), it'll be too soon. What am I going to do? Hanging myself in a server closet begins to look attractive.


  • Garbage Person

     @Smitty said:

    If I never see another fucking XmlDocument (for the .NET devs among you), it'll be too soon. What am I going to do? Hanging myself in a server closet begins to look attractive.
    Hey, XmlDocuments are great. The problem is their misuse (i.e. any time when not dealing with an XML Documet)

     

     



  • To be honest the official way to do this also features a lot of WTFery:

    [code]
    System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol = "$";

    string text = number.ToString("C");
    [/code]

    Notice that you have to change the currency symbol for the current running thread. Also the fact that Microsoft seems to think that language is somehow tied to a specific currency. It might be the case in America, but if your software needs to support a dozen languages and a dozen currencies, it's laughable. Yes, some people even want to see the same price in a local currency and euros at the same time.

    Also the fact that you have to use the "C" format string, because in some languages the monetary number format is different from the general number format.



  • @SlyEcho said:

    Also the fact that Microsoft seems to think that language is somehow tied to a specific currency.

    Your code sample looks more like the currency is tied to a specific culture. Can't two different cultures share the same currency, but speak different languages or the other way round?



  • @SlyEcho said:

    Notice that you have to change the currency symbol for the current running thread. Also the fact that Microsoft seems to think that language is somehow tied to a specific currency.

    Culture != language. The US and UK have different (standard) date formats, and yet speak the same language. Ditto Spain and Mexico.

    It saddens me that you're using these .net classes and apparently haven't even read the most basic summary documentation on them. Given, .net's definition of the word "Culture" is a little funky.


  • ♿ (Parody)

    @blakeyrat said:

    It saddens me that you're using these .net classes and apparently haven't even read the most basic summary documentation on them. Given, .net's definition of the word "Culture" is a little funky.

    I'd guess that they didn't want to confuse this class with the actual OS Locale (the otherwise standard name for this concept). Anyways, the currency symbol is just meant to be a reasonable default that's used for that locale.

    Locales seem to be more centered around languages and countries, which makes the default currency concept pretty reasonable. IOW, it gives a reasonable default for dealing with that locale. If you're dealing with specific currencies (e.g., a FOREX system), then you're not going to rely on this stuff, and you'll undoubtedly have a fairly robust system for dealing with different currencies to begin with.



  • @Smitty said:

    This code wasn't written to support localization.
     

    Perhaps it was written for the time, surely not too far ahead, when the US currency is no longer the dollar, but the renminbi.



  • @GreyWolf said:

    @Smitty said:

    This code wasn't written to support localization.
     

    Perhaps it was written for the time, surely not too far ahead, when the US currency is no longer the dollar, but the renminbi.

    Some anime has the currency as the "double-dollar", symbol: $$. That always made me laugh because it's so ridiculous.



  • @SlyEcho said:

    To be honest the official way to do this also features a lot of WTFery:

    <FONT size=2 face="Lucida Console">System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol = "$";
    string text = number.ToString("C"); </FONT>

    Notice that you have to change the currency symbol for the current running thread. Also the fact that Microsoft seems to think that language is somehow tied to a specific currency. It might be the case in America, but if your software needs to support a dozen languages and a dozen currencies, it's laughable. Yes, some people even want to see the same price in a local currency and euros at the same time.

    Also the fact that you have to use the "C" format string, because in some languages the monetary number format is different from the general number format.

    I've got bad news for you...  Unlike dates and general numbers, it's not safe to localize currency that may have been entered in another locale.  Example:  User in Mexico enters the price of something as 100 pesos (which localized is "$100.00").  This data gets stored in a database used for a web-based store front.  A user in the US goes to buy the item and sees it as 100 US dollars.  Oops.  It's much more accurate to fix the representation of the unit of currency than to try to figure it out.

    In other words, the implementation is WTFey because if you are doing it, you are probably already doing something that is WTFey.  I can't think of a case where you would have enough information to accurately convert from one currency to another, but not have enough information to display it precisely without localization.  Localizing would be like saying "I'm going to convert this to a very specific currency, but display it as being the user's preferred currency".



  • Even dates are not always safe to "localize". If a person born in UTC+12 time zone is born on (say) 24 Dec 1980, he/she is still born on 24 Dec 1980 in case he moves to UTC-12 time zone.

    Or if someone says he wants to fly half around the world, stay at a hotel and then rent a rental car there at say 9am, you cannot just take that as local time of his current location and convert it to the destination time zone since he most likely meant local time at the place where he arrived.

    But yes, for currencies the problem is less sublte than for dates that sometimes denote a specific moment in time (which has to be converted when time zones change) and sometimes does indicate local time or no time zone at all.



  • @Zemm said:

    I have PHP code with a $dollar variable, but it could contain "$", "A$", "€" or "£", as set from the database


    AM$ ?



  • I don't get it. One of the hallmarks of experience is coding in flexibility in areas where you're probably going to need it. Another hallmark is making a clear separation between unrelated things. In this case, the unrelated things are: 1) the numeric quantity and 2) the funky symbol we stick on the front of that quantity when we write it down.

    What happens when some doofus manager comes along and decrees "No longer shall we print $100, we shall print USD 100. In fact, everywhere we used to print $, we shall print USD." The programmer who has implemented the code this way has no problem doing that. The programmer who thought building in some flexibility at an obvious point was a bad idea, will suffer.

    The WTFs on this site just get weaker and weaker every time...



  • @Smitty said:

    string total = strDollarSign + iTotal.ToString();

    Oh, I get it! TRWTF here is using toString() on Apple's new calculator, the iTotal. Right?



  • @blakeyrat said:

    Culture != language. The US and UK have different (standard) date formats, and yet speak the same language. Ditto Spain and Mexico.

    I know this of course. Maybe it was a mistake to try to simplify it for you guys.

    @derula said:

    Your code sample looks more like the currency is tied to a specific culture. Can't two different cultures share the same currency, but speak different languages or the other way round?

    My point is that currency is not tied to culture at all!

    If I run a web shop in Europe and I suppose the user can view the site in local languages and in English, I wouldn't want selecting the English language to switch the currency to dollars. And if you think I'm not using cultures correctly then see what happens when I run this line of Powershell code:

    PS C:\> []system.globalization.cultureinfo]::createspecificculture("en-DE").numberformat.currencysymbol
    $

    So if you speak English in Germany you must be using dollars! (What actually happens is when it can't find the culture "en-DE" it falls back to "en-US".)

    What we have done here is to turn the currency symbol off altogether when the language is set at the beginning of the request handler. But then suddenly we needed to display prices in euros too and management insisted on the € symbol...



  • @SlyEcho said:

    @blakeyrat said:
    Culture != language. The US and UK have different (standard) date formats, and yet speak the same language. Ditto Spain and Mexico.

    I know this of course. Maybe it was a mistake to try to simplify it for you guys.

    Oh yes, we're far too dumb to understand your shining genius. Obviously the fact that multiple people felt compelled to shower you with the output of their vastly inferior brains doesn't mean you communicated poorly, it means nobody other than you is operating on near the same supergenius level as you are. If you hadn't simplified the concept, this forum could never contain your brilliance, as its database has not enough petabytes to record even a split-second of your mind's output.

    THE PRECEDING PARAGRAPH MIGHT CONTAIN... eh you know



  • @blakeyrat said:

    Oh yes, we're far too dumb to understand your shining genius. Obviously the fact that multiple people felt compelled to shower you with the output of their vastly inferior brains doesn't mean you communicated poorly, it means nobody other than you is operating on near the same supergenius level as you are. If you hadn't simplified the concept, this forum could never contain your brilliance, as its database has not enough petabytes to record even a split-second of your mind's output.

    THE PRECEDING PARAGRAPH MIGHT CONTAIN... eh you know SELF-REFERENCE

    FTFY

     



  • High five, Toshir0!!



  • Pffft, XmlDocument is for newbs - all the cool kids nowadays are using XDocument.



  • Everyone missed the real WTF:  Using Hungarian Notation in C#

    Sadly the code I work with in my job does the same thing sometimes, and sometimes not, and sometimes classes start with underscores.



  • @ObiWayneKenobi said:

    Everyone missed the real WTF:  Using Hungarian Notation in C#

    Sadly the code I work with in my job does the same thing sometimes, and sometimes not, and sometimes classes start with underscores.

    Have you considered murder? I hear it's a very effective behaviour-conditioning mechanism.



  • @ObiWayneKenobi said:

    Everyone missed the real WTF:  Using Hungarian Notation in C#
    For anything other than a control, I agree.



  • @ObiWayneKenobi said:

    Everyone missed the real WTF:  Using Hungarian Notation in C#

    Sadly the code I work with in my job does the same thing sometimes, and sometimes not, and sometimes classes start with underscores.

     Welcome to my personal hell.  Here we have awesome treasures like [code]string() arrStringArray;[/code] and [code]bool bBooleanValue;[/code] spread throughout the codebase.

     Also, to stave off the inevitable pedantry, I used parentheses to denote a string array because I can't figure out how to escape square brackets in this editor.  I swear I'm not a closet VB dev.



  • you need to know html to have this [] appear in Community server.



  • Or double the closing square bracket: array[]]



  • @Smitty said:

    Welcome to my personal hell.  Here we have awesome treasures like <font face="Lucida Console" size="2">string() arrStringArray;</font> and <font face="Lucida Console" size="2">bool bBooleanValue;</font> spread throughout the codebase.

    But it can be fun sometimes, e.g., if you like riddles or keep asking your colleagues about which prefix to use in C code given the current phase of the moon ("Hey, do we use s, str, sz, psz, ac, pc, pac, pch, pstr, lpstr, lpcstr, lpwstr, lptstr, or bstr for strings today?"). Also, DefInt a-z (in some BASIC dialects).



  • @fatbull said:

    if you <a href="http://msdn.microsoft.com/en-us/library/aa260976(v=vs.60).aspx#CodeSpippet1">like riddles</a>

    "Spippet"?

    ...

    *sigh*



  • @fatbull said:

    @Smitty said:

    Welcome to my personal hell.  Here we have awesome treasures like <font face="Lucida Console" size="2">string() arrStringArray;</font> and <font face="Lucida Console" size="2">bool bBooleanValue;</font> spread throughout the codebase.

    But it can be fun sometimes, e.g., if you like riddles or keep asking your colleagues about which prefix to use in C code given the current phase of the moon ("Hey, do we use s, str, sz, psz, ac, pc, pac, pch, pstr, lpstr, lpcstr, lpwstr, lptstr, or bstr for strings today?"). Also, DefInt a-z (in some BASIC dialects).

    Even thought I can read C++ template code and vary rarely get lost, I have trouble parsing Hungarian Notation like that found in the MSDN code snippet. Am I damaged.



  • @SlyEcho said:

    My point is that currency is not tied to culture at all!


    Indeed. It's not tied to anything other than specific user selection. One of the budget airlines I sometimes fly with drives me nuts because they price everything in the currency of the country I'm flying from. So if I'm flying Eurozone to UK (single or return) the price is in euros, but if I'm flying UK to Eurozone the price is in pounds. If they let me choose then I could pick the currency my credit card operates in and save the exchange fees.



  • Yeah.  Here some of the older code uses it, and it was mandated long ago that all the keys in the Web.config file should use the three basic ones ("s" for string, "i" for a number, "b" for a bool).  Very annoying.  Of course we're also forbidden to refactor code here because it "produces no business value"


  • Garbage Person

    @hoodaticus said:

    @ObiWayneKenobi said:

    Everyone missed the real WTF:  Using Hungarian Notation in C#
    For anything other than a control, I agree.

    <3 a man after my own mind.


  • @pjt33 said:

    @SlyEcho said:

    My point is that currency is not tied to culture at all!


    Indeed. It's not tied to anything other than specific user selection. One of the budget airlines I sometimes fly with drives me nuts because they price everything in the currency of the country I'm flying from. So if I'm flying Eurozone to UK (single or return) the price is in euros, but if I'm flying UK to Eurozone the price is in pounds. If they let me choose then I could pick the currency my credit card operates in and save the exchange fees.
    I'm pretty sure I remember some EU legislation on this to the effect that airline tickets must be purchased in the currency of the departure country. But now I can't find anything about it on google.



  • @ObiWayneKenobi said:

    Here some of the older code uses it, and it was mandated long ago that all the keys in the Web.config file should use the three basic ones ("s" for string, "i" for a number, "b" for a bool).  Very annoying.

    But what if you're storing a long or a short? You can't prefix those with "i", think of the terrible confusion it would cause! I suggest you propose a new standard, that all numeric values be prefixed with "n" instead. to prevent such confusion. Should your company decide to adopt this new standard (and they sound stupid enough to), it will allow you to spend time doing necessary refactoring and bill it as "changing i to n in config files". As an added bonus, it would be the most awesome troll ever.

    @ObiWayneKenobi said:

    Of course we're also forbidden to refactor code here because it "produces no business value"

    Lemme guess, they say that about unit testing too? If so, you might want to find another job.


  • ♿ (Parody)

    @The_Assimilator said:

    @ObiWayneKenobi said:

    Of course we're also forbidden to refactor code here because it "produces no business value"

    Lemme guess, they say that about unit testing too? If so, you might want to find another job.

    Oh, come on. A blanket statement is a bit of a WTF, but refactoring for refactoring's sake is likely to reduce business value by all of the bugs you introduce in the process. Sure, it's a lot of fun for the developer, since you can get rid of the previous idiot's nonsense and replace it with the current idiot's nonsense, but why would anyone want to pay for that?

    OTOH, a bit of refactoring while fixing a particular issue or adding some new requirement makes more sense, and can be justified more easily. It's not like you'd have to identify it as refactoring, either.



  • @boomzilla said:

    @The_Assimilator said:
    @ObiWayneKenobi said:

    Of course we're also forbidden to refactor code here because it "produces no business value"

    Lemme guess, they say that about unit testing too? If so, you might want to find another job.

    Oh, come on. A blanket statement is a bit of a WTF, but refactoring for refactoring's sake is likely to reduce business value by all of the bugs you introduce in the process. Sure, it's a lot of fun for the developer, since you can get rid of the previous idiot's nonsense and replace it with the current idiot's nonsense, but why would anyone want to pay for that?

    OTOH, a bit of refactoring while fixing a particular issue or adding some new requirement makes more sense, and can be justified more easily. It's not like you'd have to identify it as refactoring, either.

    Where did I say I support refactoring for refactoring's sake? From what Obi said I, understood that his company doesn't permit refactoring of any kind even if it's necessary/applicable.


  • ♿ (Parody)

    @The_Assimilator said:

    Where did I say I support refactoring for refactoring's sake? From what Obi said I, understood that his company doesn't permit refactoring of any kind even if it's necessary/applicable.


    I suppose reasonable people can disagree. I'm not sure where that leaves us. But I'd just reiterate...How could anyone, especially a PHB, discriminate between bug fixes and bug fixes plus a bit of refactoring. You couldn't cover a big refactoring, but those are the most dangerous, and most likely to "reduce business value" anyways.


  • BINNED

    @blakeyrat said:

    @arotenbe said:

    The WTF is presumably the potential localization problem, combined with the inferred lack of cohesion in a thousand-line class that includes this function.

    So yeah, I'm numb to it too.

    It would be epic if the class was actually named HurpDerp.


    Once a function gets above a thousand lines, the "HurpDerp" is implied.



  • @boomzilla said:

    I suppose reasonable people can disagree. I'm not sure where that leaves us.

    Where did I say I'm reasonable? ;)

    @boomzilla said:

    But I'd just reiterate...How could anyone, especially a PHB, discriminate between bug fixes and bug fixes plus a bit of refactoring. You couldn't cover a big refactoring, but those are the most dangerous, and most likely to "reduce business value" anyways.

    The PHB can't. But if the guy who happens to review your work is a douchebag who's (a) highly familar with the codebase (b) stuck far enough up the PHB's ass, he can very easily tell the PHB that you're doing refactoring "when you're supposed to be working". Yes, this has happened to a friend of mine.



  • @The_Assimilator said:

    if the guy who happens to review your work is a douchebag who's (a) highly familar with the codebase (b) stuck far enough up the PHB's ass, he can very easily tell the PHB that you're doing refactoring "when you're supposed to be working". Yes, this has happened to a friend of mine.
     

    If he's that big a douchebag, (a) is not necessary.



  • @The_Assimilator said:

    The PHB can't. But if the guy who happens to review your work is a douchebag who's (a) highly familar with the codebase (b) stuck far enough up the PHB's ass, he can very easily tell the PHB that you're doing refactoring "when you're supposed to be working". Yes, this has happened to a friend of mine.

    Code reviews? You assume much, sahib.



  • @blakeyrat said:

    @The_Assimilator said:
    The PHB can't. But if the guy who happens to review your work is a douchebag who's (a) highly familar with the codebase (b) stuck far enough up the PHB's ass, he can very easily tell the PHB that you're doing refactoring "when you're supposed to be working". Yes, this has happened to a friend of mine.

    Code reviews? You assume much, sahib.

    Yeah, every time I do that I end up being wrong, which is why pessimism is my default state.


Log in to reply