Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

“Thinking in Scala" if I have a Java/C++ background?

I'm familiar with developing server-side applications in Java, but now I'd like to start using Scala. Can you describe the paradigm shift that is necessary? Here are a few questions that might help you frame an answer:

  1. How do I architect and design web applications differently? What is the biggest difference?
  2. What should I stop doing/using; What should I start doing/using instead?
  3. Are there any client-side considerations/restrictions?

I'm not looking for a detailed comparison between Java and Scala.

like image 588
Amit Avatar asked Jun 25 '15 05:06

Amit


People also ask

Is Scala harder than Java?

7- The learning curve of the Scala vs java programming language is high as compared to that of Java. The coding in Scala can be extremely challenging to predict due to less coding. Also, the syntax in Scala is more complicated than Java.

What are the advantages of Scala over Java?

The Advantages of ScalaScala has an exact syntax, eliminating boilerplate code. Programs written in Scala require less code than similar programs written in Java. It is both an object-oriented language and a functional language. This combination makes Scala the right choice for web development.


1 Answers

The key difference between Scala and Java is Scala's use of functional programming.

  1. For web applications, you will use different frameworks. Play is currently the most popular flavour. It feels similar to MVC work in other frameworks but leans more towards functional purity (though most Play apps are far from being pure)
  2. You should stop thinking in terms of mutating fields in memory and think about data flows of immutable values. Do not use a var, when you can do it with a val. Loops will mostly be replaced with higher order constructs like map and fold. Avoid nulls, and use Options instead.
  3. Assuming a web client side, no. Unless you want to compile Scala to JS. Then the same stuff applies.

Learning wise, I would start with Twitter Scala school, then once you grok that, I recommend the book Functional Programming in Scala. I think these two resources will guide you in the FP direction, as opposed to writing Java-style programs with new syntax. Then, find the right spot in the OOP/FP scale that suits the problem at hand.

like image 65
triggerNZ Avatar answered Oct 28 '22 20:10

triggerNZ