Skip to content

Instantly share code, notes, and snippets.

@redbar0n
Last active December 18, 2020 13:59
Show Gist options
  • Save redbar0n/c8df586b912b30a2ef86c530d0e67d47 to your computer and use it in GitHub Desktop.
Save redbar0n/c8df586b912b30a2ef86c530d0e67d47 to your computer and use it in GitHub Desktop.
Is there any IDE that allows you to augment your code with the form of your data in real time?

Here's a crazy idea. Take the following simple example (in javascript):

    var m = [[1], [2], [3]];
    // ... a lot of code in between, perhaps m was passed through
    // several functions without TypeScript type declarations, so you might mistakenly
    // think m is a simple array like [1, 2, 3] at this point...
    var m2 = [];
    m.forEach(x => {
      m2.push(x);           //# [[number], [number], ...] will be the form of m2 here
    });
    
    console.log(m2);

You might think that m2 will have the form [number, number, ...] after the forEach loop. But it won't, as the special //# comment above would have made you aware of. The above is a trivial example, but it is made to illustrate a larger point.

A cause of many bugs is that you don't actually see the data while coding. So you might think you're doing something, while you're in fact doing something else. Ideally, you'd like to see the data at every step in your code, in real time, while coding (something like Bret Victor has imagined: http://worrydream.com/LearnableProgramming/). However, the problem is that any such showing of the actual data, amounts to a full execution of the code. But maybe we don't need to see the actual data, but merely the form of it? Could that solve a part of the problem?

What if your IDE could provide you with hints of the form of your data, by showing what's exemplified in the comment in the above example, when you are writing code (not when debugging*)? It should be possible in theory, by static code analysis, without having to execute the entire code to do it (I think). If the type info isn't possible to infer - maybe because of receiving data from external API calls - then it could show this instead: //# [[something, [something] ...] will be the form of m2 here Which would also be valuable to see while coding, since it still reveals the form of the data construct you are operating on.

'* - I know you can always run debugging, but that's not what I'm talking about. This is about having the IDE augment the code automatically. Not necessarily by injecting comments like the //# above, although that would be one rudimentary way. Another way would be to float the information above the code.

@redbar0n
Copy link
Author

YES! It exists!! https://quokkajs.com

@redbar0n
Copy link
Author

O M G. This is from the same guys, but will show test results inline! https://wallabyjs.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment