Geek Culture
Published in

Geek Culture

Why Haskell?

My Intro into Functional Programming

It's been a long time since I’ve written a blog! I had a wonderful vacation but I just know everyone is dying to know what my next project is. It's Haskell! This week I’ve been learning the basics of functional programming and Haskell. But Sara, why are you moving away from Object-Oriented Programming? Why Haskell?

That’s a good question. The chart below ranks programming languages based on the PYPL PopularitY of Programming Language Index. This is determined by analyzing how often tutorials for a specific language are searched on Google. Where is Haskell? Oh, it's near the bottom at number 27 and showing a decrease in popularity over the last year.

source: https://pypl.github.io/PYPL.html

So, again, why Haskell? Functional programming has been gaining in popularity over the last couple of years, with languages like Java and Python even adopting some of the concepts from functional programming. Secondly, and more important to me, it's adding some new tools. If I wanted to learn another OOP language, it would mainly consist of learning new syntax. However, by deciding to learn a new programming paradigm, I will diversify my skills much more and learn a totally new approach to solving problems. I understand this will be more of a challenge than if I wanted to learn Java next (especially given my C# experience) but hopefully, the effort will pay off.

Functional Programming

First, I had to get familiar with the concept of functional programming. I know what a function is; we all do, and we use them all the time, even in OOP. But, here's the difference. In OOP we try to build objects that represent, as closely as we can, the real world. You have a set number of functions you can use to add, modify and have objects interact with each other. In functional programming, instead of building new objects, we build new functions.

Functional programming is programming using pure functions. It doesn't use shared state or mutable variables. This leads to no side effects since for the same inputs we would expect the same outputs. Pure functions do not modify variables, but they can return new ones. Some more characteristics of FP are:

  • focuses on results, not the process by using expressions and declarations rather than execution of statements
  • uses conditional expressions and recursion (no loops)
  • value output doesn’t depend on a local or global state, only the arguments passed to the function

Why Use Functional Programming?

The use of functional programming is growing. It's great for big databases, parallel programming, and machine learning. Functional programming leads to stable infrastructures that are reliable, fault-tolerant, and less prone to errors. The following are some of the reasons companies are starting to shift towards FP:

  • use of immutability and lack of side effects leads to fewer errors, code safety, and higher reliability
  • pure functions are easier to test and debug, especially unit testing
  • allows parallel processing and concurrency which is good for data analysis and large sets of data
  • code is usually shorter and clear, therefore easy to maintain and offers better modularity

What is Haskell?

Haskell is a purely functional programming language. It is general-purpose and statically typed. Programs in Haskell are always written as mathematical functions which have no side effects. It is mainly used in research and academia. However, it is also used in a number of companies. It has applications in a range of fields like aerospace, defense, web startups, social media, and hardware design. Recently, it has become popular in finance tech companies (due to its security).

See some example uses in the industry here.

Why Use Haskell?

Along with the benefits of functional programming, Haskell has its own benefits that promote security and stability and allows building fault-tolerant programs. Haskell’s advantages include:

  • it, by default, uses lazy evaluation, which means things only get evaluated if they are needed. This can result in faster programs.
  • it includes automatic memory management to make it memory safe and avoid memory leaks and overflows (a common problem in languages like C or C++).
  • it is statically typed, which adds an extra layer of security to the code. It may take more time during development but makes it easier to debug.
  • it facilitates clean, more reliable code which leads to shorter development time, scalability, and eases refactoring.

Read more:

Why Not More Haskell?

I spent a lot of time talking up Haskell and Functional Programming. Well, if it's so great, why was it so low on the list of popularity? There are a few reasons for this. Firstly, Haskell is still primarily used in academia and research. There are companies that use it (see list above) however, even they struggle to find good candidates that have experience. It can be rather complex and so not a lot of new programmers will try to learn it. Lastly, it's a matter of fit. Most companies still have a majority of their code in “traditional” languages like C++, Java, Python, or Ruby. Integrating the existing code with Haskell would be a huge and almost impossible task.

Conclusion

I’m excited to continue on this journey in Haskell. The main benefit will be the opportunity to expand my mind. Haskell and functional programming will allow me the chance to attack problems in a way I couldn’t before. It’s not about a specific new language, it's a new mindset.

References

A new tech publication by Start it up (https://medium.com/swlh).

Recommended from Medium

An Inside Look Into The Python World

Swagger examined (part 2): The DBSync’s Swagger API

macOS: How to completely reinstall Monosnap?

2020 in review: Software Development industry trends and changes & the outlook for 2021

An Introduction To Git And How To Use It For The Projects

DevSecOps Series (Part 1): Automated, efficient and secured deliveries with CI

Breaking apart your Monolith: Free your Front-end

Gravitee.io AM 3.1

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sara Khandaker

Sara Khandaker

I love seafood, exploring new cities, board games and learning to love to code. https://github.com/sarakhandaker/portfolio

More from Medium

A Common Mistake: Head Recursion

Unleashing the Power of Bio-inspired Parallelism With Membrane Computing

Which special characters must be escaped in regular expressions

Quick Thought — Why the fanaticism regarding programming languages?