Functional Programming in 40 Minutes • Russ Olsen • GOTO 2018

GOTO Conferences
9 Nov 201841:35
EducationalLearning
32 Likes 10 Comments

TLDRIn this talk, the speaker demystifies functional programming by explaining its simplicity and origins from mathematical functions. They discuss the practical aspects of being a functional programmer, transitioning from object-oriented programming, and address the common misconception that functional programming requires forgetting everything about traditional programming. The speaker also highlights the benefits of using immutable data structures and pure functions in making programs easier to understand and maintain.

Takeaways
  • 😀 Functional programming is a fundamentally simple idea that has been mystified and often misrepresented as requiring programmers to forget everything they know about programming.
  • 👓 The speaker identifies as a 'closure programmer' and acknowledges that the perspective on functional programming will be influenced by this background.
  • 🔍 The main focus of the talk is to clarify what functional programming is, its origins, and to demystify the concept by explaining it in a straightforward manner.
  • 📚 The speaker aims to cover the experience of transitioning from an object-oriented tradition to functional programming, especially for beginners.
  • 🛠 Functional programming is presented as a refactoring of traditional programming concepts rather than a complete overhaul, keeping familiar elements like namespaces and data types.
  • 🔗 The idea of 'pure functions' is introduced as central to functional programming, where functions rely solely on their inputs and have no side effects.
  • 🔒 The concept of immutable data structures is highlighted as a key component of functional programming, which helps in maintaining the integrity of data across function calls.
  • 🌳 Persistent data structures are explained as an efficient solution to manage immutability without excessive copying of data, using tree-like structures for efficient modifications.
  • 🔄 The speaker discusses the challenges of integrating side effects, which are essential for real-world applications, into a functional programming paradigm.
  • 💼 The 'Pedestal' library in the Closure world is used as an example to illustrate the practical application of functional programming in production code.
  • 📈 The composition of the 'Pedestal' library is analyzed, showing that a significant portion of the codebase is made up of functions, emphasizing the functional style of programming.
Q & A
  • What is the main theme of the talk given by the speaker?

    -The main theme of the talk is to demystify functional programming, explaining its fundamentally simple idea and how it can be integrated into existing programming practices without forgetting everything one knows about programming.

  • What does the speaker suggest about the nature of functional programming?

    -The speaker suggests that functional programming is not about forgetting everything about programming but rather a refactoring of existing knowledge with a new set of rules to make programs easier to write and understand.

  • What is the speaker's perspective on the use of closures in functional programming?

    -The speaker's perspective leans towards using closures in functional programming, noting that their point of view and the examples provided will have a 'closure spin' to them.

  • What are the three main points the speaker wants to cover in the talk?

    -The three main points the speaker wants to cover are: explaining what functional programming is and its origins, discussing the experience of being a functional programmer and the transition from object-oriented to functional style, and finally, addressing the practicality and effectiveness of functional programming in real-world applications.

  • What does the speaker mean by 'refactor' in the context of programming?

    -In the context of programming, to 'refactor' means to reorganize or rewrite existing code to make it more efficient, maintainable, or scalable without changing its external behavior.

  • What is the speaker's view on the state of traditional object-oriented programming?

    -The speaker believes that traditional object-oriented programming may have become messy and could benefit from a refactoring approach, suggesting that functional programming principles might offer a way to address these issues.

  • What is the significance of mathematical functions in the context of functional programming?

    -Mathematical functions serve as an inspiration for functional programming, particularly the concept of pure functions, which are deterministic and have no side effects, helping to create more predictable and easier-to-understand code.

  • Why does the speaker propose the use of immutable data structures in functional programming?

    -The speaker proposes the use of immutable data structures to avoid the complexity and potential bugs associated with mutable state, allowing for more straightforward reasoning about program behavior and simplifying concurrent programming.

  • What is the role of atoms in Clojure, as mentioned by the speaker?

    -In Clojure, atoms serve as a container for mutable state, allowing for updates to state in a controlled manner. They act as a bridge between the functional programming paradigm and the need to interact with the stateful, side-effectful world.

  • What is Pedestal in the context of the speaker's talk?

    -Pedestal is a set of libraries in the Clojure programming language, used for building web applications and services. It is mentioned as an example of a large codebase written in a functional style, demonstrating the practical application of functional programming concepts.

  • What insight does the speaker provide about the composition of the Pedestal library?

    -The speaker provides insight that the Pedestal library is composed mostly of functions, with a smaller portion dedicated to protocols and other constructs, highlighting the emphasis on functions in functional programming.

  • How does the speaker describe the experience of programming in a functional style for beginners?

    -The speaker describes the initial experience of programming in a functional style as feeling like wearing handcuffs due to the constraints of the new rules, but over time, these rules become more natural and beneficial, making the code easier to understand and reason about.

  • What is the final question the speaker attempts to answer in the talk?

    -The final question the speaker attempts to answer is whether functional programming works in practice and if it can be effectively used by ordinary programmers to write applications and libraries.

Outlines
00:00
📚 Introduction to Functional Programming

The speaker, a self-proclaimed programming language enthusiast, introduces the topic of functional programming. He aims to demystify the concept, emphasizing its simplicity despite common misconceptions. The speaker's focus is on functional programming with closures, a specific flavor of the paradigm. The talk is structured to explain what functional programming is, its origins, the experience of programming functionally, especially for beginners transitioning from object-oriented programming, and the practicality of functional programming in real-world applications.

05:02
🛠 Refactoring and the Messiness of Programming

The speaker discusses the evolution of software systems, which often start well-designed but become messy over time due to changing requirements and bug fixes. He likens the process of refactoring to starting with a 'clean sheet of paper,' where existing working components are retained while the system is reorganized under a new paradigm. The speaker suggests that traditional object-oriented programming may be reaching a point where it needs such a refactor, hinting at functional programming as a potential new paradigm.

10:02
🔍 Borrowing Concepts from Mathematics

The speaker explores the idea of borrowing concepts from mathematics to improve programming practices. He highlights the work of mathematicians who use functions as an organizing principle, drawing a distinction between mathematical functions and programming functions. The speaker introduces the concept of pure functions, which are akin to mathematical functions in their predictability and lack of side effects, as a potential foundation for a new approach to programming.

15:04
🔄 The Challenge of Mutability

The speaker addresses the issue of mutable data structures in programming, which can lead to complex and hard-to-trace bugs. He proposes a solution to this problem by advocating for the use of immutable data structures. These structures, once created, cannot be altered, thus preventing unexpected changes and making programs easier to reason about. The speaker also introduces the concept of persistent data structures, which allow for efficient copying and modification without the overhead of traditional copying mechanisms.

20:04
💡 The Bridge to Side Effects

Despite the benefits of pure functions and immutable data, the speaker acknowledges the necessity of side effects in programming, as they are often the desired outcomes of software applications. He discusses the need for a bridge between the functional programming paradigm and the real world, where side effects like file writing or database updates occur. The speaker introduces the concept of atoms in the context of the Clojure programming language, which serve as a controlled way to handle mutable state within a functional paradigm.

25:05
🔗 Managing Concurrency with Functional Programming

The speaker discusses the advantages of functional programming when it comes to concurrency. Immutable data structures inherently prevent certain classes of concurrency issues, as one thread cannot inadvertently change data that another thread is using. The speaker also explains how atoms in Clojure can be used to safely update state across multiple threads, thus providing a form of collision detection and resolution without losing updates.

30:07
🛑 The Reality of Functional Programming

The speaker emphasizes that functional programming is not a magic solution to all programming problems. It does not eliminate common issues such as off-by-one errors or the potential for writing bad code. However, it does offer a structured approach to writing programs that can lead to fewer concurrency-related issues and more maintainable code. The speaker encourages programmers to try functional programming to experience its benefits firsthand.

35:10
📈 The Pedestal Library as a Case Study

The speaker presents the Pedestal library as a case study to illustrate the practical application of functional programming in a production environment. Pedestal, a set of libraries used extensively in the Clojure community, consists of a large number of functions, a few protocols for defining interfaces, and other components like agents and atoms. The speaker uses Pedestal to demonstrate the dominance of functions in functional programming and to argue for the effectiveness of the paradigm in building robust applications.

40:11
🎯 Conclusion: The Essence of Functional Programming

In conclusion, the speaker reflects on the nature of functional programming, emphasizing that it is about writing a large number of functions within a structured and testable framework. He likens the initial constraints of functional programming to learning to ride a bicycle, where initial challenges give way to greater ease and efficiency. The speaker asserts that functional programming works and encourages the audience to explore it further.

Mindmap
Keywords
💡Functional Programming
Functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data. In the video, the speaker emphasizes that functional programming is fundamentally simple and not as mystified as often portrayed. It involves writing programs that are easier to understand and maintain by focusing on pure functions and immutable data structures.
💡Closure
Closure refers to a programming language feature where a function can access variables from its containing scope even after the outer function has finished executing. The speaker identifies as a 'closure programmer' and discusses how his perspective on functional programming is influenced by this, highlighting how different languages implement functional programming concepts.
💡Pure Functions
Pure functions are a core concept in functional programming. They are functions that, given the same input, will always return the same output without causing any side effects. The speaker explains that in functional programming, you aim to write pure functions that only look at their parameters and produce output, which helps in making programs easier to reason about.
💡Immutable Data Structures
Immutable data structures are data structures that cannot be modified after they are created. The speaker discusses the importance of immutability in functional programming, stating that it prevents data from being changed unexpectedly, which simplifies reasoning about code and avoids many common bugs related to shared mutable state.
💡Side Effects
Side effects are changes to the outside world that are observable outside the function, such as writing to a file or changing a global variable. The speaker points out that while functional programming aims to minimize side effects, they are essential for practical applications. The challenge is to bridge the gap between pure functional code and the real-world side effects.
💡Atoms
Atoms in the context of the video refer to a concept in Clojure, a functional programming language, which is used to manage state in a functional way. The speaker explains that atoms allow for updating state in a controlled manner, ensuring that the functional purity of the program is maintained while still allowing for mutable state.
💡Persistent Data Structures
Persistent data structures are data structures that preserve the previous version of the data when modified. The speaker mentions that these structures are efficient in functional programming because they allow for modifications without copying the entire data structure, thus maintaining performance while adhering to the principles of immutability.
💡Object-Oriented Programming
Object-oriented programming (OOP) is a programming paradigm based on the concept of 'objects', which can contain data and code: data in the form of fields (often known as attributes or properties), and code, in the form of procedures (often known as methods). The speaker contrasts OOP with functional programming, suggesting that the latter might offer a cleaner approach to managing complexity in software development.
💡Refactor
Refactoring is the process of restructuring existing computer code without changing its external behavior to improve nonfunctional attributes of the software. The speaker uses the analogy of refactoring to describe how functional programming can be seen as a way to reorganize and simplify existing codebases by applying functional principles.
💡Pedestal
Pedestal is a library or set of libraries in the Clojure programming language designed to help build web applications. The speaker uses Pedestal as an example to illustrate how functional programming can be applied in real-world, large-scale software development, emphasizing its practicality and effectiveness.
💡Protocols
In the context of the video, protocols in Clojure are a way to define a set of functions that can be implemented by different types. The speaker mentions that Pedestal uses protocols to define interfaces, which is a key aspect of how components in a functional program can interact with each other in a predictable way.
Highlights

Functional programming is a fundamentally simple idea that has been mystified.

The speaker identifies as a 'closure programmer', indicating a specific flavor of functional programming.

Functional programming is presented as a refactoring of existing programming concepts rather than a complete overhaul.

The talk aims to clarify misconceptions about functional programming needing to forget traditional programming concepts.

The speaker discusses the challenges faced when systems become messy and the need for a new organizing principle.

A comparison is made between the refactoring process in software and mathematicians' approach to abstraction.

The concept of pure functions, which are akin to mathematical functions, is introduced as a key aspect of functional programming.

Immutable data structures are proposed as a solution to the problem of side effects in programming.

The introduction of persistent data structures as an efficient way to handle immutability in large datasets.

The necessity of a bridge between functional programming and the real-world side effects is emphasized.

The concept of atoms in Clojure as a way to handle mutable state in a functional context is explained.

Agents are presented as another method to bridge the gap between functional programming and side-effectful operations.

The speaker's personal experience of programming in a functional style feels like 'programming with handcuffs' at first.

Pedestal, a Clojure library, is used as an example to illustrate the practical application of functional programming.

The breakdown of Pedestal's codebase shows the predominance of functions in a functional programming project.

The talk concludes with the assertion that functional programming works and encourages the audience to explore it further.

Transcripts
Rate This

5.0 / 5 (0 votes)

Thanks for rating: