Scala School
twitter.github.io
twitter.github.io
- a "JSFiddle" like editor for Scala: http://scalakata.com
- Interactive tours: http://scalatutorials.com/tour, http://www.scala-tour.com, http://www.simplyscala.com
- Learn Scala in X minutes: http://learnxinyminutes.com/docs/scala/
- Typesafe Activator: http://www.typesafe.com/activator
- Official docs of course: http://docs.scala-lang.org/
- To manage dependency, use SBT (http://www.scala-sbt.org/).
- For IDE, I recommend Scala IDE (http://scala-ide.org/).
Scala Notebooks, which can be classified as a learning resource https://github.com/n8han/scala-notebook/ - It is an in-work conversion of iPython notebooks using d3 instead of matplotlib.
Another great analysis resource is Saddle, a scala data munging library (analogous to pandas, around the 0.8 revision). http://saddle.github.io/
I usually combine it with Rogue (https://github.com/foursquare/rogue), an "ORM"-like for MongoDB. I used Finagle and Rogue to build a fast and lightweight REST API.
For Scala written libraries, here's a link to Github page: https://github.com/trending?l=scala
I could be wrong but I think Finagle reflects this in that Thrift is more of a first-class citizen than REST (although I'm sure the latter is possible).
(That said, I do think the twitter scala style guide is very good: http://twitter.github.com/effectivescala )
As for bridging Twitter Future with (now) Scala Future, that should be coming soon, once the execution context stuff is squared away.
Casbah was always created to be a straight MongoDB driver, with no ORM features. It has no dependencies on "external" projects other than the MongoDB Java driver, so that you can use it where-ever and write standard queries.
It has been awhile since I played with Rogue, so forgive any mistakes but the big one: Rogue is specifically built as an ORM, with integration into Lift.
Really, you are going to use Rogue vs. Lift to accomplish very different tasks. There is Salat (https://github.com/novus/salat), to provide ORM features on top of Casbah.
Pick which tool works best for your use case! I happen to think quite highly of Rogue as well, as there are some tremendously impressive features in it including detecting potential Table scans. Rogue is fairly well battle tested on the Foursquare systems, and the authors are both very, very good at what they do.
However, all the Scala positions I've found are looking for engineers with experience using Scala in production. How can I make that jump? Are there any opportunities out there for junior engineers who are proficient in Scala?
C# is a bit more advanced in Java (they have lambdas), and in someways better than Scala (reified generics). But the best thing about C# is that...it forces you to to settle on less elegant but functional designs in a "worse is better" style. I found myself obsessing over my Scala code to come up with perfect solutions because...I could...while in C# perfect solutions obviously don't exist. C# relieves the burden of choice, which is an interesting trade off to keep in mind when designing PLs.
[1] http://bling.codeplex.com/
[2] http://research.microsoft.com/apps/pubs/default.aspx?id=1898...
def f1:Option[Int] = Some(1)
def f2(a: Int):Option[Int] = Some(a + 1)
val r = for {
a <- f1
b <- f2(a)
c = a * b
} yield c
r.getOrElse("generic error")
Individual error messages with scalaz's Validations def f1:Option[Int] = Some(1)
def f2(a: Int):Option[Int] = Some(a + 1)
val r: Validation[String, Int] = for {
a <- f1.toSuccess(e = "f1 failed")
b <- f2(a).toSuccess(e = "f2 failed")
c = a * b
} yield c
r.fold(e => s"error: $e", r => s"result: $r")The problem really stands that no one knows how to build decent data-flow debuggers. Haskell programmers prefer static safety over debugging just as much as because their debuggers suck as the type system is so powerful. In Scala, you have the option to write crash-early strict code: do it, you will make your life so much easier as a result.
I suppose that conceptually, I consider returning None inside a chain of flatmapped options as the equivalent of terminating early. It's not hard to pass along an object describing the error instead of None, which gets you the equivalent of a thrown exception.
Also: can you point me towards any examples of this antipattern? I 'd like to see it in action, if only so I can avoid it in my own code.
For simple programs that do not need to be debugged, laziness is great, you can write some very concise code. Once you are debugging however, you want to expose as much control flow as possible to break and step through. I say this from writing 10s of thousands of Scala code in a fairly complicated context (Scala compiler + Eclipse) with non-trivial control flow (mostly event driven).
That way, you can be immediately productive.
I have obtained much better results by first developing a nice logical model (not necessarily 100% formal, but at least rigorous enough to be amenable to formalization), and only then picking a programming language into which the model can be translated with a minimum amount of effort. In this regard, a good language is one that allows translating as many logical constraints as possible into statically verifiable constructs (such as types). The nice thing about static verification is that errors in the translation can be detected as soon as you make them. Heck, in some cases, even errors in the original conceptual design can be detected.
Scala is a better language than Java because its type system is so much more powerful. Using Scala as if it were Java nullifies this advantage, and leaves you only with the inconvenience of having to learn a new syntax. So, what is the point?
Scala only has very limited inference. In fact, so limited that, based on this criterion alone, I would take Java's powerful refactoring tools over Scala's inference anytime. (One of my main uses of inference is enabling fearless aggressive refactoring.)
But let's say Scala had a type system amenable to global inference with a nice principal types property. This does not prevent you from having to annotate types when, at a module boundary, you want a term to have a more specialized type than its principal type. (Within module boundaries, it is admittedly no big deal to have terms whose types are more generic than their use would warrant.)
> "no semicolons, and a shorter form of final"
You cannot tell me with a straight face that cosmetic syntactic changes are a particularly compelling reason to switch languages. (Well, you can, but then you cannot convince me you are a pragmatic engineer.)
> "it's already an improvement over java."
Yes, but, without taking advantage of Scala's powerful type system, is the improvement over Java substantial enough to justify the investment in learning a new language?
What investment? You just write the same code that you were writing in Java. You can do that on day 1 (at least, assuming your IDE and build system have scala support already) - on day 1 your productivity is just as high (or slightly higher, because of the cosmetic syntax improvements) as it was in Java. On day 2 your productivity is higher, as you pick up a little bit of scala. So there's no initial cost - just an improvement. I know this is possible because I have done it.
> There will be some very tense discussions about how things things ought to be implemented (...)
Encoding as much as possible of the problem domain's logical constraints in types. Any property enforced by a type checker (and not subverted via a type system escape hatch) is a property that you do not have to test.
> (...) and if not well managed, it can feel like "this approach is wrong. your code is bad and you are a bad engineer"
My experience with most programmers using Java/C#/Python/whatever is precisely that: "Their approach is wrong. Their code is bad. And they are bad engineers." I have to waste my precious time subverting their brittle type systems (downcasts, reflection, assuming stuff is not null, etc.) and enforcing correctness the hard way (extensive testing or even good old non-computer-assisted brain usage), when I could simply read type signatures, get free theorems, run a couple of tests for checking stuff that cannot be inferred from types, and move on to the next thing.
If you see your time as much more precious than your colleagues, and default to treating them with contempt, you're going to have a hard time finding colleagues. Which you may not care about.
But what should matter to you is that it's basically a self-fulfilling prophecy. If you treat your colleagues like that, they're never going to get better, and they're going to be the ones who eventually vote to throw out all your beautiful code and go back to Java, where they at least understand what's going on and nobody condescends to them all day.
to lower the bar, don't use framework. i even coded http://ngajakjalan.com (one of my projects written in Scala) without framework, just plain servlet+JSP. again, eventually you'll think, "i keep doing the same thing, there's got to be some library out there already doing this for me", and start exploring.
Ensime in Sublime is kinda pointless I think since it only updates on file change. The REPL and SBT integration is nice.
I use Sublime for quick examples in Scala, or as a VIM alternative for larger projects (as opposed to my main editor like with Ruby).
For most of my Scala work I use IntelliJ though. The lack of half-decent theming in Eclipse and Preferences/Settings being all over the place really puts me off ScalaIDE personally.
Going from Zero to Code in IntelliJ and SBT (on OSX) is pretty trivial. Given a command-line "Hello World" with a traditional Maven layout:
First, install IntelliJ, navigate to "Plugins" under preferences and install the Scala plugin.
Now make sure you have Homebrew installed (http://brew.sh)
$ brew update
$ brew install sbt --devel # currently 0.13.0-RC5
$ cd ~/src/
$ mkdir hello-world
$ cd hello-world
$ mkdir project
$ echo "sbt.version=0.13.0-RC5" | tee project/build.properties
$ cat <<EOS | tee project/plugins.sbt
resolvers += "Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.5.0-SNAPSHOT")
EOS
$ cat <<EOS | tee build.sbt
name := "hello-world"
version := "1.0-SNAPSHOT"
EOS
$ mkdir -p src/main/scala
$ cat <<EOS | tee src/main/scala/Whatever.scala
object Whatever extends App {
println("Hello World!")
}
EOS
$ sbt
> compile
> gen-idea
> run
And there you go. It could be simpler if we were having a LOC competition, but this is actually very close to the exact setup I use for projects day in and day out, including getting a jump on the next version of SBT and best-practicey stuff like setting the SBT version in build.properties.If this were a Play app, you might have a "project/plugins.sbt" that looked something like this (to get a jump on the upcoming Scala 2.10 version of Play, that integrates with SBT 0.13.x):
// Comment to get more information during initialization
logLevel := Level.Warn
resolvers := Seq("Maven Central" at "http://repo1.maven.org/maven2/",
"Typesafe Snapshots" at "http://repo.typesafe.com/typesafe/snapshots/",
"Typesafe Releases" at "http://repo.typesafe.com/typesafe/releases/",
"Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/")
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0-M2")
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.5.0-SNAPSHOT")
This just adds a few more common resolvers you might use for dependencies, and locks you to the latest Play milestone snapshot. You can pretty much otherwise copy/paste files/folders from a sample Play app, like you might see with the Typesafe Activator for example.Good luck!
(just remember "brew doctor" first).
Also for non-maccies: http://www.scala-sbt.org/0.13.0/docs/Getting-Started/Setup.h... (it would be nice to discuss the red hat and debian distro families in that Setup page, it looks like you can't currently "apt-get sbt"
> The lack of half-decent theming in Eclipse and
> Preferences/Settings being all over the place
> really puts me off ScalaIDE personally.
Agree. I can recommend http://eclipsecolorthemes.org/ combined with https://github.com/jeeeyul/eclipse-themes.However, If that is not a requirement for you, you should really be using the Scala IDE (Eclipse plugin), it has great autocompletion, refactoring, and more.
I have to say I also started with Scala IDE because, when starting with a completely new language, I tend to just install the default IDE so that I don't have to fight two battles in the beginning but can concentrate fully on the language. Otherwise, you'll loose interest / give up even faster.
the unicode didn't render properly on chrome stable, windows 7
"From ∅ to Distributed Service"
otherwise quite interesting