Live data from Hacker News

How Scala Changed My Programming Style

artima.com

11–20 of 21 posts

Re: How Scala Changed My Programming Style

#11

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.

Using i++ was the recommended practice before C++ came along and let people change what i++ means. That convention was even the reason it's C++ and not ++C.

In C++, it's suggested to do ++i because it will sometimes result in fewer calculations if i is an object with overloaded increment operators.

Re: How Scala Changed My Programming Style

#12
post #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 wil…

"A lot of the "OMG Scala My guess would have been that they were excited about Scala before they wrote the book.

Re: How Scala Changed My Programming Style

#13

I can't describe how happy I'll be when we have lambdas in C++. Them + the STL will be a very lightweight gateway drug into functional programming for a lot of programmers.

With a special meaning for 'lightweight'. (C++ itself is quite heavy, but people are accustomed to it already.)

Re: How Scala Changed My Programming Style

#14

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 use ++i in for loops because pre-incrementing is the semantically correct option. I've never understood why i++ came into favor; can anyone shine some light on it for me?

Re: How Scala Changed My Programming Style

#15
1. "I enjoy the benefits of static typing such as types as documentation"

Documentation as a side effect of types is somehow better than a system designed for good documentation?

"code completion in IDE"

See 1

"execution speed"

See LuaJIT, Self, Javascript ... etc

The reasons people often give to justify losing (types) so much flexibility (late binding) never add up to me.

Re: How Scala Changed My Programming Style

#16

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 use ++i in for loops because pre-incrementing is the semantically correct option. I've never understood why i++ came into favor; can anyone shine some light on it for me?

My hypothesis: it has better rhythm -- the repetition of 'i' at the beginning of each piece of the for loop makes it nice and easy to remember. I bet people would tend to learn this when they were first learning how to code and then never change because it never caused them any problems.

Re: How Scala Changed My Programming Style

#17

Earlier quoted context omitted.

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.

C++ copies values differently (or at all) for different types under prefix increment vs. postfix increment? Seriously?

Re: How Scala Changed My Programming Style

#18

Earlier quoted context omitted.

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

C++ copies values differently (or at all) for different types under prefix increment vs. postfix increment? Seriously?

Yes. When overloading prefix and postfix increment, there are two functions to write, and the postfix version returns a copy of what you've incremented. It's impossible for a compiler to optimize this away in the general situation.

Re: How Scala Changed My Programming Style

#19
post #13

I can't describe how happy I'll be when we have lambdas in C++. Them + the STL will be a very lightweight gateway drug into functional programming for a lot of programmers.

With a special meaning for 'lightweight'. (C++ itself is quite heavy, but people are accustomed to it already.)

In terms of cognitive load.

Re: How Scala Changed My Programming Style

#20
post #11

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.

Using i++ was the recommended practice before C++ came along and let people change what i++ means. That convention was even the reason it's C++ and not ++C. In C++, it's suggested to do ++i because it will sometimes result in fewer calculations if i is an object with overloaded increment operators.

Is this true? It was never explained to me this way, and it doesn't make much sense. The increment will always be performed unless it can be optimized away. In places where the two are equivalent, using i++ might impose a space penalty if you have to store both values, which can be a significant consideration for large objects. I don't know what you mean by "change what i++ means" since you can't redefine ++ for any types for which it has a meaning in C. (Or maybe you can, but I wouldn't know because it would never done in sanely written code; the possibility definitely isn't taken into account in any C++ coding recommendations I've read.)

Mainly I was taught that situations that require i++ are less common, more subtle, and easier to get wrong, so programmers should make them stand out by using ++i everywhere else.

Post reply on HN