Live data from Hacker News

Choosing Scala

teaching.software-carpentry.org

11–20 of 65 posts

Re: Choosing Scala

#11

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…

Even better:

  scala> println("5" + 5 + 5)
  555

Re: Choosing Scala

#12

Coming from CS and computational math background, I used mostly C++ for production and Python for prototyping and data analysis. I wanted to learn some new language for JVM, Clojure and Scala being the main (if not the only) contenders. I may learn Clojure anyway, but what tipped the scale to learning Scala first was wonderful Coursera course in functional programming by Martin Odersky, using Scala as a language, obv…

Might want to take a look at Nimrod (http://nimrod-lang.org/)

* (Mostly) Python-ic syntax (indentation-based)

* Type inferance

* OOP (but only when you want it)

* Good expressivity

* Compiles via c (FAST, easy linking with C libs, no runtime required, prodoces standalone binaries)

* Lean core (Not a "kitchen sink" language, but has good support for FP and OOP)

Re: Choosing Scala

#13
As a software engineer I find Scala to be a very powerful tool, but one which takes some time to learn. I could see it being a useful teaching tool if they stay away from obscure corners of the language. I'm glad that they didn't go with Java, but I'd only go with Scala if the students are a sharp bunch. Python would also have been a suitable choice.

Re: Choosing Scala

#14
All very good reasons to use Scala for teaching. I think you will also find that those students who really get it will sink there teeth in deep and not hit the bottom of the language any time soon. Thats good for those kids in the class who are comming into the university with programming experience. I know when I was doing my introductory programming classes I spent more time trying to figure out neat things I could do with C++ and Java then actually working on class work.

Re: Choosing Scala

#15
post #12

Coming from CS and computational math background, I used mostly C++ for production and Python for prototyping and data analysis. I wanted to learn some new language for JVM, Clojure and Scala being the main (if not the only) contenders. I may learn Clojure anyway, but what tipped the scale to learning Scala first was wonderful Coursera course in functional programming by Martin Odersky, using Scala as a language, obv…

Might want to take a look at Nimrod ( http://nimrod-lang.org/ ) * (Mostly) Python-ic syntax (indentation-based) * Type inferance * OOP (but only when you want it) * Good expressivity * Compiles via c (FAST, easy linking with C libs, no runtime required, prodoces standalone binaries) * Lean core (Not a "kitchen sink" language, but has good support for FP and OOP)

I'm rather excited about Nimrod, it actually looks a bit like Scala (pascal-style declarations). Scala has a lot of appeal for (most) organizations where the JVM is very widely used. I guess I tend to look at things from the position of a software engineer rather than from a teaching perspective. I'm really hoping that Nimrod gets a lot of traction (don't want it turning into a D).

Re: Choosing Scala

#16
post #8

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…

Since print() most likely expects a string, isn't the result exactly what you would expect? Why would you want a warning in this case?

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

Re: Choosing Scala

#17
post #8

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…

Since print() most likely expects a string, isn't the result exactly what you would expect? Why would you want a warning in this case?

You should never be able to "sum" different types, and definitely not different type families.

And I don't want a warning, I want a huge fatal end-of-the-world big red flag error message blinking on my screen until I fix it.

Re: Choosing Scala

#18
My alma mater recently switched to Scala for its intro courses, my undergrad thesis mentor really pushed for it and has written an intro textbook using Scala. He's also the reason I used Scala for my senior thesis, which led to me suggesting it at the startup I work for (first hire) and Scala becoming the basis of our backend.

I think the OP really nails the reasons Scala makes sense as an intro language. Students can start with simple concepts and gradually see how these lead to the complicated stuff.

Re: Choosing Scala

#19
post #8

Earlier quoted context omitted.

Since print() most likely expects a string, isn't the result exactly what you would expect? Why would you want a warning in this case?

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 different context.

For the numeral types, it will not protest if you sum up a float with an int (and I think most programming languages won't either). The rules of the language are quite clear: the int would be coerced to a float, then the two float be added, and a float will contain the result.

For the string operation, you could force the operands to have all the same types, but you could also practice the same kind of coercion: convert everything (yes, it works for every object of any sort) to a string, then concatenate.

OK, it may be odd mathematically, but let's see it for what it is: a very handy syntactic sugar in the form of an overloading of the meaning of +, which obey simple rules, and thus have no potential to mean something else than what the programmer meant.

Re: Choosing Scala

#20

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> "5" + 5
  res0: java.lang.String = 55
Don't use print in the REPL...

> Python gives me a TypeError. And so does Common Lisp. I was expecting the same from Scala

  scala> val i:Int = "5" + 5
  :7: error: type mismatch;
  found   : java.lang.String
  required: Int
       val i:Int = "5" + 5
                       ^
You can easily get a compiler error, if you enforce the type. The inheritance of Javas "I'll call .toString on anything" is definitely not something I'll defend, but it's much less of a problem than it may appear. To do anything interesting with that "fake" integer, you'll have to call a method that only accepts integers - and the compiler will throw an error then. E.g.:

  scala> math.max("5" + 5, 5)
  :8: error: overloaded method value max with alternatives:
    (x: Double,y: Double)Double 
    (x: Float,y: Float)Float 
    (x: Long,y: Long)Long 
    (x: Int,y: Int)Int
   cannot be applied to (java.lang.String, Int)
              math.max("5" + 5, 5)
                   ^
Post reply on HN