4 ms·
Very interesting work! It seems that educational text editors are becoming a trend after Antirez published his :-) Excuse me the shameless plug, I'd like to s
by arximboldi 9y ago
Very interesting work! It seems that educational text editors are becoming a trend after Antirez published his :-)
Excuse me the shameless plug, I'd like to show mine too: https://github.com/arximboldi/ewig https://github.com/arximboldi/ewig
It is written in C++, but using a style that is unlike what most C++ developers use: it is composed mostly of pure functions. The architecture is very much like that of Elm programs, and there is even a `store` class like in Redux.
Like the project from OP, it is about 2K lines of code. But it also supports asynchronous loading/saving, copy-paste (you can copy-paste a 1GB file instantly), very robust undo, dirty markers, UTF-8 (not perfect), etc.
The magic? Immutable vectors based on RRB-Trees. This is like the vectors in Clojure/Scala, but also supports log(n) slicing, concatenations, insertions---these operations are fundamental for a text editor, and I'd say, to most interactive software supporting big data models [1].
The code has been written in a style as simple as I could. I'd like to think that even non-C++ developers might be able to understand it. It might be specially interesting for web developers invested in Clojure, Elm or Redux and the single-atom architecture.
Probably one day I should go ahead and just write a blog post about it or a tutorial or something. But so far I don't have a blog I am not really a social media person. The code is still moving also...
PS. And thanks a lot to @kostspielig her help writing and reviewieng the code! <3
[1] The data-structure can be found here: https://github.com/arximboldi/immer https://github.com/arximboldi/immer
- jnbiche 9y agoAwesome project, you're inspiring me to pick back up a text editor project I had started to learn Rust a while back. Yours is much more featureful, however! By the way, if anyone else is thinking about doing the same, HN had a great discussion on an article (also very useful) on the various data structures one can use for text editors: https://news.ycombinator.com/item?id=11244103 https://news.ycombinator.com/item?id=11244103
- arximboldi 9y agoThanks for the link and the encouragement! You have your Rust project somewhere online? I'd love to take a look at it. I sometimes fantasize about rewriting Ewig in Rust, as a learning project (have been reading about it but didn't dare to write code in it yet). But I'd like to use RRB-Vector there too. Sadly, this data-structure is not really trivial to implement... (the concat algorithm in particular). Maybe one day I'll find the time :-)
- jnbiche 9y agoIt's not on a public repo, and I abandoned it half-done a couple of years ago while using Rust Nightly, so it will need some work I think to run on current Rust. I stopped because I got frustrated and confused with Rust's lifetimes, and just quit Rust for over a year. Fortunately, a few months ago, after another attempt at Rust writing a simple ML-like language, something clicked and now I'm enjoying writing Rust. If you do attempt Rust, just expect to be frustrated for a while with Rust's ownership system, it's a new concept for almost everyone. I think it's kind of like monads in Haskell, you struggle with it until suddenly it "clicks" and then it doesn't seem very hard, but it then becomes hard to convey your understanding to someone else. Rewriting Ewig in Rust, including the persistent tree-based immutable vector, would be an excellent exercise. Indeed, just starting with the RRB-Vector would be a great project. By the way, your immutable data structures library is quite impressive, it would be nice to have such a library in Rust. As far as I know, there is no such maintained library of functional data structures in Rust.
- bluecheese33 9y agoI tried a rust one as well [1], (antirez based). It's a decent amount of fun, would like to try implementing some of the more interesting features/data structures. [1] https://github.com/khadiwala/kilo-rs https://github.com/khadiwala/kilo-rs
- widdershins 9y agoVery nice, I've been wondering when someone would implement some Clojure-like data structures in C++. I will be playing with this next weekend.