Scala vs. F#, Round 2: Application Programming Features
Scala vs. F#: Object-Oriented Features
Although F# is primarily a functional language, it supports most common object-oriented (OO) features such as single inheritance of classes and multiple inheritance of interfaces, parametric polymorphism through generics, enumerated types, structs and records. Like C# and Visual Basic, F# supports delegates, which provide implicit access to object properties through the language-provided Invoke delegate method. However -- unlike Scala -- F# does not support any form of multiple class inheritance.
Scala is a hybrid functional/OO programming language, so its functions and functional programming features are first class language constructs and the OO ones are as well. Every value in Scala is an object. In addition, Scala supports parametric polymorphism, enumerations, as well as direct and pseudo-multiple inheritance through classes and mixins.
Scala vs. F#: Compilation and Execution of Programs
The F# compiler and runtime are available as .exe and .msi installs. At the time of writing, Windows was the only platform supported, so the only option to run F# on Mac or Linux platforms is by using a Mono .NET CLR implementation. F# programs, recognized by the extension .fs, are compiled into .exe files on Windows, most commonly through the Visual Studio IDE (2008 and later), although they can be created in an external editor and compiled using a standalone CLR compiler.
The F# installation, whether via installFSharp.msi or fsharp.zip, also comes with an interactive compiler, so F# programs can be written and evaluated via a console and without the IDE.
Scala is available for download as a JAR file for any platform that supports Java. It is also available as a binary distribution for Windows and OSX/Linux platforms. In either form, the Scala compiler/interpreter runs on top of a JVM.
Scala requires Java version 1.5 or later, but there is a version available that is compiled for Java 1.4.
Scala programs can also be run interactively through the interactive interpreter called REPL (read-eval-print-loop), both as single-file Scala scripts or completely interactively. Scala programs can also be compiled by class files and combined with other class files into JAR files and then invoked as Java applications.
Scala vs. F#: Typical Application and Areas of Adoption
F# is the most recent addition to the .NET family of languages, so it is still in an introductory phase. F# has been used internally by Microsoft Research for log analysis and custom search tasks, but Microsoft plans to introduce F# as their specialized language for multicore and high-performance computing.
Anecdotally, the programming community -- especially those familiar with functional programming and derivatives of the ML programming language -- have responded very favorably to F#. However, its exclusive availability on the .NET platform may prove to be a hindrance to wider adoption, given that the majority of scientific and high-performance platforms are Linux based.
Between Scala and F#, Scala certainly has the highest-profile adopter: Twitter's entire message-processing application is implemented in Scala. The source code for the Twitter application is available online for review. Several other high-profile organizations such as Siemens, Sony, Xerox and NASA also use Scala in a variety of smaller-scale projects.
Because of Scala's transparent yet complete and flexible integration with Java, Scala can be implemented on virtually any type of project. However, empirical evidence seems to suggest that the most common rationale for Scala adoption has been to reduce the size of a code base to Scala's succinct syntax.
Instead of a Performance Review
Although Scala and F# deserve a detailed performance review to do them justice, such a review is beyond the scope of this article. As a compromise, I will offer only my opinion on the methodologies of well-known performance profiles of these two languages.
While Java's virtual machine system is available on all platforms, it does not offer Scala any of the potential or actual benefits or any of the out-of-the-box optimizations that F#'s .NET and Windows environments do. Within the confines of the .NET runtime environment on Windows, F# may very well benefit from internal CLR optimizations that are specific to the language.
Similarly on Linux, where F# is not natively available, performance comparisons can be performed only with F# running on Mono, an open source, third-party CLR implementation. For a thorough runtime and memory-consumption comparison of F# and Scala on Linux, check the details at the excellent and detailed programming language benchmarking website Computer Language Benchmark Games. Some independent sources indicate that Mono lags behind the .NET CLR in both performance and features, but benchmarks on Linux indicate that F# may run three times slower than Scala. Yet F# runs with almost equally superior memory utilization over Scala.
About the Author
|Edmon Begoli is a software architect with 14 years of professional experience on large commercial and public software projects. He is a member of the R&D staff at Oak Ridge National Laboratory.|
Page 2 of 2