flak rss random

documentation is thoroughly hard

Documentation is good, so therefore more documentation must be better, right? A few examples where things may have gotten out of control.

more...

Posted 18 May 2017 20:24 by tedu Updated: 19 May 2017 02:48
Tagged: openbsd software

meaningful short names

Why don’t unix commands have any vowels in the name? cp and mv are obviously devoweled standins for copy and move. But they’re less intuitive for new users. The user wants to copy a file. Why shouldn’t the name of the command be exactly the operation the user wants to perform?

What exactly does the user want to do? Instead of copying files, maybe I want to link two files. What does that mean? In unix, we have hard links and symbolic links. If I replace the “original” file, do I want the link to refer to the original file or the replacement? Or maybe what I mean by link two files is to combine two object files into an executable. Do we call that loading instead? ln is the name of a command, but link is the name of a concept. And sometimes the concept evolves over time. The linker is called ld because it used to be the loader. (I think.)

grep is a remarkably useful tool, but with a most unintuitive name. Why not call it find like Windows does? I want to find some text, I run find. So obvious. But some users may want to find files in the filesystem, not strings in a file. What command do they run? Probably locate.

There may be a great deal of historical accident in the names of commands (what if the inventors of awk had different initials?), but that doesn’t mean we can’t recognize the value of unique and precise identifiers.

Posted 03 Mar 2017 02:31 by tedu Updated: 14 Jun 2017 22:55
Tagged: rants software

RC40 card cipher

The Solitaire cipher is perhaps the best known encryption algorithm implemented with a deck of cards. Ignoring security, it has a few drawbacks. It’s pretty complicated. I can never quite remember the rules. Sure, with practice it’s possible to memorize, but ideally we want something easy to teach. It’s also pretty slow. Even with practice, the shuffling and cutting manipulations take time.

more...

Posted 10 Feb 2017 14:27 by tedu Updated: 10 Feb 2017 14:27
Tagged: gadget security

to errno or to error

Unlike other languages which have one preferred means of signalling an error, C is a multi error paradigm language. Error handling styles in C can be organized into one of several distinct styles, such as popular or correct. Some examples of each.

more...

Posted 24 Jan 2017 20:52 by tedu Updated: 24 Jan 2017 20:52
Tagged: c programming

an enchanted forest fable

One day you wake up, infused with the entrepreneurial spirit. Enthused even. The time has come to bring forth your vision of a better future. You hike up the road to magic mountain to meet the wizard. Impressed with your spark, he gives you his blessing and so you go to work. Soon, your dream will become reality. Banana peeling as a service.

A few short months later, and you already have 101 customers. Growth is spectacular! Just like the wizard and his magic beans promised. Of course, 99 of those customers are fellow inhabitants of magic mountain and the other two are your mom and college roommate, but magic growth is magic growth.

A few long months later, and you still have 101 customers. But not to worry. Elsewhere on magic mountain there’s a deep fried burritos as a service dream become reality, and they actually have paying muggle customers. With only a tiny pivot, your banana peeling expertise can become burrito unwrapping expertise. You are a true master of the monad. And so, your incredible journey synergizes into theirs.

Some may ask why it was necessary to absorb an entire village of banana peelers instead of hiring a single burrito unwrapper, and why it was necesssary to pay everyone so many millions of hexes, but that’s just quibbling. The council of elder wizards met under the moonlight and decided this was the happiest outcome for everyone.

The end.

Posted 04 Nov 2016 19:02 by tedu Updated: 04 Nov 2016 19:02
Tagged: business

sorted arrays, theory and practice

The average time to check if a random array is sorted is e - 1. This was not the result I was expecting, but it’s also easy to check.

#include <stdio.h>
#include <stdlib.h>

typedef unsigned int unt;

const unt length = 100;

unt
sortlen(unt *arr)
{       
        unt i;

        for (i = 0; i < length - 1; i++)
                if (arr[i] > arr[i + 1])
                        break;
        return i + 1;
}       

void
shuffle(unt *arr)
{       
        unt i;
        
        for (i = 0; i < length - 1; i++) {
                unt j = i + arc4random_uniform(length - i);
                unt t = arr[j];
                arr[j] = arr[i];
                arr[i] = t;
        }       
}       

int
main(int argc, char **argv)
{       
        const unt trials = 1000000;
        unt arr[length];
        unt i;
        unt count = 0;
        
        for (i = 0; i < length; i++)
                arr[i] = i;
        
        for (i = 0; i < trials; i++) {
                shuffle(arr);
                count += sortlen(arr);
        }       
        printf("avg sort len %f\n", (double)count / trials);
}       

And the results:

carbolite:/tmp> ./sort                 
avg sort len 1.718539
carbolite:/tmp> ./sort 
avg sort len 1.717483
carbolite:/tmp> ./sort 
avg sort len 1.718032

I’m not sure if it’s reasonable to expect the inputs to such a function to be uniformly random arrays. Any program which checks if an array is sorted probably deals with sorted arrays more frequently. But at least the math checks out.

Posted 30 Oct 2016 23:34 by tedu Updated: 30 Oct 2016 23:34
Tagged: math programming

chromebook printing troubles

I have a chromebook which is quite nice for what it does. A dedicated browsing machine, fast and low maintenance. Alas, I am sometimes required to go outside, and worse yet talk to people, and even worster, show those people information. It is inconvenient to hand over my phone, no rotate it back, your other yaw, scroll a little, here, oh wait, let me unlock it again. I print such things on paper. Double alas, the chromebook makes this difficult.

more...

Posted 24 Oct 2016 19:41 by tedu Updated: 24 Oct 2016 19:41
Tagged: computers rants software

new world economy

The New Yorker money issue, October 10. There’s some good articles about evolving, er, disrupting, business practices.

more...

Posted 23 Oct 2016 22:31 by tedu Updated: 23 Oct 2016 22:39
Tagged: business magreview

off to be the wizard

Amazon started adding animations to selected books (Kindle in Motion, they call it). I figured I’d give it a try and read Off to Be the Wizard, by Scott Meyer of Basic Instructions fame. There’s not really much to animate here, only about one illustration per chapter, but now they dance back and forth.

more...

Posted 20 Oct 2016 05:33 by tedu Updated: 20 Oct 2016 05:34
Tagged: bookreview

process listing consistency

POSIX specifies that there is a ps utility to list processes, although it doesn’t describe how the command is implemented. In fact, it’s not possible to implement ps using only POSIX interfaces. However it’s implemented, it’s unlikely to use double buffering, which means on a sufficiently busy system, the results may be inconsistent. If lots of processes are being created and exited while ps runs, some of the output may be “before” and some “after”. Much like a game without vsync.

more...

Posted 06 Oct 2016 12:26 by tedu Updated: 06 Oct 2016 12:26
Tagged: c openbsd programming