- An excellent (IMO) list of questions without answers (which is good): Scala Job Interview Questions
- A brief (but good) list courtesy of Typesafe... er Lightbend (including very thorough answers): 4 Interview Questions for Scala Developers
- A list of questions with answers (but I'm not sure I like the answers): Top 25 interview questions on Scala
- etc.
Naturally, I couldn't resist the idea of writing up some of my own questions/answers:
Question: Name two significant differences between a trait and an abstract class.
Answer: Abstract classes have constructors with zero or more parameters while traits do not; a class can extend any number of traits but only one abstract class; see also To trait or not to trait? for more differences.
Question: What type of construct follows the match keyword?
Answer: A partially-defined function.
Question: What exactly is wrong with a recursive function that is not tail-recursive?
Answer: You run the risk of running out of stack space and thus throwing an exception.
Question: Explain the concept and usage of an extractor.
Answer: An extractor is essentially the opposite of a constructor and is defined by the unapply(t: T) method defined in the companion object of a type T; for a case class, which provides a built-in unapply method, it returns a Option[TupleN] based on the number N of parameters in the constructor (exception: if N=0, then the returned type is Boolean; if N=1, the returned type is Option[T]); extractors are typically used following the case keyword in match expressions. For more information, see The Neophyte's Guide to Scala Part 1: Extractors.
Question: What relatively minor difference in the definitions of their respective non-empty-constructors results in the major distinction between a List and a Stream?
Answer: The tail parameter is defined as call-by-name.
Question: What exactly is wrong with a recursive function that is not tail-recursive?
Answer: You run the risk of running out of stack space and thus throwing an exception.
Question: Explain the concept and usage of an extractor.
Answer: An extractor is essentially the opposite of a constructor and is defined by the unapply(t: T) method defined in the companion object of a type T; for a case class, which provides a built-in unapply method, it returns a Option[TupleN] based on the number N of parameters in the constructor (exception: if N=0, then the returned type is Boolean; if N=1, the returned type is Option[T]); extractors are typically used following the case keyword in match expressions. For more information, see The Neophyte's Guide to Scala Part 1: Extractors.
Question: What relatively minor difference in the definitions of their respective non-empty-constructors results in the major distinction between a List and a Stream?
Answer: The tail parameter is defined as call-by-name.
Tks very much for your post.
ReplyDeleteAvoid surprises — interviews need preparation. Some questions come up time and time again — usually about you, your experience and the job itself. We've gathered together the most common questions so you can get your preparation off to a flying start.
A word to the curious. Every few days some troll adds a comment like this one. I go in and delete it. I would ignore it except that it has a link to a bad web page which you don't want to visit by mistake.
DeleteThis is my attempt to foil them -- perhaps if they see this comment here, they won't bother to add another one.
This comment has been removed by a blog administrator.
ReplyDelete