I often see that 1. object-oriented programming 2. Modular Programming 3. does functional programming mean an idea? In actual work, it seems that there has always been a problem solving problem. do you not pay special attention to the differences between the three ideas? I often see that
1. object-oriented programming
2. Modular programming
3. Functional programming
Are these three ideas? In actual work, it seems that the problem has always been solved, and no special attention has been paid to it.
Are there any obvious differences between the three ideas?
Reply content:
I often see that
1. object-oriented programming
2. Modular programming
3. Functional programming
Are these three ideas? In actual work, it seems that the problem has always been solved, and no special attention has been paid to it.
Are there any obvious differences between the three ideas?
My understanding:
-
Object-oriented programming and functional programming are usually different in different languages. For example, if you use Java, it is generally object-oriented programming. for example, if you use JS, it is generally functional programming.
-
Modular programming is more about partial organization. whether it is object-oriented or functional programming, modular functions are required to organize functions to achieve high cohesion.
We recommend that you find some materials of different programming paradigms. In fact, you can give it a try to get a deeper understanding.
Both object and function programming are based on procedural programming.
Procedural programming is embodied in structured programming:
Feature: separates the data in the program from the function used to process the data.
Basic structure: sequence structure, selection structure, and cyclic structure
Design Method: top-down, gradually refined, modular, and structured coding
The language that supports object programming is embodied in providing class encapsulation.
Languages that support functional programming are embodied in the fact that a function is also a volume. for example, it can be passed as a parameter (closure) or a value of a hash table.
For example:
Java cannot transmit functions as data at all.
Both JS and PHP can transmit functions as data.
Function table (hash table + anonymous function ):
The function name is the key, and the anonymous function is the value.
JS (organize functions using function tables to reflect first-class functions ):
var func = { foo: function(arg){alert(arg);}, bar: function(arg){alert(arg);}};func.foo("php"); //func["foo"]("php");func.bar("best"); //func["bar"]("best");
PHP (for array programming: encapsulate functions and variables in an array ):
$func = array( 'foo' => function($arg){echo $arg;}, 'bar' => function($arg){echo $arg;});call_user_func_array($func['foo'], array('php'));call_user_func_array($func['bar'], array('best'));
How to complete your work faster. There are a lot of considerations at work. For example, just give you one minute. Let you write an alert bullet box. You still need to judge and make an encapsulation? Impossible. For example, if your company uses an object-oriented approach, you will not. if you do not encapsulate it, you will write it in disorder. Is it necessary? These are just your habits or work specifications. they are all for faster and better work.