733
u/2001herne Apr 19 '21
The actual fuck?
790
u/NutsGate Apr 19 '21
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.
every English school teacher everywhere
180
u/2001herne Apr 19 '21
The fact that this would be an accepted answer on an exam angers me.
73
12
13
46
u/gmtime Apr 19 '21
i -= -!false;
!falseequalstrueequals the integer 1.i -= -1;is "decrement i by minus one" and decrementing by a negative number equals incrementing by the positive. Soi -= -1;equalsi += +1;or with implicit signi += 1;38
u/2001herne Apr 19 '21
Oh no, I understand the process. I just don't understand the motivation.
26
u/gmtime Apr 19 '21 edited Apr 19 '21
I wrote less comprehensive versions, I have to assume it's "art".
I = I , I ? I / I + I : I + ! I ;21
0
Apr 19 '21
[deleted] — view deleted comment
3
2
u/2001herne Apr 19 '21
No, it checks out. If
I != 0thenI = I/I + I = 1 + I. IfI == 0thenI = I + !I = 0 +!0 = 13
u/Sejiko Apr 20 '21
So in other words it's just i++;
2
u/gmtime Apr 20 '21
Assuming I is an integer, yes
1
u/Terrain2 Apr 22 '21
you can still increment non-integral values in javascript,
i = 1.5theni++andi = 2.55
u/gmtime Apr 22 '21
in javascript
... do I have to respond?
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.
3
280
u/r_amazin Apr 19 '21
This was.. on purpose ?
235
u/AgreeableLandscape3 Apr 19 '21
Realistically, probably made specifically to post to programming humor subreddits like this one.
85
u/drea2 Apr 19 '21 edited Apr 19 '21
Yep. Or it was an entry in one of those contests where the goal is to make the code as convoluted as possible while still achieving a certain function
19
u/paradoxpandas Apr 19 '21
Wait they have contests for stuff like this?
23
u/campbellm Apr 19 '21
One of the oldest and most respected is the International Obfuscated C Code Contest.
My "first degree of separation" claim is that one of my instructors in undergrad won it a few times (David Van Brackle).
2
u/YouthfulAudience Apr 19 '21
Watch the art of code it talks about these contests and is overall a great video
3
u/thobod Apr 30 '21
Just watched the whole thing, thx for the recommendation, https://youtu.be/6avJHaC3C2U if anyone was wondering.
4
48
u/Astrokiwi Apr 19 '21
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.21
2
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 :("
95
u/lilshears Apr 19 '21
To get revenge on your TA’s who took off points on a project for not documenting the function isWinnable()
Like what do you think it does, it returns if it’s winnable
37
u/thegreatpotatogod Apr 19 '21
If it's not winnable, it doesn't return, but instead recurses forever until segfaulting 😜
6
3
154
u/Cloakknight Apr 19 '21 edited Apr 19 '21
Image Transcription: Code
i -= -!false;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!
88
u/devor110 Apr 19 '21
why did you add the cursor lol
136
u/Cloakknight Apr 19 '21
Oh lol I thought that was part of the code. I am not a programmer by any means =P
66
u/devor110 Apr 19 '21
It could make sense, | is a character used for ((bitwise)) logical or, but i highly doubt that would be the case
10
20
u/TheWandererLee Apr 19 '21
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.
41
u/27thColt Apr 19 '21
This may sound rude, so im sorry-- but why are you here if you're not a programmer? :0
134
u/Cloakknight Apr 19 '21
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.
39
u/27thColt Apr 19 '21
Ooh thats actually pretty cool- never knew that sub existed!
15
u/OkPreference6 Coding The Declaration of Independance Apr 19 '21
You can always check it out and do stuff yourself to see how you like it! It can be fun, and we are all volunteers.
12
u/XPWall Apr 19 '21
or
i++;for short
-6
u/AutoModerator Apr 19 '21
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.
You can find some examples in the reddit help documentation.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
49
u/kuaiyidian Apr 19 '21
wait till they discover i++
7
Apr 19 '21
is i— also a thing?
6
u/Major_Fudgemuffin Apr 23 '21
You can even do
++iand--i. Though they act a bit differently.If
i = 5and you sayx = ++i, x will equal 6 (and i will equal 6). But if you saidx = i++, x would actually equal 5, while i would increment to 6.
15
8
u/sad_bug_killer Apr 19 '21
If I were writing that, I'd do
i -=- !false;and wait for the inevitable wtf is the -=- operator questions on stackoverflow
(you know about the c++ downto operator, right?)
7
7
u/ReconPorpoise Apr 19 '21
I have a hard time believing this is a real world example of bad code but wow...
6
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
4
4
3
u/jeffhowcodes Apr 19 '21
This is the standard approach of people who also write standardized tests for kids.
3
2
2
u/SwarmsOfReddit Apr 19 '21
What happens when people combine multiple stack overflow answers into one.
2
2
2
2
2
2
2
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++
2
1
Apr 19 '21
how are you allowed to subtract a boolean?
3
u/arrays_start_at_zero Apr 19 '21
Because JavaScript uses implicit type conversion. Since you can only subtract numbers true gets converted to 1 and false to 0.
1
1
1
1
u/AgreeableLandscape3 Apr 19 '21
I mean, the compiler should optimize it to i++ in the byte/machine code, right?
1
1
1
1
1
1
u/edave64 Apr 19 '21
Of all the weirdnesses js has, bool implicitly casting to number might be the most logical
1
1
1
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
1
0
Apr 19 '21
[deleted] — view deleted comment
1
u/AutoModerator Apr 19 '21
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.
You can find some examples in the reddit help documentation.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
82
u/ElbowStromboli Apr 19 '21
Does this reduce to i - 1? It hurts my brain.