What is the difference between a function and a module?

I am very new to C ++ and don’t understand what is the difference between modular programming and function-oriented programming . I have never done modular programming, so I just know the modules by which it contains functions. What is the difference between sequential (function-oriented language) and modular programming? Thanks in advance. EDIT: I read about C ++ OOP.It started out a bit like unstructured programming , which gave me a basic understanding of structured programming than modular programming and finally OOP .

+4
source share
2 answers

Modular programming is basically a strategy for reducing communication in a computer program, mainly through encapsulation.

Before modular programming, local code consistency was ensured by structured programming, but there wasn’t enough global consistency: if you decided that your spellchecker would be implemented as a red-black tree, then this implementation would be affected by everything else in the program, so the programmer working on , say, text rendering, will be able to access the red-black nodes of the tree to do important things with them.

Of course, this became hell when you needed to change the implementation of your dictionary, because then you would also have to fix the code of other programmers.

Worse, if the implementation details included global variables, then you had to be extremely careful who changed them and in what order, or strange errors occurred.

Modular programming applies encapsulation to all of this, separating the implementation (private from the module) from the interface (which the rest of the program can use). Thus, a dictionary module can display an abstract type, which will be accessible only through module functions, such as findWord(word,dictionary) . Someone who is working on a dictionary module should never look beyond this module to see if anyone can use implementation details.

+2
source

Fahad

These are both ways to structure your code. If you are interested in function-oriented programming and want to understand it a little better, I would look at lisp. C ++ is not really a function, since each function should return a value, but C ++ functions can return void (which makes it more likely a procedure than a function), so this is not a real functional programming language in this sense.

"I never did modular programming, so I just know modules by definition that it contains functions." Modules at the level of functions above.

This is a good start. Think of a function as a unit of work that does something, and when you have several functions that you can group in a certain way, you put them in a module. So, string.h has many functions for working with strings, but you just include the header, and you have access to all these functions directly. You can then reuse these modules in other projects, as you have already used the modules before, and they (I suppose) debugged and tested and stopped people from rethinking the wheel. The thing is to benefit from experience.

I suggest you think about the project you want and write some functions, and think about how you want to organize the code for another developer.

I hope this will be useful to you.

+2
source

Source: https://habr.com/ru/post/1336565/


All Articles