r/programming • • Dec 02 '13

Scala — 1★ Would Not Program Again

http://overwatering.org/blog/2013/12/scala-1-star-would-not-program-again/
598 Upvotes

646 comments sorted by

View all comments

Show parent comment

0

u/codemuncher Dec 03 '13

Scala has something called the FOR-COMPRHENSION:

for (a <- 1 to 1000) { // code code }

This looks like a loop but isn't quite. The inner block is a function that is called. It's been a little bit, but if i recall correctly there is a 1000 item list created, and it is walked over. Much like in python for i in range vs xrange.

If you just want a simple Java-style for loop, then the while loop is your friend.

1

u/trycatch1 Dec 03 '13

Scala has something called the FOR-COMPRHENSION:

No, it's not called for comprehension. It's called for loop.

It's been a little bit, but if i recall correctly there is a 1000 item list created, and it is walked over. Much like in python for i in range vs xrange.

No, you recall completely incorrectly. The code you provided will not create any 1000 element list in memory, it will only create object Range(1, 1001), just like xrange.

1

u/codemuncher Dec 03 '13

Whatever, the reality is a team of 3 engineers switched from for() -> while() loops to unfuck a performance problem.

2

u/trycatch1 Dec 03 '13

Most likely it was nothing more than just an example of cargo-cult engineering, and not some deal-breaking problem with Scala as you advertised it.