Live data from Hacker News

Choosing Scala

teaching.software-carpentry.org

31–40 of 65 posts

Re: Choosing Scala

#31

I really want to understand what the fuss is about with Scala so I fired up a REPL and found a tutorial and went to work. Then I can across this: scala> print("5" + 5) 55 And I stopped there (for now). At least my C++ compiler will warn about that (although it will still compile even if it doesn't print anything save for the newline): #include using namespace std; int main(int argc, char *argv[]) { cout Python gives…

Scala inherits essentially all its expression syntax from Java, including the string +. This was done because a lot of other things in Scala are new, so we did not want to rock the boat too much with changes that might seem arbitrary. That said, I believe string + is probably the most criticized feature in Scala's expression syntax. People are generally moving away from it, towards String interpolation, which is avai…

Fair enough. Thanks for the answer. :)

Re: Choosing Scala

#32
I don't come from a CS background, but I have been programming professionally many years and recently got started with Scala. I had tried Go before and I like Go. I also really like Scala.

Scala requires much more work to learn than Go. I don't think I ever ventured out much from the offical Go documentation, the spec and effective Go and the library documentation to learn Go. With Scala I've already bought 3 books, and have bookmarked nearly 100 sites. I frequently have very many tabs opened with various scaladocs, examples and stackoverflow questions open.

My favorite thing in Scala is Akka. I quite like Akka and I like the functional programming that's possible with Scala. The build tools, like sbt require getting used to but I'm able to pretty much get along just fine without an IDE. I do have intellij open but I hardly look at it. I do all coding in vim and testing with sbt.

About 14 days in and I can connect to TCP and parse JSON ok. That's where I'm at. There have been some pretty frustrating moments, mostly dealing with 3rd party libraries (like scalaz, not documented much) and sbt, but once overcome it feels rewarding.

My other favorite things in scala: it has a REPL, s"String $interpolation" and pattern matching.

Re: Choosing Scala

#33
post #32

I don't come from a CS background, but I have been programming professionally many years and recently got started with Scala. I had tried Go before and I like Go. I also really like Scala. Scala requires much more work to learn than Go. I don't think I ever ventured out much from the offical Go documentation, the spec and effective Go and the library documentation to learn Go. With Scala I've already bought 3 books,…

[deleted]

Re: Choosing Scala

#34
If anyone wants to get a taste of Scala, and don't want to install anything, I created http://scalatutorials.com/tour, (no sign up, no installation, 100% free and open source) with syntax coloring and lightning fast execution of code (thanks to scalakata.com, and Scala's presentation compiler) If it looks familiar, I was a "bit" inspired by the "Tour of Go"

Re: Choosing Scala

#35

I really want to understand what the fuss is about with Scala so I fired up a REPL and found a tutorial and went to work. Then I can across this: scala> print("5" + 5) 55 And I stopped there (for now). At least my C++ compiler will warn about that (although it will still compile even if it doesn't print anything save for the newline): #include using namespace std; int main(int argc, char *argv[]) { cout Python gives…

The problem is that you don't understand Scala operators. There are none. That + sign there is simply the name of a method in the class of the object preceding it.

So you invoked print("5".+(5))

What else would you expect. The nice thing about Scala is that you can leave out some of the extra syntax that is not needed for the compiler to decode the meaning.

Now as for why the String class has a + method to do string concatenation? I don't know but this is far from the first language that I have come across that conflates string concatentation with numeric addition. Maybe it comes from the Java libraries? In any case, it is not really a problem to most people because we follow the maxim, if it hurts, DON'T DO THAT!

Re: Choosing Scala

#36

Earlier quoted context omitted.

Because it crosses type boundaries. One would normally expect the plus method of Ints to only work on Ints, and similarly Strings for Strings.

Well, why? I mean, I'm so used to work in Java which has the same behaviour, so I may have been totally unable to see the problem due to the familiarity of that code, maybe, but I still don't understand the problem. First, let state the basis: the meaning of the + operator is overloaded. For numeral types, it makes the sum of the operands. For string, it concatenates them. These are two different meanings in differen…

The thing is, it's not just an overload; it's an overload and a typecast. Those are two separate questions, and OP is really complaining about the typecast, not the overload.

The ints vs. floats thing is kind of a red herring. In that specific case, at least you're still talking about numbers. The argument against having contagion for 5 + 5.5, and overloading for "5" + "5.5", but throwing an exception for "5" + 5.5 is that the first is a pair of numeric types, the second is a pair of strings, but the third is a pair of unrelated types. You can say white is lighter than black, and a feather is lighter than an anvil, but you can't say that white is lighter than an anvil because that's nonsense.

Incidentally, this is why, say, Python and Ruby (and I imagine Lisp) people insist upon the distinction between dynamically typed and weakly typed. If I fire up a node.js repl, I find that '50' + 5 is '505', but '50' - 5 is 45, and am reminded why JavaScript drives me nuts. In the extreme you get things like [this](http://phpmanualmasterpieces.tumblr.com/post/33198366857/lay...) and [this](https://www.destroyallsoftware.com/talks/wat). I realize that Java probably doesn't do anything near that bad, but the point is that it's a question of balancing convenience vs. error prevention, and that we're talking about a very strictly-typed language which will naturally attract people who tilt toward wanting the error detection, and even dynamic languages that swing the other way on most things often find that you don't need to make your math operators cast numbers into non-numeric types (and risk the resulting runtime errors) to have convenient string handling.

In fact, I think Ruby's string interpolation is actually a better syntatic sugar than Java's `+` cat overload. Consider that I want to print a string along the lines of "1 + 5 = 6" but with arbitrary integers. Here's how it might look in Ruby:

    puts "#{x} + #{y} = #{x+y}"
It's hard to imagine a syntax much better than this, especially for short strings, since the shape is basically identical to the string it's creating.

Python 3 is less pretty, but still reasonable:

    print("{} + {} = {}".format(x, y, x+y))
    print(x, "+", y, "=", x+y)
Meanwhile, neither Ruby nor Python makes you declare types as a rule. In fact, one of the non-backward compatible changes in Python 3 was to make it so that 1/2 returns .5, since that's how numbers work and it's probably what you meant (there are still ways to specify integer division if you want). However, in either language, if you write "5" + 5, they will raise a ValueError because that doesn't actually mean anything, is likely to be a bug, and is always easily rewritten in a concise but less ambiguous way. Speaking of which:

> have no potential to mean something else than what the programmer meant

is just false. There is a very obvious way for it to mean something other than what the programmer wanted: When the programmer forgot to cast a string to a number and tried to add it to a number. This is particularly a risk in dynamic languages or those using type inference (it's harder to pull off in languages where you have to explicitly declare all your variable types, which may make it a non-issue in Java speficially).

Re: Choosing Scala

#37
I really wanted to like Scala, I came to the language looking for a Haskell on the JVM, but then just found it sacrificing too much, mainly for Java compatibility.

The close compatibility with Java does allow an easy transition for Java developers, but it's a transition to writing what it repeatedly deemed unidiomatic Scala by the Scala community. And then I've seen the same community scoff at unenlightened Scala developers that are writing "Java++".

Half of Scala could make a really nice language, but the complexity of the full thing is not something I want to work with again.

Re: Choosing Scala

#38
I really want universities here to pick up Scala as well. You can teach all aspects of modern programming paradigms using it, while retaining real world applicability and the wonderful JVM and it's ecosystem.

I use typesafe stack and it's really, really good.

Re: Choosing Scala

#39
post #32

I don't come from a CS background, but I have been programming professionally many years and recently got started with Scala. I had tried Go before and I like Go. I also really like Scala. Scala requires much more work to learn than Go. I don't think I ever ventured out much from the offical Go documentation, the spec and effective Go and the library documentation to learn Go. With Scala I've already bought 3 books,…

Having worked with Scala for the past almost two years, I can tell you this: you're missing out by not using IntelliJ. It is a huge timesaver, not just from the code completion or the inspections, but also by being able to fire up FSC outside of IntelliJ and have your code recompile very, very quickly when you make changes. The one thing that IntelliJ doesn't do very well yet is work with sbt. It works, sure, but the maven support in IntelliJ is that much further along, so I generally still use maven for in-IDE dependencies, and then write up an sbt file when I publish my work.

Re: Choosing Scala

#40

I really want to understand what the fuss is about with Scala so I fired up a REPL and found a tutorial and went to work. Then I can across this: scala> print("5" + 5) 55 And I stopped there (for now). At least my C++ compiler will warn about that (although it will still compile even if it doesn't print anything save for the newline): #include using namespace std; int main(int argc, char *argv[]) { cout Python gives…

Scala inherits essentially all its expression syntax from Java, including the string +. This was done because a lot of other things in Scala are new, so we did not want to rock the boat too much with changes that might seem arbitrary. That said, I believe string + is probably the most criticized feature in Scala's expression syntax. People are generally moving away from it, towards String interpolation, which is avai…

Mr. Odersky can you please take a compiler course based on Scala as well, pretty please? :P
Post reply on HN