<https://lord.io/blog/2019/text-editing-hates-you-...
# of-graphics
i
https://lord.io/blog/2019/text-editing-hates-you-too/ Folks who are given to arguing that complexity is spiraling out of control, what say you to this?
❤️ 1
d
Because of Unicode, it's essentially impossible to implement a text editor as part of a single person dev project. Which is sad, because I'd like to build a radically different kind of text editor as part of a projectional editor for my programming language.
Just counting the number of characters in a Unicode string is extremely difficult, and also highly controversial. If you pick two random programming languages, they probably return different results for counting the characters in a Unicode string.
s
Sounds to me like structural editing is the way forward — even if you’re not editing a programming language, but just Unicode text. And we already have it for text input on mobile platforms, looking at the examples with Chinese characters and emojis. I’m using an iPhone right now, and as far as I know there’s no way for me to input a thumbs up emoji followed by a skin tone modifier separately using the built-in keyboard. If you relate that to structural editing like I just did, that would be a syntax error. The onscreen keyboard in iOS prevents me from inputting that incorrect state. Let’s not forget that the “easy” way of text editing from the past based on ASCII was based on Americans building something that didn’t even consider any other languages, alphabets, scripts, and cultures. That was all bolted on afterwards with code pages until we got to Unicode. Now we have a technology that sort of works for almost every person on the planet who can read and write (and Klingons!) — and that turned out to be a little more complex problem to solve. But I take that over any simple solution that only works by excluding a majority of people based on their language or culture.
d
Because Curv is a hobby research project (no corporate sponsorship, no paid staff), I restricted it to ASCII only. There was a poll of users about whether we should support non-ASCII characters in identitifiers and operators, and the vote was NO: people generally do not know how to type non-ASCII characterts on a keyboard, and this change would make it too difficult to read/modify/reuse other people's source code.
It's pretty common for an open source language to spend a year or two just implementing and debugging Unicode strings. Unicode text editing is a whole lot more complex than that. There are some interesting questions I want to explore in my project, and Unicode support would make that impossible. I just don't have the resources.
I hope you are not making a social justice argument against one person programming language research projects. Aside from being ASCII only, my project also renders a user interface onto a display using fairly simple minded GPU shader code. There is no testing for accessibility for colour blind people, and there are no hooks for screen readers for the blind (I would have no idea where to even start). But it's a research project, and if I manage to demonstrate a new idea worth copying, then well funded projects with hundreds of developers could incorporate that idea into a system that is fully accessible. So I don't think I need to feel guilty about my non-accessible research project.
👍 1
s
Nah, I don’t have any problem with researchers or hobbyists cutting corners to focus on what's important to learn something or test a hypothesis. I was more coming from a perspective where you intend to build a product that you hope will have some significant success. We finally start talking about bias in tech and I think that's important for tech in general, and also for the future of coding. I guess the larger point here is that you shouldn’t be in a position where Unicode support, accessibility, etc. are creating such huge efforts for you. It should just be a foundation you can build on, regardless of what underlying language, environment, and platform you build on. These are areas where we need good solutions so that people like you have a chance to work on important new ideas and still build on an infrastructure that doesn’t exclude people. That we don’t live in a world like this yet, isn’t your fault and not your responsibility. But it would be great if we had more people taking on these responsibilities. And in the discussion of exploding complexity it's easy to categorize Unicode as a bloated mess designed by committee. And maybe it is and could be done much better. It's just dangerous to compare it with a simpler past, ignoring the non-technical aspects of the design shortcomings of those simple solutions and fall exactly into the trap that makes many people outside our industry look at us as privileged white nerd boys that dream of changing a world that happens to exclude most of them.
🍰 1
Or put much simpler: yes, complexity is spiraling out of control. I’m not sure how good an example Unicode is to illustrate that problem. I should also point out that the linked article primarily makes a point about the complex interactions of text editing and Unicode just happens to play a part in this. It would be much easier for me to argue about exploding complexity if we were talking about if you really need a VIPER architecture for your to do list app on the App Store. ;-)
😆 1
i
@Stefan with respect to your last comment
I should also point out that the linked article primarily makes a point about the complex interactions of text editing and Unicode just happens to play a part in this.
I didn't mean for Unicode to be the focus of the discussion. Rather, I had in mind the complexities of text editing, and whether those complexities are the sort that can be reduced (and thus are part of the "spiralling") or not, and why, and how.
There's a lot of discussion about languages needing to reduce inessential complexity to a minimum. But even if we do that, we are still left with thorny problems in our strings (Unicode) and our numbers (NaN and loss of precision) and our UIs (text editing is so complex you're forced to leave it to your host platform? — that precludes a lot of ideas for creative ways to work with text, I fear). Would a certain type system make the text editing problem any more tractable? Would visual programming? What can we, as tool creators, do?
s
Yeah, I guess my comment on this was drowned out by my social justice rant. I can see why this works so well on Twitter. ;-)
Sounds to me like structural editing is the way forward — even if you’re not editing a programming language, but just Unicode text. And we already have it for text input on mobile platforms, looking at the examples with Chinese characters and emojis.
I’m using an iPhone right now, and as far as I know there’s no way for me to input a thumbs up emoji followed by a skin tone modifier separately using the built-in keyboard. If you relate that to structural editing like I just did, that would be a syntax error. The onscreen keyboard in iOS prevents me from inputting that incorrect state.
To add a bit more to this: the complexities of implementing this also could benefit from a more declarative approach. If you read the article, the author is basically describing the rules of how the interaction should behave in the text — that should be more or less directly translated into code, perhaps as rules constraining the movement of the caret/cursor and which keyboard interactions are possible.
d
To make things simple, I support ASCII only. I don't support NaN, because it ruins the semantics of equality (a==b is no longer an equivalence relation). In Curv, 0/0 raises an exception instead. I only support a single numeric type, which is a float. I'm willing to jettison "traditional" features & semantics that add a lot of complexity, if they don't directly support my research goals.
I want to explore creative ways to work with text, so I don't want to rely on the host platform's editing code. So yes, I'd like to learn how to make text editing, projectional editing, structure editing, and visual language editing, more tractable, so that it's feasible to code my own editing framework.
i
I thought you couldn't do equality with float values, even ignoring NaN.
0.3 - 0.2 != 0.1
(Just realized I started this thread in #CE1R695T7 instead of #C5T9GPWFL — that's what I get for doing it in the dark at 1am)
d
Many algorithms, and more importantly, many end users, implicitly assume that equality is an equivalence relation: (1) a==a, (2) a==b implies b==a, (3) a==b and b==c implies a==c. End users can assume this without knowing what an equivalence relation is. Without NaN, IEEE floating point equality is an equivalence relation, even if a lot of other semantics are screwed up.
"Would a certain type system make the text editing problem any more tractable?" Maybe this is a reference to Hazel? Hazel.org says "Uniquely, every incomplete program that you can construct using Hazel's language of type-aware edit actions is both statically and dynamically well-defined, i.e. it has a (possibly incomplete) type, and you can run it to produce a (possibly incomplete) result. Consequently, Hazel serves as an elegant platform for research on the future of programming."
"Would visual programming make the text editing problem any more tractable?" Did you have an idea about this? If so, please elaborate.
w
I wrote custom text input/editing/rendering for http://strlen.com/treesheets/ and custom font rendering for http://strlen.com/lobster/ and I am pretty sure I am violating a ton of rules in these 2 articles 😞
But yeah, that "Text Services Framework Interfaces" is wild, I am pretty sure simpler designs are possible.
d
I'm less interested in general text editing than I am in structured program editing. One of my lines of thought: Users should not be responsible for laying out a program by manually inserting tabs, spaces and newlines. The editor should perform automatic syntax-directed layout. The layout should be automatically recomputed when the width of the output window changes. So it is the system that chooses where line breaks occur, not the user. The position of line breaks changes when you resize the window. How do you design a syntax for a programming language that is compatible with automatic layout?
w
That said, Unicode has gotten to a point that no-one should attempt to handle that by themselves anymore 😞
Sadly, "just use the unicode related services in the OS" is often not sufficient, first there are 6? OS-es to cater for, and second, they don't all integrate well with custom rendering needed in newer representations / editors / games
d
Another line of thought: a projectional code editor that displays your code either using a text based syntax, or using a visual/graphical syntax. You can just flip back and forth, editing the program first using the text representation, then the graphical representation, and the automatic layout algorithm makes either form look good. The text based syntax is useful for copy and paste of text to/from the internet, and for people who like typing text and don't mind memorizing syntax. The graphical syntax has the benefits that are associated with visual programming languages, eg node+wire languages. The question is, how do you design an abstract syntax for a programming language that maps onto either of these presentations, and how does the automatic layout work in the two cases?
s
I think part of the problem is thinking that there are two distinct representations, one for text, one visual/graphical. There are only graphical representations! If you have an old command line terminal in text mode you just happen to have a relatively simple graphical representation that fits same-size glyphs into a fixed grid. So we can abstract that away and think in rows and columns instead of pixels. And that's where we accidentally forget about the translation from logical character position to pixel position because it's completely transparent (and it was even done in hardware back then). Then you start using proportionally spaced fonts or introduce emojis or start playing with different typefaces and suddenly your glyphs have different sizes and don’t line up that neatly anymore and it gets more complicated. Still just a layout algorithm taking little rectangles and arranging them within larger rectangles. Once you can see the nested rectangles, you can arbitrarily play with what gets nested into what and how multiple rectangles on the same level are laid out. And then you're pretty much at the level of arbitrary 2D view hierarchies — what most user interfaces are made out of these days. iOS offers a UI element called collection view, which comes with a flow layout. People use it mostly to arrange photos or graphical elements in rows or columns, filling them up, and then breaking into the next row/column. That is almost the same algorithm that calculates glyph positions in a paragraph of text and could be generalized to use the same algorithm. For historical reasons though (and because the requirements for text rendering Apple has were always ridiculous) it's not today.
👍 1
2
d
@Stefan That seems like a good starting point.
"A foundation you can build on, regardless of what underlying language, environment, and platform you build on. These are areas where we need good solutions so that people like you have a chance to work on important new ideas." Okay, here's my wish list. The foundation is a platform independent API/language that supports native executables on Windows, Mac, Linux, Android. It supports web apps, via WASM. It supports GPU rendering and GPU compute and a modern performant GPU API, which runs on all of the above platforms, so this has to be WebGPU. I'd like the UI framework to render its graphics using a 2D/3D graphics API with the same expressive power as Curv, where all graphical objects have a signed distance field that you can manipulate. So actually I think the entire UI will be rendered on the GPU and I have to build the complete framework from scratch. (And now we have a tie-in to #CE1R695T7.)
😎 1
w
Text is pretty intrinsically hard. All the same, with most system complexity I've run across, you usually have a much simpler system available if you give up a few features. For example back in the day, I remember having an XML parser for about 10% of the grammar which handled all the XML that we cared to throw at it.
s
I'd like to build a radically different kind of text editor as part of a projectional editor for my programming language.
@Doug Moen can you describe what you're looking for in more detail? Have you written this up somewhere? One way would be to customize one of the existing text editors.
On the original topic: yes there is a fair bit of essential complexity in both designing and implementing text editing type stuff. Yet I feel a lot of incidental complexity pops up while implementing editors as well. Even when you've figured out all the corner cases and decided their behavior - how do you encode it? How do you detect the layout and reflow? How do you keep track of events and of different versions of your buffer? The standard APIs dictate a lot here and the usual programming tools limit what you can 'see'. For instance, we don't usually see the layout live as we edit code. Here's an example of what may be possible:
a
Very interesting topic. I agree with @Stefan about “there are only graphical representations”! I hit text editing complexity quite hard while implementing this user interface prototype for iOS: https://www.achrafkassioui.com/backspace-mirror/ Backspace Mirror attempts to reduce the stress of deleting text when holding backspace. Since the deletion eventually accelerates, I wanted to show at which point the pace of the cursor would change. The hardest part was to programmatically highlight the text before the cursor using web APIs. Traversing the DOM tree that represents styled text was incredibly complicated. I had to decouple the text (one layer) from the highlights (another layer) to get a working solution. Interestingly enough, Ken Kocienda writes about this exact same problem in his book Creative Selection: https://twitter.com/achrafkassioui/status/1192935988097699842?s=21 He calls caret insertion the hardest programming problem he ever faced.
😮 2