Scala tutorial for people who can code already
-
I'm starting a new job, and I need to learn Scala. And I need it fast - I'm starting on March 1. I have a little prior experience with Scala, but it was just college classes years ago, and programs never exceeded 30 lines. Can someone recommend me some resources that will teach me all the important aspects of Scala that will let me work on arbitrarily huge enterprise projects? Not just language, but also project management, common programming patterns and effective use of standard library. I can spend about 30 hours total on it.
-
@gąska You're not going to pick up a whole new language, complete with idioms, in a new and mostly unfamiliar paradigm, in 30 hours.
Did you tell the interviewers that you don't have much experience with Scala? If you did, and they hired you anyway, they'll probably be understanding and willing to give you some time to get up to speed.
-
-
@masonwheeler said in Scala tutorial for people who can code already:
@gąska You're not going to pick up a whole new language, complete with idioms, in a new and mostly unfamiliar paradigm, in 30 hours.
I picked up enough Python to pass online interview in 3 hours. And I'm kinda used to functional programming.
Basically I'm looking for some tutorial that's not 50% string manipulation and 50% overriding methods in derived classes.
-
@gąska said in Scala tutorial for people who can code already:
And I need it fast - I'm starting on March 1.
Granted, you do not need to be an expert, but if you did, then you will have real challenges in finding a way to practice 1,000 hours per day for the next 10 days ;)
-
You checked this, right?
Also, I'm doing Scala now at work so feel free to ask me anything.
-
@gąska said in Scala tutorial for people who can code already:
@masonwheeler said in Scala tutorial for people who can code already:
@gąska You're not going to pick up a whole new language, complete with idioms, in a new and mostly unfamiliar paradigm, in 30 hours.
I picked up enough Python to pass online interview in 3 hours. And I'm kinda used to functional programming.
Basically I'm looking for some tutorial that's not 50% string manipulation and 50% overriding methods in derived classes.
My advice for learning a new non-esoteric programming language when you already know how to program:
Find an open source program written in that language and dissect it.
-
Congratulations on the new job, I know it's been something of a journey.
I know jack shit about Scala, but a quick Googling shows it has a debugger which seems to work, so I'd second Ben's suggestion. Grab that debugger, step through a decent-sized Scala program written by someone else and see if you can figure out what's going on and why.
(That said the Scala community is also full of people who write stuff like this:
We believe the purest and more functional your code is, the less you'll need to debug it
So. Good luck I guess.)
-
@gąska Check out http://danielwestheide.com/scala/neophytes.html - it goes into some of the more interesting patterns in Scala that you will encounter within 20 (extractors, pattern matching, optional, either) and 40 minutes (type classes, implicits, path-dependent types) respectively.
-
http://danielwestheide.com/scala/neophytes.html - everything you need and nothing you don't (maybe this will go through this time?)
-
@ben_lubar gonna try that tomorrow, see how it goes. This looks like a good candidate.
-
@masonwheeler said in Scala tutorial for people who can code already:
@gąska You're not going to pick up a whole new language, complete with idioms, in a new and mostly unfamiliar paradigm, in 30 hours.
I did. Scala's easy as shit.
I used the O'Reilly Programming in Scala, that's my recommendation.
-
I can't offer any real advice, but I offer you all my
thoughts and prayersmoral support. I can never find a goddamn tutorial that starts where I need it.
-
@gąska said in Scala tutorial for people who can code already:
effective use of standard library
One of the key things about Scala is that it sits on top of the JVM and has access to the Java standard library and all the wide range of third party libraries out there (not all of which are shit). Your chances of learning all of that in 30 hours are nearly zero; there's a very big ecosystem. (I really doubt that you'd be able to make more than a scratch in 300 hours, it's that large.) OTOH, virtually everyone doesn't know it all (even before the third-party stuff) so there's no reason to worry about that.
You need passing familiarity with basic types and collection types. Assume that for most other things you can think of, there'll be something out there that can help provided you can come up with the right terms to put into a web search. (Also, Scala has some fairly complex notions for specifying covariant and contravariant generics, etc.; I've never learned that stuff in detail.)
-
@justhelpingout said in Scala tutorial for people who can code already:
@gąska Check out http://danielwestheide.com/scala/neophytes.html - it goes into some of the more interesting patterns in Scala that you will encounter within 20 (extractors, pattern matching, optional, either) and 40 minutes (type classes, implicits, path-dependent types) respectively.
Whoops, that stayed in the moderation queue way too long.
-
Status: Oh good, I can read this thread without annoying people...
Well, except that one guy...
-
@justhelpingout Welcome to the forum!
-
This post is deleted!
-
Tomorrow my ass.
Anyway, I've finally got time to sit through the links you all threw at me (thanks BTW). Immediately after starting out, I've found the first thing I have NFC how it works and how to use it, and it seems pretty important.
Can someone explain the extractor objects - what exactly (EXACTLY) the methods
apply
andunapply
do, what the parameters and their types mean, what's the output type and where the output value goes, and how the hell a string expression becomes an object?
-
@gąska
apply
is just a method like any other and it is what is called whenever you seesomeVariable()
- that is,someVariable() === someVariable.apply()
andsomeVariable(1, 2, 3) === someVariable.apply(1, 2, 3)
just like with Java'sFunction
interface.unapply
is used in the extactor portion of acase
expression - if it returns aSome
then the case matched, if it returnsNone
the case is not. The value returned is bound to the inner portion of the LHS of the case:object Extractor { def unapply[T](value: T): Option[Int] = if (value.isInstanceOf[Int]) Option(value.asInstanceOf[Int]) else None } 123 match { case Extractor(boundVar) => boundVar + 3 }
effectively, syntactical sugar for:
var result = null; val cases = List(... LHS and RHS of case statements); for (case : cases) { val bindings = case.LHS.unapply(matchArg); if (!bindings.isEmpty()) { result = case.RHS.evalWithBindings(bindings) break; } }
if you hand-wave a lot :-)
-
@justhelpingout yeah, it makes more sense now. Thanks!
-
@Gąska Caveat: I am not a Scala coder. But I wrote up a comparison between Scala and SML/NJ for one of my college classes. The class was on the design of various programming languages, and we had been using SML as the example for functional programming. This project was to pick a language of our choice that we hadn't covered in class and compare it with one that we had. The professor recommended Scala among several others.
For your purposes, this might be a quick worksheet into what you might already know and what you would need to work on. Primarily, Scala might almost be called "functional Java" because Scala code compiles to Java bytecode and runs on the JVM. (Edit: Ah, @dkf already mentioned that.)
These were the slides that I used when I gave my report in front of the class, so they're a little skimpy. Please don't hesitate to ask if you have any questions about what I meant.
-
What do you mean by
@gąska said in Scala tutorial for people who can code already:
how the hell a string expression becomes an object?
If you're talking about this part
val CustomerID(name2) = "--asdfasdfasdf"
Then that's an example of an error. It says you expect an object CustomerID with some name, but you're trying to give it a String
-
@homobalkanus I've had a misconception that CustomerID is a proper value type, whereas it's just a fancy accessor for string.
-
This post is deleted!
-
@gąska said in Scala tutorial for people who can code already:
@homobalkanus I've had a misconception that CustomerID is a proper value type, whereas it's just a fancy accessor for string.
It's neither. CustomerID in this case is an object, which is like a class that is simultaneously the only instance of itself. CustomerID's analog in Java would be CustomerID.INSTANCE. You're then using it as a pattern matching element.
You may be able to get more of a handle on how that works if you start playing with the regex library. Regex objects are used as pattern matchers for their match groups.
-
@gąska Also remember that unapply() only works with fixed numbers of extraction variables, whether by direct return or by tuples. If you want a variable number of extraction variables, you need to instead write
unapplySeq()
which returns aSeq[<return type>]
.
-
Question to active Scala users: how often do you find yourselves writing extractors? Do you make more than one extractor per data type? What are typical use cases?
-
@gąska said in Scala tutorial for people who can code already:
Question to active Scala users: how often do you find yourselves writing extractors? Do you make more than one extractor per data type? What are typical use cases?
We use them whenever a particular data type can be deconstructed into one or more values (that's why case classes implement them automatically). Other than that, really it's just for DSL wankery.
-
@gąska said in Scala tutorial for people who can code already:
Question to active Scala users: how often do you find yourselves writing extractors? Do you make more than one extractor per data type? What are typical use cases?
I don't write them. I use case classes which already utilize them. Think of them as syntactic sugar to access certain properties. For example, you can assign elements of a tuple to variables like this
val someTuple = ("a", "b") val (first, second) = someTuple
Which is equivalent to
val first = someTuple._1 val second = someTuple._2
The most common usage is in match statement
someTuple match { case ("a", "b") => println("matches if first is 'a' and second 'b'") case ("a", somethingElse) => println("matches if first is 'a' and assigns second to variable somethingElse that can be used her") case sameTuple => println("always matches and assigns the whole someTuple to variable sameTuple") }
Like @pie_flavor said, you probably won't write them yourself unless you're writing a DSL