Spatial languages: Writing code in 2D

(shukla.io)

40 points | by BinRoo 3 days ago

6 comments

  • pja 1 minute ago
    Was this post prompted by this year’s ICFP competition?

    https://icfpcontest2026.com/

  • dahart 5 minutes ago
    This is cute, and it’s fine and fun to play around, but I don’t know, takes itself way too seriously or something. I apologize for being negative, but blowing my mind? No, not exactly. The attempt at the end to justify isn’t compelling to me and feels pretentious or something; the so-called Sapir-Whorf hypothesis (a misnomer according to the link) is about words and concepts, not about layout. This article fails to consider how to say or to read 2D code, or even think about why text is normally 1D. Language is expressed in one dimension because of time. We don’t speak in 2D, therefore we don’t write in 2D. We do visualize parse trees as trees (2D pictures) all the time, which isn’t mentioned. Also not mentioned are all the massive downsides of trying to write & edit & maintain 2D code, as well as the fact that we have good ways to write 3+ argument functions in 1D.

    Nitpick - the andFlip function is wasting a whole dimension with unnecessary lines, and also modifying its input argument unnecessarily (yuck!), and it takes 3 arguments as an array for no good reason.

    Better: andFlip = lambda a,b,c : not c if (a and b) else c

    Except this is really just a normal 2 argument ternary, it does nothing interesting with a or b individually, it treats them as a unit, so I’d argue this shouldn’t even be a function.

  • jerf 58 minutes ago
    "All this time we’ve been writing expressions in 1D space, but what happens when we unlock an extra dimension?"

    Text is a serialization of an n-dimensional work space. "N-dimensional" doesn't have a formal definition I'm aware of but the major characteristic of it is that a new dimension can pop up anywhere. If you feel like you want to double-click on that, you can see my earlier comment here: https://news.ycombinator.com/item?id=35096647

    A conventional textual language can represent everything mentioned there, whereas 2D layouts struggle almost immediately to represent things that textual layouts represent quite easily.

    It can still be a useful "see the world differently" exercise, but it's the opposite of "freeing your mind"... it's stepping into a fairly small subset of functionality, albeit an unconventional one, and seeing what you can still manage to do even so. Rather than "unlocking a new dimension" it's actually throwing away n-2 of them. The experience of using this for any period of time would reveal this, as it would be a constant struggle to represent even very simple algorithms in this format.

    I post this mostly because of the "familiarity breeds contempt" effect that programmers seem to get hit with for text. There is a reason we use text and it's not lack of imagination or being stuck in our ways... it is actually an incredibly rich and powerful format that poses a serious challenge for any alternative to overcome because of the astonishing combination of compactness combined with representational power.

    • vitally3643 12 minutes ago
      A certain subset of programmers apparently just really, really hate this whole messy concept of "thinking about things".

      Text works and is hard because it's a projection of a mental representation. The whole reason we can work with N-dimensional structures in text is because the dimensionality lives in the programmer's head. There isn't really any other way to represent say a >3 dimensional array other than laboriously flattening it into text and expecting the next guy to rotate the hypercube in his mind. That's neither a good nor bad thing, it's purely a fact of our 3+1 dimensional universe.

      A shocking number of problems can be best represented in higher dimensions and there's simply no way to encode that information losslessly. Being simple 3D creatures (I'd argue 2D in fact) the only way to do that is by projecting it down into a lower-dimensional space.

  • cavoirom 2 days ago
    in the same spirit, checkout Orca: https://100r.co/site/orca.html

    It is used to compose songs. You can see the demo in the linked page.

    • atoav 36 minutes ago
      It is mentioned at the bottom of the page, but yeah Orca ia pretty good.
  • BinRoo 3 days ago
    I ventured out to better read Qiskit code, and came back with this fun idea of 2D expressions
  • shevy-java 1 hour ago
    Soon we have an IDE that works in 3D. So, not only do you have to look left-right, then top-bottom, but also before, and behind. That's scaling code! You write in 3D now.

    Or, you stick to oldschool old people. Keep things simple.

    • ivanjermakov 42 minutes ago
      I think humans are pretty good at thinking/operating in a 3D space. It's just that digital interface and programming tooling is not there. Obviously because usually there is no direct translation from domain model to physical 3D shapes. But it can well for those that translate: 3D modelling, spatial reasoning, motion tracking, mechanics, etc.
      • xpct 30 minutes ago
        I imagine this varies by person, but thinking about a source file is already reminiscent of 2D space navigation, where the X axis is typically gated by conditions. In a similar vein, when I think about functions from different source files, I do hold some type of "depth", or "stacked panels" in my brain.

        I think this is because I reason about programs being in some state ~= being positioned at a certain function with some context I carry around. I'm sure it's not the only way to think about it, but it's a reasonable abstraction over what computers do. It's how we oriented our debuggers and early IDEs on as well, and carried this over to modern tools.

        Definitely something I'll be thinking about during the next few days.