It does mean a thing

Some notes on software and beyond

Prepositions and Arguments

I had some crazy idea how to make C++ code more readable using prepositions. It would take some discipline to use and probably serious industrial people would consider me mad.

Haven’t you seen a function which parameters’ order is not really easy to remember?

1
strcpy(name, value);

What if we add a pass-through wrapper functions called from and to?

1
2
3
4
5
6
7
template <typename T>
inline T&& from(T&& value)
{
    return std::forward(value);
}

// same definition of 'to' and maybe 'at/by/with/...'

Then the call would look

1
strcpy(to(name), from(value));

Much readable.. and not really idiomatic and maybe kind of dangerous. The major drawback of such an approach is that one can easily mix things up and there is no way to validate usage of these prepositions. Nevertheless, it comes for free runtime-wise; it restricts usage of prepositions as names and finally, it is purely optional — you just put on some hints.

Comments