Sunday, November 02, 2008

The best of F# and C# -- Nemerle? Scala? various approaches to mixed OOP - functional languages

Today I was pointed out to yet another mixed OOP and functional language: Nemerle. I looked at the Nemerle features and immediately spotted something very familiar, "Probably the most important feature of Nemerle is the ability to mix object oriented and functional programming styles. The top-level program structure is object oriented, while in the body of methods one can (but is not forced to) use functional style. In some programming problems this is very handy." It sounds exactly the same as what is stated about Scala programming language, "Scala is a general purpose programming language designed to express common programming patterns in a concise, elegant, and type-safe way. It smoothly integrates features of object-oriented and functional languages." A main platform for Scala is JVM, but it's CLR variant already exists and is planned to be fully developed.

I think that both C# and Java in their pursuit of simplicity dropped too many functional features which existed in their common parent - C++. I've just blogged about it today. So, both communities felt the need for more functional OOP languages. It looks like that both Scala and Nemerle chose the same approach which creators of Java used: to build up on the base of familiar and wide-spread language in a hope that it gives an immediate advantage of huge number of programmers who are familiar with the syntax and want to try new language. I don't know about Nemerle yet and I still know too little about F#, but Scala language found a very natural and consistent way of combining object oriented and functional features and is even better OOP language than Java.

I think people are absolutely right, when they are saying, that it's hard to catch up with F#, "because the syntax of the ML - derivative languages is just too foreign for those with only imperative language experience". I felt it by myself when I was trying to start learning language using "Expert F#" book, having no prior ML experience.
But there is a flip side: now, when - thanks to an excellent "Real World Functional Programming" book by Tomas Petricek I started to understand both functional concepts and beauty of ML syntax, I feel that more graduate approach taken by Scala (and probably - Nemerle) may in fact postpone real understanding of a functional nature of new languages. It's possible to program in Scala as in "improved Java" and never learn its functional features. And thanks to more steep approach of F# I now better understand and try to pursue functional approach in Scala and better understand ideas behind LINQ...