Programming Thread

Viewing single post

Started by the-pi-guy, Mar 13, 2016, 10:39 PM

previous topic - next topic

ethomaz

Mar 28, 2016, 04:16 PM Last Edit: Mar 28, 2016, 04:20 PM by ethomaz
Haven't used C#, but from what I've seen it looks a lot like Java.

Some random person says this:Same.  :P
I spent like half an hour, only to find the fix is putting it on the other side. 
I pretty much always write it like foo++, but this apparently needed to be written ++foo.  Not exactly sure why. 
There are differences.

++var add first and return the val after

var++ return the val first and add after

Eg.

a = 1
b = ++a 
// result b = 2 ; a = 2

a = 1
b = a++
// result b = 1; a = 2

It is weird but that is what happen in most modern languages.

And the languages are dropping this ++ -- notation... this sintax will be deprecated soon.

Edit - A good explanation why modern languages are dropping ++ --

https://github.com/apple/swift-evolution/blob/master/proposals/0004-remove-pre-post-inc-decrement.md

Swift 2.0 didn't compile with ++ or -- code anymore.