115
cs8898
5y

Hmm,

boolean with a stop function, looks wierd

Comments
  • 13
    Did you know a bool can also suck?

    bool programmingStyle = false;
    if ( programmingStyle. sucks( ) )
    {
    learnonothersitesbutthisonebecausemyfunctionnamingsalsosucks( );
    }
  • 3
    That's actually a real and useful thing. So let's say you have something complicated to check, instead of having like a 3 line if you could make a function which returns true or false.
  • 7
    @Dacexi I don't quite understand what you are saying. Do you mean a function which returns bool? This rant is about a method on the bool type: in this case true.stop()
  • 2
    @danielspaniol oh yeah okay. That's a bit strange 🤔
  • 1
    You assume sad() is a stateless function.
  • 7
    I guess sad() return an object implementing a toBoolean method.
  • 4
    If it wasn't a strict comparison it would work.
  • 9
  • 2
    @theCalcaholic Well, it's hacky. But sometimes I did it too...
  • 1
    @gofrendi It is :D Wouldn't write something like it in production code.
  • 2
    @gofrendi Apparently it's what you learn at that course. ^^
  • 0
    That code doesn't make any sense... Sad sounds like a property rather than a function. === true is also useless code inflation.

    Should be

    if(sad) {
    sad.stop();
    beAwesome();
    }

    ... and even then... ".stop()" on a boolean?? But I guess that's what this rant was initially about.
  • 0
    @arminlinzbauer Correct. :)
    But it's possible, since Javascript is not a strongly typed language (compare my jsfiddle from another comment).

    Of course that you CAN do something doesn't necessarily imply that you SHOULD.
  • 0
    @arminlinzbauer On an additional note:

    In Javascript '=== true' is NOT redundant.

    === checks for type and value equality. If you don't compare a variable to true with '===' it might still be 'truthy' (evaluate to true if interpreted as boolean). For example, the following expression will print true:

    if( "false" && { } && (function() {}) && 5) {
    console.log("true");
    }

    Please note, that I didn't test these statements - is entirely possible I made a mistake.
  • 1
    @theCalcaholic Verified the JS statement - it's correct.
  • 1
    Well, OpenClassrooms is a quite good french website to learn programming basics. And when I talk about basics, it's just an introduction. They don't go deeper than the surface of every language or technologies and back in past, they were a lot hated because they gived bad advices and bad practices.

    I learned my first programming languages on this website, almost ten years ago, and that's worst than it was before :/
  • 1
    @theCatholic - I'm aware of that, but for something as simple as that, a 'truthy' value should be enough to justify the execution of this block imo...
  • 3
    Totally overriding prototype methods because fuck the next developer and his understanding of a string.

    Or, uh, Boolean in this case.
  • 0
    Back in the day they were called "Le site du zéro" which translates to "The zero's website"

    Guess they're loyal to their ideology..
  • 1
    @theCalcaholic Sometimes courses like that are overpriced.

    The marketing is pretty good however. Like, "follow this course, and you will be the next Mark Zuckerberg"
  • 2
    @arminlinzbauer I'm not 'theCatholic'! D:
  • 1
    @theCalcaholic you were just outed friendo!

    Uh, also, do you know how to unreport a comment? I done did fucked up and accidentally reported yours when I was meant to hit reply. Fml.

    If you want, report this one for me! It’d make me feel better about the situation.
  • 0
    @theCalcaholic so sorry :0 I've been staring on a monitor for 9 hours straight, I guess my vision got a bit blurry...
  • 1
    @arminlinzbauer @jamescodesthing No problem. :D

    (The name thing happens to me occasionally)
  • 2
    That's not real JavaScript!

    In 2017 real JS has to be chained and nested to the fuck!

    if ( sad().isTrue === true ? true : false) {
    return new Promise( (resolve, reject) => {
    try {
    resolve(sad().stop().beAwesome().call(this));
    } catch(err) {
    reject(Error(err.statusText));
    }
    };
    }
  • 2
    @Noob I disagree. In 2017 we have ES17 with async/await! 😍
  • 1
    @theCalcaholic I wanted to add a generator there as well.
    Also ES17... You live in 2026
  • 2
    @Noob Right. 😂
    ECMAScript versions always confuse me.

    ES 6 = ES 2015
    ES 7 = ES 2016
    and so on.

    I was referring to ES 7, of course, but I guess, I messed up. :P
  • 1
    @theCalcaholic I understood you. Was just trolling. ;)
  • 0
  • 2
    This place has the most polite, well mannered community I’ve seen anywhere on the Internet.

    Quick someone call me a cunt before I cry.
  • 1
    Fookin cunt..
  • 1
    Is the "===" intentionally?
  • 1
    I always hated these BS pseudocode "jokes" that people write. It is almost consistently crap code anyway
  • 1
    @wholl0p See my earlier comment. ;)
  • 1
    @nahson Way more beautiful than my code example!
  • 1
    fun Boolean.stop() = println("Why?")
Add Comment