DEV Community

Cover image for Imaginary Language Features
Andrew (he/him)
Andrew (he/him)

Posted on

Imaginary Language Features

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) {

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

  case 1: // ...

  template case 2: // ...

  template case 3: // ...

  case 4: // ...

  default: // ...

}
Enter fullscreen mode Exit fullscreen mode

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?

Top comments (9)

Collapse
 
sm0ke profile image
Sm0ke

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:

@C++

int x = 1; 

@React

// javascript magic here

@Python

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

Cheers!

Collapse
 
awwsmm profile image
Andrew (he/him)

Have you heard of GraalVM?

Collapse
 
sm0ke profile image
Sm0ke

nope, thanks.
I will take a look

Collapse
 
vorahsa profile image
Jaakko Kangasharju

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.

Collapse
 
awwsmm profile image
Andrew (he/him)

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

Collapse
 
curtisfenner profile image
Curtis Fenner

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.

Collapse
 
awwsmm profile image
Andrew (he/him)

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

Collapse
 
curtisfenner profile image
Curtis Fenner

I found a good introductory article coincidentally published yesterday!
overreacted.io/algebraic-effects-f...

Collapse
 
vlasales profile image
Vlastimil Pospichal

Use decorator.