Hacker News new | ask | show | jobs
by sftrabbit 4086 days ago
Creator of the site here. Thanks for taking a look and I really appreciate all the feedback.

I wanted to provide a place for beginners to learn about modern features of C++ and a quick reference for idioms and best practices. As the disclaimer says, the existing samples all need review, so don't take anything as gospel. If you would like to contribute please check the samples GitHub repo [0] or leave comments on the sample pages themselves.

A few good points that keep coming up:

- The Rule of Three sample especially needs a rework (it will become the Rule of Five later today).

- It isn't supposed to demonstrate the best C++ formatting style, simply because that would come down to personal preference.

- I have opted to not use `auto` unless necessary for the sake of being explicit about types so that beginners have something to reference against. This is important regardless of ones particular preference for when `auto` should be used and it would be impossible to please everybody. I will be adding a note to the site soon.

- I plan to add a "requirements" section to the sample information which will state which version of C++ the sample depends on.

[0] https://github.com/sftrabbit/CppSamples-Samples

6 comments

A suggestion: I would prefer to not have to scroll the code horizontally. C++ tends to be verbose, and so benefits from a wider window/view. Maybe place the intent and description below the sample code?
This is indeed an annoying problem. Please either decrease the font size or use 2 or 4 space indentation (without mixing tabs and spaces) or just steal some space from the sides.
You could always put the type in a tooltip on hover for auto or something like that. That way you get modern code style along with how an IDE would handle it. But yeah, there's no pleasing everyone when it comes to verbosity :)
Big thumbs up for your stance on auto - eminently sensible. There are instances where "meh, you don't need to worry about the type here" are valid, but if your code is to teach or explain then it needs to be as explicit as it can possibly be.

Edit: that's not to say that there aren't also cases where you should use auto because it is safer than using an explicit type (some integer sizing/signing scenarios spring to mind).

Great looking resource, thanks for putting this together. Is there currently a mechanism to request and vote on samples to add? It would be cool if someone could, for example, request a sample on Expression Templates (or whatever), and other users could vote on which existing requested samples are most interesting.
The current system is just to post sample suggestions to the GitHub issues page [0]. No voting however. I'm not sure there's much need for a voting system right now.

[0] https://github.com/sftrabbit/CppSamples-Samples/issues

Thank you! The way I learn best is by looking at examples first if there are any so this is a great resource for me.
Great resource for anyone looking for some idioms; wish there were something similar for Haskell!

Also, please do s/c++/C++/g, especially in the header.