OK?

Try it out on the playground

OK?’s mascot: Quentyn Questionmark.

Programming Is Simple Again

OK? is a modern, dynamically typed programming language with a vision for the future. OK?‘s mission is to do away with the needless complexity of today’s programming languages and let you focus on what matters: writing code that makes a difference.

Contents

Conditionals

Very early on in its design, it was decided that OK? would not feature a ternary operator. For those unaware, the ternary operator looks like this:

let a = isprod ? 'prod' : 'dev';

Disgusting, we agree. Einstein, Tesla, and Newton all died long ago, so there’s really only a handful of humans left on Earth who are capable of parsing that stupifying syntax. What does the question mark mean? What does the colon mean? In OK? we leave those questions for the philosophers and focus on what’s important: writing clean code.

A language only needs one conditional control flow construct, and in OK?, that construct is the switch statement. Switch statements are more versatile and expressive than ternary operators and if statements, and after a while you’ll forget those other constructs ever existed. Here’s the above statement in idiomatic OK?:

let a = switch isprod {
  case true: "prod";
  case false: "dev";
}

The switch form, although longer, is unquestionably clearer. Understanding the value of simplicity over complexity is the first step to learning OK?

Readable Switches

Given that switches are so central to OK?, we wanted to avoid some common pitfalls around switches found in other languages. In other languages it’s common to have a single switch statement take up several pages of an editor with bloated logic being shoved into each switch case, so in OK? we made it that you can only have one statement per case:

If you want to execute multiple statements per switch case, just wrap them in a function:

<div class="highlight highlight-source-go position-relative" data-snippet-clipboard-copy-content="// INVALID:
switch x {
case true:
z = z + 2
case false:
x + x = 1;
y = y – 1; //

// INVALID:
switch x {
  case true:
    z = z + 2
  case false:
    x + x = 1;
    y = y - 1; // <-- ERROR: switch blocks can only contain a single statement
}

// VALID:
let onfalse = fn() {
  x + x = 1;
  y = y - 1;
};

switch x {
  case true: z = z + 2;
  case false: onfalse();
}