Practical Language Design Musings

A BLOG

Musings about programming language design and the practice of programming and blogging about it.

In which I try not to claim that “things I don’t like” about a language is “broken”, or “considered harmful”.

But I will complain heavily about cargo-cultish practices, and the insidious insistence on “idiomatic code”.

Latest posts from WorldEngineer.me

  • http://www.johndcook.com/blog/2016/06/08/computing-higher-moments-with-a-fold/ Here is the C++ version: #include #include #include #include int main() {   auto sample = {2,30,51,72};   auto m = std::accumulate(std::begin(sample), std::end(sample), std::array{0, 0, 0, 0, 0},     [](auto& m, const auto& x) -> decltype(auto)     {       ++m[0];       auto delta = x – m[1];       auto … Continue reading How to write C++ like Haskell
  • https://github.com/awslabs/s2n/blob/master/tls/s2n_record_write.c Some people would consider this elegant. Not me. So many lines dedicated to the manual updating of buffer lengths. First and foremost, the style is just error prone and shouting for buffer exploits. Second, it’s just tedious to write and read; AND that tediousness is what makes it error prone. Third, you’re going to … Continue reading Elegant C?
  • The most missed feature in standard C++ for thirteen years, more than lambdas or variadic templates, are the hash container equivalents of std::map and std::set. The “normal” map and set containers are implemented as binary trees, and any class of objects that one may want to store in a map or set must implement strict … Continue reading Combining container hashes with C++14 metaprogramming – Cure for insomnia #1729
  • The Tower of Hanoi problem consists of moving a size-ordered stack of n discs from one tower to another tower, out of three towers {A, B, C}, one disc at a time without putting a larger disc on top of a smaller one. The cyclic version of this problem adds the further constraint that a … Continue reading Cyclic Tower of Hanoi – analysis and implementation
  • http://www.stlport.org/resources/StepanovUSA.html “I find OOP technically unsound. It attempts to decompose the world in terms of interfaces that vary on a single type. To deal with the real problems you need multisorted algebras – families of interfaces that span multiple types. I find OOP philosophically unsound. It claims that everything is an object. Even if it … Continue reading Object Orientation is unsound
  • Say you want to have an a class that allows dynamic adaptation. You can’t create it as a template class to provide “policies” in policy based design because different policies will create distinct classes. This will prevent different adapter classes from attaching to the same object. You also wouldn’t want to require adapter classes to … Continue reading Easy adapter pattern with object map
  • I was reading the Wikipedia page for Radix sort[1] and I noticed a pretty terrible example for C++, so I set about writing my own, which I’ve included in the wiki as a modernized C++14 version. 1: http://en.wikipedia.org/wiki/Radix_sort
  • Continuing on from the previous post, there was another side challenge to implement the POSIX utility wc. Someone claimed C++ makes things unnecessarily hard and the challenge was supposed to prove it. Well, it was simple and I threw in a simple (incomplete) SLOC counter as well. The challenger couldn’t argue that C++ made it … Continue reading More on brevity and clarity
  • Recently had a discussion and challenge in comparing two languages, C++ and Python. I think modern C++ is holds up really well to so-called scripting languages to do quick and dirty utility programs. This is a reasonably short implementation of a prime number finder: Several things. Mostly I’ve learned to re-embrace the spirit of C/C++ … Continue reading Interesting exercise in brevity and clarity
  • “Use template meta-programming to express design, not to express computation.” Various explanations of template meta-programming uses examples like a compile-time Fibonnacci sequence. What those tutorials should be focusing on is how to use template meta-programming to hide incidental requirements of interfaces. The ultimate goal of template meta-programming is to enable code like this:

Get new content delivered directly to your inbox.