Monthly Curations – Jun 2019

Rediscovering an older self-version

I’ve started a new blog or a new online journal so many times, some private, some public, that I’ve really lost track of all of them. This is mildly complicated because some of them were pseudonymous.

At least on my (now deprecated?) static blog I tried to merge together older content, but I just discovered an older WordPress blog, that can best be described as “explorations in programming“.

At some point, I’m going to try to merge them together (I’m guessing that means exporting-and-importing), but it’s still a bit of a revelation to discover all this stuff I wrote, almost exactly five years ago (!)

Edit (July 11 2019): It turned out to be fairly straightforward to export the old blog and re-import it into this one — the hard part was figuring out what my login/password was, five years ago! — so this blog now goes back to 2014!

Monthly Curations: May 2019

“Hello World” in Ocaml

I was curious if Zig was as good as Nim about “minimalist hello-world” builds (yes, a ridiculous metric, but still …), and found that yes, it was quite similar, but was surprised to find that Ocaml did one better on them(!)

➜  ocaml-playground cat hello_world.ml

print_string "Hello World from Ocaml !!\n"

(Yes, that’s it, just one line)

➜  ocaml-playground ocamlc hello_world.ml -o hello_world

➜  ocaml-playground ./hello_world
Hello World from Ocaml !!

➜  ocaml-playground l hello_world
.rwxr-xr-x 18k agam 25 May  0:45 hello_world

Just 18K, under half of Nim and much lower than anything else on this list!

(This is with ocamlc version 4.06.1 on Debian 9.6)

“Hello World” in Zig

  • Creating
➜  zig-playground git:(master) ✗ cat src/main.zig
const std = @import("std");

pub fn main() !void {
    var stdout_file = try std.io.getStdOut();
    try stdout_file.write("Hello from Zigland!\n");
}
  • Running
➜  zig-playground git:(master) ✗ zig build run
Hello from Zigland!
  • Looking at builds:
➜  zig-playground git:(master) ✗ l zig-cache/o
drwxr-xr-x - agam 20 May 18:34 1FaU34FwI7Ct04pmfOlMacuOykIOisQtTn1t1Q3lrQOZcsEF0qxJW3vLauzHjpwm
drwxr-xr-x - agam 20 May 18:36 fyjPplfax8VTFYlidzFwMj_gV5Dw_T9T4PVTNBaOPnxDE5dq2XRo28L0b-87xi0l
drwxr-xr-x - agam 20 May 18:36 r-sdQS7ThLQpXn2OhOye0gD2RSuygbP_R6dWnLJZKjgjdWqQxTSCKB3dHKbWucMG
drwxr-xr-x - agam 21 May 23:21 XxkweE8uWyMc9LocxqJMMKAwTGgBzcn4q3bEKH1tL8Kx-F5Gk3kopgQqLbVLXVbh
  • Debug build size:
➜  zig-playground git:(master) ✗ l zig-cache/o/r-sdQS7ThLQpXn2OhOye0gD2RSuygbP_R6dWnLJZKjgjdWqQxTSCKB3dHKbWucMG/zig-playground
.rwxr-xr-x 406k agam 20 May 18:36 zig-cache/o/r-sdQS7ThLQpXn2OhOye0gD2RSuygbP_R6dWnLJZKjgjdWqQxTSCKB3dHKbWucMG/zig-playground
  • “Release build” size:

zig build -Drelease-small=true

➜  zig-playground git:(master) ✗ l zig-cache/o/XxkweE8uWyMc9LocxqJMMKAwTGgBzcn4q3bEKH1tL8Kx-F5Gk3kopgQqLbVLXVbh/zig-playground
.rwxr-xr-x 53k agam 21 May 23:21 zig-cache/o/XxkweE8uWyMc9LocxqJMMKAwTGgBzcn4q3bEKH1tL8Kx-F5Gk3kopgQqLbVLXVbh/zig-playground

So, 406k for the debug build, 53k for the release build, very similar to Nim here, and comparing very favorably indeed to Rust or Go (!)

Monthly Curations: April 2019

Starting new C++ projects

I wanted to have a playground to try out new idioms and concepts (hah!) in C++, and it became an excuse to figure out what the right way (in my opinion) would be, given the enormous range of choices each step of the way.

I settled on two requirements: a good build system and a good standard library augmentation.

There are numerous build systems these days, but (blame familiarity here, I guess) I went with Bazel.

Similarly, familiarity led me to pick Abseil over (say) Boost or Folly.

To show how straightforward it can be these days to “just start making” something in C++, I made a small dummy program that has a single cc_binary rule and uses some basic string library functions.

(The real story is how amazing it is to have open-sourced versions of these, this setup would have been unthinkable just a couple of years ago!!)

Take a look here.