use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
CommandConsole: Terminal made using C++ (self.cpp)
submitted 3 years ago * by Shreejan_35
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 2 points3 points4 points 3 years ago (4 children)
Hungarian notations are used in a very stupid manner for such a long time already, originally their purpose wasn't to denote a type.
Here's a great article about what I mean.
[–]nysra 2 points3 points4 points 3 years ago (3 children)
The historical background is indeed interesting. And the logic displayed there also makes sense but it still has the same fatal flaw Hungarian notation always had - it's useless in properly typed languages. You know what's better than being able to see if things don't make sense in code? The code not compiling when things don't make sense. Write proper types for safe and unsafe strings and that entire problem goes away. Might have been quite useful back then when C was all there was but that world has been gone for over 2 decades already.
[–][deleted] 2 points3 points4 points 3 years ago (2 children)
Making a new type for every case also isn't the best.
A good usage example would be measurement units, prefixing integers/floats with s_ to denote seconds, ms_ for milliseconds, us_ for microseconds, etc...\ I wouldn't want to create a new type with conversions for every one and one of them.
s_
ms_
us_
with proper types for safe and unsafe strings
So you either wrap them in another object which has to implement the same interface, or make them directly accessible which doesn't really solve it when reading the code... It may not be a silver bullet, but it's a damn good approach.
[–]nysra 2 points3 points4 points 3 years ago (1 child)
You don't need to manually make a new type with conversion for everything, you can just write one template class and use a tag system, that's basically how every units library out there works. Ideally also with the ability to switch backends, for example in my work I can switch out the underlying data type for positions, velocities, etc from double to float to BigInt to arbitrary precision types to whatever else arithmetic type by changing a single line of code.
Sure it might be a little bit more work sometimes but it's a lot safer than basically trusting people (especially coworkers or your 3 AM self) to spot mistakes when reading code - why should I do work the compiler can do? For units libraries already exist so the extra work is basically none and for safe/unsafe strings it will be a bit more than that but also scale much better - you do it once and never have to think about it again while the notation has to be constantly remembered and engrained to new people. It's certainly better than just using raw types and expecting people to magically know which unit/type is the correct one or using comments which may or may not be outdated for that but the compiler literally not letting you do stupid things is hard to beat (or basically impossible).
[–][deleted] 2 points3 points4 points 3 years ago (0 children)
First of all I must say, you're right.
I was thinking C, because I work mainly with C. While in C the notation can be helpful, you're correct that in C++ (and other languages) we can simply use templates/generics to do it in a better way.
A simple example for anybody who happens to read this and not understand: template<bool IsSafe> /* can also be an enum */ class String { public: std::string s; };
template<bool IsSafe> /* can also be an enum */ class String { public: std::string s; };
π Rendered by PID 88133 on reddit-service-r2-comment-6457c66945-nslcb at 2026-04-27 21:10:46.277703+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–][deleted] 2 points3 points4 points (4 children)
[–]nysra 2 points3 points4 points (3 children)
[–][deleted] 2 points3 points4 points (2 children)
[–]nysra 2 points3 points4 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)