• (cs)

    <font size="1">

    <font>if</font> ((<font>this</font>.txtLastName.Text=="")!=(<font>this</font>.txtFirstName.Text==""))
    {
    boolIsValid = <font>false</font>;
    vldSearch.ErrorMessage = <font>"The First and Last names are required to conduct a search."</font>;
    }

    </font><font size="1">!= is cooler looking than &&</font>

  • spacey (unregistered)

    These have to be cases of "Paid by the Hour" versus "Paid by the Line" :)

    Why the hell else would anyone have spent so much time being so damn useless......

    -space

  • (cs) in reply to John Smallberries
    John Smallberries:
    <font size="1">
    <font>if</font> ((<font>this</font>.txtLastName.Text=="")!=(<font>this</font>.txtFirstName.Text==""))
    {
    boolIsValid = <font>false</font>;
    vldSearch.ErrorMessage = <font>"The First and Last names are required to conduct a search."</font>;
    }

    </font><font size="1">!= is cooler looking than &&</font>


    Yeah, cooler and wronger
  • (cs)
    Alex Papadimoulis:

    First up, and I must say this one takes the cake, is from Billy. As some background, these constants were defined in every class in the Java project. These were used throughout the system in place of their primitive boolean counterparts ...

    <FONT color=#0000ff>public static final String</FONT> TRUE = <FONT color=#ff0000>"true"</FONT>;
    <FONT color=#0000ff>public static final String</FONT> FALSE = <FONT color=#ff0000>"not true"</FONT>;
    

    They left out a bunch of useful stuff.

    Random generator = new Random(123456);

    int r = generator.nextInt();

    <FONT color=#0000ff>public static String</FONT> MAYBE = (r % 2 == 0 ? <FONT color=#ff0000>"perhaps" : "who knows");</FONT>

    <FONT color=#ff0000></FONT>public static String SOMETIMES = (r % 7 == 0 ? "not bloody likely" : "shit happens");

    public static String IDOUBTIT = (r % 31 == 0 ? "shouldn't happen" : "remember the prime directive");

    public static String RIIIIIIIIIGHT = (r % 59 == 0 ? "a subspace fracture" : "two to beam up");

  • Rich (unregistered)
    if ((this.txtLastName.Text=="")!=(this.txtFirstName.Text==""))
    {
      boolIsValid = false;
      vldSearch.ErrorMessage = "The First and Last names are required to conduct a search.";
    }

    This seems to be saying "if you provide a name, you have to provide both a first name and a last name. Not that WTFey, just badly documented.

  • (cs) in reply to John Smallberries

    "!= is cooler looking than &&"

    It's a shame that that's not its meaning though.

    (Did nobody test it with both first and last name blank?)

  • spacey (unregistered) in reply to rogthefrog

    :P

    ROLL ON THE FLOOR @

    public static String RIIIIIIIIIGHT = (r % 59 == 0 ? "a subspace fracture" : "two to beam up");

    omg rofl

    -space

  • (cs) in reply to rogthefrog

    rog wins.  You all can go home now.

  • (cs)
    Alex Papadimoulis:

    And finally, David Grant shares with this quirky piece of validation code ...

    <FONT color=#0000ff>if</FONT> ((<FONT color=#0000ff>this</FONT>.txtLastName.Text=="")!=(<FONT color=#0000ff>this</FONT>.txtFirstName.Text==""))
    {
      boolIsValid = <FONT color=#0000ff>false</FONT>;
      vldSearch.ErrorMessage = <FONT color=#ff0000>"The First and Last names are required to conduct a search."</FONT>;
    }
    

    I've done vaguely similar things to test whether any of several numerical fields were 0 and flag that situation.

    Assume a, b, c, d, e are the fields in question.

    <FONT face="Courier New">bool isValid = (a * b * c * d * e != 0);</FONT>

    Of course I put a comment explaining WTF I was doing that.

  • DragonMageWTF (unregistered) in reply to Bellinghman
    Bellinghman:
    "!= is cooler looking than &&"

    It's a shame that that's not its meaning though.

    (Did nobody test it with both first and last name blank?)



    Or more importantly, with one blank and the other not?

  • (cs) in reply to rogthefrog
    rogthefrog:
    I've done vaguely similar things to test whether any of several numerical fields were 0 and flag that situation.

    Assume a, b, c, d, e are the fields in question.

    <FONT face="Courier New">bool isValid = (a * b * c * d * e != 0);</FONT>

    Of course I put a comment explaining WTF I was doing that.

    Not that it would be likely, but isn't there the possiblity of an overflow error with that?

  • DragonMageWTF (unregistered) in reply to DragonMageWTF
    Anonymous:
    Bellinghman:
    "!= is cooler looking than &&"

    It's a shame that that's not its meaning though.

    (Did nobody test it with both first and last name blank?)



    Or more importantly, with one blank and the other not?


    or I could be the idiot to not test the proper failing condition...

  • (cs)
    Alex Papadimoulis:
     

    <FONT color=#0000ff>function</FONT> isNegative( n ) {
      <FONT color=#0000ff>return</FONT> n != 0 && n / <FONT color=#000080>Math</FONT>.<FONT color=#0000ff>abs</FONT>( n ) == -1
    }

    I'm still waiting on someone to explain why this is good way to check for a negative number.  Don't let me down, people.

  • (cs) in reply to dubwai
    dubwai:
    rogthefrog:
    I've done vaguely similar things to test whether any of several numerical fields were 0 and flag that situation.

    Assume a, b, c, d, e are the fields in question.

    <FONT face="Courier New">bool isValid = (a * b * c * d * e != 0);</FONT>

    Of course I put a comment explaining WTF I was doing that.

    Not that it would be likely, but isn't there the possiblity of an overflow error with that?

    I like living dangerously.

  • (cs) in reply to dubwai
    dubwai:
    Alex Papadimoulis:
     

    <FONT color=#0000ff>function</FONT> isNegative( n ) {
      <FONT color=#0000ff>return</FONT> n != 0 && n / <FONT color=#000080>Math</FONT>.<FONT color=#0000ff>abs</FONT>( n ) == -1
    }

    I'm still waiting on someone to explain why this is good way to check for a negative number.  Don't let me down, people.

    It's a better way than

    <FONT color=#0000ff>function</FONT> isNegative( n ) {
      <FONT color=#0000ff>return</FONT> n != 0 && n / n == -1
    }

    or

    <FONT color=#0000ff>function</FONT> isNegative( n ) {
      <FONT color=#0000ff>return</FONT> n != 0 && Math.abs( n ) / <FONT color=#000080>Math</FONT>.<FONT color=#0000ff>abs</FONT>( n ) == -1
    }

  • (cs)
    Alex Papadimoulis:
    <font color="#0000ff">function</font> isNegative( n ) {
    <font color="#0000ff">return</font> n != 0 && n / <font color="#000080">Math</font>.<font color="#0000ff">abs</font>( n ) == -1
    }



    The irony here is that the abs() function usually checks for negative in itself.  So instead of a simple comparison statement, it has maybe three compares (when including the one from abs()), a function call, a boolean operation, a negation operation (inside of abs()), and a division.

    At least it doesn't invoke the for-switch paradigm.
  • (cs) in reply to whoisfred
    whoisfred:
    John Smallberries:
    <font size="1">
    <font>if</font> ((<font>this</font>.txtLastName.Text=="")!=(<font>this</font>.txtFirstName.Text==""))
    {
    boolIsValid = <font>false</font>;
    vldSearch.ErrorMessage = <font>"The First and Last names are required to conduct a search."</font>;
    }

    </font><font size="1">!= is cooler looking than &&</font>


    Yeah, cooler and wronger

    Actually not, considering that != misses only one case while && misses two plus won't allow even valid queries ;-) So who's wronger now?

  • (cs) in reply to dubwai
    dubwai:
    Alex Papadimoulis:
     

    <font color="#0000ff">function</font> isNegative( n ) {
    <font color="#0000ff">return</font> n != 0 && n / <font color="#000080">Math</font>.<font color="#0000ff">abs</font>( n ) == -1
    }

    I'm still waiting on someone to explain why this is good way to check for a negative number.  Don't let me down, people.



    Well, it's obvious, isn't it? If the absolute value of a non-zero number is negative, then the number must belong to the set of numbers that are Not Ever Gonna Appear Twice In Value Entities. You've just mistaken the camel-case version of the acronym for the common english phrase "is negative".
  • (cs) in reply to dubwai
    dubwai:
    Alex Papadimoulis:
     

    <FONT color=#0000ff>function</FONT> isNegative( n ) {
      <FONT color=#0000ff>return</FONT> n != 0 && n / <FONT color=#000080>Math</FONT>.<FONT color=#0000ff>abs</FONT>( n ) == -1
    }

    I'm still waiting on someone to explain why this is good way to check for a negative number.  Don't let me down, people.

    Umm...because it looks cooler than:

    <FONT color=#0000ff>function</FONT> isNegative( n ) {
      <FONT color=#0000ff>return</FONT> n < 0
    }
    [:P]
  • (cs) in reply to Stan Rogers
    Stan Rogers:
    dubwai:
    Alex Papadimoulis:
     

    <font color="#0000ff">function</font> isNegative( n ) {
    <font color="#0000ff">return</font> n != 0 && n / <font color="#000080">Math</font>.<font color="#0000ff">abs</font>( n ) == -1
    }

    I'm still waiting on someone to explain why this is good way to check for a negative number.  Don't let me down, people.



    Well, it's obvious, isn't it? If the absolute value of a non-zero number is negative, then the number must belong to the set of numbers that are Not Ever Gonna Appear Twice In Value Entities. You've just mistaken the camel-case version of the acronym for the common english phrase "is negative".


    Nevermind -- old man, bad glasses, small fonts, failed to see the "n/" part. I really gotta adjust this browser.
  • (cs) in reply to finix

    Getting late.. still, it's two against one

  • (cs)
    Alex Papadimoulis:
    <font color="#0000ff">function</font> isNegative( n ) {
    <font color="#0000ff">return</font> n != 0 && n / <font color="#000080">Math</font>.<font color="#0000ff">abs</font>( n ) == -1
    }



    I'll be surprised if they didn't also created isPositive() just to cover all the bases (and I wonder if a zero would be considered positive in that respect).
  • (cs)
    Alex Papadimoulis:

    <font color="#0000ff">public static final String</font> TRUE = <font color="#ff0000">"true"</font>;
    <font color="#0000ff">public static final String</font> FALSE = <font color="#ff0000">"not true"</font>;



    Hrm... possibly against his beliefs to call anything "false", he is forced to say that FALSE = "not true".  After all, if FALSE = "false" then that would be true and thus a vicious cycle.  FALSE must be not "true" (to, of course, distinguish from TRUE).  Therefore, we must define it as FALSE = "not true".
  • (cs) in reply to WebCudgel
    WebCudgel:
    Alex Papadimoulis:
    <FONT color=#0000ff>function</FONT> isNegative( n ) {
    <FONT color=#0000ff>return</FONT> n != 0 && n / <FONT color=#000080>Math</FONT>.<FONT color=#0000ff>abs</FONT>( n ) == -1
    }



    I'll be surprised if they didn't also created isPositive() just to cover all the bases (and I wonder if a zero would be considered positive in that respect).

    There are many ways to deal with that. One simple, elegant way is the following:

    function isPositive(n, strict = true)

    {

       return (n >= 0 && (strict ? n != 0 : true));

    }

    Of course it'd be safer to have two separate functions, but I'll leave that as an exercise to the reader.

  • (cs)
    Alex Papadimoulis:

    <font color="#0000ff">if</font> ((<font color="#0000ff">this</font>.txtLastName.Text=="")!=(<font color="#0000ff">this</font>.txtFirstName.Text==""))
    {
    boolIsValid = <font color="#0000ff">false</font>;
    vldSearch.ErrorMessage = <font color="#ff0000">"The First and Last names are required to conduct a search."</font>;
    }



    Yeah, || would be more accurate to use in the place of != (or &&) there.  However, the developer also fails to check for the use of "spaces" in addition to it being blank (I knew a QA department that always tested to see if that was allowed).
  • (cs)
    Alex Papadimoulis:
    <FONT color=#0000ff>public static final String</FONT> TRUE = <FONT color=#ff0000>"true"</FONT>;
    <FONT color=#0000ff>public static final String</FONT> FALSE = <FONT color=#ff0000>"not true"</FONT>;
    

    I don't know Java. Does it really not have a built-in "false" constant?

     

  • (cs) in reply to finix
    finix:
    whoisfred:
    John Smallberries:
    <font size="1">
    <font>if</font> ((<font>this</font>.txtLastName.Text=="")!=(<font>this</font>.txtFirstName.Text==""))
    {
    boolIsValid = <font>false</font>;
    vldSearch.ErrorMessage = <font>"The First and Last names are required to conduct a search."</font>;
    }

    </font><font size="1">!= is cooler looking than &&</font>


    Yeah, cooler and wronger

    Actually not, considering that != misses only one case while && misses two plus won't allow even valid queries ;-) So who's wronger now?


    Well, != looks a lot cooler than ||.


  • SomeGuy (unregistered)
    Alex Papadimoulis:

    And finally, David Grant shares with this quirky piece of validation code ...

    <font color="#0000ff">if</font> ((<font color="#0000ff">this</font>.txtLastName.Text=="")!=(<font color="#0000ff">this</font>.txtFirstName.Text==""))
    {
    boolIsValid = <font color="#0000ff">false</font>;
    vldSearch.ErrorMessage = <font color="#ff0000">"The First and Last names are required to conduct a search."</font>;
    }



    So, was nobody going to comment on string compares in Java?
    <font color="#0000ff">this</font>.txtLastName.Text=="" <font size="4">is not always the same as</font> "".equals(<font color="#0000ff">this</font>.txtLastName.Text)
  • (cs) in reply to A Wizard A True Star
    A Wizard A True Star:
    Alex Papadimoulis:
    <FONT color=#0000ff>public static final String</FONT> TRUE = <FONT color=#ff0000>"true"</FONT>;
    <FONT color=#0000ff>public static final String</FONT> FALSE = <FONT color=#ff0000>"not true"</FONT>;
    

    I don't know Java. Does it really not have a built-in "false" constant?

    It has a boolean type that has two values possible values: true and false.  No 0 and 1 or anything like that.

    It also has a Boolean Object type that has two constants TRUE and FALSE.  I'm guessing these are supposed to be to evaulate some sort of input, I hope.

  • mfx (unregistered)
    Alex Papadimoulis:

    <font color="#0000ff">function</font> isNegative( n ) {
    <font color="#0000ff">return</font> n != 0 && n / <font color="#000080">Math</font>.<font color="#0000ff">abs</font>( n ) == -1
    }


    Now this is easy to explain. The code is Javascript, which is embedded in HTML. Early Browsers had Problems with ">" characters embedded in Javascript, so the programmer tried to avoid both of these "dangerous" characters.


    Still, Math.abs(n) != n would have been more obvious.....

  • (cs) in reply to SomeGuy
    Anonymous:
    Alex Papadimoulis:

    And finally, David Grant shares with this quirky piece of validation code ...

    <font color="#0000ff">if</font> ((<font color="#0000ff">this</font>.txtLastName.Text=="")!=(<font color="#0000ff">this</font>.txtFirstName.Text==""))
    {
    boolIsValid = <font color="#0000ff">false</font>;
    vldSearch.ErrorMessage = <font color="#ff0000">"The First and Last names are required to conduct a search."</font>;
    }



    So, was nobody going to comment on string compares in Java?
    <font color="#0000ff">this</font>.txtLastName.Text=="" <font size="4">is not always the same as</font> "".equals(<font color="#0000ff">this</font>.txtLastName.Text)


    I had assumed this was a validation JavaSCRIPT for an HTML page, but then it would have been this.txtLastName.value and not .Text.  Hrm... good call there.  It would definitely require .equals().
  • Anonymous (unregistered) in reply to mfx
    Anonymous:
    Alex Papadimoulis:

    <FONT color=#0000ff>function</FONT> isNegative( n ) {
    <FONT color=#0000ff>return</FONT> n != 0 && n / <FONT color=#000080>Math</FONT>.<FONT color=#0000ff>abs</FONT>( n ) == -1
    }



    Now this is easy to explain. The code is Javascript, which is embedded in HTML. Early Browsers had Problems with ">" characters embedded in Javascript, so the programmer tried to avoid both of these "dangerous" characters.

    Still, Math.abs(n) != n would have been more obvious.....

    Finally someone who thinks before writing.

  • vDave420 (unregistered) in reply to John Smallberries
    John Smallberries:
    <font size="1">
    <font>if</font> ((<font>this</font>.txtLastName.Text=="")!=(<font>this</font>.txtFirstName.Text==""))
    {
    boolIsValid = <font>false</font>;
    vldSearch.ErrorMessage = <font>"The First and Last names are required to conduct a search."</font>;
    }

    </font><font size="1">!= is cooler looking than &&</font>


    Except that wouldn't be the same thing...

    Consider:
    (a==b) != (c==d)

    This returns false if either ( (a==b) && (c==d)) or ((a!=b) && (c!=d)), else true

    whereas
    (a==b)&&(c==d) would return false if only one of them (a,b or c,d) were the same.

    In other words, that code is trying to make sure that EITHER none of the strings is empty OR both are empty.  && (instead of !=) wouldn't do that.

          -dave-
  • (cs) in reply to rogthefrog
    rogthefrog:
    dubwai:
    rogthefrog:
    I've done vaguely similar things to test whether any of several numerical fields were 0 and flag that situation.

    Assume a, b, c, d, e are the fields in question.

    <FONT face="Courier New">bool isValid = (a * b * c * d * e != 0);</FONT>

    Of course I put a comment explaining WTF I was doing that.

    Not that it would be likely, but isn't there the possiblity of an overflow error with that?

    I like living dangerously.

    I am not the smartest programmer in the world, but RogtheFrog, in the last WTF you were advocating for the use of delimited strings within a database field and now this.

  • Alex (unregistered)
    Alex Papadimoulis:

    First up, and I must say this one takes the cake, is from Billy. As some background, these constants were defined in every class in the Java project. These were used throughout the system in place of their primitive boolean counterparts ...

    <font color="#0000ff">public static final String</font> TRUE = <font color="#ff0000">"true"</font>;
    <font color="#0000ff">public static final String</font> FALSE = <font color="#ff0000">"not true"</font>;



    The coder here is clearly a postmodernist who feels that there is no such thing as absolute truth.  By defining the constants this way (he made a mistake declaring them final, as truth claims cannot ever be final in the postmodernist viewpoint), he makes it easier for future developers to define their own truth without making substantial alterations to the code..
  • Jonathan Pryor (unregistered) in reply to SomeGuy
    <font color="#0000ff">if</font> ((<font color="#0000ff">this</font>.txtLastName.Text=="")!=(<font color="#0000ff">this</font>.txtFirstName.Text==""))
    {
    boolIsValid = <font color="#0000ff">false</font>;
    vldSearch.ErrorMessage = <font color="#ff0000">"The First and Last names are required to conduct a search."</font>;
    }

    Given the naming convention (Hungarian-style prefixes, Pascal-cased property names), this is probably C#, not Java.  In which case <font color="#0000ff">this</font>.txtLastName.Text=="" is correct.
  • (cs) in reply to RyGuy
    RyGuy:
    rogthefrog:
    dubwai:
    rogthefrog:
    I've done vaguely similar things to test whether any of several numerical fields were 0 and flag that situation.

    Assume a, b, c, d, e are the fields in question.

    <font face="Courier New">bool isValid = (a * b * c * d * e != 0);</font>

    Of course I put a comment explaining WTF I was doing that.

    Not that it would be likely, but isn't there the possiblity of an overflow error with that?

    I like living dangerously.

    I am not the smartest programmer in the world, but RogtheFrog, in the last WTF you were advocating for the use of delimited strings within a database field and now this.



    Aww, not a fan of the Brute Force Technique?

    Also, that first gem not only would risk overflow, but I guarantee that 5 multiplies and a compare will always be slower than just 5 compare statements ;)
  • (cs) in reply to RyGuy
    RyGuy:
    rogthefrog:
    dubwai:
    rogthefrog:
    I've done vaguely similar things to test whether any of several numerical fields were 0 and flag that situation.

    Assume a, b, c, d, e are the fields in question.

    <FONT face="Courier New">bool isValid = (a * b * c * d * e != 0);</FONT>

    Of course I put a comment explaining WTF I was doing that.

    Not that it would be likely, but isn't there the possiblity of an overflow error with that?

    I like living dangerously.

    I am not the smartest programmer in the world, but RogtheFrog, in the last WTF you were advocating for the use of delimited strings within a database field and now this.

    I wasn't advocating for the wanton use of delimited strings in a db, nor am I advocating for the wanton use of this shortcut either. Using delimited strings in a db is perfectly legitimate IN SOME VERY SPECIFIC INSTANCES. The a * b * c trick is an example of something I used once in a script I wrote for myself where the variables were controlled. And the "I like living dangerously" was ironic. So nyah.

     

  • Matt Moriarity (unregistered) in reply to Jonathan Pryor

    That's what I figured too. Not that I've done much C-Pound :D programming, but I knew it wasn't Java.

  • (cs) in reply to dubwai
    dubwai:
    Alex Papadimoulis:
     

    <font color="#0000ff">function</font> isNegative( n ) {
    <font color="#0000ff">return</font> n != 0 && n / <font color="#000080">Math</font>.<font color="#0000ff">abs</font>( n ) == -1
    }

    I'm still waiting on someone to explain why this is good way to check for a negative number.  Don't let me down, people.


    I figured this is what happens when you let Math majors write code.  Points off for not including a Proof of Correctness in the comments.
  • (cs) in reply to Charles Nadolski
    Charles Nadolski:

    Also, that first gem not only would risk overflow, but I guarantee that 5 multiplies and a compare will always be slower than just 5 compare statements ;)


    You're neglecting the possibility that the first element is zero.  Those multiplications will scream.
  • (cs)
    Alex Papadimoulis:
    <font color="#0000ff">function</font> isNegative( n ) {
    <font color="#0000ff">return</font> n != 0 && n / <font color="#000080">Math</font>.<font color="#0000ff">abs</font>( n ) == -1
    }


        return n != Math.abs(n);
    isn't ugly enough?
  • Steve Wahl (unregistered) in reply to Charles Nadolski
    Charles Nadolski:

    Also, that first gem not only would risk overflow, but I guarantee that 5 multiplies and a compare will always be slower than just 5 compare statements ;)


    Not necessarily.  Compares represent branches, which can cause pipline stalls and restarts on modern processors.  And, for example, x86 comes out with a compare and jump instruction for each compare, while the multiply version just has a multiply for each followed by a single compare / jump pair.  That's 10 vs. 7 instructions for five vars.  (Determined by looking at  compiler (gcc) output for the following C code:)

    main(int ac, char **av)
    {
        int a, b, c, d, e ;
        int res1 , res2 ;

        a = 16384 ; b = 32768 ;    c = 2 ;    d = 2 ;    e = 2 ;

        res1 = ( (a != 0) && (b != 0) && (c != 0) && (d != 0) && (e != 0) ) ;
        res2 = ( a * b * c * d * e != 0 ) ;

        printf("res1 is %d, res2 is %d\n", res1, res2) ;
    }

    Which, for me, yields "res1 is 1, res2 is 0" (a 32-bit int machine).

  • (cs) in reply to SomeGuy
    Anonymous:
    Alex Papadimoulis:

    And finally, David Grant shares with this quirky piece of validation code ...

    <font color="#0000ff">if</font> ((<font color="#0000ff">this</font>.txtLastName.Text=="")!=(<font color="#0000ff">this</font>.txtFirstName.Text==""))
    {
    boolIsValid = <font color="#0000ff">false</font>;
    vldSearch.ErrorMessage = <font color="#ff0000">"The First and Last names are required to conduct a search."</font>;
    }



    So, was nobody going to comment on string compares in Java?
    <font color="#0000ff">this</font>.txtLastName.Text=="" <font size="4">is not always the same as</font> "".equals(<font color="#0000ff">this</font>.txtLastName.Text)

    I simply assumed this was written in D flat, you know one of the .NOT languages.

  • Steve Wahl (unregistered) in reply to Maurits
    Maurits:
    Charles Nadolski:

    Also, that first gem not only would risk overflow, but I guarantee that 5 multiplies and a compare will always be slower than just 5 compare statements ;)


    You're neglecting the possibility that the first element is zero.  Those multiplications will scream.

    Unless I'm quite mistaken, modern processors do integer multiplies in constant time, independent of the data, so the first element being zero has no effect on speed...

  • OneFactor (unregistered) in reply to rogthefrog
    rogthefrog:

    I've done vaguely similar things to test whether any of several numerical fields were 0 and flag that situation.

    Assume a, b, c, d, e are the fields in question.

    <FONT face="Courier New">bool isValid = (a * b * c * d * e != 0);</FONT>

    Of course I put a comment explaining WTF I was doing that.

    Isnt that a little dangerous?

    int a = 65536;
    Console.WriteLine(a*a);
    if (a*a == 0 && a!= 0) {   Console.WriteLine("WTF a*a is zero");   }

  • (cs) in reply to dubwai
    dubwai:
    Alex Papadimoulis:
     

    <font color="#0000ff">function</font> isNegative( n ) {
    <font color="#0000ff">return</font> n != 0 && n / <font color="#000080">Math</font>.<font color="#0000ff">abs</font>( n ) == -1
    }

    I'm still waiting on someone to explain why this is good way to check for a negative number.  Don't let me down, people.



    Well, it could be worse, they could have done something like this:

    function isNegative(n) {
      if n == 0 then {
        if n/Math.abs(n) == -1 then {
          return true
        }
        else {

          return false
        }
      }
      else {

        return false
      }
    }

    <font style="font-family: arial;" size="3">Be thankful for small mercies ;-)</font>
  • (cs)
    Alex Papadimoulis:
    <FONT color=#0000ff>function</FONT> isNegative( n ) {
      <FONT color=#0000ff>return</FONT> n != 0 && n / <FONT color=#000080>Math</FONT>.<FONT color=#0000ff>abs</FONT>( n ) == -1
    }

    Is there anything keeping n from being a float or double? If so, think we got a great heisenbug in here:

    n / Math.abs( n ) = -1.00000000000001.

     

    And I sure hope Javascript short-circuits the comparison if n is 0. That was tested, right?<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>

    Alex Papadimoulis:

    <FONT color=#0000ff>if</FONT> ((<FONT color=#0000ff>this</FONT>.txtLastName.Text=="")!=(<FONT color=#0000ff>this</FONT>.txtFirstName.Text==""))
    {
      boolIsValid = <FONT color=#0000ff>false</FONT>;
      vldSearch.ErrorMessage = <FONT color=#ff0000>"The First and Last names are required to conduct a search."</FONT>;
    }
    

    <o:p>

    I wouldn’t want to put the programmer out and make him write a few more lines to determine which field

    was empty and have an error message that tells the user exactly what to correct. I myself prefer to

    validate a form of numerous fields with a single massive if statement, and throw up the ever helpful error

    message “Validation failure on string(s).”  

    --RA

    Why is this forum SW refusing to wordwrap?</o:p>

  • Andrew McKinlay (unregistered)

    I've use code similar to the last quirky validation. It is the shortest way to do it, but I always worry if other programmers are going to understand it without a lot of thought. It doesn't get used enough to become a familar idiom. Usually "short", "simple", and "clear" are compatible, but in this case maybe not.

  • Steven (unregistered)

    <font>public static final String</font> TRUE = <font>"true"</font>;
    <font>public static final String</font> FALSE = <font>"not true"</font>;

    Actually, this has to be for something other than boolean tests, possibly logging or debugging.
    It just wouldn't be for boolean tests, you'd have to work around the fact it was a String everytime you used it!

    This just won't work:

    if (TRUE)
    {

    }

    It's a string, java won't let you do this, every where you used this, you could do:

    public boolean isValid()
    {
    return TRUE; //Wouldn't work, TRUE is a string
    }

    so, you'd be doing this:

    public String isValid()
    {
    return true;
    }

    and then testing:

    if (this.isValid().equals(TRUE))
    {

    }

    instead of the much better outcome you get with a true boolean.

    if (this.isValid())
    {

    }


    The only reason I can see for it is to do debugging

    if (someCondition)
    {
    Logger.debug(TRUE);
    }

    But then, you've still defined a constant with the same name as a reserved word ('true' or 'false')

    PS, the approach to solving the javascript the the < or > would best be solved with the old fashioned use of
    comments inside the script tags so that browsers that didn't get javascript will simply treat the code as comments.

    That way, you should be able to use < or > without accidently injecting unexpected html open tag code into the page for the old dumb browsers.

    <script>
    <!--<br><br>-->
    </script>[SCRIPT]
    [!--]
    your code here
    [--]
    [/SCRIPT]


Leave a comment on “WTF Simplicity”

Log In or post as a guest

Replying to comment #:

« Return to Article