Static typing. I suppose dynamic types are fine if you’re hacking together a small tool. But static (strong, preferably HM-inferred) typing allows you to reason about your program much more powerfully.
Correctness by construction, enforced by the compiler, is a good thing. I used to write a lot of unit tests; now I write many fewer, and instead I write my code closer to the ideal of “if it compiles, it runs correctly”.
Consider the following code:
#include <iostream>#include <type_traits> // base template template <typename T> struct what_type { void operator()() { cout << "T" << endl; } }; // specialization 1 template <typename T, size_t N> struct what_type<T[N]> { void operator()() { cout << "T[" << N << "]" << endl; } }; // specialization 2 template <> struct what_type<int[0]> { void operator()() { cout << "int[0]" << endl; } }; int main(void) { int x[] = {}; what_type<std::remove_reference_t<decltype(x)>>()(); return 0; }
C++ lambdas are wonderful for all sorts of reasons (especially with their C++14-and-beyond power). But I’ve run into a problem that I can’t think of a good way around yet.
If you are familiar with C++, you are aware of the importance of move semantics and rvalue references. Currently, a plethora of blog posts, conference videos, and even books explain how they operate, as well as how forwarding references (previously called universal references) combine with std::forward and templates to offer nice, optimal handling of objects with move semantics.
One can assign a lambda to auto or to std::function. Normally one would assign a lambda to auto to avoid possible unwanted allocation from std::function. But if you want recursion, you need to be able to refer to the lambda variable inside the lambda, and you can’t do that if it’s assigned to auto. So how do you do recursive lambdas without using std::function?
Use a fixed-point combinator (y-combinator) of course.
Codejam is using a different system and rules than before. I’m not sure if I want to participate in the contest. I know how to solve problem A , but I can’t find a vital bit of info about the new rules like the CPU of the servers where the codes are supposed to run.
However, this suspiciously sound like one of those badly made ACM contests.
I no longer have so much free time as before.
C++ provides a strange mix of compile-time and runtime functionality for dealing with tuples. There are some interesting parts, like std::tie to destructure a tuple, and std::tuple_cat to join together several tuples into one.
So there is evidence that the standard has been influenced by some functional programming ideas, but I don’t think the full power of tuples has been realized (in both senses), and I found myself thinking about some missing parts.