• (cs) in reply to Russ
    Anonymous:
    Anonymous:
    Anonymous:
    Anonymous:
    The next two lines of code took Christophe Beugnet hours and hours to correct. Who would have guessed that a supplier would have modified a header with this?

    <FONT size=+0>#define</FONT> false 1
    <FONT size=+0>#define</FONT> true 0
    Heh.... I'm guessing evil exiting former-programmer. [:)]



    Actually, I reckon this is from code that heavily used the strcmp family of functions - they return 0 if two strings are equal, so you end up with a lot of code like if(strcmp(str1, str2) == 0) all over the place (yes, I know you shouldn't use strcmp anyway, but bear with me). These funky defines would let you write if(strcmp(str1, str2) == true) which is slightly more readable - at the expense of making the rest of your code an impenetrable nightmare.


    On the other hand, writing

    if( strcmp( str1, str2 ) == false )

    is a nice way to shoot yourself in your foot.


    You're referring, I think, to the fact that srcmp might return -1, so the false test would fail. Good point. Perhaps this is where one of those famous tri-bools that show up so often could be used? Something like if(strcmp(str1, str2) == FILE_NOT_FOUND)

    Or it might return 2, or -2, or -3 or -4 or well any other valid integer.

  • whoever (unregistered) in reply to Russ
    Anonymous:
    Anonymous:
    Anonymous:
    Anonymous:
    The next two lines of code took Christophe Beugnet hours and hours to correct. Who would have guessed that a supplier would have modified a header with this?

    <FONT size=+0>#define</FONT> false 1
    <FONT size=+0>#define</FONT> true 0
    Heh.... I'm guessing evil exiting former-programmer. [:)]



    Actually, I reckon this is from code that heavily used the strcmp family of functions - they return 0 if two strings are equal, so you end up with a lot of code like if(strcmp(str1, str2) == 0) all over the place (yes, I know you shouldn't use strcmp anyway, but bear with me). These funky defines would let you write if(strcmp(str1, str2) == true) which is slightly more readable - at the expense of making the rest of your code an impenetrable nightmare.


    On the other hand, writing

    if( strcmp( str1, str2 ) == false )

    is a nice way to shoot yourself in your foot.


    You're referring, I think, to the fact that srcmp might return -1, so the false test would fail. Good point. Perhaps this is where one of those famous tri-bools that show up so often could be used? Something like if(strcmp(str1, str2) == FILE_NOT_FOUND)

    To properly handle strcmp() you'd need more than a tri-bool.  strcmp() can return any int value: -154 means the same thing as -1.

    The only returns you can count on from strcmp() is less than 0 , 0, or greater than 0.  There's nothing in the standard which says which less than zero or greater than zero value will be returned, and nothing can be inferred from that value except that the strings do not match and which is 'less' than the other.

     

  • cvi (unregistered) in reply to Russ
    Anonymous:

    You're referring, I think, to the fact that srcmp might return -1, so the false test would fail. Good point. Perhaps this is where one of those famous tri-bools that show up so often could be used? Something like if(strcmp(str1, str2) == FILE_NOT_FOUND)


    I'd go for
    if( Pow( strcmp( str1, str2 ), 2 ) == false )
    :P

    (Hmm.. the manpage for strcmp() says that "[strcmp returns] an integer less than, equal to, or greater than zero". Looks like it's not that easy anyway :#)
  • cvi (unregistered) in reply to cvi
    Anonymous:
    Anonymous:

    You're referring, I think, to the fact that srcmp might return -1, so the false test would fail. Good point. Perhaps this is where one of those famous tri-bools that show up so often could be used? Something like if(strcmp(str1, str2) == FILE_NOT_FOUND)


    I'd go for
    if( Pow( strcmp( str1, str2 ), 2 ) == false )
    :P

    (Hmm.. the manpage for strcmp() says that "[strcmp returns] an integer less than, equal to, or greater than zero". Looks like it's not that easy anyway :#)


    Great, not only am I late with my post, but the forum killed my smilies. Bah.
  • (cs) in reply to Drakonite
    Drakonite:

    &lt;a href="#" onclick="location='http://www.sun.com'; return false;"&gt;


    Ugh, unfortunatly I see that crap all the time. It just goes to show, web monkeys should NOT be considered programmers...
    I feel generous calling them monkeys.

    Ever looked at the login page here? Yeah, it's probably generated crap, but it's damned annoying to not have just a plain vanilla normal form submit like practically every other login page I come across.

    In my meaner moments, I think about submitting it here... The code in question is:

    &lt;a id="_ctl0__ctl0_loginButton" class="Button" href="javascript__doPostBack('_ctl0$_ctl0$loginButton','')"&gt;Login&lt;/a&gt;

  • whoever (unregistered)

    Let's see if I can get this right:

    <FONT size=+0>SELECT</FONT> ard_id, obtain_unx <FONT size=+0>FROM</FONT> lev_arts
     <FONT size=+0>WHERE NOT</FONT> (<FONT size=+0>NOT</FONT> (level_num < @iAquiredLevel) <FONT size=+0>AND NOT</FONT> (level_num = @iAquiredLevel))
    is the same as:
    <FONT size=+0>SELECT</FONT> ard_id, obtain_unx <FONT size=+0>FROM</FONT> lev_arts <FONT size=+0>WHERE </FONT>(level_num <= @iAquiredLevel)
     
    or did I screw that up?
  • (cs) in reply to Jon
    Anonymous:
    mlathe:
    as far as i know using expr is the only way to add two numbers in bourne shell (the most portable shell). anyone have a better way?


    I have seen it down as follows:

    nUID=`echo $nUID+1 | bc`

    It could be worse, I suppose - it could complile a small C program to add 1 to the value and then run that...

  • Ian (unregistered) in reply to Whiskey Tango Foxtrot? Over.

    It seems like overkill to me, but in the guy's defense, doesn't this prevent a potential spelling error? So, it's not a complete WTF, is it?

  • Peter Seebach (unregistered)

    That's a pretty normal way to do increments in shell.

    Here's my favorite:

    x=echo dummy | awk '{ x = '"$x"' + 1 } END { print x }'

    Actually seen in production code.

    Better, seen dozens of times, as it was used to iterate through numbers for a menu!  I really miss that installer.  It generated a 40-line menu for a 24-line xterm, requiring support to explain to people how to resize the window so they could see the menu items, of which only the first five were ever used.

  • (cs) in reply to R.Flowers

    "Which brings up something I often thing about: how can coders, who must master a precise syntax and set of symbols, how can they turn out to be such bad, bad spellers?"

    Well, if you look at the English language you will note that it has no precise syntax in spelling or speech. So, one really has nothing to do with the other. Note:

    know
    no

    there
    their
    they're

    I could go on, but you get my point?

  • (cs) in reply to OneFactor
    OneFactor:
    WTF Batman:
    Drakonite:

    &lt;a href="#" onclick="location='http://www.sun.com'; return false;"&gt;


    Ugh, unfortunatly I see that crap all the time. It just goes to show, web monkeys should NOT be considered programmers...
    I feel generous calling them monkeys.




    It also occurrs to me that this is one way to make sure javascript is turned on. I use NoScript in FireFox, and come across plenty of pages that use links like this to force you to enable JS. That, or they're just idiots.

    Very interesting theory about making sure javascript is on. Maybe this isn't a WTF after all...


    Yes this is, making JS-disabling users completely unable to use a website is nearly always idiotic (if only because there are very few reasons to).

    That kind of crap is usually pulled either by people who don't know jack about what they're doing (cargo cult programming and all), or by shitty CMS.
  • John Hensley (unregistered)

    Why oh why do people have so much trouble with boolean values in C? There must be thousands of projects that contain code like this:

    #define TRUE (0 == 0)
    #define FALSE (0 != 0)
    #define NOT(x) (x == TRUE)? FALSE : TRUE

    if(NOT(y) == TRUE)
    {
    ...

    (For those of you who missed the WTF: x isn't parenthesized in the macro.)

  • Anonymous (unregistered) in reply to John Hensley

    Yes, I had to do this again.

    Hooray. (CAPTCHA = doom)

  • String Cheesian (unregistered)
    Alex Papadimoulis:
    Let's start out with this single line from Victor Bilyk, who's predecessor liked the long way of writing "true" ...

    cbfQry.addParameter( <font color="#990000">"authenticate_required"</font>, <font color="#000099">new Boolean</font>(<font color="#000099">true</font>).toString() );


    Could it also be the already-internationalized-for-you way?
  • (cs) in reply to masklinn
    masklinn:

    Yes this is, making JS-disabling users completely unable to use a website is nearly always idiotic (if only because there are very few reasons to).

    That kind of crap is usually pulled either by people who don't know jack about what they're doing (cargo cult programming and all), or by shitty CMS.


    Actually, there's a very... well, I won't say good reason, but at least a rather compelling one from the POV of the less scrupulous sites, namely, those who are looking to use a Bastard Helper Object to insert a spyware downloader onto the visitors' systems. Lovely, eh?
  • (cs) in reply to Schol-R-LEA

    Ignore the above; I must have an attack of the dumbass. Feh.

  • Runtime Error (unregistered) in reply to String Cheesian
    Anonymous:
    Alex Papadimoulis:
    Let's start out with this single line from Victor Bilyk, who's predecessor liked the long way of writing "true" ...

    cbfQry.addParameter( <font color="#990000">"authenticate_required"</font>, <font color="#000099">new Boolean</font>(<font color="#000099">true</font>).toString() );


    Could it also be the already-internationalized-for-you way?


    No, its not internationalized for you, its just a dumb way of writing "true".  It looks like something thinks they know more about Java than they really do.  Not that thats an unusual thing.
  • (cs)
    Alex Papadimoulis:
    Let's start out with this single line from Victor Bilyk, who's predecessor liked the long way of writing "true" ...

    cbfQry.addParameter( <font color="#990000">"authenticate_required"</font>, <font color="#000099">new Boolean</font>(<font color="#000099">true</font>).toString() );

    I can see doing this in the case of i18n, but it is still quite a stretch.

    Alex, you really need to learn about "whose".

    I am wondering why the use of export.  IIRC, it is so the shell variable is available to further shell invocations.

    Sincerely,

    Gene Wirchenko

  • MeMyselfAndI (unregistered) in reply to DSx

    Because you may want to improve readability:

    private static final string PARM = "ThisIsAParameter".toUpperCase();

  • Tony Morris (unregistered) in reply to DSx
    Anonymous:
    <font color="#000099">private static final String</font> MBS_PASSWORD = <font color="#990000">"f4rth9fe"</font>.toUpperCase();

    I think what the real WTF is on that one, is that if you're going to hard-code a constant that always gets transformed to upper case, why not just hard-code it in upper case?


    A common misconception with some potential adverse consequences (e.g. I've watched a colleague spend 3 days on it, until he finally sought assistance) so I feel compelled to point it out, and it seems to be TDWTF culture anyway. The above declaration is not a constant.  I have demonstrated this misunderstanding here: http://jqa.tmorris.net/GetQAndA.action?qids=13
  • (cs) in reply to masklinn
    masklinn:
    OneFactor:
    WTF Batman:
    Drakonite:

    &lt;a href="#" onclick="location='http://www.sun.com'; return false;"&gt;


    Ugh, unfortunatly I see that crap all the time. It just goes to show, web monkeys should NOT be considered programmers...
    I feel generous calling them monkeys.




    It also occurrs to me that this is one way to make sure javascript is turned on. I use NoScript in FireFox, and come across plenty of pages that use links like this to force you to enable JS. That, or they're just idiots.

    Very interesting theory about making sure javascript is on. Maybe this isn't a WTF after all...


    Yes this is, making JS-disabling users completely unable to use a website is nearly always idiotic (if only because there are very few reasons to).

    That kind of crap is usually pulled either by people who don't know jack about what they're doing (cargo cult programming and all), or by shitty CMS.

    Which, of course, is why the pager on The Daily WTF forums requires JavaScript. (In fact, it's even more of a WTF - it uses POST rather than GET. Have fun bookmarking/sending links to the second and subsequent pages. What's even more WTF-worthy is that there is a way of getting to the second and subsequent pages using GET requests, but it's only used by the "last comment" links on the forum index. Oh, and the URL the comment-submission uses to send you to your posted comment always goes to the first page - though if your comment is on the first page, is does go to it OK.)

  • just a linux user (unregistered) in reply to makomk
    makomk:
    I wonder if someone's written a Greasemonkey script to spot the most common forms of this and rewrite them to normal hyperlinks? Probably, I expect. (Unfortunately, being a Konqueror user I have no equivalent to Greasemonkey available).
    You can always do it like I do it, just put up squid and use that, good things about that solution: - it speeds up the browsing - it works everywhere in every browser bad things about it: - it has some overhead
  • The Doc (unregistered)
  • mister r (unregistered) in reply to chrismcb
    chrismcb:
    Anonymous:
    Anonymous:
    Anonymous:
    Anonymous:
    The next two lines of code took Christophe Beugnet hours and hours to correct. Who would have guessed that a supplier would have modified a header with this?

    <font size="-0">#define</font> false 1
    <font size="-0">#define</font> true 0
    Heh.... I'm guessing evil exiting former-programmer. [:)]



    Actually, I reckon this is from code that heavily used the strcmp family of functions - they return 0 if two strings are equal, so you end up with a lot of code like if(strcmp(str1, str2) == 0) all over the place (yes, I know you shouldn't use strcmp anyway, but bear with me). These funky defines would let you write if(strcmp(str1, str2) == true) which is slightly more readable - at the expense of making the rest of your code an impenetrable nightmare.


    On the other hand, writing

    if( strcmp( str1, str2 ) == false )

    is a nice way to shoot yourself in your foot.


    You're referring, I think, to the fact that srcmp might return -1, so the false test would fail. Good point. Perhaps this is where one of those famous tri-bools that show up so often could be used? Something like if(strcmp(str1, str2) == FILE_NOT_FOUND)

    Or it might return 2, or -2, or -3 or -4 or well any other valid integer.



    Which is on itself another WTF. Even if a language doesn't support any abstract data types or enums, you could still use clearly named constants for the three types of responses to this function. Making it return any positive or negative number is just exposing too much of the implementation. Why not just call the function strsubstract in the first place? How any one would ever come up with adding a function in this shape to a language or library is a mystery to me.

  • mister r (unregistered) in reply to Ian
    Anonymous:
    It seems like overkill to me, but in the guy's defense, doesn't this prevent a potential spelling error? So, it's not a complete WTF, is it?


    lol. yeah he did it like that because he wanted all of his string constants to be type-checked. You could in theory go all the way with this:

       (new Sentence (
                  (new Person ("me")).toString(),
                  (new Verb ("want")).toString(),
                  (new Item ("money")).toString()
             )).toString();

    But thats just madness, if all you wanted was the string constrant "i want money".
  • Some Dude (unregistered) in reply to Omnifarious

    in ksh you can do:

    let SLEEP_COUNT=SLEEP_COUNT+1


    He obviously didn't know that, so he used   <font size="5">`</font>  to  do a textual substitution of the output of the command expr into the assignment statement.

  • macronencer (unregistered) in reply to stevekj
    stevekj:
    R.Flowers:
    R.Flowers:

     

    Which brings up something I often thing about...

    Yes, quite hilarious. Even worse, I carefully re-read what I type, given the comment's subject matter.



    The hardest posts to get correct are the ones complaining about someone else's spelling!

    I'm pretty sure there are no spelling errors in this wun.

    Best to keep it simple. Try this:

    s/who's/whose/g

  • macronencer (unregistered) in reply to Russ
    Anonymous:
    Anonymous:
    The next two lines of code took Christophe Beugnet hours and hours to correct. Who would have guessed that a supplier would have modified a header with this?

    <font size="-0">#define</font> false 1
    <font size="-0">#define</font> true 0
    Heh.... I'm guessing evil exiting former-programmer. [:)]


    Actually, I reckon this is from code that heavily used the strcmp family of functions - they return 0 if two strings are equal, so you end up with a lot of code like if(strcmp(str1, str2) == 0) all over the place (yes, I know you shouldn't use strcmp anyway, but bear with me). These funky defines would let you write if(strcmp(str1, str2) == true) which is slightly more readable - at the expense of making the rest of your code an impenetrable nightmare.

    You could try #define EQUAL 0 #define GREATERTHAN 1 #define LESSTHAN -1

    Only problem is that, IIRC, strcmp et al. don't guarantee to return particular absolute values - just that the return will be <0, ==0 or >0...

  • (cs)
    Alex Papadimoulis:

    Matt Kane was curious why he couldn't open a new tab, so he did a quick View Source on a Sun web page and learned that they found a way to reinvent the hyperlink ... within the hyperlink ...

    <a href="#" onclick="location='http://www.sun.com'; return false;">

     


    At least this particular idiot correctly used the 'onclick' event. I usually see the <a href="javascript:..."> variety, which is even more of a WTF.

  • macronencer (unregistered) in reply to macronencer

    Please ignore my previous "return value will be..." post. It seems that this forum is incapable of coping with code in posts unless you know exactly how to quote it.

    Which is actually pretty ironic, given the general topic :\

    Not sure what happened with the #define one though. Perhaps it's my use of Opera...?

  • macronencer (unregistered) in reply to meepster
    Anonymous:
    In other news, I just Totally Owned (TM) myself by receiving the 2nd post. This is America, people: winner takes all!

    I nipped outside to check. It's still England here. WTF?

  • ev (unregistered) in reply to chrismcb
    chrismcb:
    Anonymous:
    Anonymous:
    Anonymous:
    Anonymous:
    The next two lines of code took Christophe Beugnet hours and hours to correct. Who would have guessed that a supplier would have modified a header with this?

    <font size="+0">#define</font> false 1
    <font size="+0">#define</font> true 0
    Heh.... I'm guessing evil exiting former-programmer. [:)]



    Actually, I reckon this is from code that heavily used the strcmp family of functions - they return 0 if two strings are equal, so you end up with a lot of code like if(strcmp(str1, str2) == 0) all over the place (yes, I know you shouldn't use strcmp anyway, but bear with me). These funky defines would let you write if(strcmp(str1, str2) == true) which is slightly more readable - at the expense of making the rest of your code an impenetrable nightmare.


    On the other hand, writing

    if( strcmp( str1, str2 ) == false )

    is a nice way to shoot yourself in your foot.


    You're referring, I think, to the fact that srcmp might return -1, so the false test would fail. Good point. Perhaps this is where one of those famous tri-bools that show up so often could be used? Something like if(strcmp(str1, str2) == FILE_NOT_FOUND)

    Or it might return 2, or -2, or -3 or -4 or well any other valid integer.




    That's what >= and <= are for.
    So:
    if(strcmp(str1, str2) >= false || strcmp(str1, str2) <= FILE_NOT_FOUND)
    {
    ........


    Or we could of course just use:
    if(strcmp(str1, str2) >= false || strcmp(str2, str1) >= false)
    {
    .......
  • maht (unregistered) in reply to mlathe
    mlathe:

    as far as i know using expr is the only way to add two numbers in bourne shell (the most portable shell). anyone have a better way?




    most portable ? That's the WTF

    Personally I would :

    SLEEP_COUNT = `{echo $SLEEP_COUNT + 1 | bc}
  • SDiZ (unregistered) in reply to Omnifarious
    Omnifarious:
    Alex Papadimoulis:

    I don't know why it's inventive. AFAIK, that's the way it has to be done in a shell script, unless it supports the $(( ... )) syntax, in which case you can do:

    export SLEEP_COUNT=$(( $SLEEP_COUNT + 1 ))

    Which isn't really that much smaller or more understandable.



    The ksh in old unix day does not support $(( ))
  • (cs) in reply to mister r
    Anonymous:
    chrismcb:
    Anonymous:
    Anonymous:
    Anonymous:
    Anonymous:
    The next two lines of code took Christophe Beugnet hours and hours to correct. Who would have guessed that a supplier would have modified a header with this?

    <font size="-0">#define</font> false 1
    <font size="-0">#define</font> true 0
    Heh.... I'm guessing evil exiting former-programmer. [:)]



    Actually, I reckon this is from code that heavily used the strcmp family of functions - they return 0 if two strings are equal, so you end up with a lot of code like if(strcmp(str1, str2) == 0) all over the place (yes, I know you shouldn't use strcmp anyway, but bear with me). These funky defines would let you write if(strcmp(str1, str2) == true) which is slightly more readable - at the expense of making the rest of your code an impenetrable nightmare.


    On the other hand, writing

    if( strcmp( str1, str2 ) == false )

    is a nice way to shoot yourself in your foot.


    You're referring, I think, to the fact that srcmp might return -1, so the false test would fail. Good point. Perhaps this is where one of those famous tri-bools that show up so often could be used? Something like if(strcmp(str1, str2) == FILE_NOT_FOUND)

    Or it might return 2, or -2, or -3 or -4 or well any other valid integer.



    Which is on itself another WTF. Even if a language doesn't support any abstract data types or enums, you could still use clearly named constants for the three types of responses to this function. Making it return any positive or negative number is just exposing too much of the implementation. Why not just call the function strsubstract in the first place? How any one would ever come up with adding a function in this shape to a language or library is a mystery to me.



    Actually, the design of strcmp() is quite clever.  Observe:

      a == b    ->    strcmp(a, b) == 0
      a > b     ->    strcmp(a, b) > 0

      a <= b    ->    strcmp(a, b) <= 0
      a != b    ->    strcmp(a, b) != 0

    Perfectly regular, perfectly predictable, perfectly comprehensible.  Introducing constants like STRCMP_GREATER or whatever will actually make things LESS flexible: I'd rather write

       if (strcmp(a, b) >= 0) {...}

    than what I suppose you're suggesting, which would either be

      if (strcmp(a, b) == STRCMP_EQUAL || strcmp(a, b) == STRCMP_GREATER) {...}

    or

      if (strcmp(a, b, STRCMP_GREATER_OR_EQUAL)) {...}

    because the standard C way of doing it is the only way that includes the standard operator that indicates what I'm actually interested in testing.
  • (cs) in reply to makomk

    The first ones java not vb. (In vb its ToString not toString)

  • (cs) in reply to Iago

    Iago:

    Actually, the design of strcmp() is quite clever.  Observe:

      a == b    ->    strcmp(a, b) == 0
      a > b     ->    strcmp(a, b) > 0

      a <= b    ->    strcmp(a, b) <= 0
      a != b    ->    strcmp(a, b) != 0

    Perfectly regular, perfectly predictable, perfectly comprehensible.  Introducing constants like STRCMP_GREATER or whatever will actually make things LESS flexible: I'd rather write

       if (strcmp(a, b) >= 0) {...}

    than what I suppose you're suggesting, which would either be

      if (strcmp(a, b) == STRCMP_EQUAL || strcmp(a, b) == STRCMP_GREATER) {...}

    or

      if (strcmp(a, b, STRCMP_GREATER_OR_EQUAL)) {...}

    because the standard C way of doing it is the only way that includes the standard operator that indicates what I'm actually interested in testing.

    strcmp() should really be called strdiff().

    I find this a little non-intuitive to read:

    <FONT face="Courier New" size=2>  if ( strcmp("hello world","hello world") ) {</FONT>

    <FONT face="Courier New" size=2>    printf("hello\n");</FONT>

    <FONT face="Courier New" size=2>  }</FONT>

    Anyone who didn't know the peculiarity of strcmp() would probably expect to see "hello" printed.

  • (cs)
  • Anonymous Coward (unregistered) in reply to Tony Morris
    Anonymous:
    Anonymous:
    <font color="#000099">private static final String</font> MBS_PASSWORD = <font color="#990000">"f4rth9fe"</font>.toUpperCase();

    I think what the real WTF is on that one, is that if you're going to hard-code a constant that always gets transformed to upper case, why not just hard-code it in upper case?


    A common misconception with some potential adverse consequences (e.g. I've watched a colleague spend 3 days on it, until he finally sought assistance) so I feel compelled to point it out, and it seems to be TDWTF culture anyway. The above declaration is not a constant.  I have demonstrated this misunderstanding here: http://jqa.tmorris.net/GetQAndA.action?qids=13


    Of course it is a constant.  It is not a compile-time constant expression and therefore cannot be inlined.  That doesn't mean it is not a constant, i.e. a variable whose value cannot be changed.
  • a=$(($a+1)) (unregistered) in reply to ptomblin

    when I do, I do increments that same way.<i>

    Well, c'mon. POSIX sh specifies '$(('. You can rely on it as baseline functionality on sensible platforms.

    http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_04

  • (cs) in reply to a=$(($a+1))

    Re: ksh stuff

    Right, the reasons why it's a WTF. Let's remind ourselves of the script:

    #!/bin/ksh

    1. If this is on Unix (as opposed to a Unix-a-like) then this should be #!/usr/bin/ksh (all the big flavours of Unix soft link /bin to /usr/bin) so it wastes a file system look up.

    export SLEEP_COUNT=expr $SLEEP_COUNT + 1

    1. Using the ` is so 1980s. Even raw bourne shell supported the $( ) for returning output from a subshell.
    2. As it's Korn shell this can be done either by, SLEEP_COUNT=$(($SLEEP_COUNT + 1)), or by (( SLEEP_COUNT += 1 )). $(( )) is a builtin version of expr and (( )) is an alias to the builtin let. The technique used is a waste of a process.
    3. Does the variable need to be exported? Exporting should only be used to make it available to any child processes, if you don't spawn any children, why bother?

    On the bash vs sh vs ksh vs ksh93 vs perl (evil evil language) there is no comparision: ksh88 or ksh93 + awk wins hands down. (Before you ask, bash screws up scope and the vi editing mode in bash blows goats; finally - look at the manual page for bash under bugs, then you should understand).

    Also, Bourne shell is not really the lowest common denominator anymore. I've never seen a Unix or Unix a like since the 1990s that doesn't support either ksh or bash.

  • mister r (unregistered) in reply to Iago
    Iago:
    Anonymous:
    chrismcb:
    Anonymous:
    Anonymous:
    Anonymous:
    Anonymous:
    The next two lines of code took Christophe Beugnet hours and hours to correct. Who would have guessed that a supplier would have modified a header with this?
    #define false 1
    #define true 0
    Heh.... I'm guessing evil exiting former-programmer. [:)]



    Actually, I reckon this is from code that heavily used the strcmp family of functions - they return 0 if two strings are equal, so you end up with a lot of code like if(strcmp(str1, str2) == 0) all over the place (yes, I know you shouldn't use strcmp anyway, but bear with me). These funky defines would let you write if(strcmp(str1, str2) == true) which is slightly more readable - at the expense of making the rest of your code an impenetrable nightmare.


    On the other hand, writing

    if( strcmp( str1, str2 ) == false )

    is a nice way to shoot yourself in your foot.


    You're referring, I think, to the fact that srcmp might return -1, so the false test would fail. Good point. Perhaps this is where one of those famous tri-bools that show up so often could be used? Something like if(strcmp(str1, str2) == FILE_NOT_FOUND)

    Or it might return 2, or -2, or -3 or -4 or well any other valid integer.



    Which is on itself another WTF. Even if a language doesn't support any abstract data types or enums, you could still use clearly named constants for the three types of responses to this function. Making it return any positive or negative number is just exposing too much of the implementation. Why not just call the function strsubstract in the first place? How any one would ever come up with adding a function in this shape to a language or library is a mystery to me.



    Actually, the design of strcmp() is quite clever.  Observe:

      a == b    ->    strcmp(a, b) == 0
      a > b     ->    strcmp(a, b) > 0
      a <= b    ->    strcmp(a, b) <= 0
      a != b    ->    strcmp(a, b) != 0

    Perfectly regular, perfectly predictable, perfectly comprehensible.  Introducing constants like STRCMP_GREATER or whatever will actually make things LESS flexible: I'd rather write

       if (strcmp(a, b) >= 0) {...}

    than what I suppose you're suggesting, which would either be

      if (strcmp(a, b) == STRCMP_EQUAL || strcmp(a, b) == STRCMP_GREATER) {...}

    or

      if (strcmp(a, b, STRCMP_GREATER_OR_EQUAL)) {...}

    because the standard C way of doing it is the only way that includes the standard operator that indicates what I'm actually interested in testing.


    Which in itself is another WTF: that you can't overload operators and have functions that dispatch based on the types or their arguments. In haskell the quicksort function below, obviously also works for strings, but do you see a stringCompare anywhere?
     quicksort []           = []
    quicksort (pivot:tail) = quicksort [y | y <- tail, y < pivot]
    ++ [pivot]
    ++ quicksort [y | y <- tail, y >= pivot]

    So whats going on?  Is the ( >= ) operator overloaded for strings ? Well, look at the type:

      quicksort :: Ord a => [a] -> [a]

    It takes a list of things of type 'a and returns such a list. Yet the whole function is bound by the context of 'Ord a'. Which says that whatever type you choose for 'a, there needs to exists an instance of Ord a. Which exists both for Lists and for Characters (strings are just list of characters). You can make instances for your own datatypes if you want to, or have them automatically inferred using deriving:

      data Maybe a = Just a | Nothing deriving Ord

    The deriving Ord part makes that you can compare Maybes.
  • An apprentice (unregistered) in reply to mister r
    Anonymous:
    Which in itself is another WTF: that you can't overload operators and have functions that dispatch based on the types or their arguments. In haskell the quicksort function below, obviously also works for strings, but do you see a stringCompare anywhere?

    That's all well and good, but does Haskell support ternary logic {True, False, FileNotFound}? If not, then it's unusable in real life projects.

  • Daniel (unregistered) in reply to .*

    I agree. I think this is in fact the only way to increment in POSIX shell, which should
    be used for any shell scripts. ksh or bash or zsh or whatever specific dialects are much less
    portable.

    IMHO this is perfectly valid, portable code. Of course it is a waste of resources and
    may appear clumsy, but thats what is available if you want to be portable.
    In most cases it won't matter anyway....

  • (cs) in reply to rikkus
  • whoever (unregistered) in reply to mister r


    Which in itself is another WTF: that you can't overload operators and have functions that dispatch based on the types or their arguments.

    Umm, you realize that strcmp() was defined something like 30 years ago, right?  It may not be a great function definition, but operator overloading and other OO techniques were developed a bit later - you know, when computers had more than 16KB of RAM.

     

  • grammarian (unregistered)

    Yup, but whose', notwho's'...

  • AC (unregistered) in reply to Ralph the parrot
    Anonymous:

    It reminds me of the time I intentionally hid some code by indenting it into the horizon.


    That's why you use editor that wraps long lines.  Not only because somebody else might have been evil, but creating a code like that is too easy to accidentally do by yourself (accidentally hit del at the end of long line when next line has deep indentation, for example).
  • aswefawfsadfafe (unregistered) in reply to felix
    At least this particular idiot correctly used the 'onclick' event. I usually see the <A href="javascript:...">variety, which is even more of a WTF.
    No, the WTF is that he used href="#", which if you're not at the top of the page, will reset your page to the top.
     
    There is nothing wrong with href="javascript:".  In fact, all JavaScript should be prefaced with javascript:, just like all VBScript should be prefaced with vbscript:, and any other script languages should be prefaced with their proper moniker.
     
    There are two correct ways of handling the onclick event:
     
    do <A href="javascript: doWhatever();">
     
    do <A onclick="javascript: doWhatever();">
     
    Of course, #2 doesn't work in IE, so really #1 is your only real choice until MS blows up and dies.
     
    God I f'ing hate Community Server.
  • (cs) in reply to aswefawfsadfafe
    Anonymous:

    The correct way is:
    <a href="normal.html" onclick="dosomething(); return false;">

    The browser will fall back to just going to normal.html when there is no javascript support, otherwise it will dosomething(). Works in all modern browsers without a problem.

Leave a comment on “A Friday Mixer”

Log In or post as a guest

Replying to comment #:

« Return to Article