• (cs)

    The funniest thing about this to me is that not only does it reinvent the wheel, it reinvents it as an oval.

    I've had to write code to do this in a language that didn't have this feaure (or at least I didn't know what it was) and I would just add "000000" to the front and then substring the last 6 characters.

  • (cs)

    Cripes.

    // not far from...
    public int intValue(int i) {
        return i;
    }

  • (cs)

    Three words:  W T F???

    In Perl (non-production code!) I've used inelegant formatting constructs like this:

      index="000000$i"
      rtindex=$((${#index}-5))
      nrtindex=${index:$rtindex}

    But switch/case?  Ack!

    (Note I am not a particularly expert Perl programmer, and there's almost certainly a more elegant way to do that.)

  • (cs)

    Why not use an XSLT stylesheet to format this output?

  • (cs) in reply to dubwai
    dubwai:

    The funniest thing about this to me is that not only does it reinvent the wheel, it reinvents it as an oval.

    I've had to write code to do this in a language that didn't have this feaure (or at least I didn't know what it was) and I would just add "000000" to the front and then substring the last 6 characters.



    You could also do...

    while(strWhatever.GetLength()<6)
        strWhatever.Insert('0');

    Though your version might use fewer CPU cycles :)
  • (cs)
    Alex Papadimoulis:
    ...a highly-paid consulting company that "adapts leading-edge technology..."



    Well, they sure did that. Adapted the hell out of it, I would say.
  • (cs) in reply to stevekj
    stevekj:

    ...
    In Perl (non-production code!) I've used inelegant formatting constructs like this:

      index="000000$i"
      rtindex=$((${#index}-5))
      nrtindex=${index:$rtindex}


    erm... that's not perl. You've got $s missing off the variables to the left of the equalss, no semicolons, $(...) is invalid, and I'm not even going to try to guess what ${index:$rtindex} is supposed to do.

    Not trying to troll, that's just too alarmingly non-perl to not comment. But in terms of elegant solutions,
    $str = sprintf '%05d', $i;
    and
    $str = '0' x (5 - length "$i") . $i;
    both spring to my mind. And (take note all perl-is-ugly fundies) neithier of these are particularly ugly (unlike stevekj's non-perl there ;] ).
  • noone (unregistered)

    So the first one would be from CSC Australia, then?

    http://au.country.csc.com/en/mcs/mcs43/index.shtml contains the incriminating quote, though thankfully no actual code.

  • (cs) in reply to Irrelevant
    Irrelevant:


    erm... that's not perl.


    I think it's P#.
  • Rick Mogstad (unregistered)

    inputEmployeeNo.PadLeft(6, "0"c)   seems the easiest way to do it to me...


  • Matt (unregistered) in reply to loneprogrammer
    loneprogrammer:
    Why not use an XSLT stylesheet to format this output?


    uh, because like the original post says, the .NET Framework has extensive built-in support for number formatting?
  • (cs)

    adapts leading-edge technology, best practices, and experience to help customers realise their business objectives

    Looks awfully lot like what can be found on this page...

    http://au.country.csc.com/en/mcs/mcs43/index.shtml

  • (cs) in reply to Rick Mogstad
    Anonymous:
    inputEmployeeNo.PadLeft(6, "0"c)   seems the easiest way to do it to me...




    Any VB.NET people know if you can use that method?  If so, that's a one-line replacement for WTF #1.
  • (cs) in reply to Charles Nadolski
    Charles Nadolski:
    Anonymous:
    inputEmployeeNo.PadLeft(6, "0"c)   seems the easiest way to do it to me...




    Any VB.NET people know if you can use that method?  If so, that's a one-line replacement for WTF #1.


    I would just leave the emp no as an int value and do

    intValue.ToString("000000")

    It may be that the conversion to string was only done for the length-check/padding anyway.

  • (cs) in reply to Irrelevant
    Irrelevant:
    stevekj:

    ...
    In Perl (non-production code!) I've used inelegant formatting constructs like this:

      index="000000$i"
      rtindex=$((${#index}-5))
      nrtindex=${index:$rtindex}


    erm... that's not perl. You've got $s missing off the variables to the left of the equalss, no semicolons, $(...) is invalid, and I'm not even going to try to guess what ${index:$rtindex} is supposed to do.

    Not trying to troll, that's just too alarmingly non-perl to not comment. But in terms of elegant solutions,
    $str = sprintf '%05d', $i;
    and
    $str = '0' x (5 - length "$i") . $i;
    both spring to my mind. And (take note all perl-is-ugly fundies) neithier of these are particularly ugly (unlike stevekj's non-perl there ;] ).


    It's actually bash (UNIX shell), not Perl.  And it does work, though it's still not a particularly good solution (bash has a printf command just like the C function, you know...)
  • (cs)

    [:S]  Wow.  That was depressing.  WTF!

  • (cs) in reply to yawmark

    yawmark:
    Cripes.
    There are 3 kinds of people in the world. Those who can count, and those who can't.

    Actually there are 10 kinds of people in the world. Those who count binary and thouse who don't.

  • diaphanein (unregistered) in reply to nonDev
    nonDev:

    yawmark:
    Cripes.
    There are 3 kinds of people in the world. Those who can count, and those who can't.

    Actually there are 10 kinds of people in the world. Those who count binary and thouse who don't.

    But if only you and dead people can read hex, how many people can read hex? [:D]

  • (cs) in reply to Charles Nadolski

    Charles Nadolski:


    You could also do...

    while(strWhatever.GetLength()<6)
        strWhatever.Insert('0');

    Though your version might use fewer CPU cycles :)

    Not sure about CPU cycles but if String is immutable in the language in question, this creates a bunch of junk Objects.  Never more than 6 but still.

  • Cthulhon (unregistered) in reply to diaphanein
    Anonymous:
    nonDev:

    yawmark:
    Cripes.
    There are 3 kinds of people in the world. Those who can count, and those who can't.

    Actually there are 10 kinds of people in the world. Those who count binary and thouse who don't.

    But if only you and dead people can read hex, how many people can read hex? [:D]


    Well, that's 1 (you) plus DEAD which is 57005 is decimal, so one can reasonably assume that about 57006 can read hex.
  • MeMe (unregistered) in reply to diaphanein
    Anonymous:
    nonDev:

    yawmark:
    Cripes.
    There are 3 kinds of people in the world. Those who can count, and those who can't.

    Actually there are 10 kinds of people in the world. Those who count binary and thouse who don't.

    But if only you and dead people can read hex, how many people can read hex? [:D]



    A better question would be...

    If only you, me and dead people can read hex, how many people can read hex?

  • (cs) in reply to nonDev

    Those who understand binary and those who don't. ( 10 - 3  == 1 )

     

    There are 11 kinds of people, those who understand string theory and those who don't.

     

  • (cs)

    This is the line I really like:

    Select Case (inputEmployeeNo.Length) ' Evaluate userid.

    In what way is "inputEmployeeNo.Length" evaluating a userid (whatever that may be)?  It's evaluating the length of the ID in digits, not the ID itself.  Insane.


    Incidentally: the Perl idiom I would use is sprintf("%04d",$n) rather than any other silliness.  Why?  Because it's good enough, it's fast enough, and it's obvious to anyone who's familiar with the C [sf]printf format, which is a large majority of programmers.

    Oh, and regarding the kinds of people: my favourite version is:

    There are two kinds of people in the world: those who divide the people in the world into two kinds, and those who don't.

    But the original poster who brought it up was misquoting a subtly different (and considerably wittier) original:

    There are three kinds of people in the world: those who count, and those who don't.

    No, it's not a typo; it's wit.
  • Dave Markle (unregistered)

    Just in case you were wondering, Example 2 is C#.  sob

  • bubezleeb (unregistered) in reply to RyGuy

    Check out this page http://au.country.csc.com/en/mcs/mcs46/index.shtml in Firefox (and perhaps other Non-IE browsers) to see how much on the leading edge they are!

  • (cs)

    Read The F_ing Manual!
    Read The F_ing MSDN!
    Read the F_ing Intellisense!

    WTF, just read!!!

  • (cs) in reply to Jon Limjap

    At least in the second example you get an empty string if you input the wrong month. Reminds me of something with 13 months in a fiscal year? Month 13? Oh, thats "" [:O]

    Drak

  • (cs) in reply to Rick Mogstad

    Anonymous:
    inputEmployeeNo.PadLeft(6, "0"c)   seems the easiest way to do it to me...


    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemstringclasspadlefttopic.asp

  • Mario (unregistered)

    Sigh:

    strEmployeeNumber = Right("000000" & inputEmployeeNo, 6)
    Or: -for those that really want an "if" statement:
    if len(cstr(l_intMonthNum))> 1 then
    return cstr(l_intMonthNum)
    else
    return cstr("0" & l_intMonthNum)
    end if

  • (cs)

    In the mid to late 80s I worked as an analyst programmer at a company developing applications for the shipping industry, specifically to be used on board ships.

    One of the other developers was clue impaired and routinely did...

     

    if this = that then do something else i = i

     

    he insisted that strange things happened if he excluded an else clause and this was his way of doing a no-op.

    The same guy wrote a screen clearing routine like this (it was basic)

    print

    print

    print

    ... (20 more) ...

    print

    when asked about loop optimisation and if that was what he was doing, he didnt know what I was talking about.

     

    so, you see, some things don't change.

  • (cs)

    In that month number format, forgetting for the moment the general stupidity, would it not be better to throw an exception on the default case?

  • (cs) in reply to fatgeekuk

    "when asked about loop optimisation and if that was what he was doing, he didnt know what I was talking about."

    Loop optimisation, hell. What about CLS?

  • (cs) in reply to Mike R

    Well yes, but we where developing on both

     

    HP-150b (using MS CBASIC on MSDOS) and IBM PCs, the HPs did not support things like CLS as the

    system was a NONIBMPC MSDOS system that was effectively a graphic terminal with a PC shoved in the bottom of the case, so the interface between the "PC" and the terminal was done by printing sets of ANSI command strings. :-(

    But, even so, there WAS an ANSI sequence for clear screen. so, no excuses I spose.

  • (cs) in reply to fatgeekuk

    10 print "{insert inverted heart symbol here}";

    Usually the first line of any program I ever wrote on my VIC 20

    Drak

  • Zatanix (unregistered) in reply to Mike R

    Or perhaps more normal:     PRINT"§"      , where § is a reversed heart

  • Zatanix (unregistered) in reply to Zatanix

    argh, drak beat me to it! :)

  • (cs)

    For when you absolutely have to have your data your way!

  • (cs) in reply to fatgeekuk
    fatgeekuk:
    if this = that then do something else i = i

    he insisted that strange things happened if he excluded an else clause and this was his way of doing a no-op.

    I imagine he once got caught by the construct:

    IF A=B THEN
            IF C=D THEN
                  do something
    ELSE
            IF E=D THEN
                  do something else

     

     

     

     

  • (cs) in reply to bubezleeb
    Anonymous:
    Check out this page http://au.country.csc.com/en/mcs/mcs46/index.shtml in Firefox (and perhaps other Non-IE browsers) to see how much on the leading edge they are!


    Heh, I didn't notice it at first, for those wondering what the WTF is, just scroll down the page.
  • Miles Archer (unregistered)

    How about a bogosort version? That would be cool.

  • (cs) in reply to Miles Archer
    Anonymous:
    How about a bogosort version? That would be cool.


    Hire a bunch of monkeys to smash the keyboard until the proper number of zeroes are padded to the string?
    This looks like a job for Primate Programming Inc.
  • (cs) in reply to Jon Limjap
    Jon Limjap:
    Read The F_ing Manual!
    Read The F_ing MSDN!
    Read the F_ing Intellisense!

    WTF, just read!!!


    I made a comment a couple days back that we shouldn't blame noobs for not knowing the framework, but are there still people who program without google groups or msdn in .NET?  I can't possibly disagree with that quote...

    About that website though - any company with 4,000 employees is going to have tonnes of horrible programmers (let's include whoever made that website).  Most of the ones that have been procedural programming for the last 10 years and just switching into oo now are too stubborn to learn anything new properly.  Before you slag me for that you should know I worked for a company with 46,000 IT staff and half the programmers did daily WTF's - mostly VB6 and cobol programmers stepping over to .NET.

  • (cs)

    I know where you can find a stupider solution.  On our HR website, you login with your employee id.  They just have a blurb that says: "<label for="par0">Employee ID # use zero(s) BEFORE your ID# if it's under 100,000</label>:"

    If you guess wrong on the number of digits they're thinking about, you get this: "Employee ID# not found. Please read directions carefully - check your Employee ID# entry; be sure to enter a total of 6 digits, using zero(s) as needed."

    Why code it, when you can just force the user to fix it?

  • (cs) in reply to sas
    sas:
    be sure to enter a total of 6 digits, using zero(s) as needed


    On your last day, hack in to the database and set the identity seed to 999999 - they won't be able to hire anyone else ;)
  • (cs)

    In terms of speed and memory consumption, both WTFs are probably better than the usual straight-forward solution.

    The first example does the most simple possible action - append the string to a constant length string.
    Probably there will be only one intermediate object, a StringBuilder used by the compiler, which cannot be avoided.

    The second example always returns a constant string, so it doesn't even have to create a new object.

    This are examples where ugly WTF-solutions probably perform better than anything else. Although I doubt anyone will ever notice the difference

  • (cs) in reply to Charles Nadolski
    Charles Nadolski:
    Anonymous:
    inputEmployeeNo.PadLeft(6, "0"c)   seems the easiest way to do it to me...




    Any VB.NET people know if you can use that method?  If so, that's a one-line replacement for WTF #1.


    Yes, this works in VB.NET as well as C# I would imagine.  Its a method in the string class, so it should work in any managed language.

    The real syntax would of course be

    inputEmployeeNo = inputEmployeeNo.PadLeft(6, "0"c)
  • AdmittedHack (unregistered) in reply to Charles Nadolski

    They have their site map / site outline at the bottom of every page ..  WTF ???

  • joss (unregistered) in reply to ammoQ

    Exactly. The second example is good code IMHO, its totally clear how it behaves, its not bug prone, its a few lines longer than obvious alternative, but so what, its much faster than the alternatives and although this wouldnt make a difference unless it was called very frequently, why the hell not just write a fast function in the first place.

  • (cs) in reply to Cthulhon

    Anonymous:

    Well, that's 1 (you) plus DEAD which is 57005 is decimal, so one can reasonably assume that about 57006 can read hex.

    I can read some hex too, that would mean deaf people can read hex

  • Scott Vachalek (unregistered)

    Well assuming they had the profiler numbers to back it up, there is probably a performance advantage here over the default implementations, especially the latter case.  Particularly against the Java alternatives, which probably carried over to C#--they are probably an order of magnitude or two slower. 

    An array lookup would have been cleaner still, and we can probably assume there was no such excuse, but heck I just have to play devil's advocate sometimes...

Leave a comment on “IFormatProvider? Oh no, not me ...”

Log In or post as a guest

Replying to comment #:

« Return to Article