Perfection is when there is nothing left to take away
This question seems silly on the surface, to put it mildly, as both languages are compiled to produce most optimal code, often by the same compiler engine using the same optimization techniques. However, if widely-used programming practices and common libraries are factored into this mix, the result is not as straightforward as it may seem.
The C++ #include directive is probably the most commonly misused construct of the language. Generally accepted and rarely disputed practice today is to use angle brackets for standard headers and double quotes for internal header files and, sometimes, for 3rd-party libraries, which at the first glance is well-aligned with the C++ standard that suggests the following use of the #include directive:
Note: Although an implementation may provide a mechanism for making arbitrary source files available to the < > search, in general programmers should use the < > form for headers provided with the implementation, and the " " form for sources outside the control of the implementation.
A few days ago a developer asked me if we intend to replace all archaic printf-style calls within the project with modern, object-oriented string stream equivalents. I heard this sentiment many times over the years, often substantiated by the fact that buffered stream operations are faster than frequent parsing of the format string. Let's test this theory and format a simple string in a loop using both methods.
A couple of days ago a developer asked me why their Visual Studio 2005 debugger no longer breaks when a C++ exception is thrown, even though C++ exceptions were not suppressed in the exception configuration and the debugger was attached to an IIS worker process to debug native code.
Thinking that something might be wrong with how C++ exceptions were handled, I stuck a statement dereferencing a NULL pointer into the code:
*(char*) 0 = 0;
Some STL containers, such as std::map, are designed to use std::pair to maintain keys and values. A special convenience function, std::make_pair, is often used to create pairs without having to specify template argument types. Typical code that makes use of an STL map looks like this:
std::map<std::string, std::string> m; // map<key,value>
printf("%s", m.find("1")->second.c_str()); // prints "one"
While most content management systems, such as blogs, allow users edit HTML directly, more specialized ones, such as discussion forums, allow users to use alternative syntax that is easier to control and adapt to particular needs. BBCode, which stands for Bulletin Board Code, is one example of such alternative.
var s = new String("0123456789");
var c = s;
Much to my surprise, the code appeared to work just fine when compiled in ASP and it also worked in FireFox, Opera, Chrome and Safari, although failed in Internet Explorer.