TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

The evolution of a structural code editor

242 pointsby crowdhailer5 months ago

27 comments

narag5 months ago
This is the way. Programs are not text, there&#x27;s an impedance mismatch that shows at the seams.<p>There&#x27;re good reasons it hasn&#x27;t been done more: text is good for troubleshooting, &quot;every program should do one thing well&quot; and maybe preventing lock-in.<p>But with programming tools reaching maturity, we&#x27;ll see more of this. Also there&#x27;s an AI-related aspect: bots can understand structure just fine.
评论 #42612497 未加载
评论 #42621960 未加载
评论 #42613132 未加载
评论 #42613145 未加载
评论 #42612960 未加载
评论 #42620072 未加载
评论 #42620263 未加载
danielvaughn5 months ago
I’m obsessed with structural editors because it feels intuitively like the right approach to creating software. However I’ve yet to come across an interface that really clicks. Still love it though. Right now I’m building a structured editor for creating UIs, so can attest to how difficult it is to get it right.<p>It’s a super interesting problem space.
评论 #42612027 未加载
评论 #42624978 未加载
评论 #42615059 未加载
评论 #42622608 未加载
cfiggers5 months ago
I enjoy Lisp and Lisp-alike languages specifically because with the right editor support you can do a lot of this kind of structural editing stuff without giving up the niceties of source code as text.
评论 #42622691 未加载
评论 #42612565 未加载
评论 #42620785 未加载
xigency5 months ago
This is a topic I&#x27;ve been contemplating heavily and it&#x27;s very instructive to see the iterative progress you&#x27;ve made here.<p>I think development tools like this are necessary to expand coding outside of just the desktop experience. For example, I&#x27;ve seen kids program some pretty impressive robotics with just a touchscreen and Blockly.<p>Also, from a compilers perspective, it feels almost absurd to rely on plaintext. Imagine how much harder code merging is using line diff compared to diffing syntax trees.<p>Thanks for sharing!
评论 #42612717 未加载
评论 #42612013 未加载
评论 #42619985 未加载
unshavedyak5 months ago
Awesome! Glad to see more exploration in this space. I too am exploring this, though i am perhaps making it yet even more complicated. I want to represent relationships between AST nodes in a visual way. Eg, i love Node editors in Blender and if it was given a good keyboard based UX i could imagine editing structural code in it.<p>I still imagine the code would be visually text, but i&#x27;m imagining that you&#x27;d be able to see a series of nodes in a code flow graph for your current editing context.<p>I figure AST editing (to some degree) is a generally good thing, but also representing code flow somehow is also a desired thing. It&#x27;s what i do in my head, so can it be visualized in a beneficial way?<p>Difficult to say. Keyboard first will also be a challenge as i&#x27;ll need to have a lot of intelligent alignment and visual compression.<p>Thanks for the post! Love to see work in this space.
评论 #42612174 未加载
评论 #42611392 未加载
评论 #42611458 未加载
like_any_other5 months ago
For structural code editors to thrive, what is needed is a universal, simple, minimal, txt-like format for the AST, so that AST-editors are not locked to a single programming language each.
评论 #42613649 未加载
评论 #42613656 未加载
penteract5 months ago
Having made my own forays into making a structural editor, I&#x27;d like to sing the praises of plain text: storing something that has been created by pressing buttons at a keyboard as something very close to the sequence of buttons that have been pressed is a great idea.<p>The magical ability of plain text is to go back in time and ask &quot;what if I pressed a different button a minute ago&#x2F;yesterday&#x2F;last year?&quot;. This lets you see and fix mistaken keypresses, and even shapes the kind of mistakes you can make in a moment of confusion into ones that are quickly fixable.<p>The direct representation of buttons pressed also really helps with teaching&#x2F;learning: With plain text, for mechanical questions on the level of &quot;What buttons do I press to make a program that looks like that?&quot;, the answer is obvious for anyone who knows how to type. Try the editor discussed in the article to appreciate how different answering that question can be in a structural editor. Seeing and explaining how someone got where they did is also straightforward (&quot;you missed a semicolon&quot;, &quot;you misspelt a variable name&quot;). Ideally, those are problems that don&#x27;t happen in a structural editor, but people who press a slightly wrong sequence of buttons will probably still exist.<p>These arguments get much weaker when you aren&#x27;t using a physical keyboard; I think this is the reason the article starts by talking about writing programs on a phone and a TV. In those environments structural editing has much more to offer.
评论 #42621453 未加载
naikrovek5 months ago
I have wanted something like this for so long that I can’t remember when I started.<p>Strongly coupling source code to plain text is a lost opportunity to improve tooling.
评论 #42611179 未加载
评论 #42611106 未加载
评论 #42610995 未加载
评论 #42617271 未加载
andrewl5 months ago
I’m always glad to see new work on tools, and amplifications to our capabilities of any sort.<p>I played with Smalltalk, and later Pharo, a bit, but it was years ago. As I recall the editor was always aware of the state of the system. And I <i>think</i> it was at a level beyond what any current IDE can do. While I do not remember if it allowed you to enter invalid code, it was definitely an interesting approach.<p>So I will be following Eyg for sure.
评论 #42613707 未加载
EdiX5 months ago
I used a structural text editor a while back (technically a structural text editing mode for emacs). I went in completely buying the structural text editing propaganda (it&#x27;s more logical, it will make you more efficient, it&#x27;s the future...) but I eventually found the experience so excruciatingly bad and stupid that I now think the whole endeavour is a complete waste of time, the idea sounds good on paper but there are some fundamental unsolvable problems with it.<p>The problem is that, when you want to make a change to piece of source code you know its current state and you know how you want it to look like at the end. With a normal text editor you will simply make a bunch of changes that turn the text as it into what it should be, it will normally go through a series of invalid states but you don&#x27;t have to think about what those states will be or care about them. With a structural text editor this is impossible, invalid states <i>can not be represented</i> so when you want to make a change to your source code you don&#x27;t just care about the beginning and end state, you also want to find a series of valid states that takes you from the beginning to the end where each one can be reached from the previous one with an editor command.<p>For example, let&#x27;s say you have a function call:<p><pre><code> (afunc 1 2 3) </code></pre> and you want to turn it into a conditional function call based on a flag:<p><pre><code> (if flag (afunc 1 2 3)) </code></pre> with a normal text editor you:<p><pre><code> 1. type &quot;(if flag &quot; before the call 2. type &quot;)&quot; after the call </code></pre> It doesn&#x27;t matter the order in which I do these operations or how I move the cursor.<p>With a structural text editor, I have to:<p><pre><code> 1. create a new form before the function 2. type &quot;if flag&quot; 3. select the entire function call 4. cut it 5. paste it as the first branch of the if </code></pre> This is however only possible if the context where the function call currently is allows adding a new node before it (i.e. it&#x27;s inside the equivalent of a lisp progn). If not I&#x27;d have to use a different strategy, for example:<p><pre><code> 1. select the entire function call 2. use a command to create a node around it 3. type &quot;if flag&quot; </code></pre> I did this for a few months, eventually I realized that I didn&#x27;t want to think about the syntactical validity of the intermediate states my program goes through while I&#x27;m editing it, because they exist for mere seconds, and I didn&#x27;t want to memorize the large palette of commands necessary to create those intermediate states. It was all additional cognitive load that accomplished nothing but satisfy someone&#x27;s esthetic sense that source code should always be in a syntactically valid state.<p>So of the benefits listed in the article:<p>1. &quot;No syntax errors&quot; is actually a major detriment of the structural editing model<p>2. &quot;Better type information&quot; is a lie, all that the structural text editor guarantees you is that the program is syntactically valid, not that it will pass type checking<p>3. &quot;No keywords&quot; is a lie, it&#x27;s only true if you use a new programming language and don&#x27;t store it on disk as text which opens a whole other can of worms (can&#x27;t even read source code without a special text editor, won&#x27;t work with github, won&#x27;t work with any versioning system, won&#x27;t work with grep, can&#x27;t copy paste a chunk of it in an email...)<p>4. &quot;Rich visualization&quot; is an entirely different story from structural text editing but as far as I know nobody has ever shown visual programming to actually provide any kind of tangible benefit<p>5. &quot;Reduced complexity&quot; is the one I give them, yes if you are making a structured text editor you don&#x27;t have to write a fault tolerant parser, it does make <i>your</i> (aka the text editor&#x27;s implementor) life easier<p>Fans of structural text editors usually mention that they will unlock &quot;more powerful refactoring tools&quot; but actually all you need for those to be &quot;unlocked&quot; is a dumb parser and an automatic code formatter, like &quot;go fmt&quot;. Refactoring a function to be inlined into another is still a difficult operation to implement correctly but it isn&#x27;t like the difficult part is running a parser on the source code, it&#x27;s dealing with variable shadowing.
评论 #42614407 未加载
评论 #42621928 未加载
评论 #42613201 未加载
评论 #42620307 未加载
marhee5 months ago
A mature (and very effective) structural editor is the FLUID user-interface designer, part of the FLTK UI framework (C++). It outputs C++ and works very well.<p>I remember dismissing it as a toy back when starting to work professionally with FLTK. Soon I realised I was mistaken; it is excellent to create UI&#x27;s with for C++&#x2F;FLKT.
perlcommunity5 months ago
<a href="https:&#x2F;&#x2F;www.jgrasp.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.jgrasp.org&#x2F;</a>
dominicrose5 months ago
For some reason this reminds me of semantic highlighting. A constant is not just an identifier - like a variable - it&#x27;s a constant. There&#x27;s more semantic in the text than the usual syntax highlighters highlight.<p>Some code formatters are good and exist for json or edn (extensible data notation) or even full programming languages like smalltalk or even more complex ones like typescript.<p>In a team it&#x27;s true that code can be chaotic because not everybody uses a formatter and obviously we all have different coding style, even if the tooling made it more structured.<p>So yes it would help to enforce more structure in a seamless way so we can focus on the important stuff without creating huge diffs in pull requests.
norir5 months ago
I think structural editors are a great feature to add on top of a language with a definite textual representation. If you can pretty print the ast (as the fib example shows), you should generally be able to parse the output to generate the structured output.
herrington_d5 months ago
&gt; Better type information. Because the program is always in a valid state the type checker can always run and give meaningful feedback.<p>Note that programs can be syntactically well-formed but ill-typed. For example `let x = true + 1` has valid syntax but produces an &quot;undefined&quot; type for the variable `x`, if the type system does not support type error recovery.<p>A quote from the great paper from POPL 2024, <a href="https:&#x2F;&#x2F;hazel.org&#x2F;papers&#x2F;marking-popl24.pdf" rel="nofollow">https:&#x2F;&#x2F;hazel.org&#x2F;papers&#x2F;marking-popl24.pdf</a><p>&gt; If a type error appears _anywhere_, the program is formally meaningless _everywhere_
评论 #42613611 未加载
daveloyall5 months ago
Since this is a post about a programming tool, I expected links to repositories. I like to pick up a tool and turn it around in my hands before I decide if it is a good tool or not.
tcoff915 months ago
Haven&#x27;t lisp coders been doing this forever with emacs?
评论 #42617603 未加载
codery5 months ago
<a href="https:&#x2F;&#x2F;github.com&#x2F;disconcision&#x2F;fructure">https:&#x2F;&#x2F;github.com&#x2F;disconcision&#x2F;fructure</a><p><a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=CnbVCNIh1NA" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=CnbVCNIh1NA</a>
criddell5 months ago
Is it far enough along where you could work on the code editor <i>in</i> the code editor?
评论 #42611451 未加载
评论 #42611907 未加载
otikik5 months ago
I think this is the way, but tying it to a new language will not help making this initiative popuplar at all. It would need to be tied to a more popular existing language such as Python or Javascript.
datadrivenangel5 months ago
In the data science space, people have been going back and forth on the benefits of Notebooks, which seem very similar, and were historically stored as json under the hood.<p>There are many many benefits to plain text.
评论 #42611012 未加载
eternityforest5 months ago
I was able to use this without reading the manual, so I suppose it passes my favorite test of UI!<p>But I do wish it was more clear what you have selected, and what things are selectable.
cbm-vic-205 months ago
This is neat.<p>I wonder if this could be generalized to other languages with Tree-Sitter and LSPs. It could be helpful for programmers with accessibilty issues, among many other use cases.
评论 #42612130 未加载
hokkos5 months ago
I remember coding on my casio scientific calculator, you could only input full keyword by selecting from a menu, it was quick and you couldn&#x27;t make syntax errors.
评论 #42611445 未加载
评论 #42611619 未加载
mebazaa5 months ago
My first thought: maybe competitive programmers could find it useful, if it’s a way to reduce the amount of key presses needed to write their code? (At the very least, that’s a crowd that would be motivated enough to get accustomed to that way of writing code.)
评论 #42611464 未加载
评论 #42611114 未加载
rzwitserloot5 months ago
I&#x27;ve been toying with the idea of making something very very much lik this, but, for an existing language. Which makes it far, far more complicated; I&#x27;m sure various aspects of the design of whatever language one would build this for are needlessly convoluted due to not having been designed with this kind of editing in mind.<p>A few concerns:<p>* As developers, our &#x27;world&#x27; is so defined by text, we textify things that aren&#x27;t: We write marked up documentation in plain text (HTML, markdown, etc) and we despise using tools like LibreOffice to write that sort of thing, and we even &#x27;draw&#x27; helpful graphs in `.dot` files. We do this for a good reason: It &#x27;works&#x27; with our other tools. git itself, and the cavalcade of git-understanding frontend version control systems, are excellent at showing you diffs between textual representations. They don&#x27;t do &#x27;diffs between these 2 png files&#x27; or &#x27;diffs between these two .docx files&#x27; well or at all.<p>Hence, these projects either balloon, or need a pragmatic take. Either you staple &#x27;also reinvent git&#x27; onto the project (and in passing you are increasing the hurdle to adopt or try out this stuff for any interested folk), or you think about how to adapt the idea to fit existing practices.<p>In this specific case the latter seems like the obvious answer: The way to store the program is as a file that, if opened in a text editor, looks just like it. But, I _can_ edit files in git and it looks like a text file even if it really isn&#x27;t; so what happens if I edit an eyg file with a text editor? How &#x27;perfect&#x27; must it be? What happens if in hand-editing the file I added some whitespace that shouldn&#x27;t have been there as per the canonical storage rule?<p>These are all easily solvable details, of course. But it&#x27;s where my brain went. I&#x27;m pretty sure the correct answer is &#x27;the source file is still text and is still readable; it&#x27;s just that the language has some extreme style requirements (think about a language that has no line continuation facilities whatsoever, long lines will just have to be long lines, and dictates exactly how many tabs you can insert; indenting with spaces is not allowed at all, that sort of thing). This is fine because the language is meant to be read as plain text but only edited with the structural editor.<p>* I often try to think how it would be if I was doing my programming work with a structural editor. From time to time I do things that seem blatantly annoying if I only had a structural editor. Where I really _want_ to dip into syntactically utterly invalid gobbledygook because I&#x27;m doing some text edits which will get back to valid code but I go through invalid code. For example, block-based copy&#x2F;pasting (block = multiselect&#x2F;multicursor). I&#x27;m having a hard time seeing how that would work in a structural editor but I use it from time to time. It feels like a structural editor can hopefully come up with alternatives for all the use cases but I&#x27;m not sure. Should there instead be a &#x27;fallback&#x27; option where your source file turns into raw text mode and your edit functionality is like any plain jane text editor, you do your text-based transformations and then when done exit that mode, at which point the structural editor reparses what you have. I think that&#x27;s right but it means the language does, actually, need all the bells and whistles after all: A Parser, an AST, good error handling for syntax errors, and so forth.
评论 #42614772 未加载
crabbone5 months ago
&gt; Unlike traditional text-based editors, these tools treat code as a structured tree rather than a flat sequence of characters.<p>This is such an obvious lie... Of course, even the disastrously bad editors like VSCode or IntelliJ tools understand code to have structure and allow interaction with that structure. Hell, even text editors not intended to deal with code will usually be able to deal with some structure, like identifying words, lines, perhaps even paragraphs and operating on them.<p>&gt; No syntax errors. Zero time is spent on missing quotes, semi-colons or other details.<p>Usually paid for by inability to copy and paste chunks of code... not sure if it&#x27;s worth the price.<p>&gt; Better type information. Because the program is always in a valid state the type checker can always run and give meaningful feedback.<p>Why would you want to run typechecker <i>all the time?</i> What&#x27;s the benefit? I run it when I&#x27;m interested in the results... otherwise it&#x27;s just noise. By the time I&#x27;m interested in results, I&#x27;d get code in a decent enough shape to compile, so it won&#x27;t be a problem.<p>Other known downsides of this approach: having to access the code in places where the editor isn&#x27;t available, s.a. reading diffs, debugging, running third-party tools unaware of structured format (which, given how our programming practices have developed, will be inconsistent between versions and platforms).<p>All in all, I&#x27;ve seen these attempts multiple times before, and it always looks like the benefits simply aren&#x27;t worth the effort. Or, maybe, too many stars need to align in order for this to actually become really useful in the day-to-day programming work, and so it doesn&#x27;t happen because of some circular dependency where the tools won&#x27;t be built, until the product is good enough to use, but the product is never good enough to use because there aren&#x27;t any tools?
评论 #42616191 未加载