Live data from Hacker News

How Scala Changed My Programming Style

artima.com

1–10 of 21 posts

Re: How Scala Changed My Programming Style

#4

I have no idea why anyone would use ++i (though technically correct) instead of i++ in a for loop's incrementation clause since the incrementation is done after the loop body, not before... That just seems like willfully confusing intuition.

If you were confused in such a way you'd end up thinking that i would be incremented with "i++" before the loop body ran. For "++i" to be confusing would be seriously messed up.

Re: How Scala Changed My Programming Style

#5
A lot of the "OMG Scala The essential idea behind the post is this: using a language like Scala can make you use a mainstream language like C# or Java differently. By using a language that makes immutability the default it teaches you when mutable state is actually necessary and when it isn't. This will lead you to write code in whatever normal language that also has less mutable state, and fewer side effects. It will therefore be easier to test and have fewer bugs.

And, no, I have not written any Scala books and have no Scala-related products/services to sell you.

Re: How Scala Changed My Programming Style

#6

I have no idea why anyone would use ++i (though technically correct) instead of i++ in a for loop's incrementation clause since the incrementation is done after the loop body, not before... That just seems like willfully confusing intuition.

I think using ++i instead of i++ everywhere is clearer, actually -- there's no need to think about temporaries, and the order of evaluation is (marginally) more transparent.

Not that pre- and post-increment are ever that intuitive or transparent...

Re: How Scala Changed My Programming Style

#7

I have no idea why anyone would use ++i (though technically correct) instead of i++ in a for loop's incrementation clause since the incrementation is done after the loop body, not before... That just seems like willfully confusing intuition.

look at for loops like this: for (FOO; BAR; BAZ) { BODY }

as: FOO; while (BAR) { BODY; BAZ; }

Hence, ++i and i++ mean the same in this context. The difference, as mentioned already, is that i++ creates a copy of i.

Re: How Scala Changed My Programming Style

#9

I have no idea why anyone would use ++i (though technically correct) instead of i++ in a for loop's incrementation clause since the incrementation is done after the loop body, not before... That just seems like willfully confusing intuition.

look at for loops like this: for (FOO; BAR; BAZ) { BODY } as: FOO; while (BAR) { BODY; BAZ; } Hence, ++i and i++ mean the same in this context. The difference, as mentioned already, is that i++ creates a copy of i.

Uh? Maybe with a brain-damaged compiler?

Re: How Scala Changed My Programming Style

#10

Earlier quoted context omitted.

look at for loops like this: for (FOO; BAR; BAZ) { BODY } as: FOO; while (BAR) { BODY; BAZ; } Hence, ++i and i++ mean the same in this context. The difference, as mentioned already, is that i++ creates a copy of i.

Uh? Maybe with a brain-damaged compiler?

Or with C++. There's no reason to adopt i++ sometimes and ++i other times depending on what the type is.
Post reply on HN