Raymond Chen points out that you can help yourself by using the compiler to output assembly listings which can help to answer questions such as which parameter comes first under the current calling convention.
Explicit user-defined conversion operators
You can now mark user-defined conversion operators as explicit:
explicit operator bool() const;
This is an improvement over previous idioms that have been employed to avoid a class of bugs that occur when a type is inadvertently converted.
Filed under C++
Online C++ Compilers
Today I took a look at some Online C++ compilers – this would have been very useful when checking portability of some code in my recent post on C++11 Concurrency.
First, here’s LiveWorkspace.org which makes g++ 4.72 and 4.8 available as well as clang 3.2:

Second, Rise4Fun allows you to try Visual Studio:

As anticipated, the Counter class (which contains a mutable member of type int&) compiles under Visual Studio, but doesn’t under clang 3.2 or gcc (which is correct according to the C++ standard). What’s great about LiveWorkspace is how quickly you can switch between compilers to see how they like the same code. For example, the amended code that treats int& as a template parameter compiles under g++ 4.7.2 and 4.8, but doesn’t under clang 3.2:
#include <iostream>
template<typename T>
class Counter
{
mutable T m_t;
public:
Counter(T t) : m_t(t){}
void Increment() const { ++m_t; }
};
int main()
{
int count = 0;
Counter<int&> counter(count);
counter.Increment();
std::cout << count << "\n";
return 0;
}
Filed under C++
Excel and The London Whale
The problems of using Excel within financial institutions are well-known – the control risks are huge because it’s so easy for a rogue trader to manually edit trade data/market data and re-save the sheet. This article describes the role Excel played in under-estimating the risks involved in financing The London Whale’s trading strategies:
JPMorgan’s Chief Investment Office needed a new value-at-risk (VaR) model for the synthetic credit portfolio (the one that blew up) and assigned a quantitative whiz (“a London-based quantitative expert, mathematician and model developer” who previously worked at a company that built analytical models) to create it. The new model “operated through a series of Excel spreadsheets, which had to be completed manually, by a process of copying and pasting data from one spreadsheet to another.”
Another question is, how do you test a spreadsheet? And how do you re-use fragments of a sheet?
the spreadsheets that people create with Excel are incredibly fragile. There is no way to trace where your data come from, there’s no audit trail (so you can overtype numbers and not know it), and there’s no easy way to test spreadsheets
Filed under Finance
Qualities of Uber-Productive people
Great article on how to achieve high productivity.
Productive people aren’t braver than others; they just find the strength to keep moving forward. They realize fear is paralyzing while action creates confidence and self-assurance.
I subscribe to the school of thought that, in order to finish a project, you have to keep starting – to get over the fear of imperfection, you don’t focus on completion, but focus on beginning again and again.
Think about a time you put off a task, finally got started, and then, once into it, thought, “I don’t know why I kept putting this off–it’s going really well. And it didn’t turn out to be nearly as hard as I imagined.”
Read more: http://www.inc.com/jeff-haden/7-qualities-of-uber-productive-people.html#ixzz2KoR5fDv8
Filed under Soft skills
Introduction to C++11 Concurrency
Marius Bancila wrote a neat introduction to C++11 concurrency.
Filed under C++
Apple SmartWatch – yes please!
When I awoke this morning, I didn’t know that I wanted a smart watch. Having read this article, though, I’ve realised my set of gadgetry won’t be complete until I get one. The reviews of the currently available smart watches weren’t very complimentary, so I’ll wait to see what Apple come up with.
Filed under Technology
How to write managed C++ using templates
Occasionally, I write some managed C++ code as a glue-layer between C++ and F#. Today was such an occasion, and I found myself writing the same piece of code in several places with different types. Obviously, my reaction was to refactor to share the common code – given that the behaviour was common and independent of the underlying type, a template class seemed appropriate – but can you use templates with managed C++?
It turns out that you can – here’s the code, the aim of which was to take some COM object from native code and wrap it as an option of some expected strong type. If you haven’t seen managed C++ before, the syntax looks pretty ghastly – it may help to mentally substitute & for ^. If you aren’t familiar with F# option, it’s like boost::optional;.
template<typename T>
FSharpOption<T^>^ getOptional( IUnknown* raw )
{
FSharpOption<T^>^ optionalValue =
optionalValue = FSharpOption<T^>::None
if ( raw != nullptr )
{
T^ cooked = (T^)Marshal::GetObjectForIUnknown(IntPtr( raw ));
if (cooked != nullptr)
optionalValue = FSharpOption<T^>::Some(cooked);
}
return optionalValue;
}
Here’s how you would call the template function to get back the managed C++ equivalent of the F# type MyType option:
FSharpOption<MyType^>^ myValue = getOptional<MyType>( _rawValue );
Filed under C++
Software code should read like well-written prose
I’ve long felt that well written software should not only be human-readable, it should be a good read. It’s a view held by Robert Martin who describes clean code as elegant, efficient, readable like well-written prose.
This came to mind when I finished reading a thriller, “The Lion” by Nelson DeMille. I’ve read several of his books, not least “The Charm School” which was brilliant. Now, The Lion didn’t have a great plot – in fact, having read a couple of his John Corey books already, I could pretty much predict the finale after the first couple of chapters. But it didn’t matter, because the story was so well told I enjoyed the journey. The next book I picked up is a science fiction tale set around the time of World War II but with a time-travelling twist – it has an exciting plot and I haven’t a clue what will happen. Yet it’s less enjoyable, the prose is stodgy and I’m struggling to get to know the characters.
Now, to me, the plot in a novel is analogous to software design, whereas the story telling is analogous to the implementation code. Whilst I’d prefer good story telling with a weak plot to a great plot with poor prose, the opposite is true of software – good design trumps good implementation code every time. That’s where software and fiction are so different – software is alive and will be maintained and extended throughout its life, whereas a novel is frozen in time the moment the author deems it finished. You can always re-implement badly implemented pieces of code – but it’s a much bigger task to re-work an entire design.
Filed under Programming
Lessons on hiring
Good article about an unexpected problem from hiring too many B-players in your firm. Here are the author’s definitions:
A player: Fully self-sufficient and takes initiative that positively impacts the company.
B player: Does some things well, but not fully self-sufficient, and not consistently strong.
C player: Just average, and does not excel in any area.
D player: Poor performer, and shouldn’t last long if you are a half-capable manager.
F player: Should be out…like yesterday.
Here’s the problem with B-players, the inconsistency catches you by surprise the first time, so then they need careful monitoring – something you don’t have time to do.
When you have someone on your team that you think is doing well enough, you will likely trust them with mission-critical tasks like hiring or pushing code. This will impact the entire evolution of your company. If you entrust important decisions to someone who is just “good enough,” you will watch the opportunities pass.
The author claims that a star engineer isn’t just worth 10x the average, s/he is irreplaceable by any number of lower quality people.
Filed under Soft skills