5

I have trouble understanding the concept of modules. Are they translation units? Are they like .ccp files and .h files?.

In my textbook it is described as, "A modular design consists of a set of modules, which are developed and tested separately. Modular programming implements modular designs and is supported by both procedural and object-oriented languages. The C programming language supports modular design through library modules composed of functions. The stdio module provides input and output support, while hiding its implementation details; typically, the implementation for scanf() and printf() ships in binary form with the compiler. The stdio.h header file provides the interface, which is all that we need to complete our source code. This chapter describes how to create a module in an object-oriented languages using C++, how to compile the source code for each module separately and how to link the compiled code into a single executable binary. The chapter concludes with an example of a unit test on a module.

MODULES

A well-designed module is a highly cohesive unit that couples loosely to other modules. The module addresses one aspect of the programming solution and hides as much detail as practically possible. A compiler translates the module's source code independently of the source code for other modules into its own unit of binary code."

sangmin park
  • 547
  • 3
  • 7
  • 16
  • 8
    Maybe get a better textboook - neither C nor C++ currently implement modules as such. They do provide the facilities needed to build _libraries_, however. –  Feb 17 '18 at 17:24
  • 3
    "Module as a language feature", "module as a way to structure your software", "module as a way to organize your source files", etc and etc, are all different although related. Maybe you don't even know "module" can mean so many things. The text you quote are not very good anyway. –  Feb 17 '18 at 17:28
  • 6
    I'm upvoting the question, which seems perfectly reasonable. I do wish I could downvote the textbook. – Lightness Races in Orbit Feb 17 '18 at 17:31
  • The answer to this question is in both of the descriptions of the tags ([tag:module] and [tag:modular-design]) that you added to this question. – Arnav Borborah Feb 17 '18 at 17:35
  • The book was probably written long before the C++ committee starting thinking about modules. It uses the word "module" as a synonym for "library", one that exposes as little as possible and was thoroughly tested to be proven to be reliable. In practice C and C++ programmers have created modules for decades. Separately built chunks of executable code, DLLs on Windows, shared libraries on Unix. That practice is just not standardized, ISO has to make everybody equally unhappy and that is hard to so when everybody has been doing it for so long. – Hans Passant Feb 17 '18 at 17:40
  • @NeilButterworth: We a modules TS. Since about last week or so. – Cheers and hth. - Alf Feb 17 '18 at 17:43
  • The word **module** means different things in different contexts. Today it generally refers to a collection of functions, types and constants supported by a somewhat separated implementation, with some means of module initialization and cleanup. Examples include Pascal **`unit`**, Ada **`package`**, Modula, Modula-2 or Oberon **`module`**, Java `package`, etc.. This is mainly what C++20 modules will bring. However, depending on the context the word can refer to a single function, or, well, anything really. – Cheers and hth. - Alf Feb 17 '18 at 17:49
  • This quote says so much of nothing that you could replace all instances of "modular-design" with "object-oriented design" and "module" with "object" and it would still be a completely valid statement. – Joseph Franciscus Feb 17 '18 at 22:17

1 Answers1

7

In this context (i.e. the general English sense), a module is something that bolts on to other things to form a single whole; that's as far as the definition goes without further specification.

If you're reading this as there being some concept called "module" baked into C++, there isn't (yet). The author is just describing how "things come together" when you bolt on different libraries and such into one finished program.

The wording you've quoted doesn't really say much of any valuable substance.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055