Believing in booleans



  • @morbiuswilters said:

    Another one I see a lot is:

    if (!isSomething) {
      // do stuff
    } else {
     // do other stuff
    }


    It's less readable. I usually invert it when I see it.

     

    That could come about because the else got tacked on at a later date. I've done this before and seen it done, I don't think it's less readable. If I'm writing the if/else at the same time, I do write it the way you do though.

     



  •  @Sutherlands said:

    In C#, sure, that's not necessary, but C/C++ don't have an actual bool value, so explicit comparison can get rid of bugs.

    I'm pretty sure C++ has boolean values http://www.learncpp.com/cpp-tutorial/26-boolean-values/  Do they ever exhibit non-boolean behaviour?



  • @mightybaldking said:

    Not good enough.  The actual code is:

     if (myBoolean == true)

    {

      // do something

    }

    else if (myBoolean == false)

    {

      // do something else

    }

     

     

    Wouldn't this be better?

    switch(myBoolean)

    {                                                                                                                                                                                                                        
                    case true:                                                                                                                                                                                                       
                            // Do something                                                                                                                                                                                          
                            break;                                                                                                                                                                                                   
                    case false:                                                                                                                                                                                                      
                            // Do something else                                                                                                                                                                                     
                            break;                                                                                                                                                                                                   
                    default:                                                                                                                                                                                                         
                            // FileNotFound                                                                                                                                                                                          
                            break;                                                                                                                                                                                                   
    }

     


     



  • @esoterik said:

    I figured this one out, its a case of igoring the context of a best practice. The single return policy is only a best practice when using C & Malloc/Free, in a context with say RAII, or in a managed environment it is an anti-patern. If you are unlucky enough to have to maintain that kind of C code, you know you have to follow the single return policy or it will bite you in the ass!
    That's why the phrase "best practice" is useless. The phrase is supposed to mean "nugget of truth distilled from years of experience that, if followed, will lead to success". Unfortunately, the context of the experience is so important to the application of the practice that the practice is almost useless without the experience that goes along with it. You end up with what most people see in real life - people with a lot of experience succeed and attribute that success to "best practices", while inexperienced people continually mis-apply these best practices in a futile attempt to replicate the success of an experienced professional without actually having any experience.



  • @rstinejr said:

    if (myBoolean == true)
    {
    // do something
    }
     

    i use this if it's not obvious from the name of the variable that it is boolean

     @rstinejr said:

    if (val > 200)
    {
    myBoolean = true;
    }
    else
    {
    myBoolean = false;
    }

    ...instead of

    myBoolean = (val > 20);

    and this out of habit, because i never thought about it too much, and (yes, trwtf) i learned/realized that you can use the second form only some 3-4 years after i started programming (i started when i had about 12, so that might justify me a little), and i kind of fell uncomfortable using it, it requires me to stop and think even if for a fraction of second, where the more explicit/less "correct" form flows naturally through my brain.

    however, i tend to use this more

    myBoolean = false;

    if(val > 200) { myBoolean = true; }

     

     



  •  plus, i usually work with PHP so i prefer not to let language infer what i want to do and expect it to behave in a sane way. who knows if

    myBool = (val > 20)

    doesn't actually return the difference between val and 20 if it's true, and 0 if false, and the difference gets eval'd as bool true when comparing, but in this assignment myBool would actually end up with number?

     



  • @SEMI-HYBRID code said:

    however, i tend to use this more

    myBoolean = false;

    if(val > 200) { myBoolean = true; }

     

     

    I REALLY dislike that. The initial set is almost a head fake that misdirects the reader. Sure, someone who understands the language can figure it out, but why do the stutter step?

    Along that line, many people insist that every variable in Java or C# be given an initial value, on the theory that it can offer some sort of protection if somehow the variable gets used without being assigned a value. But neither Java nor C# will compile if that is the case, so by unnecessary initialization you may actually hide a programming error that the compiler would find for you if you only gave it the chance.



  • @rstinejr said:

    why do the stutter step?
     

    Certainly not with naked code like that, but inside aloop, one sometimes wants a flag to become true or false and then stay that way for the remainder of the loop. If val does not increase linearly in the loop, (val > 200) might switch back and forth.



  • @rstinejr said:

    Here's an anti-pattern I've seen at every company I've worked for in the last 20 years, in C, C++, Java, C#, and python:


    if (myBoolean == true)
    {
    // do something
    }
    Weird I never saw that, except in cases where the boolean type isn't actually a boolean type (like old C or Win32 BOOL).


  • and the similar painful way of changing a boolean from true to false (i forget why this was a thing)

    if foo == true:
        foo = false
    elif foo == false:
        foo = true
    

    instead of

    foo = !foo
    


  • @rstinejr said:


    if (myBoolean == true)
    {
    // do something
    }

    I use this all the time, as it allows me to understand that the variable is in fact a boolean to begin with, without having to trawl though the rest of the code, include files, header files or wherever you thought it would be most annoying to actually declare the variable and its type (if you ever did, some languages aren't that fussy).

    [CODE]if (something) {

    // do something

    }

    [/CODE]

    Tells me absolutely nothing ... is "something" an object that is not empty, an integer that is not 0, a string that is not empty or null, who knows ?

    I am a firm believer that readable code shouldn't have to mean you have to read ALL of it to understand what is going on.

     



  • @daveime said:

    @rstinejr said:





    if (myBoolean == true)


    {


    // do something


    }


    I use this all the time, as it allows me to understand that the variable is in fact a boolean to begin with, without having to trawl though the rest of the code, include files, header files or wherever you thought it would be most annoying to actually declare the variable and its type (if you ever did, some languages aren't that fussy).

    if (something) {

    // do something

    }

    Tells me absolutely nothing ... is "something" an object that is not empty, an integer that is not 0, a string that is not empty or null, who knows ?

    I am a firm believer that readable code shouldn't have to mean you have to read ALL of it to understand what is going on.

     

    But, that's wrong. Not "you don't need a superfluous comparsion!" wrong, but "this code has a bug in it" wrong. Comparing booleans to TRUE is always wrong. I posted an (admittedly contrived) example in C# above, but it applies a million times more in unmanaged code:

    BOOL success = DoSomeOperation();
    
    if(success == TRUE) {
        //rejoice!
    }
    
    //elsewhere...
    
    BOOL DoSomeOperation() {
        int completed = 0;
        while(someCondition) {
            //do something
            completed++;
        }
        return (BOOL)completed;
    }
    

    The bug is not obvious from outside the function, but BOOL is not restricted to FALSE (0) and TRUE (1). We always joke about TRUE, FALSE and FILE_NOT_FOUND, but that's discriminatory to the other 4,294,967,292 possible BOOL values.

    If you insist on dumb comparisons in if statements, then at least compare against FALSE:

    if(FALSE == something) {


  • @SEMI-HYBRID code said:

     plus, i usually work with PHP so i prefer not to let language infer what i want to do and expect it to behave in a sane way. who knows if

    It works the same as it does in every other language. Are you seriously this ignorant of your primary tools?



  • @daveime said:


    ...I use this all the time, as it allows me to understand that the variable is in fact a boolean to begin with, without having to trawl through the rest of the code...

    Dude, if you have to trawl thru the code to know that in Java or C#, foo is a boolean when you see

    if (foo)

    ...then you need to leave coding to other people.

    (Similarly, if you see a the same expression in C or C++, you know that the foo can be cast to int and the block is entered only if the int is not zero.)

    Learn the programming language. And quit writing trashy code!



  • @rstinejr said:

    Dude, if you have to trawl thru the code to know that in Java or C#, foo is a boolean when you see

    if (foo)

    FTFY. Through the use of implicit conversion operators, foo might not be a boolean in C#



  • @dhromed said:

    @rstinejr said:

    why do the stutter step?
     

    Certainly not with naked code like that, but inside aloop, one sometimes wants a flag to become true or false and then stay that way for the remainder of the loop. If val does not increase linearly in the loop, (val > 200) might switch back and forth.

     

    This is also extremely useful for data validation code. Set "isValid = true" at the top, then follow with a raft of checks, any of which could set it to false. Lets you neatly avoid gigantic nested-if structures and/or gigantic boolean-packed single if statements.

     

     



  • @morbiuswilters said:

    @SEMI-HYBRID code said:
     plus, i usually work with PHP so i prefer not to let language infer what i want to do and expect it to behave in a sane way. who knows if

    It works the same as it does in every other language. Are you seriously this ignorant of your primary tools?

     

    1. it was an attempt at snarky joke commenting on state of PHP

     

    2.

    $val1 = "false";

    $val2 = 0;

    $res = ($val1 == $val2);

    would you be so kind as to tell me what value will the $res variable have after these three lines? 

     



  • @delta534 said:

    @rstinejr said:

    Dude, if you have to trawl thru the code to know that in Java or C#, foo is a boolean when you see

    if (foo)

    FTFY. Through the use of implicit conversion operators, foo might not be a boolean in C#

    Well, my C# is pretty rusty. But if you are using a non-boolean in a C# conditional and relying on the conversion to boolean, then shame on you.

    Anyhow, the complaint "I don't know anything about it I have to dig thru code" is bogus. In real code, the condition variable would have a meaningful name, e.g., "isFirstPass" or perhaps even "bIsFirstPass". Seeing an explicit comparison if this to "true" or "false" does not add to code clarity. (If the variable does not have a clear name, then you need to address that problem.)

    BTW -- in C or C++, if a function indicates success by returning zero, then I usually write

    if (myFunc() == 0)
    ...because in this case I think it brings attention to what the return value means.


  • @SEMI-HYBRID code said:

    $val1 = "false";

    $val2 = 0;

    $res = ($val1 == $val2);

    would you be so kind as to tell me what value will the $res variable have after these three lines?

    It's true, obviously. A better question is why you are writing code like that if you're not smart enough to understand how type coercion works..



  • @rstinejr said:

    BTW -- in C or C++, if a function indicates success by returning zero, then I usually write

    if (myFunc() == 0)
    ...because in this case I think it brings attention to what the return value means.

    That's horribly unclear. It should be:

    if ((myFunc() == 0) == true)


  • @morbiuswilters said:

    @SEMI-HYBRID code said:

    $val1 = "false";

    $val2 = 0;

    $res = ($val1 == $val2);

    would you be so kind as to tell me what value will the $res variable have after these three lines?

    It's true, obviously. A better question is why you are writing code like that if you're not smart enough to understand how type coercion works..

     

    i know, obviously, that's why i asked. a better question would be what are you doing on tdwtf forums if you don't understand irony, sarcasm, and other slightly sophisticated kinds of humor

     



  • @morbiuswilters said:

    @rstinejr said:

    BTW -- in C or C++, if a function indicates success by returning zero, then I usually write

    if (myFunc() == 0)
    ...because in this case I think it brings attention to what the return value means.

    That's horribly unclear. It should be:

    if ((myFunc() == 0) == true)

    I stand corrected. Dang, makes me want to hang my head and cry. ;-)



  • @morbiuswilters said:

    @SEMI-HYBRID code said:

    $val1 = "false";

    $val2 = 0;

    $res = ($val1 == $val2);

    would you be so kind as to tell me what value will the $res variable have after these three lines?

    It's true, obviously. A better question is why you are writing code like that if you're not smart enough to understand how type coercion works..

     

     

    btw, let's put the type coercion aside:

    $res = ((string)$val1 == (int)$val2)

    this also returns true. is that also standard behavior displayed by all other languages? i don't think so.

     



  • @rstinejr said:

    In real code, the condition variable would have a meaningful name, e.g., "isFirstPass" or perhaps even "bIsFirstPass".

    bIsFirstPass == Die in a fire.



  • @SEMI-HYBRID code said:

    btw, let's put the type coercion aside:

    $res = ((string)$val1 == (int)$val2)

    this also returns true. is that also standard behavior displayed by all other languages? i don't think so.

    facepalm You didn't "put type coercion aside". Here's what you did:

    • cast a string to a string
    • cast an int to an int
    • compare a string to an int, which coerces the string into int form. Since there are no numerical digits in the string, it is coerced to 0.
    • (0 == 0) == true

    If you had wanted to force the comparison to avoid type coercion, you can just use the === operator, without the casts: ("false" === 0) == false



  • @morbiuswilters said:

    @SEMI-HYBRID code said:

    btw, let's put the type coercion aside:

    $res = ((string)$val1 == (int)$val2)

    this also returns true. is that also standard behavior displayed by all other languages? i don't think so.

    facepalm You didn't "put type coercion aside". Here's what you did:

    • cast a string to a string
    • cast an int to an int
    • compare a string to an int, which coerces the string into int form. Since there are no numerical digits in the string, it is coerced to 0.
    • (0 == 0) == true

    If you had wanted to force the comparison to avoid type coercion, you can just use the === operator, without the casts: ("false" === 0) == false

    ("true" == 1) == b:0;
    ("true" == 0) == b:1;
    ("true" == true) == b:1;
    ("false" == true) == b:1;
    ("1" == 1) == b:1;
    ("0" == 0) == b:1;
    ("0" == false) == b:1;
    ("1" == true) == b:1;
    (1 == true) == b:1;


    okay, first: you're right.

    second: if i never had any problems arising from my misunderstanding of php's type coercion, does that mean my code/coding was good or bad?

    third: if you have to discuss or think about how basic operations such as these work in a language, there is something wrong with the language.

    fourth: i learn at least one new thing every day

    fifth: i should have stayed with strongly typed languages where these comparisons actually make sense

    sixth: none of the above makes you less of an asshole

     



  • @SEMI-HYBRID code said:

    second: if i never had any problems arising from my misunderstanding of php's type coercion, does that mean my code/coding was good or bad?

    Probably good. People who complain about type coercion have never used it or are doing something stupid.

    @SEMI-HYBRID code said:

    third: if you have to discuss or think about how basic operations such as these work in a language, there is something wrong with the language.

    You have to be aware of types in every language. There's nothing wrong with type coercion.

    @SEMI-HYBRID code said:

    fifth: i should have stayed with strongly typed languages where these comparisons actually make sense

    Strong typing: a crutch for a weak mind.

    Most of your examples show a fundamental misunderstanding of how type coercion functions. If type coercion confuses you then you're probably also making a mess in strongly-typed languages.


  • ♿ (Parody)

    @morbiuswilters said:

    There's nothing wrong with type coercion.

    Come and see the violence inherent in the PHP!



  • @morbiuswilters said:

    @SEMI-HYBRID code said:
    third: if you have to discuss or think about how basic operations such as these work in a language, there is something wrong with the language.

    You have to be aware of types in every language. There's nothing wrong with type coercion.

     

    as boomzilla said, come and see for yourself: http://habnab.it/php-table.html

    i actually wanted to post this link to you a few messages ago. i can't help myself but think it doesn't really make a lot of sense. i can't really explain why, i'll have to think about it more, but something about it just doesn't feel right. to quote one blog about many PHP wtfs for starters, "[ == ] It’s not transitive. "foo" == TRUE, and "foo" == 0… but, of course, TRUE != 0". i know that "foo" == TRUE is supposed to mean that foo is set, and making "foo" == false doesn't make a lot of sense either, but to me, that means there's something really wrong with the comparison logic, when there's no easy way out of this illogicality. it would be probably more logical if "foo" == 1 - if there's no number in the string,both "foo" and "0" should be taken as bools in "foo" == 0 and "foo" == 1. what i'm trying to say is that it should coerce to most basic type available, "foo" == 100 should coerce to ints/floats, "foo" == 1 to bools, "1" == 1 to bools, "1" == anything else than 0 or 1 to ints, "foo" == "bar" to strings, etc... THAT way, it would make sense, at least to me, but i suspect i'm not the only one.@morbiuswilters said:

    @SEMI-HYBRID code said:
    fifth: i should have stayed with strongly typed languages where these comparisons actually make sense

    Strong typing: a crutch for a weak mind.

    Most of your examples show a fundamental misunderstanding of how type coercion functions. If type coercion confuses you then you're probably also making a mess in strongly-typed languages.

    i wouldn't call it "fundamental misunderstanding", it's more of that i have a strong idea how it should work for me to make sense, and it's hard to get rid of my expectations. which might be bigger problem than simply not understanding it, i admit. but are my expectations i explained above so wrong? anyways, no, i tend not to compare fundamentally different types (e.g. int and bool) in strongly typed languages. sincerely, i never needed to, afaik (not counting comparing floats/doubles to ints, etc...), and can't really imagine a situation when i'd need to. it seems to me that the main reason to compare very different types (bool vs int/string) arises from language being loose typed, nothing else.

    @morbiuswilters said:

    There's nothing wrong with type coercion.

    i agree, there's nothing wrong with the mechanism/idea itself, it's just specifics of implementation in php.



  • @morbiuswilters said:

    There's nothing wrong with type coercion.
     

    There's something wrong with PHP's type coercion.

    Javascript's, at least, is sensible.



  • @dhromed said:

    @morbiuswilters said:

    There's nothing wrong with type coercion.
     

    There's something wrong with PHP's type coercion.

    Javascript's, at least, is sensible.

    That's funny, because I tend to find Javascript's more obnoxious. Do you have examples where JS makes more sense than PHP?



  • @SEMI-HYBRID code said:

    it would be probably more logical if "foo" == 1

    So, in your mind, this makes sense:

    9 + "foo" == 10

    And you want to be my latex salesman?

    But really, I stick by my original point: if you are spending a lot of time worrying about type coercion you're probably doing something really goofy. And if you ever find yourself in a position where you're relying on some aspect of type coercion you find "weird", do yourself and all maintenance programmers a favor: just make things explicit.



  • @morbiuswilters said:

    @SEMI-HYBRID code said:
    it would be probably more logical if "foo" == 1

    So, in your mind, this makes sense:

    9 + "foo" == 10

     

    ...no, it does not, but neither does 9 + "foo" == 9

     



  • @morbiuswilters said:

    Do you have examples where JS makes more sense than PHP?
     

    In PHP:

    "somestring" == 0  -> true

    which is completely ridiculous.

    Check out thta table linked above. Most are sensible, yes, but there are some that make a grown man cry.

    In JS,  "somestring" == 0  -> false

    That makes sense.



  • @morbiuswilters said:

    That's funny, because I tend to find Javascript's more obnoxious. Do you have examples where JS makes more sense than PHP?

    I... what? How on earth do you get that idea?

    Values in Javascript have strict types that don't magically bounce around or coerce. Compare:

    PHP: "2" + "2" => 4

    Javascript: "2" + "2" => "22"

    Similarly,

    PHP: "2" == 2 => true

    Javascript: "2" == 2 => false

    If you want integer operations, then make sure you're using integers.

    Edit: To be fair, if you use . then it will actually conctenate, so maybe this isn't a fair comparison.



  • @pkmnfrk said:

    Values in Javascript have strict types that don't magically bounce around or coerce.
     

    WHAT.

    Javascript: 2 + "2" => "22"

    Number coerced into string. If Morbs finds this superior behavior "obnoxious" compared to PHP, well, that' because he's a moron.



  • @pkmnfrk said:

    Values in Javascript have strict types that don't magically bounce around or coerce.
     

    This is a falsehood.

    @pkmnfrk said:

    Javascript: "2" == 2 => false

    This, too, is a falsehood.

     

    Hit F12 and flip to the console.

     



  • @Zylon said:

    Number coerced into string. If Morbs finds this superior behavior "obnoxious" compared to PHP, well, that' because he's a moron.
     

    I actually find some moronicness in JS's conversions. I think that it should be:

    2 + "2" => 4

    2 + "splorp" => "2splorp"

     

    Instead, I think Javascript does "Fuck this, and fuck you, I'm making it all strings.".



  • @dhromed said:

    2 + "splorp" => "2splorp"
     

    I have always hated the concept of overloading the addition operator to include string concatenation.



  • @SEMI-HYBRID code said:

    @morbiuswilters said:

    @SEMI-HYBRID code said:
    it would be probably more logical if "foo" == 1

    So, in your mind, this makes sense:

    9 + "foo" == 10

     

    ...no, it does not, but neither does 9 + "foo" == 9

    That's the only thing that does make sense. If a non-numeric string is going to coerce to something, it should be 0, not 1, not anything else. Also, my original point stands: why are you adding a number and a non-numeric string? Even having to worry about this is a sign that your code is seriously screwed up.



  • @too_many_usernames said:

    @dhromed said:

    2 + "splorp" => "2splorp"
     

    I have always hated the concept of overloading the addition operator to include string concatenation.

    Agreed. Another area where PHP is superior to JS.



  • @dhromed said:

    @Zylon said:

    Number coerced into string. If Morbs finds this superior behavior "obnoxious" compared to PHP, well, that' because he's a moron.
     

    I actually find some moronicness in JS's conversions. I think that it should be:

    2 + "2" => 4

    2 + "splorp" => "2splorp"

     

    Instead, I think Javascript does "Fuck this, and fuck you, I'm making it all strings.".

    If only there were some way to have different operators for addition and string concatenation.. if only..

    But basically you illustrated what I find annoying about JS type coercion; it's easy to go number -> string, but going string -> number requires ugly workarounds (like multiplying by 1) or using parseFoo (in which case it's no longer type coercion). And because of JS's overloading of the + operator, you end up with the following:

    "4" * 2 => 8
    "4" / 2 => 2
    "4" - 2 => 2
    "4" + 2 => "42"  // what the fuck?

  • ♿ (Parody)

    @morbiuswilters said:

    @SEMI-HYBRID code said:

    ...no, it does not, but neither does 9 + "foo" == 9

    That's the only thing that does make sense. If a non-numeric string is going to coerce to something, it should be 0, not 1, not anything else. Also, my original point stands: why are you adding a number and a non-numeric string? Even having to worry about this is a sign that your code is seriously screwed up.

    Seems like it should result in an error. Because something is screwed up, and this seems like a great way to silently allow a bug to stay alive. Isn't the point that this is more likely to happen as the result of a bug than a deliberate decision?

    A statically typed language would have caught this at compile time (or when you assigned something incorrectly to get to this situation). Seems like the least a dynamic language could do would be to catch it at run time for you. I guess this would go against the philosophy of "do something, even with obviously wrong code" that seems to be a part of both javascript and php.



  • @dhromed said:

    @Zylon said:

    Number coerced into string. If Morbs finds this superior behavior "obnoxious" compared to PHP, well, that' because he's a moron.
     

    I actually find some moronicness in JS's conversions. I think that it should be:

    2 + "2" => 4

    2 + "splorp" => "2splorp"

     

    Instead, I think Javascript does "Fuck this, and fuck you, I'm making it all strings.".

     

    Then you're a spectacular moron, for thinking that the coercion behavior should change depending on what's in the string. What a glorious breeding ground for bugs THAT would be.

     

     



  • @boomzilla said:

    Seems like it should result in an error. Because something is screwed up, and this seems like a great way to silently allow a bug to stay alive. Isn't the point that this is more likely to happen as the result of a bug than a deliberate decision?

    A statically typed language would have caught this at compile time (or when you assigned something incorrectly to get to this situation). Seems like the least a dynamic language could do would be to catch it at run time for you. I guess this would go against the philosophy of "do something, even with obviously wrong code" that seems to be a part of both javascript and php.

    PHP just assumes if there is no number in the string then the numeric value of the string is 0. I think what JS does is worse: 9 + "foo" => NaN. So it is an error in JS, except it happily rolls along anyway until some later codes explodes on the NaN (or outputs it for a user to see).

    I wouldn't be opposed to PHP and Javascript throwing an exception in a case like this. However, I think it's mostly irrelevant. Yes, the edge cases of type coercion allow you to shoot yourself in the foot. So what? If you can't get type coercion right you're probably not going to get encapsulation and subtype polymorphism right, and the compiler can't fix that shit for you. A lot of the whining about type coercion boils down to "The language lets me do something stupid" which, of course, all languages do to some extent. The focus should be on hiring competent developers, not worrying about what trivial language features might protect stupid people from writing stupid code.



  • @morbiuswilters said:

    Also, my original point stands: why are you adding a number and a non-numeric string?
     

    Today I learned that in Morbs-land, nobody ever prints numbers.

     

    @morbiuswilters said:

    I think what JS does is worse: 9 + "foo" => NaN.
     

    No, in Javascript, 9 + "foo" is "9foo".

    Little wonder you don't like JS's coercion rules-- apparently they exist entirely in your own imagination.


     

     


  • ♿ (Parody)

    @morbiuswilters said:

    Yes, the edge cases of type coercion allow you to shoot yourself in the foot. So what? If you can't get type coercion right you're probably not going to get encapsulation and subtype polymorphism right, and the compiler can't fix that shit for you. A lot of the whining about type coercion boils down to "The language lets me do something stupid" which, of course, all languages do to some extent. The focus should be on hiring competent developers, not worrying about what trivial language features might protect stupid people from writing stupid code.

    I guess I'd rather not handicap people with tools that make it more difficult than it needs to be, but we just have a different evaluation of the cost / benefit ratio here. I make mistakes all the time in code that I write, and a piece of code throwing an error and giving me a stack trace, etc, makes it a lot easier and faster to get from here to solid code.

    Actually, your argument sounds a lot like a short version of a bridget99 rant.



  • @Zylon said:

    Today I learned that in Morbs-land, nobody ever prints numbers.

    What does that have to do with anything?

    @Zylon said:

    No, in Javascript, 9 + "foo" is "9foo".

    Whoops, I meant to type 9 - "foo" => NaN. Which was my point: the operators aren't even consistent.



  • @boomzilla said:

    I guess I'd rather not handicap people with tools that make it more difficult than it needs to be, but we just have a different evaluation of the cost / benefit ratio here.

    I don't really see it as being that big of a deal. I've seen tons of shitty PHP (in addition to shitty JS, shitty Java, shitty C, shitty C++..) and I can't think of a time I've ever seen type coercion being a problem. I mean, these are people who don't understand that a class can have instances and that a constructor isn't a super-function where all of your class logic should go. But type coercion never really tripped them up.

    @boomzilla said:

    Actually, your argument sounds a lot like a short version of a bridget99 rant.

    Now you're just being hurtful.. :(



  • @morbiuswilters said:

    @Zylon said:
    Today I learned that in Morbs-land, nobody ever prints numbers.

    What does that have to do with anything?

     

    Other than the fact that I was directly responding to something that you said??? In JS, the moment strings get involved, you aren't ADDING, you're CONCATENATING. That happens a whole hell of a lot when generating output, and is thus not "a sign that your code is seriously screwed up".

    Yes, it's inconsistent with how every other mathematical operator coerces, which is unfortunate. But from the perspective of someone who know what they're doing, it's perfectly fine. You use "+" to assemble big blobs of output, knowing that it will dutifully coerce everything in its path into a string of some type, and then NEVER use bare string-bearing variables in actual mathematical calculations. That's just good practice, no matter what the coercion rules.


Log in to reply