- Use and availability of frameworks for Web, GUI and database development
- Support for object orientation
- Properties of the runtime environment
In this second installment of my Scala and F# language comparison, I describe how each language stacks against the other in these areas — with the caveat that it is difficult to compare two languages thoroughly and justly when one (officially) runs on only one platform. F# is implemented by Microsoft and made available only for Microsoft’s Windows platform, while the open source Scala is available to all platforms. However, Scala is compiled to Java as an artifact and therefore interpreted through Java’s virtual machine system.
Editor’s Note: This is the second article in the Scala vs. F# series. The first installment compared Scala’s and F#’s functional programming features.
Scala vs. F#: Application Development Frameworks
F# is a Common Language Runtime (CLR)-compliant language that is part of the .NET development toolset, which makes it suitable for all typical application development tasks. In fact, .NET developers can develop, debug, test and deploy F# programs as CLR executables through Visual Studio (2008 and later) in the same manner as they would C#, C++ or Visual Basic programs.
What differentiates F# from other .NET languages is the immutable, stateless nature of its functional execution. This attribute makes F# better suited for scientific, massively parallel and high-performance computing applications. Beyond functional programming-specific tasks and syntax, F# programs also have access to .NET DLLs, which are accessed and used in the same manner as they are used in other .NET programs.
Scala, being an open source, Java-compliant and Java-compiled language, is available for all operating systems that support Java. Scala development plugins and syntax-definition files are also available for most of the popular text editors and IDEs, including NetBeans, Eclipse and IntelliJ’s IDEA.
F# database-access routines are part of the core language, and they are accessed through the System.Data and System.Data.SqlClient libraries. F# database-access implementation depends on the underlying ADO.NET mechanisms and configuration at the .NET runtime.
As Scala runs on top of a Java Virtual Machine (JVM), it leverages Java’s JDBC. Database routines are invoked either directly through JDBC or through other Java or third-party database extensions. There are several Scala-specific, third-party open source libraries available for this purpose, but I cannot attest to their maturity and stability.
GUI development in F# is fully supported through .NET’s WinForm library. The GUI development API resides in the System.Drawing and System.Windows.Forms libraries, which are standard shared .NET DLLs.
GUI development in Scala is accomplished through Java Swing. As with JDBC, access to Swing features and APIs is done in Scala syntax, so the Swing development feels natural to Scala programmers.
Web development in F#, like database access and GUI development, is accomplished through the shared .NET System.Web library. ASP developers can specify F# as one of their server-side languages and then implement the HTTP-handling logic entirely in F#.
Scala does not feature any specialized Web development components. However, mature Scala-based, third-party frameworks are available for Web development. At the time of writing, the Lift Web framework was the best known and best-established framework for developing Web-based applications in Scala.
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.
In my opinion, the greatest practical difference between the OO features in F# and those in Scala seems to be Scala’s support for pseudo-multiple inheritance through traits 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.|