Functional programming
Functional programming is one of the programming paradigms that is based on the following principles:
- Functions are first-class objects, first-class citizens. This means that variables can be assigned just like other objects and primitive values; functions can be used as arguments to other functions or as their return values.
- Functions operate on immutable data structures. Data structures in functional programming are typically immutable or unchangeable. Operations performed on data structures, however, create new data structures as needed and return them as results. For example, in purely functional programming languages, once lists or other data structures are created, they cannot be modified.
- Functions have no side effects. In functional programming, functions typically have no side effects at all and behave more like mathematical functions. This means that functions in functional programming always return the same result for the same input and do not cause any side effects. In purely functional languages, side effects are prevented by the language itself.
- Functional programs employ a declarative programming style. Imperative programming is a programming paradigm in which the computer is given very precise, individual instructions on how to solve a problem. Imperative programs use explicit loop statements (while, for, and so on), conditional statements (if-else), and sequences of them. Functional programs, on the other hand, employ a declarative style, meaning the program specifies what to do rather than how to do it. As a result, functional programs are typically more readable, more meaningful, and more compact than equivalent imperative code.

Various languages may not be purely functional, but they can still support the functional paradigm. For example, consider JavaScript, which isn’t a purely functional language but allows for functional programming. Consider the following JavaScript array iteration program:
1 2 3 4 5 6 7 8 9 10 11 12 | set of objects to iterate over// const people = [ {name: "Tom", age:38}, {name: "Kate", age:31}, {name: "Bob", age:42}, {name: "Alice", age:34}, {name: "Sam", age:25} ]; iterating over array objects// for(let i = 0; i < people.length; i++){ console.log(people[i].name);} |
This code is intended to print each array value. That’s what should happen. However, the code is actually more focused on how it should all work: initialize the counter variable, check the termination condition, access the array element at a specific index, and then increment the counter variable.
Thus, imperative programs contain a lot of unnecessary code (boilerplate), which reduces program readability and increases program bloat. Of course, if we’re talking about the code above, which is extremely simple and easy to navigate, then if you encounter deeply nested loops and conditional statements, you can get lost in the program.
Using functional programming, problems can often be formulated in a much more readable manner. For example, the forEach() method, which iterates through an array and receives a callback function as a parameter, is much more suitable for this task. The callback function receives the current array element being iterated over and performs certain actions on it:
1 2 3 4 5 6 7 8 9 10 | set of objects to iterate over//const people = [ {name: "Tom", age:38}, {name: "Kate", age:31}, {name: "Bob", age:42}, {name: "Alice", age:34}, {name: "Sam", age:25} ];const printName = (p)=>console.log(p.name);people.forEach(printName); |
While functional code isn’t necessarily shorter in terms of lines, it’s much more readable. Unlike imperative code, the focus is now on the program logic ( what the program does) rather than the loop itself ( how it does it).
Explore More IT Terms
#
A
- A Guide to SQL Query Formatting
- A/B testing
- Agile
- Algorithm complexity in 5 minutes
- Algorithms and Data Structures in C#
- An overview of the C # programming language
- An overview of the Python programming language
- Anaconda Python
- Android
- Android App Bundle
- Android SDK
- Angular
- Ansible
- Apache
- Apache Airflow
- Apache Kafka
- Apache Tomcat
- App Store
- AppCode
- Array-based stack
- ArrayList
- ASCII
- ASP.NET
- Assembly Language Lessons
B
C
D
- Data Analytics: applications of data analysis in companies
- Data Engineer - Who is it, what does a data engineer do, and an overview of the profession
- Data modeling: what it is, types, and process steps.
- Data preprocessing: a complete guide for beginners and professionals.
- Data structure
- Data structures
- Defining Aliases
- Defining Arrays
- Deque
- Developing a Website from Scratch
- Digital data: understand the importance of this asset for businesses.
- Doubly linked lists
E
F
H
- Handling errors and exceptions
- How to effectively organize your workflow
- How to Learn Java: Tips for Beginner Developers
- How to Learn PHP: A Beginner's Guide
- How to Use S3 Storage in Kubernetes with CSI
- HTML
- HTML and CSS: Definition, Application, and Operating Principles
- HTML and CSS. Layout from Scratch: What to Learn, Where to Learn, and How Long Will It Take?
- HTML Frame Structure
- HTML Link Formatting
I
- if..else construction
- Inheritance in Java: A Complete Guide to Principles and Implementation
- Inserting an Image
- Interactive Python Tutorial – Learn Programming from Scratch
- Interview Problem: Finding a Deleted Element in O(N)
- Interview Scare: The FizzBuzz Challenge
- Introduction to C++
- Introduction to Machine Learning
- Introduction to programming languages
- IT Specialist Resume (CV)
J
K
M
O
P
S
- SFML Graphics Library Tutorials
- SQL commands: see what they are, what the main ones are + examples
- SQL Interview Questions and Tasks
- SQL Lessons
- SQL Stored Procedures
- SQL Syntactic Sugar: The COALESCE Function
- Stack
- Start in analytics: Python or R
- Statistical analysis: importance for decision making.
- String formatting in Python
- Swift Lessons
- switch/match construct
T
W
- What are databases, and why do they need DBMS and SQL?
- What do Linux distributions consist of?
- What is .NET and what is it used for?
- What is a GPU in a computer, in simple terms?
- What is Big Data? Introduction, Types, Characteristics, and Examples
- What is Golang and what is it used for?
- What is Haskell and what is it used for?
- What is Kotlin and what is it used for?
- What is Linux? The History of Linux
- What is machine learning, and how does it work?
- What is Power BI: everything about the data analytics software
- What is the C++ programming language?
- What is the OSI Model: A Complete Explanation of the Seven Layers and Their Role in Networking
- Where to start learning the C programming language?
- Which Linux distribution should you choose? A Linux distribution overview
