Cover image for Imaginary Language Features

Imaginary Language Features

awwsmm profile image Andrew (he/him) ・1 min read

This really interesting proposal for an any case in a switch statement (with subtle differences from default) by Meghan...

...got me thinking: what imaginary language features would be cool to program with? In response to Meghan's proposal I thought of a template case:

What about a template case?

switch (number) {

      before: // do something before
       after: // do something after

  case 1: // ...

  template case 2: // ...

  template case 3: // ...

  case 4: // ...

  default: // ...


template could be applied to only a particular subset of cases, and the template definition could be extended to do exception handling, etc.

What are some neat ideas you've had for language features?


markdown guide

Still dreaming to this:

  1. Export the same piece of code in any language automatically

  2. Multiple languages mixtures. Imagine a big program with the core part written in C++ (for speed), the GUI in React and the AI/ML in Python. The imaginary source code:


int x = 1; 


// javascript magic here


if something:
   print('Python here .. <('_')>  ')



I find myself every now and then missing the loop-and-a-half construct where you need to do some preparation before testing the loop condition and this preparation needs to be repeated on every iteration. The syntax could be something like this:

do {
  // Stuff
} while (condition) {
  // More stuff

which already resembles the two existing loop syntaxes, while and do-while. So this would execute Stuff always first, and while the condition is true, it would execute More stuff, Stuff, and then test the condition again.

The way to accomplish this now is with an infinite while loop with a conditional break in the middle. I find this somewhat inelegant, and also harder to see that there is a condition that causes the loop to terminate.


Can you give an example of when this would be useful?


There's a couple features that have been described in academia but not caught on in any mainstream languages that I think will be important in the company decades.

The main one is functional effects/algebraic effect handlers. They let you capture, inspect, and undo any kind of IO or state mutation that a piece of code does. This makes auditing the security of code easier, it makes testing easier and faster (you can control all non determinism, even being able to check things like "no possible ordering breaks this invariant"; you can also control all scheduling and waiting so no need to have long running tests just for the sake of IO). It also can make the overall reasoning about code more explicit, making it easier to understand and later refactor/replace.


Could you give an example of this in pseudocode? I'm not sure I understand.


I found a good introductory article coincidentally published yesterday!