What is the point of making a syntactic distinction between standard and user-defined types?

Although here I will refer specifically to C++ and Bjarne Stroustrup’s naming conventions, in principle, I’ve seen that people use somewhat similar rules for other languages here and there.

So, the basic idea is that one should be able to distinguish standard types from user-defined types while reading the code. For instance, Bjarne Stroustrup suggests that one uses

an initial capital letter for types (e.g., Square and Graph)

which, taking into account that

The C++ language and standard library don’t use capital letters

allows achieving the goal mentioned above.

But why do we need to do so? What can be the purpose of distinguishing standard and user-defined types?

I could not find any Bjarne Stroustrup’s reasoning on that matter, and besides, I myself think in diametrically opposite way. 😀 I know, I know, “Who am I to dispute Stroustrup?” But, listen, a bunch of the C++ language features, e.g. operator overloading, serve the purpose to allow user-defined types a similar level of syntactic support as standard types. And then all this is baffled by a different naming discipline…

P.S. Not to mention that often one word is not enough to name a class and an underscore-separated word that starts with a capital letter looks so foreign.

8

There is absolutely no purpose or benefit in such. One of the goals of C++ was to treat UDTs and primitives interchangably, and whilst they haven’t entirely succeeded, this is one area where you don’t have to differentiate.

When it comes to naming, Stroustrup is nuts, and this is a scientifically-proven fact.

6

Naming conventions are about supporting human (i.e. programmer and maintainer) comprehension of the code.

UDTs can be specified so that declaration of variables, initialisation, expressions, and statements work on them differently than is the case for standard types. For problem finding, it is useful for the maintainer to have some cue that some section of code might do funky things (e.g. the implementation of a user-defined integral type used within some function might have a flaw in how it does addition).

There are many ways of providing such cues (comments, design specifications, etc). The advantage of naming conventions is that they are present in the code, whereas comments can be omitted, out of date, etc.

One reason I use capitalized words for types, is to distinguish variables from types. This allows to declare a variable with, apart from the capitalization, the same name:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Foo foo;
Graph graph;
</code>
<code>Foo foo; Graph graph; </code>
Foo foo;
Graph graph;

This can be useful for classes of which only one instance is used in each context, e.g. configuration settings.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật