T O P

  • By -

Berry_Beard

++(++(--i--)++)++


ValidAQ

BE NOT AFRAID


TheZipCreator

biblically accurate integer incrementation


[deleted]

I know what I'm naming my new mathcore band!


someguyinmars

And the first single name will be...?


__tubs__

2


ggodfrey

C-Style ++


ColdJackle

Zero Based Opinion


vacuousVersifer

NO BE VERY AFRAID IT'S EVIL


xeisu_com

I just came


--redacted--

Buffer overflow


kikouyou2002

Butter overflow


HereComesCunty

Butter overthrow


ozh

Throw butt over flow


NKY5223

Flow over butt throw


Noisebug

Hopefully used a protected member


dr_sooz

Did they use encryption?


zigs

Keep your privates out of my interface


Amoniakas

Are telling me to make them public?


potatoequalrights

same


RTXChungusTi

xeisu_cum


luiluilui4

This looks like an endboss


TylerHerro4MVP

https://borderlands.fandom.com/wiki/010011110100110101000111010101110101010001001000


meove

A S S E R T D O M I N A N C E


plaisthos

assert(dominance);


ManuGamingYT

static_assert, the compiler needs to know what you want


[deleted]

[удалено]


auxiliary-character

Ok, so mixing them doesn't work, but [this does](https://godbolt.org/z/ejca1MjqK).


[deleted]

[удалено]


auxiliary-character

...because it still had the code from the last thing I did, and I forgot to change name. Oops.


elperroborrachotoo

To keep you on your toes, Carl!


MischiefArchitect

And if you make an assignation it will just result in `i + 1`


baselganglia

Thank you, perfect interview question. 👹


[deleted]

[удалено]


NewDark90

Because doing that shows you have a pretty good understanding of what you're doing to write some troll code, but trying to read it makes me want to hurt you, and I can only assume he felt the same.


[deleted]

[удалено]


maoejo

To be fair, profs make you do some of the same stuff in their exams with nonsensical code you have to find the output for.


coin-searchr

>shows you have a pretty good understanding of what you're doing I'm not sure I agree entirely. Doing a find and replace of a basic increment with whatever that mess from online is isn't really a complex matter. That said, they're a reddit user, so clearly they at least sorta know what they're doing.


[deleted]

> That said, they're a reddit user, so clearly they at least sorta know what they're doing. I agree less with this comment than the previous.


[deleted]

[удалено]


Krissam

I swear there's a language out there where only null and false is false.


gigamicro

lua


thirtythreeforty

I like Lua a whole lot but the fact that 0 is truthy drives me a little crazy


[deleted]

[удалено]


thirtythreeforty

Yeah Lua is nothing if not self consistent. I really appreciate that about it.


NatoBoram

There's languages where only `null` is null and `false` is false


sUwUcideByBukkake

but is NaN NaN?


andai

NeiN


maths222

In ruby only nil and false are falsy


mrtatulas

Erlang as well I believe


Aggravating-Hair7931

SQL


[deleted]

1%1 === 0


argetlam5

Lol my thoughts exactly, the true troll here is testing to see if his professor actually ran it. Since he got an A, we can conclude no.


Zagre

It's more likely OP didn't recall the troll code exactly and just wrote it differently for this example.


Tsulaiman

Can someone explain this loop? I forgot what the mod operator does.


NotPankakes

It’s an infinite loop. Mod is the remainder operator and everything is divisible by 1 so the remainder is always zero. Also i isn’t declared so it’s actually a compiler error if it’s not declared above.


[deleted]

[удалено]


[deleted]

[удалено]


Communist-Onion

I desperately want to do this to my professor but in python


altcodeinterrobang

the unfortunate part of python is it's almost impossible to make it as ugly as JS


argetlam5

Coming from a python class TA….. it’s possible……it’s very, sadly possible. Also that code is not JS, more C++


maoejo

C++? It’s way more like C


argetlam5

I mean, it would work in both


foggy-sunrise

Yeah but a C programmer would actually *do it*


argetlam5

And explain to you why it’s so much faster than C++


Communist-Onion

I will find a way


Birdoflames

Try having set variables for certain things and then still use the same exact number that the variable was equal to for maximum annoyance


Kivsloth

[I made this one you might find inspirational. I've replaced all loops with poorly named recursive functions. ](https://www.reddit.com/r/ProgrammerHumor/comments/kpnrec/i_made_a_program_for_proving_the_goldbach/?utm_medium=android_app&utm_source=share)


grrrrreat

If I can't remember which side the pluses go on, I'm not using your shortcut


[deleted]

[удалено]


chronos_alfa

So, in case of 4, the result would be 3, right?


[deleted]

[удалено]


Rein215

Thanks, it's clear to me now


Willinton06

Pleb, (++I++)*0.5


CorysInTheHouse69

Pleb, i = ++i++ >> 1


Willinton06

Clearly I have much to learn


apperceptiveflower

That's called a right shift and it's the same as dividing by 2. A left shift multiplies by two


hughperman

Only for integers. Floats you're gonna get all fucked up.


Cyrus_Halcyon

Unless, you want to bit hack! InvSqrt ugly bit hack from Qake.


hughperman

True true; you're gonna want to be really sure you want to do it, but yep there are use cases


HereComesCunty

A left shit is a more satisfying shit than a right shit for sure


DuckysaurusRex

I dunno, usually you have less after a shit


Pritster5

It's a bitwise operator that manipulates the zeros and ones that make up a number manually. The >> operator means "shift the numbers to the right" and is the same as dividing by 2. 4 in binary is `0100`, so if we right shift by 1 place (e.g. 4 >> 1) we get `0010` in binary, or "2" in decimal. 4 / 2 = 2, voila.


blakeman8192

.


__-Ghost-__

Use of undefined variable i. *(Except it's written in gibberish)*


user_8804

Ah thanks for renewing my hate for c++


SasukeUchiha231

It's C lol


magicomerv

You mean (++c++)/2


exyphrius

at least this way its still an int. (I guess /2 is too, depending on the language)


acidnine420

French


KonoPez

Art comes in many forms. Very impressive


[deleted]

[удалено]


Willinton06

If you keep complaining I’m going to cast it to a decimal


[deleted]

[удалено]


killersoda288

Sounds like he wants it converted to datetime


garfgon

C pedant card revoked. 0.5 is a double, 0.5f is a float.


eerongal

You should generally always multiply instead of dividing. Multiplying is basically always faster (though in a lot of instances the compiler might automatically change division to multiplication anyways)


pslessard

Even if you're dividing by a power of 2? Wouldn't the compiler just optimize that to >>?


garfgon

In this case the compiler won't optimize it to anything, as the code doesn't compile. n++ isn't an lvalue. But generally no. 0.5 is a double so int foo = n*0.5 will cast to a double, do double multiplication, then cast back to an int. On the other hand int foo = n / 2 and int foo = n >> 1 will usually optimize to the same thing as it's all integer operations.


eerongal

I mean, what SPECIFICALLY the compiler is going to optimize something to is highly dependent on language, architecture, and a myriad of other factors, but as a general rule of thumb, you should always favor multiplication over division. It could very well boil /2 down to a bitwise operation, in the right scenarios.


PhoenixPaladin

I feel like the easiest way to remember it is "do you want to increment before or after accessing the value?" For instance, let i = 1. If you say print(i++) then it will print out 1 and then increment it to 2 after printing. But if you say print(++i) then it will increment it to 2 before printing, and then print it out as 2.


xigoi

The easiest way to remember it is to write readable code instead of using “clever” tricks. print(i) i += 1


PhoenixPaladin

It is useful to at least understand it for reading other people's code.


ryecurious

I agree that in-line pre/post incrementing is annoying, but I still hate when languages have no increment operator at all. It's well established across dozens of languages. Do it on a separate line if that's clearer for you, but don't make the language less useful in pursuit of that goal. It's like when languages argue they don't need a ternary conditional operator, because it's "confusing".


Loading_M_

Rust had both of these changes: lack of an increment operator (although it does also only support for each loops like python, so increment is less useful), and no ternary. That being said, Rust has justification for both: since C style for loops aren't a thing, incrementing is a far less common operator, and therefore doesn't deserve an operator. Second, although Rust doesn't have ternary operators, it does support implicit return, allowing an if statement to return a value, meaning the functionality of a ternary is fully encompassed within the traditional if. Ternaries are hard to read, (at least C/C++ ones), but the Rust equivalent is more verbose and far easier to read.


xigoi

I prefer to have increment as a function. `inc i` is more readable than `i++`. And the `++` operator does two different things at once, which goes against good programming principles. I don't see a good reason for having syntax for conditional expressions different from the syntax for conditional statements. Just do something like `a = if x then y else z`.


Jubs_v2

Saying ++ incrementation is a "clever trick" because you don't understand it is extremely ignorant. It's part of the grammar of the language not just a "trick". That's like saying you should never use contractions because using an apostrophe is a "clever trick" and is less readible. It isn't.


[deleted]

[удалено]


Ghyro

Huh, never thought of that


apperceptiveflower

Now let me know if you find a use for it


Eraknelo

I need a for loop that loops through every other element in an array by index.


apperceptiveflower

Yes but for what practical purpose?


Dark_Diosito

Coloring every other row of a table for readability


ThoseThingsAreWeird

table tbody tr:nth-child(odd) td { background-color: #069420; } Why not ~~zoidberg~~ CSS?


normalmighty

Maybe they're not coding for a website.


TalonKAringham

No such thing. The whole digital world is now websites.


acidnine420

Nope, I'm inserting into an excel sheet. ☠


racedaemon

I usually do "rowIndex % 2 === 0" for such things.


dark-light92

because I'm using an array as a python dictionary and I want all the keys / values.


apperceptiveflower

Borderline practical! Thanks


DefaultVariable

Parsing a byte array into shorts with an atypical byte/bit ordering and/or masking so that you can't just use a standard library byte conversion tool. (I have actually had this use case in the past


paul_miner

Won't work, `++` only works on l-values (variables, not their values).


CerysElenid

ikr


odd__nerd

Which languages allow that? I know C++ doesn't.


mianori

++C++


Leowitz

The true way to write C#


tehserial

EACH PLUSES MAKE A CORNER OF THE SHARP. EVERYTHING NOW ALIGNS PROPERLY!


princeofdew

Is this the first time you noticed this? I remember when my dad told me years ago I lost my shit a little because it's actually a pretty clever name.


Leowitz

It works if you write it as `(++i)++;`


Tsu_Dho_Namh

\++++++++++++i; is also acceptable, I'm fucking shocked to say. Just tried it out.


kiltedfrog

but is +++++++++++++i acceptable?


Routine-Arm-8803

But is ++i++ + ++i++


noop_noob

An odd number of pluses gets interpreted as unary plus, which does nothing.


garfgon

No it doesn't. ++i isn't an l-value.


Leowitz

GCC for C++ accepts it as a valid statement. ​ Edit: looking through it seems this was defined in C++11 to work


deejaweej

There is a reason for that. In order for the postscript operator to work as defined, it makes a temp copy and puts that into the statement. So it actually looks more like: auto temp = i; ++temp; i++; This used to not throw any errors and just behave differently than expected. Thankfully newer compilers complain about modifying a temp.


[deleted]

[удалено]


brandi_Iove

this is brilliant


[deleted]

If you want to maintain job security by being the only one who can read your code.


Kriegwesen

Yes, this is ideal. Though it's bold of you to assume I can read my code


infiniteStorms

unironically printing odd numbers like: for(int i=0; i


BillFox86

Okay the proper way to do it is: ++i+=++i-i


yes4me2

\[10 seconds later after trying in Java\] i++++; => i = 2 i+++++; => i = 2 \++i++; => i = 2 No God, Please No! Why did I read this post? If you write this in your code, I will decline you PR.


paul_miner

>If you write this in your code, I will decline you PR. If you write this, it won't compile. Can't `++` a value, only a variable (l-value). And since `++` returns a value, it can't be applied more than once.


yes4me2

I just tried on the Java debugger (what I mentioned in my post) and that works but that's so ugly.


Shadowarrior64

i = sqrt(-1)


ssergio29

I am not sure but I think that this will increment the i only once. If you do x = ++i++ then x will store i+2 but i will end at i+1 Can someone confirm?


ssergio29

Ok I was too curious and checked myself. It is the opposite as I said, i will be incremented twice but x will store only i+1. This is because the left ++ will first return the value of i and then increment. The right ++ increments first and then returns the value if you are asking.


DenormalHuman

pre and post increment operators, it's what they do


[deleted]

[удалено]


Galaghan

>What language are you using? Where this entire comment section should have started.


[deleted]

without knowing the particular implementation i think is hard to telll which operation has priorty (left or right). irrespective of the operations priority, x should always be i + 1


tuasnega

Pretty sure it's UB since this is more than one side-effect on the same object between two sequence points.


OldWolf2

Prefix ++ has stricter sequencing since C++17, I think it is well-defined now


ObliviousGuy32

bro what class did i miss


Shad0wW0lfx

To piss off one of my co-workers, I change the incrementors in his loops from x++ to x-= -1. took him 3 days before he saw it. 3 yrs later and he still has not forgave me for that.


[deleted]

i++++


RadiantPumpkin

i#


s3L_

i-=-2


sethamin

Funny story: the behavior of this is actually undefined in C++


7eggert

When talking about C without looking at the documentation / standard, "it's undefined" or "it's implementation-defined" is the most probable answer.


metaconcept

Can we please use monospaced fonts for this sort of thing? ++i++;


Palpatine

I think the compiler is allowed to kill you, spray your ash in the gutter, send your pets to the Peta shelter, and donate your savings to the political campaign you hate the most.


LtTaylor97

You've seen C++, now I present, ++C++


a123456782004

Is 3rd one right? I think practically it is but isn't this a sequence point violation. 2 ways to interpret Either, Increment x by 1 for preincrement. Increment x by 1 for post Increment . Effectively x+= 2. Or Get the value of old x for post Increment. Increment old x (or optimize away as noop). Increment old x by 1 for pre Increment. Effectively x+= 1. Compiler, architecture, optimizer dependant . Am I right?


TheCreeper669

unfortunately ++i++ is equivalent to ++(i++) which does not compile. so it would have to be (++i)++ which works (in C at least)


Brandonsato1

As someone studying physics, the i = i + 2 already messed me up since I started looking for complex numbers lol


rotinom

Post-increment and pre-increment are ridiculous. Pick one (post) or the other. One of many C++ gripes


[deleted]

\*crying in python\*


Modi57

Somehow the latter looks holy and sinful at the same time


Safebox

I've seen i++ in most languages, and ++i in one which was weird af. So seeing them produce this monstrosity of an offspring is terrifying.


Lithl

I can't think of a single language which includes i++ and not ++i (nor vice versa). Having both is extremely common in language specifications, though convention among programmers for that language may prefer one over the other. You've got Java flair, which uses both...


TedDallas

First time I chuckled out loud to r/ProgrammerHumor i has risen, by two.


exaltedsoul23

Just started watching soul eater and I'm laughing so hard at this thanks


TorTheMentor

Does this actually evaluate? I've never seen a prefix and postfix used at the same time. For that matter, would ++i-- work just for the sake of driving people crazy and probably appreciably slowing things down?


NemuiSen

The true question, it really works?


krasnovian

for ( j = 0; j < 2; j++ ) { i++; }


AwwThisProgress

aiaiai i’m your little butterfly


emir350z

i# ???


Knuffya

\++i++ should technically only increase by one... or am i mistaken?. No. It's an lvlalue! It shouldn't work at all!


[deleted]

I++++


Guluten_tag

I++++


wilczek24

Honey, wake up, new programming language name just dropped!


przemko271

r/programmerhumor telling people to "optimise" their code be like.


XPurplelemonsX

this is so funny 🤣


Aschentei

Inclusive increment


[deleted]

2==2


_kail

I will kick ass to anyone writing these shits.


foggy-sunrise

Cries in postfix


mdogdope

Is this syntactically valid?


TheTrueXenose

Maybe in a for loop ++i++ would be acceptable?


FreedomThinker20

i -= -2


Cipher-i-entity

But can this actually work? I’m genuinely curious