One of the two mandatory rituals in learning a new language is to print “Hello World!”
The other ritual that has been gaining ever more popularity in recent times is what some of my colleagues have begun calling as “42 epidemic”.
The 42 epidemic is about printing the number 42. Why 42? Why not 40? Or something else? And that unanswered question is exactly what lends magical flavor to this trend. One possible explanation is that almost all languages(perhaps with the exception of 'pure' Prolog) are expected to do two basic things – string manipulation and number manipulation. If you are able to do these two basic things you are all set to implementing more complicated data structures.
This simple blog is about covering these two mandatory baby steps in Scala. Without any further ceremony, here is the code –
println("Hello World!")
println(42)
If you are on a REPL, the ‘code’ is even simpler-
res963: String = Hello World!
res964: Int = 42
Well, that is all there it is for dipping your toes in Scala. Scala REPL is also a bit different than those of other modern day languages. Type :help on the REPL to find out what all it can do for you. Among other things there is facility for editing classpath, replaying what has happened, type discovery of expressions and your secret database in :h? .
Though a word of caution – Scala is much more difficult, if not impossible, to learn on the fly. This is especially true if you write computer programs for a living. Because if you do writing code for a living, you would surely be writing a lot of imperative code and that is something you need to learn to avoid in Scala. Or at the very least, it is not idiomatic in Scala.
No comments:
Post a Comment