comparing: haskell, scala, go · comparing: haskell, scala, go alleledev(@queertypes) august28,2014...
TRANSCRIPT
Comparing: Haskell, Scala, Go
Allele Dev (@queertypes)
August 28, 2014
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Contact Me
Github: cabreraTwitter: @queertypesBlog: Read, Review, Refactor
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Overview
IntentLanguage summariesLibrary ecosystemToolsType systemsKnown issuesLearning resourcesRecommendations
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Intent
To summarize options under consideration
To explore ecosystems and tooling for optionsTo compare the type system level guarantees and ability toabstract/reuseTo document known issuesTo point to resources to learn moreTo offer strategic recommendations
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Intent
To summarize options under considerationTo explore ecosystems and tooling for options
To compare the type system level guarantees and ability toabstract/reuseTo document known issuesTo point to resources to learn moreTo offer strategic recommendations
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Intent
To summarize options under considerationTo explore ecosystems and tooling for optionsTo compare the type system level guarantees and ability toabstract/reuse
To document known issuesTo point to resources to learn moreTo offer strategic recommendations
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Intent
To summarize options under considerationTo explore ecosystems and tooling for optionsTo compare the type system level guarantees and ability toabstract/reuseTo document known issues
To point to resources to learn moreTo offer strategic recommendations
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Intent
To summarize options under considerationTo explore ecosystems and tooling for optionsTo compare the type system level guarantees and ability toabstract/reuseTo document known issuesTo point to resources to learn more
To offer strategic recommendations
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Intent
To summarize options under considerationTo explore ecosystems and tooling for optionsTo compare the type system level guarantees and ability toabstract/reuseTo document known issuesTo point to resources to learn moreTo offer strategic recommendations
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Haskell
Appeared: 1990Home page: current, WIPCompiler: GHCLatest release: 7.8.3, July 11, 2014Native assembly generationOS: Linux, Windows, OS X >=10.7, iOS, FreeBSD, SolarisPlatforms: x86, ARMParadigms: functional, non-strictNotes: Renowned type system, concurrent/fast runtime, cryptolTry: Haskell
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Haskell
factorial :: Integral a => a -> afactorial n
| n < 2 = 1| otherwise = n * factorial (n - 1)
data Tree a =Empty
| Branch a (Tree a) (Tree a) deriving (Show, Eq)
insert :: Ord a => Tree a -> a -> Tree ainsert Empty x = Branch x Empty Emptyinsert (Branch v l r) x
| x <= v = Branch v (insert l x) r| x > v = Branch v l (insert r x)
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Scala
Appeared: 2004Home page: siteCompiler: ScalaLatest release: 2.11.2, July 24, 2014JVM byte code generationOS: Anything that can host the JVMPlatforms: JVMParadigms: functional, object-oriented, strictNotes: Effective type system, leverages JVM libraries, sparkTry: Scala
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Scala
sealed trait Tree[A]case class Empty[A]() extends Tree[A]case class Branch[A](v: A, l: Tree[A], r: Tree[A])
extends Tree[A]
object samples {def insert[A <% Ordered[A]]
(t: Tree[A], x: A): Tree[A] = t match {case Empty() => Branch(x, Empty(), Empty())case Branch(v, l, r) =>
if (x <= v) Branch(v, insert(l, x), r)else Branch(v, l, insert(r, x))
}def factorial(n: Int): Int = {
if (n < 2) 1 else n * factorial (n - 1)}
}Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Go
Appeared: 2009Home page: siteCompiler: GoLatest release: 1.3.1, August 13, 2014Native assembly generationOS: Linux, OS X, Windows, BSDsParadigms: imperative, object-orientedNotes: Concurrency support, fast compilation, dockerTry: Go
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Go
func factorial(n int) int {if n < 2 {
return 1}return n * factorial(n - 1)
}
type Tree struct {l, r *Treev interface{} // not type-safe; think (void *)
}
func insert(t Tree, x interface{}) Tree {// not-even-going-to-try.jpg
}
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
At a Glance (compiler, rts, stdlib, tests)
Summary Haskell Scala Go
Appeared 1990 2004 2009Latest ReleaseDate
July 2014 July 2014 August 2014
Platform x86, ARM* JVM x86Paradigm Functional,
ImperativeOO,Functional
OO,Imperative
REPL Yes Yes NoLOC Main 394539 (Haskell) 268572
(Scala)432018 (Go)
LOC Other 45760 (C) 29919 (Java) 151908 (C)
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Library Support
A language without a breadth of a libraries is a language that israrely usedA language lacking package management infrastructure isharder to adoptAn FFI is important to leverage works that came before
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Haskell
Package index: Hackage/StackageCount: >6000Package manager: cabalPackage format: Cabal file - exampleFFI: Yes (C, JS)
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Scala
Package index: MavenCount: >80000 (mixed with Java)Package manager: sbt, othersPackage format: scala exampleFFI: Yes (Java, JNI/C)
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Go
Package index: Go-SearchCount: >50000Package manager: gopm (experimental)Package format: .gopmfile (CONF)FFI: Yes (C)
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
At a Glance
Packages Haskell Scala Go
Index Hackage Maven Go-SearchCount >6000 >80000
(+Java)>50000
Manager cabal sbt gopm (exp.)FFI C, JS Java, C C
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Tooling
What editors are available?How about IDEs?Profiling?Debugging?Others?
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Haskell
Editorsemacs + ghc-modvim + ghc-modEclipseFP
ProfilingGHCcriterionThreadScopeHeap ProfilerTest Coverage
Debugging: N/AOthers
Type search: Hoogle, HayooStyle: hlint
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Scala
Editorsemacs + scala-mode2 + ensimevim + vim-scalaEclipse + Scala IDE
ProfilingScalaMeterJava HeapAudit
DebuggingScala IDE
OthersType search: ScalaexLinting: Wart Remover, Scala Style
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Go
Editorsemacs + go-modevim + go-modeVarious IDEs, including IntelliJ
Profilingpprofgo testing bench
Debuggergdb
OthersLinting: govet
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Type Systems
A programming language is a frontend to its type systemA powerful type system is a proof engine
Curry-Howard Isomorphism
Proofs are the only means to rule out errors; testing cannot dothis
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
At a Glance
Type SystemHaskell Scala Go
AnalysisTime
Static Static Static
ImmutableDefault
Yes (all) No No
1st-ClassFunctions
Yes Yes No
TypeInference
Yes Yes* Poor
EvaluationModel
Lazy Strict Strict
Modules Yes (weak) Yes (strong) Yes (strong)
Scala type inference will sometimes yield an AnyAllele Dev (@queertypes) Comparing: Haskell, Scala, Go
At a Glance
Type SystemHaskell Scala Go
ImplicitCasts
No Yes No*
Generics Yes Yes NoHigher Kinds Yes Yes No
NullableValues
No Yes Yes
Strong TypeAlias
newtype case class No
There’s a case where Go allows for implicit conversion
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
At a Glance
Type System Haskell Scala Go
Sum Types Yes Yes NoProductTypes
Yes Yes No
RecursiveTypes
Yes Yes No
PatternMatching
Yes Yes No
EffectTracking
Yes Possible* No
Effect tracking can be achieved via scalaz, with a few caveats
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
At a Glance
Type System Haskell Scala Go
Overloading Typeclass Implicits NoRecords Yes Yes YesSubtyping No* Yes YesDependentTypes
No* No* No
Subtyping impedes static analysisDependent types can be faked in type systems on par withHaskell’s/Scala’s, within limits
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Known Issues
Compilers aren’t free of defectsAdopting a language entails owning these defects and workingaround quirks
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
At a Glance
Issues Haskell Scala* Go
Known 942 4772 1216Critical 5 157 N/AMajor 42 443 N/AFFI C, JS Java, C C
Scala issues include: compiler backend, collections, concurrentlib, enumeration, macros, misc. compiler, optimizer, patternmatcher, presentation compiler, quasiquotes, reflection, replGo issue tracker does not support priorities
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Haskell
TrackerNotable:
int-to-float broken on ARMCabal Hell (with sandbox workaround): more
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Scala
TrackerNotable: Listen to Paul . Phillips
tl;dr - issues with type inference, casting, and inheritancetl;dr2 - issues have long turn-around timeRunar: more criticisms of ScalaSuggestions for improving Scala are abundant
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Go
TrackerNotable
No support for genericsExtensibility issues
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Learning Resources
Picking up a new language takes some effortAvailability of channels to learn should be considered inchoosing a language
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Haskell
Learn You a Haskell for Great Good: siteReal World Haskell (dated): site, what’s outdated?Parallel and Concurrent Programming in Haskell: siteEmacs Integration: siteSetting up a Project: siteMany, many research papers: indexWhat I Wish I Knew When Learning Haskell: siteCommunity Curated Learning Guides: siteStyle Guide: site
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Scala
Programming in Scala: siteFunctional Programming in Scala: buyScala for the Impatient: buyTwitter’s Scala School: siteStyle Guide: site
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Go
Effective Go: siteHow to Write Go: siteAn Introduction to Programming in Go: siteGo Bootcamp: siteStyle Guide: site
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Recommendations: Go
An improvement over untyped languages, safety-wiseLack of generics harms safety, abstraction, and reuseLack of package index/manager harms adoptionFeature-starved type system impedes use of modern patternsFamiliar patterns for OO/imperative programmers availableFast compilation time is niceMy thoughts: the weakest of these three choicesRecommendation: use only to modify an existing (go) codebase
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Recommendation: Scala
Potent type system can lead to proofs of correctness in codePro: association with JVM means access to JVM librariesCon: association with JVM carries over JVM problemsDevelopers can use OO patterns or adopt pure FP
Good: familiar, lower barrier to entry, a cleaner JavaBad: mutable state abounds, coupling, need more trust in teamsetting
Recommendation: great! Use especially if you need access toJVM libraries
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Recommendations: Haskell
Potent type system can lead to proofs of correctness in codeRequires unlearning old patterns
Accelerated greatly by communal knowledge and breadth ofresourcesWith prior FP knowledge, takes a few days to get ramped up
Purity aligns development style more closely in team settingLess room for errors, greater chance of correctness if it compilesApplies to third-party libraries by extension
Great selection of librariesGreat for understanding link between proofs, mathematics. andprogrammingRecommendation: excellent! prefer to Scala if JVM librariesnot needed
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
What I Left Out
Industry useAcademic useCommunity eventsNotable libraries (property testing, async, web, etc.)Runtime system comparison (GC style, performance, memory,etc.)Representative applicationsOther powerful languages:
Ocaml, Idris, typed Erlang, typed Racket, Rust, Elm, Purescript
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Caveats
I specialize in HaskellI have less knowledge of Go/Scala tools/resources
My biases:Preference for non-optional. strong typingPreference for functional programmingPreference for purity
My belief: FP + types -> (working code, sooner) & (easiermaintenance)
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go
Thank You!
Allele Dev (@queertypes) Comparing: Haskell, Scala, Go