Wait correct me if I'm wrong but isn't it more like:
I -= -!false
I -= -true // -(!false) = -(true)
I- = -1 // using a sign before most of the basic dtypes changes them into `Number`s (+"123" = 123, -"69" = -69, +true = 1, -true = -1, etc.). This is hence also used to check if a string can be converted to a number or not (`if (+string)` or similar)
I += 1
?
Edit: I meant i and not I (stupid autocorrect's autocapitalization)
I don’t think that is necessarily true in this case since true + true is still evaluates to 2. true and false can just be used interchangeably with 1 and 0.
true + true = 2 because again +true is 1 and when you add diff dtypes in js, js implicitly changes the other dtypes. Like 1 + 2 + "3" = "123"true + true = true + 1 = 1 + 1 = 2 ig. Again, I might be a bit wrong here
It looks like this comment contains a code block delimited with triple backticks. Unfortunately reddit does not have universal support for this syntax and your comment will not render correctly on old reddit and most mobile apps.
For the benefit of people on old reddit, this link will take you to a correct rendering of the comment.
/u/SFM61319, it would be appreciated, but not required, if you could edit your comment to use the more compatible four space indention format. For single lines or inline code you can use single backticks.
In some languages true and false can be used interchangeably with non-zero values and zero, so !false = true and !0 = true. Likewise, that conversion works both ways so true + true will equal 2. It even applies to strings, so doing i-= -!”” Would actually produce the same result. The reason why using an empty string would work is a bit different though. The ! is a bit wise operation for not, so it converts it into 1s and 0s or true and false. That’s why !”” + !”” = 2, but “a” + “a” = “aa” not 2.
I believe doing the math part of this convoluted operation first makes it clearer, so because there haven't been enough attempts to explain this yet:
i -= -!false // (-= -b) is equivalent to (+= b)
i += !false // !false evaluates to true
i += true // true evaluates to 1, while false evaluates to 0
i += 1 // we're done. Thankfully.
This is artistic programming. The passage seen here is initially seen to convey negativity. But the author has skillfully disguised a positive increment for the self, or i.
!false equals true equals the integer 1. i -= -1; is "decrement i by minus one" and decrementing by a negative number equals incrementing by the positive. So i -= -1; equals i += +1; or with implicit sign i += 1;
Let's just say that incrementing on non-integral values is non-trivial. JS apparently chose that incrementing is the same as adding 1, but that does not have to be in all languages.
I could imagine this is a beginner who didn't understand what they were doing and just kept on adding things until it worked. Like randomly adding and deleting *s until your C code compiles.
Btw iirc the vertical line text cursor is almost always taller than a regular vertical bar pipe character |
The cursor does not have a character representation as far as I'm aware, it's dependent on the OS/graphics of the device. For example on my phone it is blue and 3px wide.
I transcribe with /r/TranscribersOfReddit and this is one of the subs that we partner with to do transcriptions and type out images for people who use text-to-speech or who have low data and can't load images.
It looks like this comment contains a code block delimited with triple backticks. Unfortunately reddit does not have universal support for this syntax and your comment will not render correctly on old reddit and most mobile apps.
For the benefit of people on old reddit, this link will take you to a correct rendering of the comment.
/u/XPWall, it would be appreciated, but not required, if you could edit your comment to use the more compatible four space indention format. For single lines or inline code you can use single backticks.
Without context, I refuse to believe this is actual code. It’s more likely someone intentionally showing the crazy things you can do with JavaScript types.
It looks like this comment contains a code block delimited with triple backticks. Unfortunately reddit does not have universal support for this syntax and your comment will not render correctly on old reddit and most mobile apps.
For the benefit of people on old reddit, this link will take you to a correct rendering of the comment.
/u/AliFurkanY, it would be appreciated, but not required, if you could edit your comment to use the more compatible four space indention format. For single lines or inline code you can use single backticks.
82
u/ElbowStromboli Apr 19 '21
Does this reduce to i - 1? It hurts my brain.
733
u/2001herne Apr 19 '21
The actual fuck?
280
u/r_amazin Apr 19 '21
This was.. on purpose ?
117
u/OkPreference6 Coding The Declaration of Independance Apr 19 '21
What were you even trying to do.
I cant find a single reason to do this except to show someone "coding is harrrdddd :("
154
u/Cloakknight Apr 19 '21 edited Apr 19 '21
Image Transcription: Code
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
49
u/kuaiyidian Apr 19 '21
wait till they discover i++
15
u/IBJON Apr 19 '21
Totally using that in production tomorrow.
8
u/sad_bug_killer Apr 19 '21
If I were writing that, I'd do
and wait for the inevitable wtf is the
-=-operator questions on stackoverflow(you know about the c++ downto operator, right?)
7
u/Glori4n Apr 19 '21
I don't think I could come up with something like this even if I tried.
7
u/ReconPorpoise Apr 19 '21
I have a hard time believing this is a real world example of bad code but wow...
6
u/Armed_Citizen_2A Apr 19 '21
You’re fired
6
u/lachlanhunt Apr 19 '21
Without context, I refuse to believe this is actual code. It’s more likely someone intentionally showing the crazy things you can do with JavaScript types.
5
u/GoodTimesOnlines Apr 19 '21
This has to be intentionally bad code
4
u/NetherFX Apr 19 '21
i -=- 1's brother
4
u/MatthewRPG576 Apr 19 '21
Code obfuscation?
3
u/jeffhowcodes Apr 19 '21
This is the standard approach of people who also write standardized tests for kids.
3
u/Flyberius Apr 19 '21
I finally worked one of these out. Finally, I am learning!
2
u/burritoboy76 depraved Apr 19 '21
This can’t be real
2
u/SwarmsOfReddit Apr 19 '21
What happens when people combine multiple stack overflow answers into one.
2
u/Darkunderlord42 Apr 19 '21
dial up tones coming from my head intensify
2
u/sixtyfifth_snow Apr 19 '21
Oh, worse than assembly codes 🤦♂️
2
u/xxDarby Apr 19 '21
What am I even looking at here?
2
u/djhaskin987 Apr 19 '21
This line is actually making me hyperventilate.
2
u/[deleted] Apr 19 '21
delete this, do it now
2
u/LucaRicardo Apr 19 '21
When you really don't want your app being reverse engineered.
2
u/[deleted] Apr 25 '21
i -= -!false
But false is a 0 and !false is true and true is 1 so...
i -= -1
But we are subtracting a negative number which is the same as adding so to fix this...
I += 1
Or
I++
1
u/[deleted] Apr 19 '21
how are you allowed to subtract a boolean?
1
u/[deleted] Apr 19 '21
At least there's no magic numbers tho!!
1
u/sxeli Apr 19 '21
Push it and git blame —someone-else
1
u/Untwisted_Apple Apr 19 '21
A little bit confused, but he got the spirit...
1
u/AgreeableLandscape3 Apr 19 '21
I mean, the compiler should optimize it to i++ in the byte/machine code, right?
1
u/carolper2000 Apr 19 '21
What a mental workout to understand this sub
1
u/gygyor Apr 19 '21
i-=-!!47
1
u/ososalsosal Apr 19 '21
Just because you can...
1
u/GreatArtificeAion Apr 19 '21
Is !false even guaranteed to loosely equal 1?
1
u/SlightlyNotMad Apr 19 '21
I want to see more from this codebase!
1
u/edave64 Apr 19 '21
Of all the weirdnesses js has, bool implicitly casting to number might be the most logical
1
u/[deleted] Apr 19 '21
I don't know what the fuck this is but I hate it.
1
u/Aloysius204 Apr 19 '21
Too clunky. I'd go with decrementing by Euler's identity in my code.
1
u/IntuitionPumps Apr 21 '21
This is an existential crisis
1
u/Jackalotischris Apr 25 '21
I minus not false but negative so it’s true so false is false so I now equals less falsely.
1
u/eerklogge May 18 '21 edited May 27 '21
I equals I minus negative not 1
1
u/[deleted] Sep 24 '21
Why not just use i++
0
u/[deleted] Apr 19 '21
[deleted] — view deleted comment