15 Functional programming in Julia

 

This chapter covers

  • Why understanding functional programming is important in Julia
  • The differences between functional and object-oriented program design
  • Practical usage of higher-order functions
  • Making your code more readable with function chaining
  • Developing a password-keeping service

Julia is a multi-paradigm programming language, but a functional programming style is far more common in Julia than in other mainstream languages you may be familiar with, such as Python, Ruby, Java, or C++. Thus, it is natural to have an understanding of the principles of functional programming to become a good Julia developer.

Functional programming is not always the best approach to solving every problem. In this chapter, you will learn to build up a password-keeping service in both an object-oriented and a functional style, allowing you to explore the pros and cons of different programming styles (paradigms). Before building up a larger code example you will look at the core building blocks of functional programming, such as higher-order functions, closures, function chaining, and composition.

15.1 How does functional programming differ from object-oriented programming?

15.2 How and why you should learn to think functionally

15.3 Avoid deeply nested calls with function chaining

15.3.1 Understanding anonymous functions and closures

15.3.2 Using the pipe operator |>

15.3.3 Conveniently produce new functions using partial application

15.4 Implementing Caesar and substitution ciphers

15.4.1 Implementing the Caesar cipher

15.4.2 Implementing substitution ciphers

15.5 Creating a cipher-algorithm-agnostic service

15.6 Building an encryption service using object-oriented programming

15.7 Building an encryption service using functional programming

15.7.1 Defining a functional Caesar cipher

15.7.2 Defining a functional substitution cipher