BF

When you know deep-down that a Brainfuck interpreter should only ever be written in C, but you’re not quite ready to leave the comfort of C#. So in a spirit of minimalism you find yourself writing C# in a C style just for the hell of it.

public static void Execute(string program, Stream? input, Stream? output)
{
    int ip = 0;
    int dp = 0;
    var data = new byte[30000];

    while(true)
    {
        if (ip >= program.Length)
            break;
        switch(program[ip])
        {
            case '>':
                dp++;
                break;
            case '<':
                dp--;
                break;
            case '+':
                data[dp]++;
                break;
            case '-':
                data[dp]--;
                break;
            case '.':
                output?.Write(data, dp, 1);
                break;
            case ',':
                input?.Read(data, dp, 1);
                break;
            case '[':
                if (data[dp] == 0)
                    ip = JumpTo(']', +1, program, ip);
                    break;
            case ']':
                if (data[dp] != 0)
                    ip = JumpTo('[', -1, program, ip);
                break;
        }
        ip++;
    }
}


private static int JumpTo(char match, int incr, string program, int ip)
{
    while (true)
    {
        ip += incr;
        if ( (match == ']' && program[ip] == '[') || 
             (match == '[' && program[ip] == ']') )
            ip = JumpTo(match, incr, ip, program);
        else if (program[ip] == match)
            return ip;
    }
}

This made me wonder if the style of a language affects the style of its implementation. Not sure.

(For any impressionable children reading this: don’t do it this way. Use descriptive variable names and comments and put braces around your if/else clauses.)

(And for any hiring managers reading this: its deliberate, I promise.)

Climbing wall etiquette for beginners

As a service to those new to indoor climbing walls, I have collected together the following rules as a guide to contemporary de rigueur behaviour:

1. Save time and impress other wall users by arriving with your harness already on. Keep it on when you leave, too, as this will provide endless opportunities to for conversations with people you meet on your journey home.

2. If you’re climbing in the trainers you arrived in, rather than using old-style rock shoes, any mud or grit on the soles will provide valuable additional friction as it sticks to all but the the smallest holds.

3. The machines that let you climb on your own are called “The Pulleys”. The term “auto-belay” is regarded as rather old-fashioned.

4. When climbing indoors, it is important to carry appropriate safety equipment. This means as couple of prusik loops and a screwgate. Some experienced indoor climbers choose to add a spare belay device, pulley, slings and/or Mini Traxion.

5. If carrying a smartphone to take selfies, videos, or phone calls when on a route, remember to tuck the phone into the back of your harness when it is not in use. This is called “racking”. Pro tip: marking your phone with coloured tape will help make sure you get it back if you need to share your “rack” with other people.

The following apply mainly to bouldering:

6. For safety reasons, when bouldering,  it is important not to climb below another climber – as they may fall on you. However, climbing above another climber is considered perfectly safe.

7. Easy V0 or V1-grade bouldering problems are a perfect opportunity for your friends/family/colleagues/club to film you with a smartphone or video camera. Background sounds add interest to any video, so be sure to encourage them to cheer loudly as you jump down.

8. Stand out from the crowd while bouldering by wearing your harness. To really get noticed, consider wearing a chest harness and/or jumars.

9. Help other wall users to keep cool in hot weather by shaking excess sweat onto them from your arms, legs and/or hair as you climb. Bouldering topless makes this considerably easier, and you will quickly notice the gratitude of the people around you.

 

Disclaimer: Really, really, really don’t do any of the things above. Some of them are very unsafe and can get you killed or injured, or can kill or injure other wall users (or annoy them, which may also get you killed or injured). Just don’t do any of these things.