Using “super” in C++

Bjarne Stroustrup mentions in Design and Evolution of C++ that super as a keyword was considered by the ISO C++ Standards committee the first time C++ was standardized. Dag Bruck proposed this extension, calling the base class “inherited.” The proposal mentioned the multiple inheritance issue, and would have flagged ambiguous uses. Even Stroustrup was convinced. After discussion, Dag Bruck … Read more

What’s the best way to convert a number to a string in JavaScript?

like this: Actually, even though I typically do it like this for simple convenience, over 1,000s of iterations it appears for raw speed there is an advantage for .toString() See Performance tests here (not by me, but found when I went to write my own): http://jsben.ch/#/ghQYR Fastest based on the JSPerf test above: str = num.toString(); It should be … Read more

Iterate through a C++ Vector using a ‘for’ loop

Is there any reason I don’t see this in C++? Is it bad practice? No. It is not a bad practice, but the following approach renders your code certain flexibility. Usually, pre-C++11 the code for iterating over container elements uses iterators, something like: This is because it makes the code more flexible. All standard library containers … Read more

Iterate through a C++ Vector using a ‘for’ loop

Is there any reason I don’t see this in C++? Is it bad practice? No. It is not a bad practice, but the following approach renders your code certain flexibility. Usually, pre-C++11 the code for iterating over container elements uses iterators, something like: This is because it makes the code more flexible. All standard library … Read more

Iterate through a C++ Vector using a ‘for’ loop

Is there any reason I don’t see this in C++? Is it bad practice? No. It is not a bad practice, but the following approach renders your code certain flexibility. Usually, pre-C++11 the code for iterating over container elements uses iterators, something like: This is because it makes the code more flexible. All standard library … Read more

Best way to return multiple values from a function? [closed]

Named tuples were added in 2.6 for this purpose. Also see os.stat for a similar builtin example. In recent versions of Python 3 (3.6+, I think), the new typing library got the NamedTuple class to make named tuples easier to create and more powerful. Inheriting from typing.NamedTuple lets you use docstrings, default values, and type annotations. Example (From the docs):