javascript - Question about difference between some ideas

WBOY
Release: 2023-03-01 17:24:02
Original
976 people have browsed it

I often see
1. Object-oriented programming
2. Modular programming
3. Functional programming
Do these three refer to the same idea? In actual work, it seems that problems have always been solved, and there is no special Attention
Is there any obvious difference between the three ideas?

Reply content:

I often see
1. Object-oriented programming
2. Modular programming
3. Functional programming
Do these three refer to the same idea? In actual work, it seems that problems have always been solved, and there is no special Attention
Is there any obvious difference between the three ideas?

My understanding:

  1. Object-oriented programming and functional programming generally use different languages ​​and have different methods, at least the emphasis. For example, if you use Java, it is usually object-oriented programming. If you use JS, it is usually functional programming.

  2. Modular programming is more of a partial organizational method. Whether it is object-oriented or functional programming, if the functions are complex, modularization is needed to organize the functions and achieve high cohesion.

It is recommended to find some information on different programming paradigms and try them out, and you will have a deeper understanding.

Whether it is object or function programming, the foundation is procedural programming.
Procedural programming is reflected in structured programming:
Features: Separate the data in the program from the functions that process the data
Basic structure: sequential structure, selection structure, Loop structure
Design method: top-down, gradual refinement, modularization, structured coding

Languages ​​that support object programming now provide class encapsulation.
Languages ​​that support functional programming are reflected in the fact that a function is also a quantity, such as it can be passed as a parameter (closure) or as a value in a hash table.
For example :
Java does not allow functions to be passed as data at all.
Both JS and PHP can pass functions as data.
Function table (hash table + anonymous function):
The function name is key, and the anonymous function is Value.
JS (use function table to organize functions, embody first-class functions):

<code>var func = {
    foo: function(arg){alert(arg);},
    bar: function(arg){alert(arg);}
};
func.foo("php");  //func["foo"]("php");
func.bar("best"); //func["bar"]("best");</code>
Copy after login

PHP (array-oriented programming: encapsulate functions and variables in arrays):

<code>$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'));</code>
Copy after login

How to get your work done faster. There are actually a lot of things to consider at work. Like, just give you a minute. Let you write an alert pop-up box. Do you still need to make a judgment and make a package? impossible. For example, your company all uses object-oriented techniques, but you don't, you don't encapsulate it, you just write it randomly. is it necessary? These are just your habits or work specifications, and their purpose is to complete the work faster and better.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!