`0<$var`



  • Continuing the discussion from Coming up for air (TL:DR; I work for retards and am TR :wtf: for not having left yet):

    @kt_ said:

    0<$var is a huge WTF in and out of itself.

    Thanks for reminding me. I've seen this popping up in recent years (in particular in JS codebases), and it seems backwards to me. Is there a reason for writing like this (performance, readability, etc.), or is it just that someone once wrote it like this in an answer on SO/SE, and others picked it up?



  • @Mikael_Svahnberg said:

    Continuing the discussion from Coming up for air (TL:DR; I work for retards and am TR :wtf: for not having left yet):

    @kt_ said:

    0<$var is a huge WTF in and out of itself.

    Thanks for reminding me. I've seen this popping up in recent years (in particular in JS codebases), and it seems backwards to me. Is there a reason for writing like this (performance, readability, etc.), or is it just that someone once wrote it like this in an answer on SO/SE, and others picked it up?

    I use to do it for a while in java after a stint in C. It was beaten out of me after a couple code reviews though.

    Mostly because of been bitten by this exactly once and seeing it in Expert C Programming: Deep Secrets.

    if(c = 0)
    

    whoops I've just assigned 0 to c and it's evaluated to 0.

    if(0 = c)
    

    compile error.

    I'm probably TR:wtf:



  • I'd assume it's just a habit they formed from programming in C/JS/etc when comparing equality where if(somevar = 0) { ... } is valid and never runs, while if(0 = somevar) { ... } causes an error.
    Who knows why they do it with the other comparisons.




  • sockdevs

    Are you sure it's not the party hat operator <$?



  • Ah, man, that's awesome.

    [code]
    int main()
    {
    int i = 100;
    // while i slides down to 0
    while ( i --
    //
    //
    //
    _
    ________/

    > 0 ) {
    printf("test");
    }
    }[/code]



  • @Mikael_Svahnberg said:

    Continuing the discussion from Coming up for air (TL:DR; I work for retards and am TR :wtf: for not having left yet):

    Sorry, you don't have access to that topic!

    I am disappoint :frowning:



  • It's in the Lounge, which is TL3+. If shadowmod is working, you can ask it what you need to do to gain TL3 here.


  • Discourse touched me in a no-no place

    @tufty said:

    // while i slides down to 0

    New C++ experimental feature: The tadpole operators

    How often have you had to write code like this:

    x = (y + 1) % 10;
    x = (y + 1) * (z - 1);
    x = (wcslen(s) + 1) * sizeof(wchar_t);
    Since the + and - operators have such low precedence, you end up having to parenthesize them a lot, which can lead to heavily nested code that is hard to read.

    Visual Studio 2015 RC contains a pair of experimental operators, nicknamed tadpole operators. They let you add and subtract one from an integer value without needing parentheses.

    x = -~y % 10;
    x = -~y * ~-z;
    x = -~wcslen(s) * sizeof(wchar_t);
    They’re called tadpole operators because they look like a tadpole swimming toward or away from the value. The tilde is the tadpole’s head and the hyphen is the tail.

    [...]

    To enable the experimental tadpole operators, add this line to the top of your C++ file

    #define __ENABLE_EXPERIMENTAL_TADPOLE_OPERATORS


  • Discourse touched me in a no-no place

    I like the (postfix) heart operator, <3, especially at this time of year.



  • Some C# style guides recommend that, when doing equality tests with a constant (generally null), you put the constant on the left:

    null == blah

    Instead of:

    blah == null

    The idea is, if you accidentally type one = instead of two, you've created a compiler error.



  • Wtf. That seems like the worst idea ever.



  • What is that even supposed to be? A sailboat? What doe a sailboat have to do with sliding?



  • As far as I remember it's also a compiler error to do a regular assignment in an if in c#. (you can get around it with parentheses)



  • Yeah well a lot of style guides recommend things that don't make sense.

    The one my boss likes recommends putting the using statements inside the namespace. What difference does that make? None, utterly none, unless you happen to have two namespaces inside a single file.

    But guess what? The style guide also bans having two namespaces in a single file. So what's the point!

    Interestingly, if VS sees the other using statements are inside the namespace, it'll add new ones there automatically when you use its "resolve reference" feature. So that saves a bit of copy & paste work at least.



  • Huh, it seems that you can actually do a conditional assignment on bools..


  • sockdevs

    That's because the type of the expression is the type of the LHS of the =, and C# doesn't coerce anything without an applicable implicit cast operator; in this case, there's no implicit cast operator bool on int


  • Discourse touched me in a no-no place

    @swayde said:

    Wtf. That seems like the worst idea ever.

    He missed April 1st by a few weeks.

    The tadpole operators explained

    The tadpole operators exploit two’s complement arithmetic and overflow.² The __ENABLE_EXPERIMENTAL_TADPOLE_OPERATORS is just a red herring.

    Start with the identity for two’s complement negation

    -x = ~x + 1

    then move the -x to the right hand side and the ~x to the left hand side:

    -~x = x + 1



  • @PJH said:

    April 1

    I actually checked the date, to be certain it wasn't 1/4.
    I must admit I believed it, c++ guys seem to enjoy the most insane things.



  • That looks like why good languages don't treat integers as booleans.



  • I don't post /click like enough either.



  • @blakeyrat said:

    What is that even supposed to be? A sailboat? What doe a sailboat have to do with sliding?

    It's not a sailboat. It's a schooner.



  • @DogsB said:

    if(0 = c)

    compile error.

    syntax error



  • Back in my day we use vi to write the application and then compiled and linked at the command line. None of this cute click a button to build and auto-fangled syntax mularkey. :cold_sweat:



  • @DogsB said:

    cute click a button to build

    On the command line, you just type go build. In vi, that's :!go build.

    @DogsB said:

    and auto-fangled syntax mularkey

    It's a lot easier than everyone having different styles. If everyone uses the same layout, the only part that changes is the part that actually matters.



  • @ben_lubar said:

    @DogsB said:
    cute click a button to build

    On the command line, you just type go build. In vi, that's :!go build.

    @DogsB said:

    and auto-fangled syntax mularkey

    It's a lot easier than everyone having different styles. If everyone uses the same layout, the only part that changes is the part that actually matters.

    :facepalm: I worry about some people on this forum. :headdesk:



  • Have you ever seen Men in Black? They have that great line where the agents are pretending to be from the FBI, and they go to this housewife and she says, "is this some kind of joke?" And Tommy Lee Jones replies:

    No, ma'am. We at the FBI do not have a sense of humor we are aware of.

    Anyway, that's basically Ben L.


  • Discourse touched me in a no-no place

    You actually have to have an awareness of humor to say something like that, though.

    In fact I always thought that Jones was badmouthing the FBI with that line, just in case the woman remembered it subconsciously.



  • Meh. Maybe he got all his information on the FBI from The X-Files, where nobody at the FBI does have a sense of humor except Mulder, and he's crammed into a crappy basement office due to it.

    Heck, in like 11 years of episodes, I'm not even sure Scully ever even SMILES. Much less tells a joke.


  • Discourse touched me in a no-no place

    @blakeyrat said:

    Maybe he got all his information on the FBI from The X-Files

    Could be. It felt funnier the other way to me, is all: sneaky/subversive.



  • @DCRoss said:

    schooner

    What does beer have to do with coding?

    Well, it's Friday so I guess lots! ;)



  • @Zemm said:

    What does beer have to do with coding?

    Based on the code I have seen in this forum, EVERYTHING.



  • @FrostCat said:

    You actually have to have an awareness of humor to say something like that, though.

    In fact I always thought that Jones was badmouthing the FBI with that line, just in case the woman remembered it subconsciously.

    I agree with everything you said. Also, I thought that was basically blakey's point about Ben and how his sense of humor is expressed.



  • I don't have anything interesting to say, so here's a picture of a walrus that just murdered something.



  • It's an easter egg reference to the 1987 Robert Downy Jr. movie, "Less Than Zero"



  • any thoughts on

    if(conditionA ^ conditionB){
    // I just did an xor!
    }
    

    I spotted a few of those last week and just thought of it now.



  • That's the integer xor.

    The boolean version of xor is called !=.



  • vs

    :interrobang:

    *edit I think I need to give up on drowsy cough bottle and go back to bed :mask:


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.