Python vs F#: which language I should learn - Stack Overflow
Hey, I know this is an subjective question, but please don't vote to close it before I get the acceptable answer.
I'm a .NET programmer (somewhat experienced), and really want to learn a functional
language. My preferred choices are F# and Python, and I'm really doubting about which
one to choose. Please clear my doubts. I'm totally new with them both, so please tell
me their benefits over each other, or why I should choose F#/Python.
Maybe I'm misleading, but Wikipedia says that:
F# (pronounced F Sharp) is a multi-paradigm programming language, targeting the
.NET Framework, that encompasses functional programming as well as imperative
object-oriented programming disciplines.
Python supports multiple programming paradigms, primarily but not limited to
object oriented, imperative and, to a lesser extent, functional programming styles.
Thanks in advance.
I doubt you'll learn much of value from Python. It's a dynamically typed OO language
with pleasantly lightweight syntax. Other than giving you even less protection (and
speed) than you'd get from C#, you'll be writing the same programs, just in a slightly
F# is a different beast altogether. It has a rich, statically checked, polymorphic,
algebraic type system. It is mostly functional, which means it strongly encourages you
to program declaratively and avoid side effects (such as assignment) wherever possible.
This has several benefits:
* the compiler will catch many more errors than you'll be used to;
* your programs will be much shorter;
* your programs will work first time (once the compiler has wrung out all
the bugs it can find) about nine times out of ten, in my experience;
* the compiler can typically generate much, much better code.
I usually reckon it takes an imperative programmer about a month to rotate their
thinking into the functional style. The downside is that after you make the adjustment,
the programming mainstream just feels rather primitive and awkward.
Go for it, it's eye-opening.
Here are some facts about the languages (I know more about F# so am likely to have
bias) which may inform your decision.
* F# ships inside Visual Studio and is a .NET language, so if you know that
platform/tools, it is an advantage for getting off the ground. Iron Python is a
.NET Python implementation that also has some VS support as an add-in.
* Both languages have REPLs. F# is compiled (even in the REPL it gets compiled on
the fly), so has good performance both as a compiled app and in the REPL. (Not sure
* F# is 'more functional' by a variety of criteria, so if you really want
"functional", I would choose F# over Python for that reason alone.
* F# is statically-typed. Python is dynamic.
* Both languages are often used in science/math domains; I think Python is older
and has more (and more mature) numerics libraries.
* You can use F# and Iron Python together in concert (I've seen a few blogs that
show basic demos of this) if you want to do both.
Sorry to throw another wrench into the discussion, but trust me, Haskell will help you
learn F# a lot faster.
I learned F# first and then learned Haskell -- and found that it would have been a lot
easier if I'd learned Haskell first.
F# is great, but it offers too many shortcuts, so you don't really learn as much.
Python is great too, but again, it's a lot more imperative than F# is even, so you
won't learn anything at all.
F#, definitely, if you want to stay in the .NET world.
Personally, I'd suggest Common Lisp as well as F#. Haskell is somewhat similar to F#;
Lisp is not, not really.
F# is a strongly-typed, type-inferenced language with the default of immutable data
(Much like Haskell). F# has the decided advantage of being pushed by Microsoft. F# is
very much in the no-side-effect world.
Common Lisp has a somewhat looser type system (But not weakly typed), and its data is
not immutable. It also does not guide you towards not having side effects.
Like the other chap, I don't think Python will offer you much in the 'mind-bending'
arena (unless you really start digging around the internals), whereas F# will start to
expand your mind from declaration one.
Python is not a functional language really. Although it has certain functional aspects
(which make it much easier to work in, imho).
I would like to add some points for Python, in light of the unfavourable opinions given up.
1. As rightly mentioned, it is useful to know different languages and styles to
gain more experience. If you are looking for a functional programming, F# is the
2. However, the concept of variety extend to the libraries involved. F# doesn't
give you a lot of variety to the other .Net languages apart from a few immutable
data structures. Python is a different language with a different standard library
and data structures. I personally regard the selection of default data structures
in Python as one of the finest in any language. Lists, dictionaries, heaps, deques,
sets, bisection algorithm, etc. All that is available in a very usable and useful
way which may serve to introduce you to new techniques that you can then use
elsewhere. To demonstrate the effort being put in the language, the sorting
algorithm used in Python is an efficient algorithm invented for Python (timsort)
and is now also used in Java.
3. If you want to expand your horizon and get outside of the .Net shell, Python
will be more useful.
4. Python is dynamic and thus gives you less compile time protection than F#. The
question is when is this protection more useful. The simple answer is that if
you have a clearly defined domain and your design is well specified then you
can go for static language like C#. If you are more on the experimenting side
then a more forgiving language is needed. F# is way better than C# in this regard
due to its type inference, but there are still cases where the flexibility of
Python duck typing is more useful.
5. One case where the languages are different is in their object oriented design.
F# would look more like C#. Python has a different and more flexible design with
metaclasses among other additions.
6. Did I say that the Python standard library is marvelous?
7. All these are points that are currently valid. In the future, F# will likely
grow more libraries and given the growth in the .Net space will be even more
impressive. Python will become much more quicker due to efforts in different
directions including Cython, PyPy and unladen swallow.
My view: if you want to learn F# because it is functional then go for it. If you want
to learn it because it is shorter, it typically isn't shorter than Python. If you want
to learn it because it is compiled and thus the compiler will catch your errors and
make your program work first time, then I am afraid you will be very much misinformed.