All posts by kalx

Unit test frameworks

I’ve never understood why people use GTest, CppUnit, Catch, oh wait, Catch2 now.
Here is my C++ unit test framework:

// test object constructor calls function
struct test {
    test(const std::function& f)
        try {
        catch (const std::exception& ex) {
            fputs(ex.what(), stderr);

Just write a int main() { return 0; } file and add .cpp files that call your tests.
They look something like this:

test my_function([]()
    assert (my_function_works());

Just make sure my_function_works throws an exception with an informative message. I use ensure for that.
More examples can be found here.
Why make things complicated?


What is a type? You see that word used all the time in computer languages but it never seems to be precisely defined. Here is my definition:

type is a set of bits together with the operations that can be performed on those bits along with the rules the operations satisfy.

This is really just math 101 but the computer science world is finally catching up. Math doesn’t mention the set of bits because everything is a set in math.

An int is a set of bits (usually 32 or 64 these days) that can be added, subtracted, multiplied, divided, complemented, etc. These operations satisfy certain rules. For example, x + y = y + x. They actually satisfy a long list of rules that most people can’t be bothered to learn until something blows up. What about 2’s complement or unsigned ints or overflow? Ain’t nobody got time for that.

As my friend Candy Chiu first pointed out to me, C++ concepts (at the time called Concepts Lite) provide a language mechanism to do precisely this. More precisely, they allow compile time checks on boolean constraints on template parameters. And template parameters are types.

Li’l help?

I’ve been quiet lately, but I’ve been putting in a lot of new work. As some of you know, I teach Computational and Quantitative Finance at Columbia and use this library in that course. I revamped the xll12 library to generate documentation that can be built with Sandcastle Help File Builder and integrated with the Help on this Function link in the Function Wizard.

My students use the library to get a front row seat with traders: if you give a trader an Excel spreadsheet they will look at it. It is nearly impossible to get them to schedule a meeting where you can get their attention for any length of time, but spreadsheets are their world and they will quickly tell you what they like, what you got wrong, and, oh, yeah, BTW can you get it do this too?

One thing I learned from Mark Joshi (of xlw fame) is that you have to make things simple. People give up easily when they run into a problem. It takes a lot of work to make things simple.

I am still working on getting a CA so I can sign add-ins and set up a WebDAV server so people don’t even need to download the add-in/spreadsheet/help file. Just waiting on D&B to update my company in their database to move forward.

What I need help on is expert users to start pounding on the code and maybe even give pull requests. I’ve set up a repository at You can build it with VS 2017.

It is not as simple as it should be yet, but I will help you get going if you find this interesting. Follow your passion.


One thing I never understood about laptops, or products in general, is why there are so many different but similar models of them. It’s confusing, but apparently people find value in things they think are tailored exactly to what (they think at the time) their needs are.

Obviously the most important consideration is your budget. The second most important is what operating system you are comfortable with: OSX, Windows, or Linux, listed in decreasing order of usability of and increasing order of maintenance. The third criterion is what you want to accomplish. Are you an artists or in sales? Mac is what you need. If you need to produce documents and spreadsheets then either OSX or Windows will work for you. If you are a developer who is hooking up to the latest in web technology you must have a Linux machine.

I always get my wife Apple products. They command a premium but they look beautiful and just work. After Steve Jobs’ earthly departure their products seem to be declining in awesomeness and increasing in price, but the MacBook Air seem to be the most popular choice among the students I teach.

I have a softspot in my heart for HP because I bought my first laptop from David and Bill. They went downhill for a while but their Spectre line is looking really good these days. (Unfortunate name choice given the latest Intel debacle.)

My current laptop is a Microsoft Surface Pro 4. I tried the first version of the Surface Book and had to return it to Satya. They are two (or maybe three, checking just now) generations past that now. The touch screen is a little too touchy sometimes, but other than that it is a very solid laptop. I made the mistake of getting in the Windows 10 Insider Program. Don’t do that unless you like a wild ride.

After HP I bought IBM Thinkpad series laptops, aside from a Sony Vaio that died on the last day of their warranty. (Didn’t those guys get hacked?) Lenovo bought out the IBM business and continues to produce high quality products. Their T series are a good value and I’ve never met anyone who bought a X1 Carbon who was disappointed.

I spent many hours getting linux (Slackware) to run on my laptop and desktop machines starting with an Intel 386 desktop that cost me $3000 back in the early 90’s. There are much better options now.

OSX is Unix based, ever since OS9 was abandoned, but it is BSD Unix. Windows 10 has their WSL: Windows Subsystem for Linux. It is a work in progress but you can install the latest version of Ubuntu and are a shell prompt away from using apt get to install gcc-9, llvm, clang, and all the latest linux based technology.

There are new options available now if you believe you can rely on an internet connection: buy the the cheapest, crappiest Chromebook available and use it to log into a virtual machine of your choice. You can pick any operating system you want, how fast and how many cores you want for a CPU, how much RAM and disk space you need.

Your only problem is figuring out what you want to achieve with all the power at your fingertips now.

WordPress Ads

Ads make the world go around these days. I think Google still makes almost all of their income from ads. I was completely creeped out by how many ads WordPress had crawling across this website. Like cockroaches. They should be gone now. Let me know if you see any still popping up.

Paste function macros

When you type a function into a cell then press Ctrl-Shift-A you will see a list of argument names for the function appear. I wrote two macros that do something more useful.
If you enter just the name of the function (with no arguments) in a cell you will see a number appear. It is the register id of the function.
If you select the cell with this number and hit Ctrl-Shift-B then the cell contents will be replace by the function called with its default arguments.
If you press Ctrl-Shift-C then the default arguments will be placed in the cells below the function and the function will now refer to these cells.
Let me know if you think I should write a Ctrl-Shift-D that creates two columns. The first column would be the name of each argument and the second column would be their default value. It would also define names for the arguments and use those in the function call instead of cell references.

Bug Report PSA

For the love of our shiny new github gods, please have the common human decency of mentioning the SHA when reporting what you think is a bug in the open source software you are using for free. If you don’t know what that means, please don’t bother the person who’s work you are freeloading off of.
Sorry if that sounds harsh, but you really should spend a few minutes learning the tools before imposing on people who spent many hours creating software you find useful. Be considerate.