1. 17

  2. 6

    There is no way to modify an existing rope: all operations on a rope return a new rope.

    I wrote a bunch of stuff that worked this way. Some stuff that even got acquired! Thought it was nice and elegant. But each and every one of those systems failed once they got beyond trivial scale. You just can’t do Go like this. It thrashes the GC and can’t be made performant.

    1. 3

      The expected maximum scale here is “human typing speed on reasonably-sized text files” and thus far seems to be okay.

      1. 1

        Incidentally do you have any recommendations for things to learn how to write fast go? My recent attempts have had very mixed success - it’s easy to write code that is much slower than naive code.

          1. 1

            You, sir, are a gentleman and a scholar

      2. 4

        rope.go in the repository talks about persistence, but it sounds more like immutability — new, modified instance is returned for every change. Is the use of word persistence correct here, I thought it implies being written to disk or some storage?

        1. 3


          In this case, “persistence” means “the old versions stick around after modification as long as you need them to.”

          Among other reasons, it’s a nice property because it makes undo/redo trivial.

          1. 2

            Yeah unfortunately it seems the term is overloaded, meaning either immutable data structures or persisted-on-disk (or equivalent) data structures, depending on the author.

          2. 3

            Nothing fancy but this is the persistent rope that I’m using in my next text editor project.

            (Said text editor is going to have something really unusual, but that’s not ready to be shown yet.)

            1. 2

              Nothing fancy

              Yup! While it’s possible to go overboard with fancy rope implementations, a basic thing which gets the job done is surprisingly simple. IIUC, this 500 lines of verbose Java is what powers text in IntelliJ: https://github.com/JetBrains/intellij-community/blob/master/platform/util/base/src/com/intellij/util/text/ImmutableText.java.