Choosing a Programming Language

Functional Programming

Frankly speaking, I never faced the question of choosing a programming language. In other words, this choice has always been obvious for me. I never took part in holy wars like C++ vs. Java that used to be so popular at the end of 1990s. When you see a huge growth of productivity with your own eyes, any discussions become meaningless.

I’ve also noticed that only people who’ve seen just one side of the given discussion usually take part in it. This may be a good idea when it comes to gay marriages. But it’s very unprofessional in the world of programming. Perhaps, that’s the reason why all informal parties of programmers in the alco-holy war format have failed. It’s hard to gather professionals in such a way.

Anyway, I’ve been thinking about the choice of a programming language for a week. However, it was the first time I thought about it during the twenty years of my career. Yes, guys, programming is what I have done for a living during the last twenty fucking years. Why now? The answer to this question lies in one word – Scala.

It definitely wasn’t last week when I heard about Scala. It was 2008 when we began to feel that Java was not so good (we learn everything in comparison). That’s when we started thinking about a programming language that would allow us to enter the next decade. The issue was strategic, and it was close related to the future of our company. That’s also when we bought the first and not yet finished book by Martin Odersky, and immediately found Fantom

The Rise of Fantom

Fantom has always been absolutely great. The product of Brian& Andy Frank (can’t stop admiring these guys) goes to the same niche as Groovy, Ceylon, and Kotlin, However, I vote for Fantom. There are certain grounds for this, but they are beyond this post. Fantom absolutely won my heart five years ago and we even made an IDE for Fantom (primarily for our own needs). We supposed it would be the main development language in our company for the next ten years.

I wasn’t unique, and I suppose JetBrains created Kotlin for the same reasons, as well as guys from itemis created Xtend, and those from Guidewire became the authors of Gosu. Well, that’s also why Brian (SkyFoundry) created Fantom. They wanted to be more productive and needed a programming language that would let them do it. In my opinion, all these languages belong to the same niche. They really let you become 2 or 3 times more productive compared to the situation when you develop in Java. This is my personal assessment, and I think it’s time to take this issue off the table. Okay, we are going to write in Fantom.

By the way, I forgot to tell you about Scala. Shocked by Odersky’s book, I realized that it’s impossible to find a team capable of writing in Scala, no matter where we would look for the right people. Actually, we could certainly find programmers able to *use* Scala, which is what happens in lots of hipster-startups that think of Scala as some sweetened version of Java and see no further than syntactic sugar. Fortunately, we do not belong to this type of “programmers”.

Just like a library, framework, technology, instrument, and so on and so forth, a programming language should increase your productivity. Using Scala in the Java-like way will decrease it, whereas tools are really bad, the ecosystem is weak, and the compiler is slow, and the list can go on. It takes us years to find a team of programmers able to write in Java. It will take us dozens of years to find people capable of writing in Scala. Thus, the search area narrows down.

Actually, my opinion of Scala was quite skeptical at that time. I thought of it as a language that came from the academic sphere, which, to my mind, had more research on the type system than real life. That’s why it got a minus from me when compared to the language created by practicing software engineers who are well aware what they need and why when trying to solve practical problems.

That’s why our choice is Fantom, and only Fantom. Especially since we have made Fantom Runtime work with Eclipse Equinox (OSGi), and also learned how to write Eclipse plugins on it. We also began creating Eclipse-based IDE on it, which made Fantom a great language for the current part of the business that makes money. In addition, we’ve met with the creators of the language in person. And made sure we can influence on its implementation in future.

The future seemed bright and light, and the light was called Fantom…

Scala Strikes Back

In October 2012, I spent a few boring nights at a hotel in Germany. Suddenly, I remembered about a first-time programmer who had recently asked me to give him advice on what courses to watch on Coursera. I have to admit that I watched no courses at that time. However, I decided to have a look at Odersky lectures for Scala programmers and watched the entire course in two nights.

The things I saw were fantastic to me. I even had a sort of a mystic feeling after watching it. Scala is definitely the highest peak of the development of programming languages for the moment. I am not talking about DSLs and languages embedded into various platforms like or JavaScript. I am also not talking about various dynamics like Ruby and Python – everything is simple here.

I will assign these languages to the same niche as JVM-based Groovy, Fantom, Kotlin, and other, born not to fly, but swim. You can think of Ruby and Python as dolphins, and consider JVM-based things primates (monkeys, gorillas, and orangutans). Well, there are also jokes of nature like JRuby and Jython. They are a sort of crawling dolphins.

On the background of this animal, diversity comes it. If I had a tumor, I would call it Scala. A small sore on the palate that would heal if I didn’t touch it all the time. Damn… I guess I’ve lost the thread… Anyway, I think that Scala is the current top of the evolution of programming languages at the moment (I’m definitely looking further than Odersky lectures right now), and we should do something about it. Actually, the question is simple. Should we write our future products in the most powerful programming language or not? The answer to this question is far from being simple.

I am not interested in such minor crap as ecosystems and support by the industry, etc. I want to know whether we should build on Scala when there are other equal languages.

I’m also not interested in a popular opinion saying nowadays we can write in any language, and multi-language projects become more popular every day. I know this well enough, but I also know how unproductive it is to mix Fantom and Gosu, or Scala with JRuby, despite the fact that all of them are JVM-based. Well, the only things they have in common are JVM classes. In other words, it’s the same what we did 20 years ago when linking with object files written in Pascal, Fortran, C/C++, etc. The level of “integration” is almost the same.

Spiral of History

It is a well-known fact that history is cyclical. Being not young, I have seen the bigger part of the previous turn of the spiral. It’s the spiral of the development of professional general-purpose compiled languages and their evolution from structurally-oriented to object-oriented. Being a practicing engineer, I don’t care about all the academic crap like Haskell. The industry of the previous turn held on C and C++, which should not be doubted. There’s also an intermediate, successful link, and it is Objective-C (Although, I wouldn’t say that it holds the industry together.), and I think it’s really important to mention it.

Thus, we have the following evolution of the previous cycle (I have to emphasize once more that I’m considering only the winners of the food chain, absolute alpha males in their habitat).

С (procedure-oriented) -> Objective-C (with ОО elements) -> C++ (object-oriented)

These three languages only are interesting for us. I don’t include Smalltalk to the list, as it was the beginning of the following turn of the spiral. The main difference of the current turn from the previous one (C/C++) is Managed Runtime and garbage collection.

Therefore, development on the previous turn moved from C to C++, from procedure-oriented to object-oriented language (still procedure-oriented at the same time) as the peak of evolution at the previous turn. Interestingly, that there also appeared and occupied their niche quite good intermediate variants like Objective-C. Some hipster programmers think that the latter is the top of programming languages, and I am not going to disappoint them today.

Now, let’s move on to the future turn. The current turn of the development of programming languages is simply a copy of the previous one. Java took the place of C in the current turn. Well, C# as well, not to offend the .NET people. This makes no difference for me. It’s like arguing about differences between PowerPC and Intel, might be interesting, but absolutely meaningless.

As I have said, the current turn differs fundamentally from the previous one in the availability of managed runtime, and a different paradigm. While the previous turn of the spiral began with the simple procedure-oriented C language and finished with extremely difficult object –oriented C++, this turn begins with the simple object-oriented Java language. The latter is much simpler than the development top of the previous turn (С++),

Keep in mind that it’s much simpler than the development top of the previous turn (С++), and it moves towards Scala, an extremely difficult language of functional programming. Scala, at the same time, is also object-oriented, just like C++ remained procedure-oriented. During this process, there appear intermediate languages like the mentioned Groovy, Fantom, Kotlin, etc. with elements of functional programming.

Looking at all of this stuff, I have no doubt that Scala will be the highest peak of development on this turn of the spiral, and it will take the same place that C++ took at the previous turn. All the intermediate things will take the niche of Objective C. As for Java, it has already taken its place.

Interestingly, I can see no languages that could define the beginning of the following turn like Smalltalk did at its time. What I know for sure is that it’s going to be easier than Scala (as simple as C and Java), but its rise will come along with some fundamental shift as the runtime did at the time. This could be distributed language or some fundamental support for concurrent computations.

Getting Back to the Point

I deliberately voiced all these thoughts as drawing analogies the choice of language is even simpler now. Should we stake on Objective-C or C++? Fantom or Scala?

The answer is not as obvious as it might seem. However, the following thing is obvious. There are tons of projects developed in C and Java. Staking on Java, you will never lose. As a rule, such projects do not change paradigms and bring useful elements. You might suffer from the weak ecosystem, but good productivity will save the situation. I might Groovy, Fantom or Kotlin the main language in our company, which seems to be a no risk variant. Well, I haven’t noticed any risks for the last 4 years.

As for the thought of making Scala the main language, it excites and scares me at the same time. If someone told me 20 years ago to write everything in C++, I would be really happy about it. But I’m scared today.

C++ and Big Projects

Unfortunately, I have no experience working on a big C++ project, and none of the people I know does. Even if some of my friends did work on such projects, they did not take care of communication between developers or third-party libraries, etc.

It’s a shame but I don’t how good or bad C++ is in the role of the main language of a company. It is definitely good for a small one and maybe some individuals. Since there appears “a C++ of its own” in any team, every project has certain individual features. Java, just like C, lacks this feature. I have no doubt that using Scala each team will invent a Scala dialect of its own, which will result in some pain in the ass.

I think that there will be the same list of problems we see in C++ projects, and I’m not talking about internal problems. I’m talking about relations with the outside world. How many string implementations have you seen in C++ projects? Staking on Scala, I will await something of the kind but on a different level of abstraction.

There’s no need in further discussions, but the following thing is obvious. Scala will give a huge growth of productivity compared to Java, just like C->C++. This is true for one developer in the vacuum. The complexity and endless options of the language will result in multiple problems that won’t be good for productivity. As far as I know, there are no big Scala projects at the moment.

In the end, we could have a look at the list of projects written in C++by Stroustrup. Not so impressive, right? I’m sure that the list of C projects would be much longer.

Comments

    3,751

    Ropes — Fast Strings

    Most of us work with strings one way or another. There’s no way to avoid them — when writing code, you’re doomed to concatinate strings every day, split them into parts and access certain characters by index. We are used to the fact that strings are fixed-length arrays of characters, which leads to certain limitations when working with them. For instance, we cannot quickly concatenate two strings. To do this, we will at first need to allocate the required amount of memory, and then copy there the data from the concatenated strings.