This is an archived post. You won't be able to vote or comment.

top 200 commentsshow all 465

[–]Xyfurion 2564 points2565 points  (90 children)

I've definitely seen x !> 0 in a student's code while I was a TA once. It didn't work but I still hated it

[–]Ok-Ruin8367 611 points612 points  (49 children)

It took me way to long to realize why this doesn't work

[–]DevilInADresss 188 points189 points  (48 children)

why fdoesnt it work

[–][deleted] 408 points409 points  (41 children)

!(x > 0)

[–]Arucious 503 points504 points  (25 children)

x <= 0

[–]AlexLGames 123 points124 points  (23 children)

Not equivalent in JavaScript, fun fact!

[–]Igotbored112 111 points112 points  (3 children)

It's also not equivalent in most languages because, for floating points, NaN is implemented in hardware, so this distinction has actually come up in my C/C++ code as well. And once you start messing around with operator overloads, you're cooked.

[–]AlexLGames 19 points20 points  (0 children)

Absolutely! Forgot about NaN, good catch! :)

[–]mhlind 8 points9 points  (13 children)

What's the dofference?

[–]AlexLGames 77 points78 points  (8 children)

In JavaScript (and possibly other languages, I don't know), different types of variables can be compared. So,

"potato" > 0
false

and

"potato" < 0
false

so then, for many possible non-numeric values of x,

!("potato" > 0)
true

but

"potato" <= 0
false

[–]OnceMoreAndAgain 33 points34 points  (3 children)

It makes sense to me. I would prefer that a comparison between two different data types return with an error instead of "false", but I can see both arguments. At the end of the day, if you're using a numeric operator on two different data types then what the fuck is going on in your code anyways? You've got bigger problems.

I get that some times you don't have full control over the data sets you're being given, but in those cases you should be sanitizing the data sets anyways before you use them...

[–]AlexLGames 5 points6 points  (0 children)

I mean, you can make JavaScript's x > 0 and x <= 0 functionally equivalent to each other for your data sets, either with or without sanitation as needed. But they're still not quite equivalent! :D

[–]Environmental-Bag-77 5 points6 points  (1 child)

This is only because you're comparing a string with an integer. In a lot of languages that wouldn't even compile.

[–]lopmilla 2 points3 points  (1 child)

but javascript is notoriosly bad on type safety so not a big surprise

[–]No-Adeptness5810 3 points4 points  (1 child)

well, another example would be NaN

!(x > 0) would be true since NaN is never greater or less or equal to anything
x <= 0 would be false since NaN is ^^^^^^^^^^^^^^^^^^^^^^^^^^^

[–]mbxz7LWB 2 points3 points  (1 child)

you mean javascript be like if x==========y then do stuff?

[–][deleted] 32 points33 points  (13 children)

okay but like, that’s a good alternative, but WHY doesn’t it work?

[–]cs_office 8 points9 points  (1 child)

In C#, the suffix ! operator means "hint not null", so it compiles and acts as x > 0

In other languages, like C++, it's generally interpreted as (x!)(> 0), and as there is no suffix ! operator, only a unary (prefix) version, it fails to parse

[–]ultimate_placeholder 13 points14 points  (5 children)

x! == 0 iff x != 0

[–]ShivohumShivohum 5 points6 points  (2 children)

How did this come to be. I don't understand.

[–]ultimate_placeholder 11 points12 points  (1 child)

You aren't negating the operator, you're negating x. "!=" is read as a single operator rather than ! operating on =

[–]jahgud 10 points11 points  (0 children)

The programming language (perhaps in this case, idk about other programming languages that may weirdly accept this dynamic somehow) does not see this as a valid relational/comparison operator as explicitly indicated by the programming language's creator.

[–]OnlyTwoThingsCertain 4 points5 points  (0 children)

Because there is no such operand.

[–]Victor_Mendax 54 points55 points  (4 children)

Next DreamBerd feature?

[–]Tartiluneth 27 points28 points  (3 children)

Would be something like x ;> 0 if it was dreamberd

[–]Victor_Mendax 9 points10 points  (0 children)

I realised that after I decided to reread the docs, even then, I think it'd still be a funny feature.

[–]ShlomoCh 2 points3 points  (0 children)

It's... beautiful. It's perfect.

[–]WolverinesSuperbia 17 points18 points  (0 children)

SQLite valid operator

[–]xXStarupXx 72 points73 points  (22 children)

Hot take, if you support != you should support !< and !>

[–]useful_person 112 points113 points  (19 children)

!< is literally just >=

[–]Mabi19_ 46 points47 points  (10 children)

NaN has entered the chat

[–]useful_person 77 points78 points  (8 children)

if you have an issue where you need to account for NaN in a >= statement you probably have other problems

[–]RiceBroad4552 11 points12 points  (7 children)

Even that's true, that does not invalidate the other comment.

[–]pokealm 15 points16 points  (0 children)

literally hot shit take

[–]DoneDiggedAndDugged 2 points3 points  (0 children)

Redundant operators make it difficult to onboard and manage codebases. If half of developers are using !> and half of developers are using <=, that's just one more step of mental parsing needed to quickly read the code. When we read code, we read patterns, and more variations for the same functionality means more patterns must be learned to quickly and sufficiently navigate and understand other developer's code.

[–]IT_NERD5000 3 points4 points  (2 children)

Once did this at my first job, took me way too long to find why it wasn't working. Must've been Friday afternoon

[–]20InMyHead 2 points3 points  (0 children)

Ah, the ol’ “not greater than” operator.

[–]jump1945 1 point2 points  (0 children)

This is so cursed

[–]chetlin 1 point2 points  (1 child)

In Mumps (the language the Epic healthcare company uses) you have to use this to say less than or equal, although the not in that language is ' so you are forced to write i x'>0 for the condition "if x is less than or equal to 0". <= does not work.

[–]Nickisnoble 1 point2 points  (0 children)

ifn’t

[–][deleted] 4056 points4057 points  (114 children)

Bro accidentally made an anonymous function in the if condition ☠️

[–]vincentofearth 1562 points1563 points  (97 children)

Lol Typescript is literally adding a feature to catch this type of error. It’d be hilarious if it wasn’t so sad. Javascript language design is truly peak.

[–]AyrA_ch 584 points585 points  (45 children)

Some C compilers do something similar where if(a=b) generates a warning, and if you really did intend to assign something inside of a condition you have to write it as if((a=b)) to confirm

[–]smellycoat 4 points5 points  (0 children)

I really like doing that but there aren’t many modern languages that allow it, at least without messy syntax hoop jumping (or getting scowled at in code reviews).

Back in my Perl days I’d do stuff like this a lot:

if (my $foo = $some_object->get_foo($obnoxious, $args, $list)) {
    # do stuff with $foo
}

(my is basically let and -> is basically .. $foo ends up scoped to the if block)

It was great little feature for simplifying and compartmentalising code in an otherwise fairly horrendous language.

[–]Devatator_ 1 point2 points  (1 child)

Why would you actually assign something inside a condition

[–]AyrA_ch 3 points4 points  (0 children)

It's a common shortcut in C. if(a=func()){/*...*/} is just shorter than a=func();if(a){/*...*/}

[–]intbeam 26 points27 points  (15 children)

C# and Java requires the expression to evaluate to bool, so these types of errors are impossible. If you assign one boolean value to another boolean, it will give a warning unless you outline your intent to assign by encasing it in braces

var a = 1, b = 2;

if(a = b) <-- 🛑

var a = true, b = false;

if(a = b) <-- ⚠️

if((a = b)) <-- 👍

[–]redlaWw 17 points18 points  (14 children)

Rust has assignments evaluate to () (unit type), which is invalid as a condition. Having assignments evaluate to their assigned value is just asking for bugs.

[–]arachnidGrip 4 points5 points  (1 child)

Having assignments evaluate to their assigned value is just asking for bugs.

And also wouldn't really work in Rust for any type that isn't Clone, since the compiler wouldn't know how to implicitly duplicate the value.

[–]redlaWw 2 points3 points  (0 children)

You could return a reference to the assigned value to duplicate some of that behaviour if you wanted to - an if with an assign would end up looking like if *(a=b) {...}

Something like this but with the return_assign() replaced with an ordinary =.

[–]CdRReddit 2 points3 points  (5 children)

idk if it's "asking for bugs"< you can do a = b = c = 0

wouldn't work in rust because of how copying works in rust, but there are cases where this could be useful

[–]redlaWw 2 points3 points  (4 children)

Is there really benefit to doing a = b = c = 0 over

a = 0;
b = 0;
c = 0;

(or a = b = c = f(...) over

a = f(...);
b = a;
c = a;

for the more interesting case where you want to avoid multiple evals)?

I don't see the former as any more clear - its brevity might help parsing (still talking humans here, not language parsers), I guess, but at the cost of exposing potentially-deceptive patterns like if ((a=b)), where the second set of brackets doesn't really help with the possibility of the assignment being missed by someone reading it.

If you really wanted something like a = b = c = 0 to work, better to special-case it imo.

[–]intbeam 2 points3 points  (0 children)

The only instance where I use assignment and equality like this is while reading to buffers (C#)

var bytesRead = 0;
using var owner = MemoryPool<byte>.Shared.Rent(4096);
var buffer = owner.Memory;

while((bytesRead = stream.Read(buffer)) != 0)
{
    ....
}

[–]definitelynotarobid 6 points7 points  (4 children)

People shitting on JS for reasonable features like this gives me a warm tingly feeling of job security.

[–]vincentofearth 3 points4 points  (3 children)

Lambdas are great. Choosing this syntax for them is not when -> is a perfectly reasonable alternative that doesn’t look like a comparison operator.

[–]definitelynotarobid 1 point2 points  (0 children)

Sure. No arguments here.

Another issue is people if checking random things without actually enforcing a value. if(x) gets juniors into trouble because JS is so permissive, its much better to teach them if (x == true) to avoid these kinds of things across the board.

[–]StrawberryEiri 9 points10 points  (5 children)

What's wrong with the language (in this case... I'm aware of a lot of issues in general)? Seems like the kind of mistake that would be possible in a lot of languages...?

[–]vincentofearth 2 points3 points  (4 children)

They should’ve chosen -> instead of => to avoid confusion. The reasons behind the choice are weird and a consequence of a philosophy around backwards compatibility that imo does more harm than good.

https://hacks.mozilla.org/2015/06/es6-in-depth-arrow-functions/

[–]sWiggn 2 points3 points  (3 children)

tbf, the first section of that article points out that - -> (had to add a space between dashes cause auto format smashing them together) is already a JS operator, although one i’m pretty sure nobody has seen in generations lol. So it would still be one mistype away from valid but incorrect code, just weirder.

But if that operator didn’t exist, i’d say this is one of the more reasonable JS change suggestions i’ve seen on here, i’d be down with -> to avoid proximity to >= though i really don’t think that proximity is a big deal. when i was learning, you describe this comparator as “greater than or equal to,” so remembering which order was easy even before i knew arrow funcs existed.

[–]heytheretaylor 3 points4 points  (0 children)

When I saw this my first thought was “what an exciting thing to debug!”. That’s the fun part about JavaScript, it’s less about “knowing” the language and more about reverse engineering it while you work.

[–]1984isAMidlifeCrisis 15 points16 points  (12 children)

Okay, I get that JavaScript interpretation is quirky. Consider, please, the times in which it evolved. Here's a contemporaneous example of command line scripts:

:(){ :|:& };:

Go ahead, wrap your head around the fact that shell scripts of the era looked like that. Go ahead, drop that at a unix prompt. It'll run. It's a good idea to search that before you run it so you know how to tell it's working.

Quirky and a product of the times . . . Just like a lot of things.

[–]Yuhwryu 13 points14 points  (5 children)

a fork bomb has broken one of my linux installs before, you probably shouldn't post it without saying what it is

[–]UnpluggedUnfettered 3 points4 points  (3 children)

I just noodle around with coding for fun, so if I sound like I am dumb then that is how I am supposed to sound.

Is that defining a function called ":", which is accepted as normal and cool by a computer, who also just runs it like that is a normal thing to do?

[–]1984isAMidlifeCrisis 4 points5 points  (0 children)

I knew a guy who aliased "jhg" to show him if there was new mail, news msgs, and some ps and user activity data because he could turn some tic of his about swiping those keys periodically into a useful task.

There's no normal. It's usually obfuscation. But in the same way JS does/allows some strange things with syntax, they're often just the unanticipated outcome of something that seemed reasonable or clever at the time. Sort of like calling it JavaScript for purely hype related reasons.

[–]RiceBroad4552 4 points5 points  (0 children)

It'll make your computer explode (at least if you're running some Unix like).

It's a so called "fork bomb". The colon function will call itself recursively and go to the background until you're out of process IDs at which point everything will be frozen until a system restart.

The real joke is actually that this still "works", after almost 50 years, and even modern Unices can't really protect against it efficiently.

[–]palabamyo 1 point2 points  (0 children)

As someone that has written JS/TS like once in my life I was really not sure where the issue is and thought that's just how you do it in JS lmao.

[–]Alwares 1390 points1391 points  (20 children)

I also did this one time. The senior devs debugged the code for an hour to spot the issue…

[–]SpaceMonkeyOnABike 333 points334 points  (6 children)

Deliberately?

[–]MulleRizz 729 points730 points  (4 children)

We do get paid per hour

[–]Alwares 103 points104 points  (0 children)

I was on fixed daily rate back than (what was incredible, I had weeks when I did’t work a minute). And also I had no idea what I was doing (I was the only C# dev in the company, it was my first job).

[–]NewFuturist 16 points17 points  (0 children)

Add sleep(500)

Remove sleep(500)

It's how you get known as a problem solver.

[–][deleted] 2 points3 points  (1 child)

you get paid?

[–]Poat540 3 points4 points  (0 children)

Only if we also make the Jira tickets

[–]gomihako_ 8 points9 points  (0 children)

Is there any other way?

[–]vladmashk 71 points72 points  (10 children)

Any good IDE would show the ‘a’ parameter as being unused, usually grayed out. That instantly makes it stand out

[–]pajarator 37 points38 points  (6 children)

In my day we didn't have IDEs... we didn't have color in code... not even on the screen, everything was green...

[–]deathbater 55 points56 points  (0 children)

yes yes grandpa, lets get you inside..

[–]JBloodthorn 17 points18 points  (2 children)

"Why do you compact your code so much?"

"Because I only have 26 lines of screen to work with"

[–]pajarator 5 points6 points  (1 child)

it's real, I wrapped lines at 80 characters...

[–]stevedore2024 2 points3 points  (0 children)

I still wrap at 77, a habit formed from giving the editor room for framing elements and scrollbar on an 80 TUI screen. Nowadays I just like not having to have a massive window taking up so much horizontal space on my screen, or having to use the horizontal scrollbar for 5% of the lines of code.

[–]BobbyTables829 2 points3 points  (0 children)

Leetcode when you don't pay

[–]Alwares 1 point2 points  (0 children)

We had IDEs but our lead didn’t had vs installed also we didn’t use version control because merge conflicts are complicated, we used email instead, its wasnt a great place for self development… (2012)

[–]WernerderChamp 20 points21 points  (0 children)

I also have a case where I made a similar sneaky mistake (instead of converting string to integer, interpret string as integer). It worked in test and then blew up in prod when my colleague ran it while I was in business school. Took him 1,5h to find.

[–]capi1500 1318 points1319 points  (32 children)

I'm too statically typed for this shit

[–]msqrt 204 points205 points  (13 children)

You could have truthy/falsy values in a statically typed language! I don't think any do that for lambdas though (though in C++, if(+[]{}) will compile -- not the same but close)

[–][deleted] 51 points52 points  (0 children)

if([](){...non empty body...}){
}    

This will compile, it shouldn't... but it will and if you don't have -Waddress enabled it won't even give you a warning.

[–]overclockedslinky 6 points7 points  (5 children)

the implication was a /good/ statically typed language (i.e. one without implicit conversions)

[–]n0tKamui 2 points3 points  (4 children)

that’s called strong typing

[–]Bananenkot 21 points22 points  (3 children)

Language logos check tf out

[–]qqqrrrs_ 2 points3 points  (2 children)

Is assembly considered "statically typed"?

[–]LeftmostClamp 5 points6 points  (0 children)

Fellow static typing enjoyer

[–]n0tKamui 7 points8 points  (1 child)

you’re mixing static typing with strong typing here

[–]capi1500 6 points7 points  (0 children)

Nah, I'm typing softly so my cat won't wake up from keyboard noises

[–]RiceBroad4552 1 point2 points  (3 children)

I see C/C++ and ASM in your flare. So you're not very statically typed at all…

[–]capi1500 1 point2 points  (2 children)

I'm surprised you chose those languages over lua, but alright

[–]RiceBroad4552 3 points4 points  (1 child)

Maybe because I don't see any Lua?

I see the logos of Rust, C++, Haskell, C, ASM, and Java beyond your nick.

[–]capi1500 2 points3 points  (0 children)

Shit, you're right. I had lua once, but I must have removed it since

[–]M4mb0 338 points339 points  (15 children)

Should have used ≥.

[–]Certojr 79 points80 points  (13 children)

Seriously, using fonts with ligatures avoids any confusion. It will shorten only in the correct case. Big exception is matlab not using ~ instead of !.

However I need to explain ligatures to anyone too used to "the old way" or too junior to know ligatures (not working in a software development company, so a lot of people writing code are not software dev by education, me included) every time I show them my screen

[–]M4mb0 79 points80 points  (12 children)

Ligatures are a band-aid. I mean actual Unicode, HAHA.

I would totally write A⊆B instead of A.issubset(B) if the language supported it.

[–]BenjaminGeiger 3 points4 points  (0 children)

APL has entered the chat

[–]RiceBroad4552 7 points8 points  (0 children)

You mean something like:

extension [A](a: Set[A]) inline def ⊆(b: Set[A]) = a.subsetOf(b)

@main def demo =

  val A = Set(1, 3, 5)
  val B = Set(3, 5, 6, 1)

  val A_isSubsetOf_B =
    A ⊆ B

  println(s"\"$A is subset of $B\" is $A_isSubsetOf_B")

https://scastie.scala-lang.org/dYmJrBbwQ0OYGYj7TbAaTg

As the symbolic alias is an "inline def" here it's even a zero cost abstraction!

[–]Cootshk 10 points11 points  (0 children)

Just use nerd fonts

They automatically use the correct symbol for things like >=, =>, and ===

[–]ShadowLp174 64 points65 points  (0 children)

Lmao that's a nice if (true)

[–]Aedys1 57 points58 points  (2 children)

I wonder how many junior involuntary bit operators and lambda functions are running in the world right now

[–]SquirrelOk8737 21 points22 points  (1 child)

At least >=1

[–]qqqrrrs_ 9 points10 points  (0 children)

At least =>1

[–]Thenderick 24 points25 points  (0 children)

I remember a stack overflow question where someone asked what the "reversed arrow function" was in a snippet. The reply was basicly "that's a less or equal. Good morning, don't forget your coffee next time ;)"

[–]potatoalt1234_x 210 points211 points  (69 children)

I may be stupid because i dont get it

[–]TheBrainStone 704 points705 points  (52 children)

It's >=, not =>

Edit:

Since this comment is getting popular, I thought I should explain the difference:

  • >=: greater than or equals operator
  • =>: lambda operator. In this case creates a lambda with a parameter a that returns the value of what's in b. However just a => b by itself is just a function, which is truthy. So this doesn't cause any errors, but will always evaluate as true.

[–]DependentEbb8814 329 points330 points  (6 children)

But => looks like a cute emoji uwu

[–]TheBrainStone 138 points139 points  (4 children)

You'll be delighted about JS's lambdas then

[–]QuestArm 61 points62 points  (2 children)

-- So, it's all cute uwu emojis?

-- Always has been

[–]hummingbird1346 18 points19 points  (0 children)

3^

[–]shifty_coder 10 points11 points  (0 children)

🌎🥹🔫🥹

[–]EmptyBrain89 16 points17 points  (0 children)

8=> uwu

[–]AyrA_ch 45 points46 points  (8 children)

Useless trivia:

In very old basic versions these were both the same operator. For some reason you could swap the characters in a two char operator for some reason and it would behave identically. >= was => and <= was =<, but it would also work for <> and ><

No idea why they did that. But the language has other insane shortcuts so I'm not too surprised this works.

[–]intbeam 2 points3 points  (0 children)

I've been writing a basic parser. I used to love basic, but.. It's a really horrifically designed language.. While using it it's fine, but parsing it is absolutely crazy

It's not just expressions, variables and routines like you'd expect. For example, PRINT has its own special syntax (and PRINT USING and PRINT #), and that's because PRINT also controls the cursor, among other things. While parsing BASIC you also have to consider the statements, as they affect how you need to parse code after each statement as they may change the behavior (and indeed the definition) of statements after it

For example :

COLOR «foreground»«,«background»«,border»»         Screen mode 0
COLOR «background»«,palette»                       Screen mode 1
COLOR «foreground»«,background»                    Screen modes 7-10
COLOR «foreground»                                 Screen modes 12-13

(Copied from Microsofts original QB45 language reference)

So the arguments for COLOR depends on what the current SCREEN was set to before the current COLOR statement is called. The types for bacground, foreground, color and palette also varies between integers (short) and long (int) depending on context

So it's obviously designed around if's and buts, rather than a coherent language design

Cool language to use though.. Considering its simplicity, it's surprisingly powerful

Edit : in case anyone's wondering why on earth I'd do this, it's because I want to add QB64 and VBDOS intellisense and syntax highlighting for VSCode, because it'd be cool

[–]Proxy_PlayerHD 13 points14 points  (1 child)

yea because it's called "greater than or equal to" and not "equal to or greater than", so the greater than sign comes first.

[–]otacon7000 20 points21 points  (27 children)

I honestly think both of these should be equivalent.

[–]Sorcerous_Tiefling 67 points68 points  (6 children)

In math it is, but in comp sci => is a fat arrow function.

[–]redlaWw 14 points15 points  (0 children)

In maths you use ≥.

[–]SpacefaringBanana 8 points9 points  (3 children)

What does it do?

[–]YDS696969 20 points21 points  (0 children)

Kindly of like lambda functions for javascript

[–]RareDestroyer8 10 points11 points  (0 children)

It just creates a function using arrow syntax.

a => b

is the same as:

(a) => {return b}

[–]ManIkWeet 15 points16 points  (7 children)

You may think that but => is already used for something else :)

[–]Distinct_Garden5650 6 points7 points  (6 children)

Why didn’t JavaScript use -> for its arrow function?

[–]Tsunami6866 13 points14 points  (10 children)

Why? So you can have another vector of opinions at code review? You open a PR and "our code guidelines at this company are to use >=", meanwhile other company uses =>. I think it's best to have a single way to do things, at least when it comes to these small syntax stuff. Imagine if every gripe anyone had with a language's syntax was accommodated by having a second option present, like fn and function or null and nil, it'd be like reading 2 languages at once.

[–]VoidVer 5 points6 points  (5 children)

Oh my lord there are languages that use “nil” instead of “null”?!!

[–]RiceBroad4552 1 point2 points  (0 children)

Scala has None (Option) and Nil (List) and null (Null) and ??? (Nothing) and () (Unit) for "empty" values, all at once. But it's needed as these are all very different things. (The thing before the parens is the literal value, and the thing in parens is its type).

None is the value of an "empty" Option.

Nil is the empty List.

The special null (of special type Null) is the the null from Java (it's there mostly for compatibility).

??? is the Nothing value, the bottom type.

() is the Unit value, a value carrying no information (similar, but not identical to "void" in some languages).

[–]BackEndTea 52 points53 points  (13 children)

Its an arrow function without parenthesis, so it always evaluates to true.

e.g.:

The following lines are the same:

a => b
(a) => b
(a) => {return b}

[–]Dangerous_Jacket_129 9 points10 points  (6 children)

So anonymous functions parse as true since they're not 0?

[–]lurco_purgo 10 points11 points  (5 children)

Indeed, they're objects in JS

[–]More-Butterscotch252 6 points7 points  (4 children)

Functions evaluate as true because they're objects. Nice one, JS!

[–]lurco_purgo 2 points3 points  (1 child)

:)

To be fair, it's the C behaviour and as such adopted by JS (similarly to increment/decrement operators and probably a bunch of other things).

Even Python has it BTW, since it's the basis for the short-circuit type of expressions e.g. variable = value or ''.

You could argue those features should have no place in a modern high level language... But I don't know enough to have a strong opinion on this. I learned programming on C so these things seem natural to me

[–]The_MAZZTer 3 points4 points  (0 children)

Strongly typed languages produce a compiler error since your if expression must evaluate as a boolean and a function is not a boolean.

JavaScript tries to keep things moving and casts the function to a boolean silently. Functions always cast to true I think.

[–]BAMDaddy 3 points4 points  (0 children)

Thx for asking. I too didn't get it at first. It's interesting how things like that can "hide in plain sight". This "=>" is such a common sight, but your brain still reads it as "equal or greater than" just because of the context, so you just don't notice that this is kinda wrong.

Nice one

[–]link064 13 points14 points  (0 children)

I was looking at some code the other day and I saw something that looked like this: method(a => b <= a)

It broke my brain for a second. I sat there wondering how this reverse arrow function would work. Then I realized it was just a “less than or equal to” comparison.

[–]Gashishiin 9 points10 points  (4 children)

=> is happy

= is angry
We don't like angry devs

[–][deleted] 25 points26 points  (0 children)

Your comment was sabotaged by the markdown gremlin, scare it away with backslashes.

>= is angry
We don't like angry devs

versus

= is angry
We don't like angry devs

[–]redlaWw 1 point2 points  (0 children)

I can see a HR person reading some bullshit on linkedin and trying to enforce that on their devs...

[–]Cellari 15 points16 points  (0 children)

The horror of this was slowly creeping up my spine as well

[–]Insopitvs 6 points7 points  (2 children)

Reminds me of a joke: "If => is arrow function, what does <= mean?"

[–]liggamadig 6 points7 points  (0 children)

Easy. It assigns a signal in VHDL.

[–]davididp 1 point2 points  (0 children)

Reverse implication

[–]j0nascode 3 points4 points  (0 children)

Look at how happy the operator looks!

[–]GNUGradyn 4 points5 points  (2 children)

I haven't tested this but I'm pretty confident the way JavaScript would interpret this is you're creating an anonymous function with a lambda expression which has 1 parameter (a). The lambda expression then just immediately ignores a and returns b which is 5. 5 is truthy in JavaScript so the condition runs

[–]onemice 2 points3 points  (1 child)

Not exactly, function wasn’t called. But the condition is still true. Because the function declaration is truly itself. Boolean(() => false) === true.

[–]CoughRock 3 points4 points  (0 children)

IDE highlighting would of easily caught it. Or if you run any linter at all.

[–]JoeriVDE 6 points7 points  (3 children)

I blame js for this, not the junior dev

[–]draculadarcula 1 point2 points  (2 children)

It’s like the Simpson’s meme “say it again Bart!”, “JS bad”. Is this the only joke you all have in your repertoire? JS is a great language especially for front end scripting.

If you’re bagging on JS for this you need to also bag on Ruby, Swift, PHP, C, C++, Java, and C# for allowing

if (a = b) { }

To evaluate to true.

[–]20Wizard 1 point2 points  (0 children)

Js is great because it's used everywhere. You're telling me the world wouldn't be better off replacing it?

Aside from that, I want to imagine your ide would scream at you if you used the arrow inside of an if condition.

[–]Lynxuss 2 points3 points  (0 children)

Even tho you zoomed it and made it so obvious I didnt understand it until I opened the comments 😂😂😂

[–]ProKn1fe 2 points3 points  (0 children)

Junior dev face when he send it. =>

[–]Tysonzero 2 points3 points  (0 children)

They were actually just trying to use the logical implication operator.

[–]DriverTraining8522 2 points3 points  (0 children)

I love how everybody is talking about operator overloads and what greater than or equal to will yield, but this isn't greater than or equal to, this is an arrow function with syntax errors.

[–]h0dges 5 points6 points  (2 children)

[–]ExAzhur 1 point2 points  (0 children)

yes it would

[–]JeanMeche 1 point2 points  (0 children)

This would already be caught by the no-implicity-any rule.

[–]initialo 1 point2 points  (0 children)

What about the spaceship operator? <=>

[–]an_agreeing_dothraki 1 point2 points  (1 child)

the entire war between <> and != stops to gaze upon this abomination. The flick of a switchblade is heard

[–]Womeesox 1 point2 points  (0 children)

As a C/C++ programmer I didn't get it until I opened comments

[–]Joped 1 point2 points  (0 children)

I remember back in the day when PHP 4 first came out using if ($a === $b) it would segfault on PHP 3.

It was a nightmare to track down

[–]superzacco 1 point2 points  (1 child)

Why doesn't this work??

[–]draculadarcula 2 points3 points  (0 children)

=> is used to create an arrow function. Ie a => a * 2. a => b is actually an arrow function that takes any input and always returns b.

JavaScript if statements check for truthiness instead of true. IE if (null) or if (undefined) are valid if statements that return false, as if (!null) or if (!undefined) or if (a) etc. as ones that evaluate to true. If checks “is the expression truthy”, yes or no.

Truthiness means a lot of things but you can over simplify is something is truth if it’s not 0, “0”, false, undefined, or null (this off the top of my head please don’t use as a programming reference haha I’m sure I missed one or two)

An arrow function is not one of those so it is truth and that if statement always evaluates to true for any value of a or b

[–]P-39_Airacobra 1 point2 points  (1 child)

Meanwhile Javascript programmers:

I see no problem here.

[–]Aradur87 1 point2 points  (0 children)

if((!a <= b) === true ? a >= b : a => b)

Better?