2

So I was playing around with JS inside of QML (Qt). I wanted to turn a number into a string and then modify individual chars based on certain criteria. Then I would convert back to a number. Should be simple right? Well JS would not let me write to the indexed element of the string. What the actual fuck? I need to drop to C++ to do actual string manipulation? I ended up looping the string and turning it into an array and then a join back to a string. There is probably a better way to do this in a more modern version of JS, but I am now starting to see why JS is a pariah on here. It has some quirks that make you question your devlife choices.

What was I working on? Some stupid crop circle thingy. I was trying to use the QML Canvas to draw some "simple" crop circles. So I started with this crop circle:
https://plus.maths.org/content/...

The result ended up being kind of a swirling crop circle thing. The static image was too boring:
https://imgur.com/gallery/900hogf

And yes, I was too lazy/cheap to license the screen capture program.

Comments
  • 0
    @AppleLover Well damn, I never thought it was like that in Python. How the heck did I miss that? I programmed it exclusively for 5+ years. Well fuck python too! lol
  • 1
    First rule of QML: Do as little in JS as possible
  • 0
    @Demolishun strings were always immutable, but it has a ton of methods that return a manipulated string.
  • 0
    Implement ropes and Span<T> while you're in there
  • 0
    @Demolishun Almost all modern languages use immutable strings for security and performance.

    For max performance there are in dome languages ways around this.
    C# has unsafe mode where you can mutate them, and in the latest version span<T> which is a form of safer mutable memory.

    But only old langs like c++ and old basic uses mutable strings.

    And in js there actually are a few new memory types that might be more like what you wanted, but its not certain that it is faster unless we are talking about strings of thousands or hundreds of thousand chars, in which case switching to c++ might still be a viable option :)
  • 0
    @nicofee First rule of anything.
  • 1
    Just checked to make sure std::string will let me edit by indices. Yes, yes it will.
Add Comment