Data type diversity

Started by
47 comments, last by Calin 1 year, 9 months ago

a light breeze said:
A non-trivial C++ program will have thousands of types

That`s probably an exaggeration coined to make a point. I imagine each type needs to be hand coded by a programmer, how many programmers does it take to keep a thousand types around while developing a program?

My project`s facebook page is “DreamLand Page”

Advertisement

The language defines the fundamental types, like bool, integral types, floating point types, etc. It includes the conversion and promotion rules.

The language also defines many compound types, and allows you to create your own. You can provide your own conversion functions, both default conversion and explicit conversion. These include arrays, functions, pointers to various novel things, references to things, classes, unions, enumerations, and pointers to members. You can also create types with templates, with typedef declarations and with using alias declarations.

All of these are a full section of the standard with many individual conversion rules and promotion rules taking a full page or more. Integral promotions and conversions, floating point promotions and conversions, floating-integral conversions, pointer conversion, pointer-to-member conversions, function pointer conversions, Boolean conversions, usual arithmetic conversions, array-to-pointer, function-to-pointer, temporary conversion, qualification conversions, the standard conversion sequence, they're all explained for the fundamental types.

Then there's another full section on user-defined conversions, conversions through constructor objects both implicit and explicit, conversion functions between user types both implicit and explicit, the default behaviors for each, and so on. You can create your own conversion rules, including conversions to fundamental types like your own operator int(), operator bool(), or operator mytype(), whatever other conversion type you want.

The bool type is a fundamental type, it has a defined behavior that meets two-state Boolean logic and also satisfies the hardware machine requirements.

If you are creating your own class, struct, union, enum, typedef, or function signatures, every one of these user-created types must implement the rules for that kind of type as specified in the standard. They are not the Wild West free-for-all, each has standardized rules. They are provided with default operations with the programmer able to specialize the behavior.

Calin said:

a light breeze said:
A non-trivial C++ program will have thousands of types

That`s probably an exaggeration coined to make a point. I imagine each type needs to be hand coded by a programmer, how many programmers does it take to keep a thousand types around while developing a program?

It is unclear to me why you would believe this is exaggeration. If anything, it is understatement. ?

No, not every type is hand-coded. The thousands number is perfectly plausible for a codebase a couple hundred thousand lines long if you just count the hand-rolled types. But it's more like tens of thousands of types once you factor in all the types generated by templates and code generators. Don't forget that AAA games tend to use C++ and can have hundreds of developers on the team, not that this is necessary for a type count of that magnitude. Maintaining a codebase with thousands of types and hundreds of thousands lines of code takes LESS developers than it would to maintain the same codebase without a type system because of the maintainability benefits of the type system.

Yes, every class, struct, union, enum, function signature, template specialization, typedef definition, and type alias is a user-created type. All the rules apply. A large codebase will have many thousand.

Every .h and .cpp combo can create many custom types. You've got the new class being created, plus typically a few typedef and using aliases for simplification, and some template specializations like std::vector<sometype> which is a specialization creating a new type. It's also common to create new function types following the function type rules just to simplify life for people using the class.

frob said:
You can provide your own conversion functions, both default conversion and explicit conversion.

the closest next thing I can think of is currency exchange, that`s not a programming notion of course but you always learn new things by association.

My project`s facebook page is “DreamLand Page”

This topic is closed to new replies.

Advertisement