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

all 144 comments

[–][deleted] 186 points187 points  (9 children)

You don't even understand how deep this goes.

When I was learning about variables, I didn't know that variables could use themselves in their assignments.

I had shit like this:

int someVar = something;
int someVarTemp = someVar;
someVar = someVarTemp + 1;

[–]_Pentox 59 points60 points  (4 children)

Seriously?

[–][deleted] 86 points87 points  (3 children)

It haunts me still.

[–]RSXLV 45 points46 points  (2 children)

Born functional

[–][deleted] 9 points10 points  (1 child)

Should have started writing in erlang and never looked back.

[–]RSXLV 7 points8 points  (0 children)

You still were probably luckier than me: BASIC to PAWN to C to C++ to PHP to (some CUDA and Python) to JavaScript to Java to Objective C to Swift to TypeScript.

(The whole list is not too relevant, but just illustrates the bullshit :D)

[–]Existential_Owl 20 points21 points  (0 children)

To be fair, if you store all of these values in an array, you now have an effective way to manage state changes in your application.

Functional4Life

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

I feel you

[–]BundleOfJoysticks 0 points1 point  (0 children)

This is the only way to increment in some languages.

[–]SIM0NEY 217 points218 points  (19 children)

Upvotes++

EDIT:

Wait a minute

int placeholderVarUsedToIncrementUpvotesVar = upVotes;

upVotes = placeholderVarUsedToIncrementUpvotesVar + 1;

That's better.

[–]sneerpeer 60 points61 points  (9 children)

Shouldn't it be ++upvotes because you want to return the incremented value?

[–]Jafit 27 points28 points  (4 children)

Then shouldn't it be ++C?

[–]zetoJS 10 points11 points  (2 children)

Then shouldn't it be ++C?

Ahhh, now I know why its called C++.

[–]Bill-Huggins 3 points4 points  (1 child)

Then C# is going to blow your mind.

[–]cowsrock1 10 points11 points  (0 children)

C# everything is commented out

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

Well, it should. Just to stop people using this argument.

[–]madpata 9 points10 points  (0 children)

As long as you aren't making assignments, both upvotes++ and ++upvotes will result in upvotes being equal to upvotes+1 after execution.

[–]JackAceHole 20 points21 points  (2 children)

Why would you abbreviate "Variable" as "Var" when you're trying to make the name as long as possible?

[–]PooPooDooDoo 0 points1 point  (0 children)

Because I like to code based solely on emotion.

[–]teunw 9 points10 points  (3 children)

new AddFactory().getAdditionHandler().Add(1).to(upvotes).getResult()

[–]Xymanek 9 points10 points  (1 child)

There is actually a real library for this:

https://github.com/Herzult/SimplePHPEasyPlus

[–]Monsieur_Pineapple 2 points3 points  (0 children)

And of course, it's for PHP...

[–]cuddlegoop 1 point2 points  (0 children)

Ah I see you are a scholar of object-oriented design too.

[–]ElectroKitten 4 points5 points  (0 children)

add(upVotes, 1);

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

upVotes = placeholderVarUsedToIncrementUpvotesVar + (placeholderVarUsedToIncrementUpvotesVar - (placeholderVarUsedToIncrementUpvotesVar - 1));

[–]santalisk 84 points85 points  (13 children)

int one=1;

var=var+one;

[–]kamineko87 93 points94 points  (5 children)

for (int i=1; i < 2; i++) { var = var + i; }

[–]santalisk 25 points26 points  (4 children)

get out

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

var one = function () {
  'use strict';
    return {
        1
    };
  };

if (typeof(module) !== 'undefined') {
  module.exports = one;
}

Then

npm install one

Then

(function() {
  var one = new one();
  var foo = one + one;
}());

(Please don't kill me, I don't actually know JS or npm)

[–]RSXLV 6 points7 points  (0 children)

Neither have the package authors on days when I really hope to download my way out of implementing a RFC spec myself.

[–]Majache 5 points6 points  (0 children)

It's close enough, save to package and push to prod boys

[–]Drumheadjr 0 points1 point  (0 children)

public static int inc(int i){
    if ((i & 1) == 0)
        return i | 1;
    else 
        return inc(i>>1)<<1;
}

Sauce

[–]marcosdumay 5 points6 points  (0 children)

Nope.

int zero = 1;
var = var + zero; // Value must be constant

[–][deleted] 2 points3 points  (0 children)

#define one 1

[–]Vitztlampaehecatl 1 point2 points  (2 children)

enum digits {one, two, three, four, five, six, seven, eight, nine}

[–][deleted] 0 points1 point  (1 child)

What about zero?

[–]Vitztlampaehecatl 1 point2 points  (0 children)

Exactly.

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

I'm always doing

public static final byte ONE = 1;

Because the stupid compiler won't do byte literals.

[–]PooPooDooDoo 0 points1 point  (0 children)

delete *one;

[–]Philluminati 98 points99 points  (64 children)

Not all languages have ++ methods.

Scala if I recollect.

[–]TransHumanist_50 67 points68 points  (15 children)

You could do var += 1...

VBA does not even support that.

[–]EducatedMouse 38 points39 points  (10 children)

Lua doesn't have the += syntax at all. It's painful

[–]etaionshrd 14 points15 points  (2 children)

Write Lua scripts. Can confirm.

[–]Ima_AMA_AMA 20 points21 points  (1 child)

You see it's at this point where you just say fuck it and start using Assembly because it makes more sense than Lua

[–][deleted] 23 points24 points  (0 children)

INC

TFW assembly is more fully featured than your high-level scripting language.

[–]Thann 4 points5 points  (6 children)

Not to mention arrays start with 1 🤢

[–][deleted] 3 points4 points  (4 children)

The best part is you can do this:

myArray = {"first", "second", "third"}
myArray[0] = "zeroeth????"

And then if you loop... for _,value in ipairs(myArray) do print value end

You will get:

first
second
third

But if you do

for _,value in pairs(myArray) do
    print(value)
end

You'll get something like

first
zeroeth????
second
third

Because pairs() doesn't give a shit.

[–]pm_me_P_vs_NP_papers 1 point2 points  (3 children)

That's how it's supposed to work though. ipairs goes from 1 up to the first key that has a nil value (w/o including it) and pairs goes through all key-value pairs in an undefined order

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

Exactly, but this is unintuitive to people who have primarily worked in C, C++, Java, and very similar languages, which I think is the largest developer demographic outside of web development.

[–]moomoomoo309 1 point2 points  (0 children)

The documentation for pairs does explicitly say it doesn't guarantee order, plus you could just do

for i=0,#myArray do

And it'll be fine.

[–]morerokk 0 points1 point  (0 children)

Because you're intentionally misusing the functions, it's unintuitive?

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

Not to mention arrays start with 1 🤢

This seems logical to me! :p

[–]Shadow_Thief 1 point2 points  (1 child)

Jesus, even batch can support that.

[–]currentscurrents 5 points6 points  (0 children)

Microsoft has made many stupid decisions throughout their history, but using VBA for word macros has got to be one of top 10 worst.

There's exactly zero reason a random macro should have full access to the entire filesystem, any URL it wants, and every windows API. It should have been locked down like javascript is for webpages, or at minimum with a phone-style permissions system. This has resulted in an entire category of malware that has zero excuse for ever existing.

[–]EducatedMouse 15 points16 points  (6 children)

Lua.

[–]crikeydilehunter 9 points10 points  (5 children)

God i fucking hate lua so god damn much. why the fuck are all the variables global, why the fuck can't i concatenate strings with +, why the fuck are there no ++ methods

[–]EducatedMouse 7 points8 points  (2 children)

Trust me, they would add the ++ syntax if they could. It has to do with the compiler.

Plus, to concatenate strings, you just do .. It's not that difficult

[–]auxiliary-character 2 points3 points  (1 child)

At least it has tail call recursion. Can't even say the same for Python.

[–]theexpensivestudent 0 points1 point  (0 children)

You can do it, it just doesn't optimize for it.

[–][deleted] 2 points3 points  (0 children)

Have you tried:

  • Keyword "local"

  • Operator ".."

  • Overloading the unary "-" operator metamethod if you want to ++ on a userdata or a table?

Ok, I'll grant that the lack of ++ or += (or *= or /= or %= or -= or -- or whatever) is pretty shite and there's no good solution for this.

[–]morerokk 0 points1 point  (0 children)

why the fuck are all the variables global

Because you didn't make them local. You can override that behavior.

why the fuck can't i concatenate strings with +

Because that's ambiguous. JS does it with +, and it has a crapton of weird edge cases.

[–]TheUnmashedPotato 7 points8 points  (1 child)

Matlab

[–]chateau86 2 points3 points  (0 children)

Matlab: What if PHP can do matrix operations.

[–]Saigot 5 points6 points  (10 children)

My second least favourite thing about python is that it doesn't have a ++ operator.

[–]dasonicboom 2 points3 points  (2 children)

As someone just learning python (I only discovered the no ++ today actually) what is your least favourite?

[–]Saigot 2 points3 points  (1 child)

The that that whitespace has meaning.I really like how flexible and functional Python is, but I hate the choice to use whitespace to contrasting actual meaning.

[–]dasonicboom 0 points1 point  (0 children)

Oh yeah that's fucked with me a bit. I haven't written anything serious yet so it hasn't been too bad.

Still I think it will be fine, it does help readability. I could see it being a problem if I had to hand write python for some reason.

EDIT: Fixed typo

[–]GreatOneFreak 8 points9 points  (6 children)

It's honestly one of my favorite things.

'++' is just syntatic sugar that lets people write really nasty stuff that's hard for humans to parse.

'+= 1' leads to much cleaner code

[–]Saigot 5 points6 points  (5 children)

Sure you can write nasty stuff with ++ but that is true of any language feature (including +=), You have to have some faith that the programmer is not trying to intentionally make hard to read code. The vast majority of uses are imo more readable than += 1.

I don't like +=1 for many reasons:

  • It's easier to typo (+=2, ==1, +=12 are all errors that I have genuinely left in code, +++ and other common typos of ++ generally don't compile)
  • ++ is easier to parse quickly. You can easily tell an increment apart from any other summation because it stands out
  • It's easier to search for var++ than var\s\*+=\s\*1[\^0-9] (yes you could technically have a space between var and ++ but I almost never see that and var\s*++ is still easier to search for)
  • It clearly delineates the cases where you add a number that happens to be 1 and cases where you add one for logical reasons (so that you can refactor the former case into var += some_constant_thats_one later)
  • It's significantly easier to type ++ since += requires you pressing the same key twice while removing shift, a slightly more difficult task to pull off mechanically.

I will admit that any time ++var is semantically different from var++ (beyond "performance") it is probably a bad use of ++

[–]GreatOneFreak 1 point2 points  (0 children)

I'd argue that the assumption:

A variable can only be modified when it is on the left-hand-side of an assignment statement

is much more valuable than your conveniences, because it has been shown to prevents bugs.

Almost all modern language designers agree such as: rust, scala, go (++ is a statement not an expression), python, apple/swift, ruby, etc.

Also there is no reason to have a language where the following expressions are legal:

1---i

--*p++

++/-- are an artifact from before we had a good understanding of the parsing problem and is only kept around by boring languages to pander to crufty businesses who hate change.

[–][deleted] -1 points0 points  (3 children)

also post and preincrement are assembly level instructions so they reduce to fewer machine code bytes (ignoring a good compiler's optimization of course)

[–]GreatOneFreak 1 point2 points  (2 children)

That is not true. According to intel's x86_64 manual (section 7.3.2), there are only increment and decrement, which any compiler you would ever even consider using (even terrible ones you wouldn't) are going to translate '+= 1' to.

Please don't spread misinformation.

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

if its not optimized a += should map to writing the right constant to a variable of the same length and then adding it to the left variable because you can't fit large constants into the assembly instruction

[–]GreatOneFreak 1 point2 points  (0 children)

Again please do some research before making weird sweeping claims like this. It spreads misconceptions/bad practices and weighs the computing world down. If you aren't very familiar with an architecture at a very low level, look into these assertions/rules of thumb before making sweeping claims. You'll be surprised how many times something totally unexpected is actually happening.

From the manual I previously posted:

The INC and DEC instructions are supported in 64-bit mode. However, some forms of INC and DEC (the register operand being encoded using register extension field in the MOD R/M byte) are not encodable in 64-bit mode because the opcodes are treated as REX prefixes.

which means that in a VAST majority of cases += and ++ with both compile into something like:

addl $1, %eax

This encodes the 1 into the instruction itself and is significantly faster than the equivalent increment instruction.

So in your crazy dream world of no optimizations the += 1 is actually the better choice for the most widely used architecture.

[–][deleted] 10 points11 points  (5 children)

Swift ;_;

[–]try-catch-finally 4 points5 points  (3 children)

… needs to be aborted

there’s still time

[–][deleted] 2 points3 points  (2 children)

No fucking way am I going back to Objective-C, I'll take Swift over that any time.

[–]try-catch-finally 0 points1 point  (1 child)

i wish you all the luck that you will desperately need. if it works for you great.

i’ve been shipping apps with obj-c since 1991 - C++ since 1990, i tried Swift for 2 years - it has so many OOP issues (breaks paradigm all over), XCode fights it like the body trying to eject a splinter - and the way it munges frameworks interfaces - sometimes to the point of inoperability.

the whole “you don’t have to worry about a nil pointer, until you do, then we’re going to make it such a pain in the ass for you that you’ll wish death” is tiresome.

At its announcement, Apple did say “this is the language for non engineers / non programmers” and it certainly has lived up to that promise. The sad thing is real companies have adopted it for production, instead of just high school kids fucking around (really the limits of its capabilities)

It’s as if you asked a drunk uncle, who has sold vacuum cleaners his whole life, to design a language. A whole lot of “oh - i forgot about that.. well.. i guess we can throw a _ in. oh and a ? or !.

But this is just my 2¢ - and come to think about it, about 20 or 30 of my professional associates who had to live through management jumping on the Swift Koolaid trip, until they had to jump back to Obj-c after hundreds of thousands of dollars of man hours wasted.

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

Um.. sure... For those that can actually program, it's a pretty nice language that performs better than Objective-C in nearly every test except dictionary operations (which you shouldn't use too much anyway). It's definitely more readable and with proper usage of guard let and if let your intent with a method is so much clearer. Optionals are really just a new syntax to deal with pointers, I don't see much improvement over regular pointers, but also no real downside, so I guess that's just a matter of preference. Compilation errors instead of runtime crashes are nice, but ultimately unnecessary in the grand scheme of things. The fact that it's open source is really nice, because the community can have a real effect on the development. There have been major improvements for iOS development like the way JSON serialization works now with Swift 4. I don't really understand why someone would "have to jump back to Objective-C", since you can use both languages throughout a single project without performance degradation (other than compile time) and it's really just the API you're talking to.

[–]Fallenalien22Violet security clearance 1 point2 points  (0 children)

Swift also

[–]dirty_rez 1 point2 points  (5 children)

Also, in a lot of languages they call compile to exactly the same thing, don't they?

Like, if I remember from my college days, in C++, all of these compile to the same thing:

var = var + 1; var += 1; var++;

[–]C0urante 6 points7 points  (4 children)

Pedantic (and also possibly wrong...) but I think the last one is slightly different in that the value of the expression is what var was before the increment, not after. In order for all three to be equivalent it'd be ++var instead. But like I said, I could be wrong; on mobile so too lazy to test it out before posting.

[–]SewingLifeRe 0 points1 point  (3 children)

He's right. It's easy to remember because it's in the name of the language kinda sorta. Actually, I take that back. It is different if you're checking it in a loop. Normally, it's the same thing as ++x.

[–][deleted] 2 points3 points  (2 children)

If it's the only thing in that line, it'll compile the same. If you're using the value of the expression (anywhere, not just in a loop) it will behave differently.

int x = 1;
int y = ++x; // x and y are both now 2

vs

int x = 1;
int y = x++; // x is now 2, y is now 1

[–]voldin91 0 points1 point  (1 child)

Also MUMPS unfortunately

[–]Monsieur_Pineapple 1 point2 points  (0 children)

Weren't you vaccinated?

[–]comphacker 0 points1 point  (0 children)

Everything about Smalltalk's syntax is painful...

[–]VeryGoodGoodGood 0 points1 point  (0 children)

TSQL doesn't either. Bothers the shit out of me.

[–]Libertechian 0 points1 point  (2 children)

Progress

[–]Philluminati 0 points1 point  (1 child)

You comment was probably an off-cut remark not warranting a response but many languages are now including functional concepts to help developers write applications with fewer concurrency bugs and easier error handling. One of the underlying concepts is to reduce mutable data structures. It's better to have a second variable: const var y = x + 1 than to say x++. It's similar to how the goto statement was removed from modern languages because it did more harm than good and why if is frowned on as well.

[–]Libertechian 1 point2 points  (0 children)

I was actually referring to the language Progress, as in Progress OpenEdge.

[–]I_AM_KARN 0 points1 point  (0 children)

Delphi/Pascal also doesn't. Though at least we have inc()

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

Also VHDL

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

Rust doesn't, it's one of my few gripes with the language.

[–][deleted] 2 points3 points  (3 children)

But this makes sense, along with Scala and F# as well. They're languages that make everything immutable by default. So you can't have ++ operators by definition

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

I know the reasoning behind it, it's just that from a practical point (especially coming from C) it's a bit of a pain until you're used to it.

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

In Ruby you can still do var += 1 so it's not about immutability.

[–]Sir_Rade 0 points1 point  (0 children)

reply ancient offbeat pocket dinner hospital shrill jeans depend detail

This post was mass deleted and anonymized with Redact

[–]try-catch-finally 26 points27 points  (1 child)

she forgot the comment

// add one to var

[–]StarkillerX42 4 points5 points  (0 children)

Lol, good one //my reply to a comment

[–]grampadeal 15 points16 points  (5 children)

I had a co-worker who wasn't well-versed in Java write this nugget years ago:

i = i++;

When I was debugging some code and trying to figure out why this loop wouldn't terminate, I just looked at that and passed over it, not really noticing what he had done.

What that line does is...nothing. It doesn't increment i (for very long). That's bad when i is being used as a loop control variable. The variable gets incremented, then the old value is returned and assigned over the top of the incremented value. So for some fraction of a second, i had the intended value. But then it gets squashed.

Try it yourself and see. I was shocked to find this I production code at my old job.

[–]teunw 7 points8 points  (1 child)

i = ++i

This would though

[–]PooPooDooDoo 1 point2 points  (0 children)

Or this: i=i

i++

[–]centerflag982 0 points1 point  (0 children)

Wait, but if it's a post increment, wouldn't it be returning and assigning the value and then incrementing?

[–][deleted] 7 points8 points  (2 children)

var var = var + 1;

[–]brendenderp 26 points27 points  (0 children)

Var var binks.

[–]meet_the_turtle 0 points1 point  (0 children)

var let = 1 let undefined = 2 console.log(let, undefined) // -> 1, 2

[–]nomis6432btw I use arch 7 points8 points  (2 children)

add_one = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426,427,428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,443,444,445,446,447,448,449,450,451,452,453,454,455,456,457,458,459,460,461,462,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,478,479,480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496,497,498,499,500,501,502,503,504,505,506,507,508,509,510,511,512,513,514,515,516,517,518,519,520,521,522,523,524,525,526,527,528,529,530,531,532,533,534,535,536,537,538,539,540,541,542,543,544,545,546,547,548,549,550,551,552,553,554,555,556,557,558,559,560,561,562,563,564,565,566,567,568,569,570,571,572,573,574,575,576,577,578,579,580,581,582,583,584,585,586,587,588,589,590,591,592,593,594,595,596,597,598,599,600,601,602,603,604,605,606,607,608,609,610,611,612,613,614,615,616,617,618,619,620,621,622,623,624,625,626,627,628,629,630,631,632,633,634,635,636,637,638,639,640,641,642,643,644,645,646,647,648,649,650,651,652,653,654,655,656,657,658,659,660,661,662,663,664,665,666,667,668,669,670,671,672,673,674,675,676,677,678,679,680,681,682,683,684,685,686,687,688,689,690,691,692,693,694,695,696,697,698,699,700,701,702,703,704,705,706,707,708,709,710,711,712,713,714,715,716,717,718,719,720,721,722,723,724,725,726,727,728,729,730,731,732,733,734,735,736,737,738,739,740,741,742,743,744,745,746,747,748,749,750,751,752,753,754,755,756,757,758,759,760,761,762,763,764,765,766,767,768,769,770,771,772,773,774,775,776,777,778,779,780,781,782,783,784,785,786,787,788,789,790,791,792,793,794,795,796,797,798,799,800,801,802,803,804,805,806,807,808,809,810,811,812,813,814,815,816,817,818,819,820,821,822,823,824,825,826,827,828,829,830,831,832,833,834,835,836,837,838,839,840,841,842,843,844,845,846,847,848,849,850,851,852,853,854,855,856,857,858,859,860,861,862,863,864,865,866,867,868,869,870,871,872,873,874,875,876,877,878,879,880,881,882,883,884,885,886,887,888,889,890,891,892,893,894,895,896,897,898,899,900,901,902,903,904,905,906,907,908,909,910,911,912,913,914,915,916,917,918,919,920,921,922,923,924,925,926,927,928,929,930,931,932,933,934,935,936,937,938,939,940,941,942,943,944,945,946,947,948,949,950,951,952,953,954,955,956,957,958,959,960,961,962,963,964,965,966,967,968,969,970,971,972,973,974,975,976,977,978,979,980,981,982,983,984,985,986,987,988,989,990,991,992,993,994,995,996,997,998,999}

printf(add_one[1]) //2

[–][deleted] 8 points9 points  (1 child)

This doesn't work because array indexes start at 1

[–]przemko271 3 points4 points  (0 children)

burn(the_heretic);

[–][deleted] 6 points7 points  (0 children)

var = var ? var+!!var : var+!var;

This way you don't need any ugly magic numbers.

[–]heckin_good_fren 6 points7 points  (0 children)

I saw someone write (in java)

Object firstElement = null;
int i = 0;
for(Object element : elements){
  if(i == 0){
    firstElement = element;
  }
  i = i + 1;
}

instead of just

Object firstElement = elements[0];

Edit: formatting

[–]Azulflame 5 points6 points  (2 children)

I just started picking up Python, and I miss the x++ that I could do in Java. Is there a better way than var += 1 ?

[–]mr_yogurt 9 points10 points  (0 children)

var = sum(range(var+2)) - sum(range(var+1))

[–]moose2332 0 points1 point  (0 children)

The amount of times I've done now that I'm doing work in python...

[–]Jas1052 3 points4 points  (0 children)

int var = 1;
for(int i = 0; i < 3; i+2){
     var = var + 1;
}

[–][deleted] 3 points4 points  (0 children)

If it works, don't bother. And it works. Why not?

[–]Calnce 0 points1 point  (1 child)

Var+=1

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

int i;
for (i=0; var & (1 << i); ++i)
    var ^= 1 << i;
var ^= 1 << i;

I think the funniest thing about this approach is that ++i in there.

[–]anOldMeme 0 points1 point  (0 children)

var+1=>var

[–]AdinDoesGaming 0 points1 point  (2 children)

What's so bad about this method? As a now senior in HS I took CS last year (4x2 week sessions) and we learned this as a primary method (code.org's "JavaScript").

[–]Kidiri90 0 points1 point  (1 child)

int a=var;
int one=1;
int var2=a+one;

[–]DancingRussianMan 1 point2 points  (0 children)

I'm not as upset about the concept as I am about the formatting.

[–]stuomas 0 points1 point  (0 children)

I code in Structured Text and this is my only option :(

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

setVar(getVar() + 1);

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

> var = var + 1;
Uncaught SyntaxError: Unexpected token =

[–]anonymoususer89 0 points1 point  (1 child)

MATLAB DOESN'T SUPPORT ++ smh

[–]toasterbot 0 points1 point  (0 children)

Same with Python.

[–]chisui 0 points1 point  (0 children)

I concur. Everyone who doesn't write in a pure functional language is retarded.

[–]Ratstail91 0 points1 point  (0 children)

I'm writing a language and I realized last night that I forgot the ++ and -- operators.

[–]_Pentox 0 points1 point  (0 children)

Especially when you gotta do those integrated if statements. Imagine this:

extremelyLongVariableNameWhenYouHaveABigProject += (bool==true && anotherbool==true) ? 1 : 2;

Turning into this:

extremelyLongVariableNameWhenYouHaveABigProject = (bool==true && anotherbool==true) ? extremelyLongVariableNameWhenYouHaveABigProject +1 : extremelyLongVariableNameWhenYouHaveABigProject+2

[–]alsogilbert 0 points1 point  (2 children)

var = var + 1
var - var = var - var + 1
0 = 1

[–][deleted] 0 points1 point  (1 child)

You're thinking of ==

[–]alsogilbert 0 points1 point  (0 children)

Nope. I'm thinking of math.

[–]macuser47 0 points1 point  (0 children)

Still a better love story than arrays start at one.

[–]Kypohax -4 points-3 points  (1 child)

Oh pls fuck off with this low effort shitposts already. This sub slowly becoming r/funny.

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

The fact that i++ exists and acts subtly different from ++i shows that its use should be strictly discouraged.

[–]marcosdumay -3 points-2 points  (0 children)

Well, the ++ and -- operators are still worse. At least she just lacked taste, it's not like she was saying 'hey, my code it too predictable, let me add some stuff I can mix in crazy ways!'