We’ve learned our lessons, made mistakes and won battles. Now, we’re here to help you and pass some wisdom and practical tips about mastering the CTO’s role.

Say that you’re going to work on custom software development. You have an amazing idea, but when it comes to execution…

Custom software development is not always a bed of roses unless you find the right software development company for your project. 

You may fall for recommendations, reviews, and ratings, but you should also trust another R factor – Research. No matter what you choose, it’s good to have a list of 5 features to consider when making up your mind. And we’ve created exactly that for you. 

Read more

Since functional programming evolved from lambda calculus and has its roots in academia, it was initially discussed in scholarly contexts. It’s no longer the case. Even though significant technologies associated with functional programming (such as Lisp or Scala) were created at universities — FP is making its way to the general “software development discourse,” and some might say that it’s taking it by storm. 

Despite the rising interest, however, not many articles on the web seem to tackle the benefits of functional programming for business. Let’s face it: hacking a new technology in spare time is great, but there’s always a practical side to business when it comes to trying out new things and having a good reason for that. And that’s precisely what we’re about to cover in this piece. 

Here’s what functional programming is, and why does it matter for your business. 

What is functional programming in the first place?

Functional programming (FP) is a programming paradigm, a certain way of thinking about software development that’s based on a few defining principles. In the case of FP, these key principles are as follows:

  1. Binding everything in pure mathematical functions. The purpose is to look for simple, repeatable actions that can be abstracted out into a function and then built upon to create more complex features.
  2. Immutable, unchangeable data — which means that you should rather create new data structures, not altering the ones that are already in place. For example, if you want to modify data in an array, you need to add a new array with the updated value instead of making changes to the “original” one. 
  3. Declarative code. The main focus here is on what to solve, rather than how to do it. 
  4. Statelessness. Functional programs should perform each and every task as it was for the very first time, without any knowledge of what happened (or not) earlier in their execution. 
  5. Recursion. There is no “for” or “while” loop in functional languages, iteration is implemented through recursion. Basically, recursive functions repeatedly call themselves, until the base case is reached. 

Functional programming vs OOP (Object Oriented Programming)

Speaking of programming paradigms, you might already be familiar with another one that’s still more popular: object-oriented programming (OOP). This doesn’t mean, however, that FP is not gaining any traction. Both functional programming and object-oriented programming are unique in their own ways. 

Here’s functional programming vs OOP at a glance to help you grasp the differences:

XFunctional programmingObject-oriented programming
Programming modelDeclarative Imperative
FocusWhat you’re doingHow you’re doing
Parallel programmingSupports parallel programmingNot suitable for parallel programming
Side effectsIts functions have no side effectsIts methods can produce side effects 
IterationRecursion“Loop” concept
Application stateFlows through pure functionsIs usually shared and colocated with methods in objects 
Key elements of the codeVariables and functions are the main elements of the codeObjects and methods are the key elements

What about programming languages, then?  

Pure functional programming languages, such as Haskell, are specially designed to serve this particular paradigm and accept only pure functions. Interestingly, you don’t need to use a pure functional programming language to bring FP principles to your code. 

There are a few languages that still make it easy to write “pure programs”, such as Scala, Clojure or OCaml.  More popular programming languages like JavaScript or Python can also support FP one way or the other – either natively or with the right library.

At Scalac, we’re big advocates of functional programming and, which shouldn’t come as a surprise, we mainly use Scala for this purpose.  There are at least a few good reasons for that:

  • The language is extremely versatile and offers advanced features, clean code, and both functional and object-oriented programming in an open-source, practical package that leverages Java’s environment. 
  • Speaking of — Scala has emerged as one of the most powerful Java alternatives. Actually, one of the reasons why Scala was created in the first place was to address various concerns developers had with Java. Nowadays, Scala provides interoperability and compatibility with Java, allowing the developers to keep their Java libraries, and leverage the advantages of JVM. 
  • When comparing it to Python, on the other hand, Scala’s maintenance is simply much faster. Despite providing the fluency and flexibility of a dynamic language like Python, it’s still a strongly statically typed language. The performance also tends to be much more efficient, especially in a multi-threaded environment.  
  • Because of its functional aspects and flexibility, Scala is also useful for expressive code and parallelism. Basically, with a functional approach and no mutation, there are no race conditions and parallelism gets a lot more straightforward. Then, lambda expressions are also helpful when communicating some aspects of parallelism. 

But, the question remains:

Why should you use functional programming (and Scala, for that matter)?

For some reason, this programming paradigm still seems complex for many. When taking a closer look at the benefits of functional programming and languages associated with it, you might have a different impression. 

To start with, adopting functional programming helps you break down every application into smaller, simpler pieces that are both more reliable and easier to understand. It’s mostly because functional code tends to be more concise, predictable, and easier to test. How come? 

  • Since pure functions don’t change any states and depend only on the input given, they are much easier to grasp
  • When there’s less code, there are also fewer bugs — not to mention that actual testing and debugging gets much easier with immutable data and pure functions that take only arguments and produce output. 
  • With the outputs depending only on the arguments passed to the function, the software can also behave more “predictably”
  • FP adopts Lazy Evaluation which avoids repeated evaluation (basically, the value is evaluated and stored only when it is needed) and supports other Lazy Functional Constructs like Lazy Lists, Lazy Maps, etc. 
  • Functional programming also means efficient parallel coding — there’s no mutable state and no state-change issues, which supports easy reusability and testability. 
  • Speaking of efficiency, functional programs consist of independent units that can run concurrently and can be more efficient as a result. 

Since Scala supports functional programming, these benefits apply to it as well. In fact, the combination of features in Scala makes it possible to write programs that are concise, elegant, and much easier to debug & maintain. 

As a result, increasingly more companies switch to both functional programming and Scala, including well-known tech giants like Twitter or LinkedIn. Interestingly, Scala also made it to the top 10 languages that developers want to learn these days. 

The rising interest from both companies and developers are contributing to the recent growth of functional programming and the adoption of Scala as the main language for many applications — also in a business setting. 

What do functional programming & Scala mean for your business, though?

There’s no doubt that knowing the principles of functional programming can broaden one’s horizons and introduce new ways of thinking about software development. But what’s in it for the companies? 

To start with, code quality. When it comes to functional programming — very often, you can do more with less code. It’s much more concise, which essentially means fewer bugs, and shorter time (and/or fewer people) to actually write it. Plus, it’s a lot easier to grasp what the code does, explain it, and even onboard new team members who can almost immediately join the project and start working on it. In the process, Time to Market often gets shorter. 

What’s also worth mentioning is that the interest in functional programming and languages that bring its principles to life stems from being tired of limitations posed by other programming paradigms and technologies. As already mentioned, Scala as a modern language has plenty of useful features that you won’t find in Python and Java. Even implementing it can be a big savings cost of the bottom line. 

What’s more, there are already some business cases that both functional programming and Scala have been applied to successfully. Health care, accounting, banking, advertising — are just a few exemplary industries.

For the time being, functional programming seems to work best with apps aimed at concurrency or parallelism, carrying out mathematical computation, and whenever there are many different operations performed on the same data set. Scala is a good fit if you have a lot of data or complex data structures and algorithms, but FP languages are also often used for artificial intelligence applications like machine learning, language processing, or modelling of speech and vision. Pretty impressive, right?

With the rising interest and so many benefits of functional programming, how come it’s not yet as widespread as it should be? 

At the end of the day, businesses rather choose the technology based on the skills of their team or the availability of developers, who are more likely to represent more traditional approaches to software development. That’s precisely why it matters not only to educate developers about FP but also give them tools to apply it in practice. 

For now, “the movement” is all bottom-up: it’s starting from developers who are tired of being limited by other programming languages, become interested in functional programming, and then teach their colleagues about it. 

As these developers start creating libraries and frameworks that solve specific business problems across multiple areas (such as backend development, analytics, distributed development) with the use of functional programming — eventually decision-makers will also get excited about FP. And, the more companies are interested in functional programming, the more developers skilled at it they want to hire. It’s a chain reaction from there. 

To facilitate the shift to functional programming, drop some of the jargon around FP and lower the barriers to entry, there are initiatives and projects like ZIO — a library for asynchronous and concurrent programming based on pure functional programming. Taking advantage of it is said to help in solving common business problems, and ensuring higher success rates of projects. This, in turn, brings more attention to functional programming, in the business world as well. 

What’s also great about ZIO is that it’s inclusive for all sorts of developers. It’s still fairly new, but it’s expected to be a great venture in the long run, mostly due to all the open-source support it gets. It might be difficult to take advantage of ZIO when developing enterprise-level software just yet, but more and more companies are already testing it in production for smaller projects. And that’s only one of the reasons why the future of functional programming definitely is bright. 

Dig into functional programming yourself 

Increasingly more companies are prepared to train development teams on how to use FP and solve business problems with functional programming, including Scalac

Switching to functional programming can be done whenever there’s a new module to implement and thus, can be done gradually. Start small, and see how big of a difference the main aspects of functional programming can make to your business. As per usual, we’re here to help

One of the biggest language learning apps in the world, Duolingo is serving hundreds of millions of users every single day. Most of the app’s backend was written in Python, yet the tech team has decided to rewrite one of Duolingo’s core features in Scala.

With this article, you’re going to find out:

Want to learn more? Let’s dive in:

Duolingo before Scala

If you’ve never learned a language with Duolingo, here’s a quick summary of how it works:

As you can see, the app’s users learn through short lessons consisting of different types of exercises. 

Here comes the question: which exercises, and in what order, should the users see? 

Duolingo’s Session Generator is the module that makes these decisions for the users creating adequate educational sequences. 

This core feature has been around since the very beginning of Duolingo. The startup, as we already know, was gaining popularity pretty fast, thus growing rapidly.The hectic pace was both a blessing and a curse. Duolingo’s tech team had to act fast and didn’t always have the time and resources to optimize all the processes accordingly. And this led to significant technical debt

For instance, the Session Generator’s architecture featured many hard dependencies. This means that if any of those failed, the whole module would stop working. In other words, many features of the module affected the performance of other features. As you can imagine, this makes potential bugs much more likely. 

Because of that, the Duolingo team decided to redesign the module’s architecture and eventually rewrite the Session Generator. Here’s how they decided on the language:

Moving to Scala

As in many companies, Duolingo’s backend was originally written in Python, one of the world’s most popular programming languages. It’s a common choice, as it’s easy to understand for developers with different kinds of experience. 

There are, however, some challenges that come with Python, one of them being the speed. 

This language tends to be visibly slower than Java or C, while Java is also considered rather slow and verbose. What’s more, Python’s dynamic typing can be the cause of many runtime bugs. 

To avoid these issues, the Duolingo team decided to move their product to Scala. Contrary to Python, Scala is a statically-typed language. It’s widely used in other complex big data apps like for example Kafka that was developed by LinkedIn and is used to handle real-time data feeds. Not surprisingly, it turned out to be a good fit for Duolingo’s Session Generator as well. The team claims that they were looking for a more modern programming language. They also think that Scala is very mature in the back end so it fits the bill.

Implementing Scala in Duolingo

JVM and Functional Programming 

There was no need to reinvent the wheel. As Scala is built on the Java Virtual Machine, developers could use existing Java libraries. One of the biggest changes was the shift towards functional programming. Andre Kenji Horie, Duolingo’s senior software engineer, is a big fan of this solution. According to him, around 99% of Duolingo’s codebase is functional. He claims that it makes things much easier to debug, much easier to maintain.

Many developers have the impression that Scala seems to have learned from the mistakes of other languages. Here’s how the Duolingo team perceives it:

  • More concise – While Java is known for being elaborate and rather slow, Scala does a lot to make the language less verbose. Thanks to it being a functional language, the developers can use simple one-liners in many cases too.
  • Less prone to bugs – As we’ve already mentioned, Scala’s static typic makes it easier to catch bugs with a compiler. Less verbosity makes the work smoother, too. Contrary to Python, Scala is much less prone to runtime bugs.
  • Saves a lot of time – Andre Kenji Horie has stressed that writing code in Scala is significantly faster than programming in Java. In the same amount of time he’d use for coding alone, he can also write unit tests for Scala. This makes the developers more confident about the quality of their work.
  • Easier maintenance – When compared to Python, the development speed is similar, yet Scala’s maintenance is much faster. Andre mentioned that after moving to Scala he suspected that refactoring would take him around an hour, like in Python. To his surprise, it only took around one minute.
  • Efficient performance – As you already know, Scala is running on a Java Virtual Machine and is doing very well in a multi-threaded environment. In other words, it means that it can do a lot of things at once. Scala’s efficiency also means that Duolingo can use 10 times fewer servers to handle the same amount of traffic, which again is a huge saving. 

Of course, there were some challenges along the way. The team has described the two main pain points:

  • Java integrations – Some of the integrations were not compatible with certain Scala-specific features.
  • Documentation – As Scala is a rather new language, finding some of the libraries required extra effort. 

Scala learning curve

What’s more, many people claim that Scala’s learning curve is quite steep. In this case, improving readability and optimizing the product’s maintenance process was far more important, and here’s where Scala is doing really well. When asked about the learning curve, software engineers from Duolingo say that it was actually a lot easier than anticipated. It proves that even though the language is new, learning it is not an obstacle. 

To sum up, the team is happy with Scala despite the tiny downsides. Andre Kenji Horie has said in a Software Engineer Daily podcast that There are some small things here and there in the language but […] it is not a big deal. He claims that pain points didn’t come with Scala itself but were more related to changing from one language to another. For instance, when they had a function that was used in Python but not in Scala, they needed to find a workaround. 

Note that this is only related to the onboarding phases. In general, the team appreciates how Scala offers a lot of useful features that are not present in Python or Java. 

Duolingo and Scala: the results

The service turned out to be much more robust after the rewrite. It’s easiest to see in the speed test results. The latency before the rewrite was 750 milliseconds, while after implementing Scala it went down to as little as 14 milliseconds. Quite impressive, isn’t it?

To top it all off, the rewrite proved to be significantly more stable. With the old infrastructure, the average downtime was around 2 hours every quarter. After switching to Scala, the first few months boasted zero downtime. Obviously, it probably won’t last forever, yet it still looks very promising.

The team claims that Scala meets their needs as it’s very mature in the back end and, as we’ve mentioned before, makes a great fit for big data applications. 

Last but not least, the shift to Scala has improved morale among developers. They feel more confident deploying the code, as they don’t have to fear they’ll break the entire app. The improving testing suite that is used in Scala makes their work much more pleasant. Considering unit tests are prepared by developers who test individual code before integration, issues can be found at an early stage. Thanks to that, they can be resolved without impacting the other parts of the code. 

Scala as the right choice for your business

Does it sound like Scala could be the right fit for your product? If you’d like to learn more about implementing Scala in other global companies, you’re sure to enjoy this Zalando case study. Of course, if you have any questions about implementing Scala,we’re always happy to help, as we’re of the biggest Scala development companies. Feel free to get in touch via live chat on the website!

The article is based on the following sources:

A growing number of big companies have swapped cumbersome monolithic applications for distributed systems. And in virtually all cases, they’ve boosted customer satisfaction, reduced costs, and increased revenues.

Read more

As Zalando kept growing to become an ecommerce giant, at some point they have decided to switch from Java to Scala. Although it’s a major move that required a lot of effort, they managed to do it in less than three months.

Want to see how they did it? Wondering if this might be the right choice for your company? Keep reading to find out more!

Java vs. Scala – the main differences

We’ll start with a quick introduction so you can see clearly what are the main differences between Java and Scala: 

  • Amount of code – This is the main difference you’ll surely notice at first sight. Scala is a drastically more concise language than Java. The number of lines is visibly reduced, thanks to the use of type inference, function passing and several other factors. 
  • Parallelism – Scala is a much better fit for parallel programming, as it’s designed to express patterns in a very concise manner. 
  • Objects and functions – While Scala is both functional and object-oriented (we’ll cover that in more detail later), you need to keep in mind that functions are acting as objects in Java. Scala treats every function as a variable, which means than one Scala function can accept another. This is one of the most impressive features of this language. 
  • Syntax – This is one of the reasons while Scala’s learning curve can be so steep. Although concise, the syntax seems a little off-putting at first, which is why some people consider Java more readable. This might be a problem for these who want to get started with Scala. 

Why Zalando chose Scala

Alright, so why exactly did Zalando decide to look for a Java alternative, then? Here’s why they thought Scala might be a better choice for some of their needs:

  • The company had years of previous experience with the Java Virtual Machine – Javier Arrieta, one of the Senior Software Engineers at Zalando, had a whopping 18 years of previous experience working with JVM. This solution is fast, efficient and quite convenient for debugging as well. Java worked fine, but there was one problem: the amount of code needed to ensure stability. The team thought that it would also be nice to use lambdas for transforming collections.
  • Scala works well with Java libraries and frameworks – This made the transition from Java to Scala much more convenient. The developers didn’t have to let go of all the libraries they’ve already been used to. They could also stick to Play, which is used for both Java and Scala development. This framework is intuitive, extensive and trustworthy, as it’s backed by Lightbend (formerly Typesafe).
  • It combines functional programming and object-oriented programming – Why choose one when you can have both? Scala presents a hybrid approach, as it combines both object-oriented (OOP) and functional programming. The possibility to choose one or the other paradigm, depending on the situation, makes Scala a really flexible choice. 
  • Scala is great for parallelization – This is one of the main advantages of functional programming. What’s more, Scala comes with a Futures API, which makes parallel programming much smoother. You can use this solution instead of sticking to traditional methods like locks, callbacks and threads. 

What kinds of challenges come with Scala

Although the Zalando team is still positive that moving to Scala was the best choice they could make, there are some challenges they had to face:

  • Compilation times – Advanced languages features in Scala make the compilation time longer. Luckily, there’s a solution to this issue. Zalando team turned to incremental compilation. This trick helped them solve the problem. 
  • Language problems – The same thing in Scala can be written in many different ways, which is both a blessing and a curse. There is no canonical style guide available and the code can get unreadable quite. When implementing Scala, it definitely pays off to implement some sort of in-house style guide. This will help you achieve consistency. 
  • Possible operator overloading – In Scala, the operator can have a different implementation depending on the argument. This case of polymorphism can lead to confusing constructions. 
  • Learning curve – As we’ve already mentioned in the Java vs. Scala comparison, Scala’s syntax can seem highly complicated to those who want to learn it. It’s a hybrid language, which is a double-edged sword: it makes work easier, but you need to consider more aspects to understand how it works. 

How Zalando introduced Scala

The team has to admit that Scala’s learning curve is pretty steep. All developers had to be introduced not only to a new language, but also new frameworks, new build tool and, above all, functional programming concepts. 

So, how do you tackle such a complex project? Of course, you need to start by providing high-quality educational materials. The team at Zalando picked Scala courses from Coursera, which turned out to be a great fit for their needs. 

The developers proceeded to learn through prototypes and greenfield projects. They were creating systems for a new environment, without integrating them with other systems yet. Another method used to introduce Scala was the layered approach. All these measures helped the team learn new skills in a controlled environment. 

Internal workshops worked quite well, as many senior Java developers were willing to learn Scala. Actually, all-Scala developers are quite a rare phenomenon – most of them have transitioned from another programming language. When it comes to exact numbers, 40% of engineers and Zalando expressed interest in learning Scala. 

In Zalando’s Dublin office, most services and data pipelines are written in Scala. The Irish team is using that language to develop the Customer Data Platform.

How the developers at Zalando adapted to Scala

It is also worth mentioning that there were two main types of Scala adoption in the company: 

  • Using Scala as Java – For developers who already had years of experience working with Java, it was almost certain to happen. You could say that they’re using Scala as an improved version of Java, with all the lambdas, pattern matching and case classes involved. 
  • Functional programming nerds – The second group, on the other hand, really got into Scala and all the exciting new opportunities that come with functional programming. They treat Scala like an entirely new programming language and are more open to trying new things. 

It’s good to keep this pattern in mind, as it’s quite likely that introducing Scala will take a similar turn in your company. Some developers may prefer to stick to their own habits and only adopt certain features of the new languages, while some may be particularly excited about implementing a new solution.

What Zalando loves about Scala

Now that Zalando has been working with Scala for quite some time, they can definitely list some of their favorite things about it:

  • Types – The team at Zalando absolutely loves types. They help them understand what kind of value they’re working with, whether it’s the customer’s password, their name, or maybe their email address. They prefer using either tagged types or value classes to manage this data.
  • Referential transparency – It’s about the substitution model. Referential transparent computation allows the team to substitute a function with parameters, which makes work so much easier. It’s also incredibly helpful for testing a program.
  • Using monads for function composition – One of the main advantages of Scala is how it allows composing functions to create more complex ones. Monads one of the most popular ways to make that happen. Thanks to them, many operations can run sequentially.

Key takeaways

As you can see, the Zalando team is very happy with using Scala instead of Java. They love to explore the wide possibilities that come with the hybrid of object-oriented and functional programming. Why not have a closer look at their process and implement a similar solution in your company? Who knows, maybe Scala is the alternative you were looking for. The case of Zalando proves that it can be successfully implemented in just a couple of weeks. 

The article is based on the following sources:


Check out also: