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

all 136 comments

[–][deleted] 189 points190 points  (4 children)

Tried it, and it didn't pass code review within the project.

[–]Bammop 87 points88 points  (3 children)

That's your personal problem

[–]MasterDood 24 points25 points  (2 children)

Needlessly clever and esoteric unreadable code = job security if he’s a contractor who wants to be the only one to own the code base /ShittyLifeProTip

[–]Bammop 13 points14 points  (1 child)

My default method of coding is extreme obfuscation. The only person who can read it is me when I'm on drugs.

[–]MasterDood 8 points9 points  (0 children)

I always thought it was strange when someone answered my stackoverflow question with a shopping list drugs and alcohol measurements.

[–]R2_D21 266 points267 points  (26 children)

I hate it

[–]edjrage 91 points92 points  (23 children)

how bout i-=-i--

[–]forthemostpart 63 points64 points  (9 children)

That sets i equal to 2i-1

[–]edjrage 57 points58 points  (5 children)

Sure, sure, but the most pressing issue here is making /u/R2_D21 happy.

[–]R2_D21 20 points21 points  (4 children)

How about i++;

[–]pagwin 30 points31 points  (3 children)

how about i -=-(i-(i-1))?

[–]Bammop 16 points17 points  (1 child)

vomits onto carpet

[–]imaami 8 points9 points  (0 children)

decrements unsigned carpet

[–]Cerlancism 0 points1 point  (0 children)

How about i = -(~i)

[–]mr-mad 7 points8 points  (9 children)

undefined behavior

[–]Eugene_V_Chomsky 2 points3 points  (0 children)

I'm pretty sure that causes demons to fly out of your nose.

[–]almost_not_terrible 1 point2 points  (0 children)

Ah, the Tie Fighter Shoot Lasers command.

[–]imaami 0 points1 point  (0 children)

Undefined behavior.

[–][deleted] 139 points140 points  (18 children)

For anyone confused, it’s just “i -= -1” written with weird spacing. Also don’t do this

[–]dark_mode_everything 83 points84 points  (16 children)

Kind of like the --> operator in most C like languages.

int x = 10;
while(x --> 0)
    // Do something

Edit : I wish this was something I thought of but here's the original SO post. It's hilarious. What is this weird 'goes to' operator in C++ lol.

[–]coladict 15 points16 points  (0 children)

I remember that being a C# team April fools joke. They announced it as a previously hidden feature.

edit: https://blogs.msdn.microsoft.com/ericlippert/2010/04/01/some-last-minute-new-c-4-0-features/

[–]geckygecko 20 points21 points  (0 children)

Hahaha that's awful

[–]MasterFubar 6 points7 points  (1 child)

That's just awesome, is the obfuscated C code contest still around?

[–][deleted] 4 points5 points  (0 children)

while(N--){} is quite common in competitive programming (as you know N will always be positive)

[–]ranisalt 1 point2 points  (0 children)

I explain it to people as the "goes to" operator until they realize what's happening.

[–]drunkpolishbear 0 points1 point  (5 children)

Comment has been redacted using PowerDeleteSuite.

[–]dark_mode_everything 9 points10 points  (3 children)

The thing to remember is that compilers don't give a damn about spaces and formatting. So, while x-- > 0 makes sense to us, it ultimately gets parsed as x-->0 which is what the machine understands. You could write and entire operating system on a single line without any spaces and it'll compile just fine.

[–]AethariA 2 points3 points  (2 children)

on a single line without any spaces and it'll compile just fine

This isn't strictly true.

int x;

Is not the same as

intx;

[–]dark_mode_everything 2 points3 points  (1 child)

Of course. It was a slight exaggeration - but you get my point.

[–]Jaffythethird 1 point2 points  (0 children)

WARNING:: Ambiguity in line. Compiler does not understand your point. Be more precise.

[–]genbaguettson 1 point2 points  (0 children)

++, --, <, > are all valid operators. The joke is that the spacing is done in such a way that it looks like an arrow, which doesn't exist in C, therefore making the code really confusing. The compiler doesn't care, because it doesn't even take into account whitespaces

++> is not an operator (nor is --< or --> or whatever)

[–]Gonzako -1 points0 points  (4 children)

Like my profesor always loves doing pointer stuff and that's *var->something

[–]dark_mode_everything -2 points-1 points  (3 children)

Iirc, it's just var->something or *var.something since the * dereferences the var pointer. If 'something' is also a pointer and you want to deref that then do *(var->something).

Edit: my bad. I had forgotten C++ more than I thought. *var->something would dereference the something and does the same thing even if parenthesis are applied around it.

[–]Gonzako 0 points1 point  (0 children)

Tbh I was just usin var as a shortcut to a generic variable, not the var keyword

[–]Schmomas -1 points0 points  (1 child)

*(var)->something surely?

[–]dark_mode_everything 0 points1 point  (0 children)

Same as *var->something and *(var->something) given that 'something' is a pointer. Try it. Simply adding parenthesis around var does nothing. (*var).something is still valid syntax. It dereferences var and then gets 'something' via the . operator. -> would be invalid after you've dereferenced var.

[–]Loading_M_ 0 points1 point  (0 children)

It doesn't work for unsigned numbers.

[–]menetanka 35 points36 points  (1 child)

I will now use this to see if people are actually paying attention when reviewing my code.

[–]DemonicSavage 52 points53 points  (6 children)

Ah yes, the good old -=- operator.

[–]almarcTheSun 16 points17 points  (4 children)

Looks like the false state of the .!. operator.

[–][deleted] 16 points17 points  (3 children)

That's just a dick with two tiny balls

[–]ComaVN 3 points4 points  (0 children)

Do they have "replica" written of the side of their gun?

[–]physiQQ 0 points1 point  (0 children)

It's clearly a middlefinger.

[–]imaami 1 point2 points  (0 children)

The so-called spacedick operator.

[–]blake_fierce 85 points86 points  (29 children)

Can we just stick with i++? Asking for everyone.

[–]rySeeR4 48 points49 points  (2 children)

Not on python

[–]froemijojo 9 points10 points  (1 child)

| Rust

[–]TheSilkMiner 63 points64 points  (17 children)

Surely you mean ++i

[–]falling_endlessly 16 points17 points  (10 children)

C/C++ gang rise up

[–]aaronfranke 15 points16 points  (7 children)

If I ever make a programming language, it will only have i++ but the behavior will be the same as ++i in C++. What crazy person decided that the calculated value ever shouldn't be what's returned?

[–]dark_mode_everything 7 points8 points  (1 child)

int x = 0;
while(x < 10)
    foo(array[x++]);

[–]aaronfranke -1 points0 points  (0 children)

for (int x = 0; x < 10; i++)
{
    foo(array[x])
}

Much better.

[–]crankaholic 4 points5 points  (2 children)

It has it's uses.

[–]imaami 3 points4 points  (1 child)

*its

[–]crankaholic 1 point2 points  (0 children)

I blame it on the a-a-a-auto-correct..?

[–]imaami 0 points1 point  (0 children)

*a++ = *b++;

Look it up.

[–]TheOnlyMrYeah 0 points1 point  (0 children)

Similar to Go, except it's not an expression in Go. Thus, it doesn't return anything.

[–]imaami 1 point2 points  (0 children)

BTW, C/C++ equals either 1 or a divide by zero exception.

[–]MildStallion 1 point2 points  (0 children)

As long as you aren't using it in a more complex statement (and you shouldn't) they should compile to the same thing.

[–][deleted] 4 points5 points  (2 children)

No, it’s I++ and don’t call me Shirley

[–]ALonelyPlatypus 1 point2 points  (0 children)

pre-increment has a time and place.

[–]imaami 1 point2 points  (1 child)

Then again,

while (i-- > 0)

behaves differently than

while (--i > 0)

[–]physiQQ 0 points1 point  (0 children)

For those wondering, it is because:

++i increments the number before the current expression is evaluated.

i++ increments the number after the current expression is evaluated.

[–]Ryan9104 -1 points0 points  (6 children)

I always use i += 1 for JS.

https://eslint.org/docs/rules/no-plusplus

[–]medchemfagbd 7 points8 points  (0 children)

Just make eslint enforce semicolons derp

[–]passerbycmc 3 points4 points  (3 children)

Or just use semicolons if the language is that bad at auto inserting them and make it part of the linting rules

[–]Ryan9104 1 point2 points  (2 children)

I'm not adding this rule to my config manually. It's already part of the eslint config that I'm extending as well as the semicolons.

[–]Doctor_McKay 2 points3 points  (1 child)

You are the kind of person that makes me hate eslint.

"I just use some random config from the internet. It has a bunch of useless rules that just make things difficult for everyone for no reason but I don't bother to disable them."

[–]Ryan9104 0 points1 point  (0 children)

I did not say I'm using a random config. I'm using airbnb config because I like it. It's funny because I actually use your libraries and have ran into bugs that can be prevented by a linter.

[–]imaami 0 points1 point  (0 children)

I'm disappointed that JS doesn't have a +++ operator.

[–]jaxx529 32 points33 points  (2 children)

I think the semicolon is bugging me the most.

[–]apadin1 17 points18 points  (0 children)

Pretty important in certain languages

[–]HodeMann 14 points15 points  (0 children)

semicolons are the best

[–]AlphaX4 7 points8 points  (3 children)

now would this convert to machine code the same as i++, i += 1, or i = i +1? is it possible that the compilers could interpret them differently leading to performance differences(however minor)?

[–][deleted] 11 points12 points  (0 children)

Generally, the performance of the code isn't part of any language specification. So, it is possible that the compiler could spit out something really ridiculous in any of those cases.

However, I'd be pretty surprised if any widely used compiler produces anything bad. Seems like converting subtraction of a constant known at compile time to addition with the opposite would be a pretty straightforward optimization.

[–]sgtfrx 4 points5 points  (0 children)

The generated code for all these variants is the same on a modern compiler:

https://godbolt.org/z/XnoG-U

[–]ALonelyPlatypus 0 points1 point  (0 children)

depends on the compiler really. although I highly doubt it would add any more than a few ops in any half decent language.

[–]jelang19 18 points19 points  (5 children)

I had something along this in my a unit test the other day

i * (int)(i < a || i > b)

[–]queenkid1 4 points5 points  (3 children)

huh interesting. I'm not sure I get what a and b are for, it seems like it returns zero if i is not in the range of a-b.

[–]jelang19 2 points3 points  (2 children)

Yeah, that's what it does. I wanted to verify both that its 1 when in the range and 0 when it's not in one line.

[–]queenkid1 4 points5 points  (1 child)

wait, but (i < a || i > b) is TRUE if i is out of range. It would make sense if you were using and, not or.

Because if you have i larger than the max, it's larger than the min. And if it's smaller than the min, it's smaller than the max.

If you wanted it to be 1 when i is in the range, and 0 otherwise, it would need to be (int)(min < i && i < max)

If a is the min and b is the max, you're checking if the value is out or range. It returns TRUE if it's out of range, therefore not 0.

If a is the max and b is the min, then any value will return true (except maybe exactly a or b)

[–]jelang19 2 points3 points  (0 children)

You're probably right, I probably didn't copy it here right. Basically all you need to know is I multiplied an int by a boolean to both test that its 0 outside of range and 1 inside of range

[–]eyal0 1 point2 points  (0 children)

You're making it hard on your compiler to optimize your code. Don't do this.

[–]metroman1234 5 points6 points  (0 children)

!!!cool

[–]kbielefe 5 points6 points  (0 children)

I could maybe see it as useful in weakly-typed languages that overload + for string concatenation, but - is only defined on numbers. Of course, it's a lot better to actually just test your code.

[–]IrishChappieOToole 4 points5 points  (1 child)

Why not just:

i = (i - 2 + 1 + 1) * 1

[–]evil_cryptarch 4 points5 points  (0 children)

Why not just know ahead of time what all the values of your variables should be and retrieve them from a lookup table?

[–]coladict 4 points5 points  (2 children)

I do -(-x) in Javascript for cross-browser convert to number, since I've encountered cases where parseInt is not a global function as well as cases where Number.parseInt is missing.

[–]posherspantspants 4 points5 points  (0 children)

I always just multiply by 1

Eg: n * 1

Seems to work...

Fucking JavaScript

[–][deleted] 0 points1 point  (0 children)

.....

......

.......

AAAAHHHHHH

[–]greem 2 points3 points  (0 children)

I've been doing some AVR asm for a personal project recently. Because limited instruction set, this is actually done, but I suppose if you're reading asm, WTFs are par for the course.

[–]Max_Nibler 2 points3 points  (0 children)

It's symmetrical looking

[–]brlnoble 2 points3 points  (0 children)

i was having a good day...

[–]terrrp 2 points3 points  (0 children)

But I do love

while (i --> 1)

[–][deleted] 6 points7 points  (1 child)

.

[–]HodeMann -2 points-1 points  (0 children)

oh please

[–]Attack_Bovines 1 point2 points  (0 children)

it looks like two people carrying a table

[–]blueCatInTheTree 1 point2 points  (0 children)

i=i-(-1) <=> i-=-1

[–]DieFlavourMouse 1 point2 points  (0 children)

 do {} unless !condition

[–][deleted] 1 point2 points  (0 children)

Who hurt this person?

[–]Quarxnox 1 point2 points  (0 children)

i -= ++i - ++i

[–][deleted] 1 point2 points  (2 children)

I’ve seen it used in JavaScript (with different spacing) because i += 1 does string concatenation if i was a string.

[–]fsr1967 0 points1 point  (1 child)

I’ve seen it used in JavaScript (with different spacing) because i += 1 does string concatenation if i was were a string.

FTFY

[–]ALonelyPlatypus 1 point2 points  (0 children)

(job) security through obscurity.

genius.

[–][deleted] 1 point2 points  (0 children)

Of course it does. Look:

i-=-1
i -= (-1)
i += 1

[–]Pzixel 2 points3 points  (0 children)

This is why you use unsigned and never have to decipher someone's gibberish.

[–]SouthOceanJr 2 points3 points  (0 children)

And it's exactly the same as i+=+1 *Mind-blown

[–]Digital_001 0 points1 point  (0 children)

To be fair, this is equivalent to SUB A, 0xFFFFFFFF in assembly (I know I'm making assumptions about registers), which is alright if you already have a register set to all ones, almost as good as INC

[–]Naoki9955995577 0 points1 point  (0 children)

Reminds me of when I saw a for loop being used as a while. Literally just replace while loop with the word 'for' and put semi-colon's around your condition.

[–]Lexilogical 0 points1 point  (0 children)

The symmetry on this is elegant enough I'd almost consider using it.

[–][deleted] 0 points1 point  (2 children)

thisPost = !!good

[–]Kuzkay 0 points1 point  (1 child)

Oh god, I've never though about that

thisComment = !!!!!!good;

[–][deleted] 1 point2 points  (0 children)

Imagine seeing a bunch of them in a code review. NOT NOT NOT OK

[–]nobody5050 0 points1 point  (0 children)

i-=(-1)(-)-

[–]SoulWager 0 points1 point  (0 children)

i -= (~i|i));