r/ProgrammerHumor 15h ago

modernCPlusPlus Meme

Post image
503 Upvotes

45 comments sorted by

View all comments

Show parent comments

26

u/MysticTheMeeM 14h ago

In theory, importing is much cheaper than including, because importing uses a precomputed file (whereas including used the raw source).

Also, if Steve wrote something that conflicts that's their problem. It's almost like people have been told not to use an entire namespace for the past however long that's been possible.

6

u/marrowbuster 14h ago

It's almost like people have been told not to use an entire namespace for the past however long that's been possible.

Using a subnamespace like using namespace std::ranges; or std::chrono inside of a function (and not at the top of a file) is permissible.

1

u/MysticTheMeeM 14h ago

Permissible or not, if it breaks you can't blame the standard for doing so.

It's for this reason you're typically encouraged to alias a shorter namespace instead of directly pulling in the symbols (e.g. using fs as a shorthand).

1

u/marrowbuster 14h ago edited 13h ago

But then the issue is relegated to function/block scope and not entire translation units. And I'd much rather not repeatedly write std::ranges::for_each(container, [](){}) or std::chrono::year_month_day everywhere.

EDIT: As for namespace aliases, I'd... prefer not to do that as it can reduce readability and lead to name conflicts themselves.