Terminology (4)Terms used in this lesson
Term on the front, definition on the back. Paste with tabs between fields and a new line between cards, or import the download in Anki as Basic.
- Qualified name
- A name together with the native path or scope that selects its declaration.
- Alias
- An additional local name for an existing imported module, package or item, or for a C++ namespace. Naming that entity another way does not itself duplicate its definitions or state.
- Module identity
- Which particular loaded or declared module owns the selected definitions and state.
- Translation unit
- For C++, the source considered by one compilation after preprocessing; it is distinct from a namespace.
Names, boundaries and declaration identity
A short name identifies a declaration within a scope. Qualified names and import bindings let a consumer select declarations from elsewhere, often using a local alias. Changing that local spelling does not itself create or merge the underlying declaration.
Source files, named regions and runtime state have distinct boundaries. To follow a call, find the declaration it names, establish how the consumer can refer to it, then identify the storage that declaration owns.
These C++ projects use headers, namespaces and separately compiled translation units. A namespace groups names; #include makes declarations available in a translation unit. Linkage determines which declarations refer to one entity across translation units. Named C++ modules are a separate facility.
01Select a declaration, not a word
Select a declaration, not a word
The museum’s desk software prints labels from two catalog helpers and issues tickets through more than one consumer file. A familiar function name is not enough to select the right operation or preserve one serial history. Follow the qualified name, then the consumer boundary, then the state behind it.
A desk header needs a room label and an artist label. Both catalog helpers call their operation label, so the consumer must choose a declaration before formatting either header. Trace the two calls across the marked files.
#include <iostream>
#include "rooms.hpp"
#include "artists.hpp"
namespace artist = artists;
int main() {
std::cout << rooms::label("North") << "\n";
std::cout << artist::label("North") << "\n";
}
// ── rooms.hpp (supplied) ──
#pragma once
#include <string>
namespace rooms {
inline std::string label(const std::string &name) {
return "room:" + name;
}
} // namespace rooms
// ── artists.hpp (supplied) ──
#pragma once
#include <string>
namespace artists {
inline std::string label(const std::string &name) {
return "artist:" + name;
}
} // namespace artists
clang++ -std=c++2c -Wall -Wextra -pedantic *.cpp -o program && ./program
Use a fresh folder for each complete project. Each path marker starts another physical file; save the first block as the entry filename and the remaining blocks at their marked paths. For the declared TypeScript 6 workflow, install TypeScript and Node type declarations locally, set the type field in package.json to commonjs while preserving its other fields, then use the guarded command. For Go, initialize the folder once with go mod init lab. The reading C++ projects have their .cpp files at the root; compile each once. Lab notes list the nested source files needed by each supplied project. The workspace keeps the entry and supplied files separate.
02A binding belongs to a consumer
A binding belongs to a consumer
The desk now delegates a display report to another physical consumer. The entry file knows the room helper; inspect the second consumer’s own source before predicting whether the complete build can produce either line.
#include <iostream>
#include "rooms.hpp"
#include "report.hpp"
int main() {
std::cout << rooms::label("East") << "\n";
std::cout << report() << "\n";
}
// ── rooms.hpp (supplied) ──
#pragma once
#include <string>
namespace rooms {
inline std::string label(const std::string &name) {
return "room:" + name;
}
} // namespace rooms
// ── report.hpp (supplied) ──
#pragma once
#include <string>
std::string report();
// ── report.cpp (supplied) ──
#include "report.hpp"
std::string report() {
return rooms::label("West");
}
03Matching source can still mean different state
Matching source can still mean different state
The desk package will allocate tickets from more than one consumer. First isolate the identity question with two calls: each counter starts at zero, and the source text looks the same. Do their native declarations select one state or two?
#include <iostream>
#include "counter.hpp"
#include "other.hpp"
int main() {
const int first = counter::next();
const int second = other();
std::cout << first << " " << second << "\n";
}
// ── counter.hpp (supplied) ──
#pragma once
namespace counter {
static int next() {
static int count = 0;
return ++count;
}
} // namespace counter
// ── other.hpp (supplied) ──
#pragma once
int other();
// ── other.cpp (supplied) ──
#include "counter.hpp"
int other() {
return counter::next();
}
04Practice
Keep the museum desks on one serial stream
The first desk, the second consumer file and a shared stream form one cumulative project. Supplied files remain visible in the coding workspace.
Three repairs to one project
Select the live operation, connect another consumer, then keep both desks on the same history.
In the frontend Import aliases keep the original framework contract. Optional
Renaming an import binding does not create another framework operation. Keep its actual contract: a React hook still follows hook rules, and Svelte tick still waits for pending DOM updates.
'use client';
import { useId as useFieldId } from 'react';
export default function LabelField() {
const id = useFieldId();
return (
<label htmlFor={id}>
Label
<input id={id} />
</label>
);
}
The aliased hook is called at component top level; changing its local name does not change hook rules.
Sources: React useId,Svelte tick.
Sign in to keep your read marks on every device. Sign in
Was this helpful?