====== Modularization Techniques in Functional Programming ====== By Ali Mohammad (amokhammad_1@edu.hse.ru) ====== Introduction ====== Functional Programming is a programming approach where functions are defined and composed to construct programs In Functional Programming, functions are high-importance data types and they can be handled like other types of data, where they could be bound to names, used as arguments, other functions could return them, which allows the software to be developed in a composable style, and combine small functions in a modular way.[1] Purely Functional Programming is a type of functional programming where functions are defined as deterministic mathematical functions, it returns the same results at any given arguments, without being affected by side effects providing referential transparency. Functional Programming is designed using simple Modularization principles, where each set of executed commands are grouped together in a function body to perform a specific task. But that doesn’t mean it is all Modularized.[2] ====== What is Modularization? ====== The basic principle of Modularization is that Software should be built using modules (components) that are loosely coupled and cohesive.[4] The point of the software modularization process is to divide a software system into subsystems to give a general view of the engineering of the whole system framework, where a subsystem is comprised of a group of software artifacts that work together with one another to execute a high-level attribute or offer high-level service for other subsystems. which implies the system ought to be comprised of various components that are joined together and work together productively and these components implement distinct functions. Modular programming accentuation breaks huge projects into little issues to expand the practicality, intelligibility of the code and to make the program convenient to roll out any improvements later on or to address the errors. ====== Modular Functional Program ====== To define a Modular Functional Program, several properties must be implemented to perform design methods evaluation while considering their abilities. **Modular Decomposability**: It means to divide the modules (functions) into different sub-modules in a systematic approach. Decomposition reduces the software complexity, and sub-modules can be handled independently. This aids in accomplishing the essential principle of modularity. **Modular Composability**:It means how to combine the created modules. software plan arrangements define how components are connected with one another. **Modular Understandability**: It means that each module should be as easy as possible to understand which makes it easier to develop software and modify it according to requirements. **Modular Continuity**: It means that when changes are made to software requirements it should cause modifications in modules independently without affecting the overall software. **Modular Protection**: It means to keep the modules safe from errors happening in a certain module at run time. run-time errors or failures are examples of these conditions. Their side effects are managed within the module. ====== Essential Elements of Modularization ====== Modularization aims to handle complexity. This is ensured by minimizing the complexity of each module. This means that modules should be designed, developed, tested, deployed, modified, and maintained as easily as possible. To achieve this goal, these essential elements must exist[5]: **Purpose**: Only One Job. each module has a purpose, which should be crystal-clear. And it should focus on one exclusive task where no two modules’ purposes should intersect. ( Single Responsibility Principle) **Interface**: easy to use, to understand, and to validate correctness without the need to understand the details of implementation. This is accomplished by using well-definition and documentation procedures which keep the module minimal, having what it needs exactly nothing more and nothing less and make it hard to misuse, most easy way of modules usage should be the correct way also **Encapsulation**: Hide Internal Data. Modules should hide their inner workings. They shouldn’t show their functional or data structure, or dependencies. This introduces a lot more flexibility into the system because changes in a module won’t affect the client. This element is the most important of modularization. According to the law of leaky abstractions by Joel, using a weak encapsulation leads to implicit dependencies, which is considered to be a big problem.[5] **Implementation**: a module must work very well to be an easy-to-use module. Without a good implementation, a module could still fail even if it has the best-designed purpose, interface, and encapsulation. A good module implementation should be correct, tested, practical and minimal. Worse implementation means leakier abstractions **Modules Connections**: the overall system complexity of the is further increased due to connections among modules. These connections must be minimized to get a well-designed modular system ====== Advantages of Modularization ====== * **Divided Development**: Modularization permits the execution of various tasks by partitioning the program into more modest portions, which empowers numerous developers to work simultaneously and lessen the development time frame. * **Readable Programs and Easy to Detect Errors**: A program with multiple functions is easy to read and understand, which minimize the risks of having errors and makes it easy to spot them, where the errors can be narrowed to a sub-function * **Code Reuse**: minimum redundant codes are developed and easier than writing a new code from scratch, with small code segments to write * **Manageability**: more improve the manageability of the small code segments. Single modules are easy to design, implement and test. And the whole software is developed using these smaller modules. * **Collaboration**: different programmers could work on the same application collaboratively, and small teams can focus on single parts of the same code due to the simplicity of the design. ====== Conclusion ====== Although functional programming mainly follows the Modularization design, I believe that by further applying the discussed above elements we could allow the code to remain flexible when facing ever-changing requirements Modularization follows the “Divide and Conquer” rules as a problem-solving strategy and Designers tend to use Modularization techniques to design and implement individual modules for easy execution and testing separately and independently due to the advantages of these techniques in the end, I believe that modularization is essential while working in a software engineering team, maximizing developer productivity. ====== References ====== - Hudak, Paul(September 1989)."Conception, evolution, and application of functional programming languages"(PDF).ACM Computing Surveys.21(3): 359–411. - Hughes, John(1984)."Why Functional Programming Matters". - Isazadeh, Ayaz; Izadkhah, Habib; Elgedawy, Islam (2017). Source Code Modularization - https://www.geeksforgeeks.org/modularity-and-its-properties/ - https://www.genui.com/resources/5-essential-elements-of-modular-software-design - https://www.geeksforgeeks.org/refactoring-introduction-and-its-techniques/?ref=rp - https://thecustomizewindows.com/2020/12/what-is-modular-programming/ - https://www.sciencedirect.com/topics/computer-science/modularization - http://singlepageappbook.com/maintainability1.html - https://360techexplorer.com/modular-programming/