Functional Programming
Introduction to Functional Programming
Introduction by Jeon Jun-min from Nerumi Tech Lab.
Overview of programming paradigms.
Types of Programming Paradigms
Procedural Programming
Step-by-step commands executed line by line.
Algorithms can be expressed in pseudo-code.
Object-Oriented Programming
Groups program elements logically (objects).
Supported languages provide ways to express components (classes).
Functional Programming
Classifies data and immutable logic that operates on it, using logic composition to process data.
Template Meta Programming
Allows coding once for different types using templates and inheritance.
Aspect-Oriented Programming (AOP)
Focuses on cross-cutting concerns that affect other parts of the program.
Other paradigms exist, but these are the main ones discussed.
Importance of Programming Paradigms
No "one-size-fits-all" paradigm exists.
Choosing the right paradigm is essential depending on context and needs.
Examples of Appropriate Paradigm Use
Procedural Programming Scenarios:
Simple shell scripting benefits from procedural approaches for clarity and efficiency.
Device drivers often use procedural programming to manage hardware through fixed procedures.
Limitations of Pure Functional Programming:
Large-scale projects often require breaking down into smaller logical units.
Object-oriented programming generally improves collaboration and maintenance in large systems.
Characteristics of Functional Programming
Separation of Data, Logic, and Side Effects:
Logic (functions) remains unchanged regardless of execution.
Side effects are dependent on execution context and can vary outputs.
Example: Accessing a global list can change outputs based on external factors.
Pure Functions:
Functions should avoid side effects and rely solely on inputs to determine outputs.
Emphasis on Immutability:
Data structures are made immutable to create new instances after operations.
Recent Growth in Functional Programming**
Increased reliance on CPUs moving to multi-core architectures.
Better parallelism potential with functional programming due to no side effects and immutable data structures.
Example code in procedural and functional styles demonstrates different approaches.
Advantages of Functional Programming
Mathematically Rigor and Static Analysis:
Code's predictability supports easier static analysis.
Potential for Parallel Processing:
Fixed inputs lead to parallelizable outputs, unlike procedural approaches that rely on sequential state.
Ease of Writing Unit Tests:
Clear input-output relationships streamline unit testing.
Disadvantages of Functional Programming**
Cognitive Shift Required:
Programmers used to procedural programming may struggle with functional paradigms.
Performance Concerns with Immutability:
Copying immutable objects can reduce efficiency in certain situations.
Readability Challenges:
Overengineering with functional concepts may reduce code clarity.
Additional Concepts
Immutability: Concept of maintaining unchangeable states.
Differentiates between mutable and immutable variables.
Monads:
Type wrapping values, providing methods to handle the wrapped type.
Examples: Java Collections, C++ Containers.
Functional operations transforming wrapped values using methods like map and flatMap.
Values and Null Handling:
Traditional use of null versus functional options to improve type safety.
Option types provide better handling of presence/absence of values.
Conclusion**
Functional programming is highly relevant today but involves a learning curve for many programmers.
Encouragement for further study in functional programming and nearby concepts for practical programming advantages.