Developing in F#, latest
member of the Visual studio family
By Elizabeth Thomas, Project
Manager, RKC infotech (August 2009)
F#, the latest member of the
Visual Studio family of languages, offers some enticing advantages over C# and
Visual Basic, stemming from its functional-object fusion nature. Originally a
research language from Microsoft Research, F# has long been a “secret weapon”
in the arsenal of .NET programmers for doing statistical- and
mathematical-heavy coding. More recently, however, a growing number of
developers have begun to see the inherent advantages implicit in writing
functional code, particularly in the areas of concurrency. The F# programming
language incorporates many state-of-the-art features from programming language
research and ossifies them in an industrial strength implementation that
promises to revolutionize interactive, parallel and concurrent programming.
F# is a remarkable language
for prototyping for the following reasons:
F# has an interactive mode
allowing you to evaluate blocks of code directly, without compiling your entire
project.
Type inference helps keep code
small, and makes refactoring your type hierarchy relatively painless. This may
not be so important in production code.
F# integration with .NET makes
it easy to prototype extensions of your existing products. In the
all-too-common case when a prototype becomes a product (due to time
constraints), it’s also easy to integrate your F# code within your .NET
product.
If prototyping makes up a
significant part of your overall development process, then F# can really help
you speed up your coding.
It is not that F# will produce
code that is significantly faster than other .NET languages. The functional
style of programming, in particular purity (no side-effects), can be applied to
other programming languages, meaning it is just as easy to write concurrent
programs in other languages as well. It does however "feel more
natural" to do so in F#.
F# has the Option type, which
can be used in place of null values. Code reliability with respect to
null-pointer exceptions can be guaranteed at compile time, which is a huge
benefit.
The more specific answer is:
F# will help a lot for certain classes of applications, but may not do much at
all for line-of-business apps. F# is well suited for math and science
applications. The functional nature of F# can also help you write more reliable
concurrent programs. Given the increasing number of multi-core processors, this
might be quite valuable to you.
Industrial applications
Many companies are already
adopting or investigating F# even though it is only available as a Community
Technology Preview (CTP) because the language is already useful for certain
kinds of applications:
Investment banks such as
Morgan Stanley, Credit Suisse and UBS already employ hundreds of F# programmers
who build in-house software.
Companies with products aimed
at technical users are already moving to make their APIs F# friendly, such as DataSynapse
.
Some companies are already
shipping software written in F#
-Flying Frog Consultancy sell
the libraries F# for Visualization and F# for Numerics that are written in F#
and designed for F# programmers.
-Coherent Graphics sell the
Coherent PDF Toolkit for .NET which is end-user software written in F# and
designed for use by non-programmers.
Advantages of F#
F# is the world’s first
language to combine all of the following features:
Type inference: types are
inferred by the compiler and generic definitions are created
automatically.
Algebraic data types: a
succinct way to represent trees.
Pattern matching: a
comprehensible and efficient way to dissect data structures.
Active patterns: pattern
matching over foreign data structures.
Interactive sessions: as easy
to use as Python and Mathematica.
High performance JIT
compilation to native code: as fast as C#.
Rich data structures: lists
and arrays built into the language with syntactic support.
Functional programming:
first-class functions and tail calls.
Expressive static type system:
finds bugs during compilation and provides machine-verified
documentation.
Sequence expressions:
interrogate huge data sets efficiently.
Asynchronous workflows:
syntactic support for monadic style concurrent programming with
cancellations.
Industrial-strength IDE
support: multithreaded debugging, and graphical throwback of inferred types and
documentation.
Commerce friendly design and a
viable commercial market.
Why F# is So Important to the
Future of Software Development?
It has been thought a lot
recently about why F# might be important to the future of all software
development. If you think about it, there’s really little in F# that doesn’t
already exist in other languages like OCaml and Haskell. But F# is significant
and different because Microsoft is behind it and because of the tight
integration with the .NET framework. But beyond the who of F# is the why of its
importance. And the why, in one’s mind can be summed up with these five bullet
points:
ORMs are failing because the
imperative, object-oriented languages in which we use ORMs are unfriendly to
sets and tuples. The database is full of nothing but sets and tuples. So we
read them into objects and wonder why there’s an impedence mismatch. F# is not
only set and tuple friendly. You can’t really think properly in F# without
these first-class constructs.
F# is appearing at the right
time and place in history to serve in the critical role of helping us to build
new DSLs.
F# allows us to revisit the
time-honored design patterns that are workflow-oriented and view them in the
light of functional decomposition. And the result this will allow many who have
been unable to grasp those patterns though an imperative lense to "get it"
for the first time.
Service-Oriented Architecture
(SOA) is predicated on the idea that strict operation contracts exist that
takes discrete, strongly-typed inputs and return strongly-typed results. F#
rolls like that. There’s no object-orientation in SOA, per se. But the
workflow, scheduling and execution core of SOA will be based on functional
languages like F# instead.
We need a model that
will make parallelism invisible. But for parallel computing to become
invisible, we need to move to a model that doesn’t require the programmer to be
involved in locking and serializing access to their code. F# is ready to help
us think that way. And it’s .NET! Beauty,
|