I love the idea of Moonscript but, is this weird to anyone else:
- class attributes are mutable and shared across all instances!?
- to give an instance its own state you gotta define attributes in the constructor
In that case, there's OOP modules for raw Lua that work well. I'd prefer to stick with Lua.
> class attributes are mutable and shared across all instances
an OOP module from Lua is likely going to work the same way. Most class based languages would behave the same (Python, Javascript are examples I can think of)
A "class attribute" is a value stored on the object that represents the class. This is a prototypical language, so all instances of a class share the same prototype associated with the class.
Regarding immutability, you could use metatable tricks or a library to enforce immutability on a Lua table. That's not something the language provides.
> to give an instance its own state you gotta define attributes in the constructor
So I believe the reason why you're making this distinction is because the prototypical inheritance and the explicit section that talks about this in the documentation. MoonScript lets you have any value be part of the prototype, not just methods/functions.
So I guess I'm writing all this to say that it's not weird, it's just the nature of prototype-based languages. I specifically call out this case in the docs to help people not get stuck.
Yes, the class stuff in MS is plain wrong, all of it (except `=>`, maybe). In my fork, I plan to drop it all. The thing is, the prototypal, copy-on-write nature of Lua object orientation is not a disability, there's no need to "fix" it, the model is powerful enough as it is, it just needs to be used well.
Some years ago I learned Io - another prototype-based language, similar to Self - and I was amazed at how expressive it is based on a very small set of core primitives. All the primitives, including async calls in coroutines, are either built-in in Lua or are trivially implemented with a small code transformation.
There's nothing wrong about it, I'm sorry you don't like it! I'm happy that you have your own ideas but to go around saying it's wrong isn't very cool. The system was very intentionally designed. Now that's it's been 9 years and I've written 100s of thousands of lines of MoonScript, the class has proved to be very reliable. It compiles to simple concepts that are easy to reason about when working with both large and small code bases.
> The thing is, the prototypal, copy-on-write nature of Lua object orientation
This line is confusing to me. There is nothing about lua that is fundamentally copy-on-write. That would have to be a choice the developer makes, but it would be hard to enforce with language primitives unless you're hiding data within meta-tables
I think you're getting hung up on details that have nothing to do with MoonScript: if you want a different language then use a different language. Don't go around saying it's wrong because it's not the language you want.
MoonScript reminds me of CoffeeScript in this regard. Lua and JS are both prototypical languages, which is a feature, not a bug. Putting some `class` syntactic sugar around it helps initially, but also causes confusion when it doesn't act like a traditional OOP class.
DLangIDE* (somehow not listed on dlang's official editor list) is sincerely the best I've used in terms of IDEs, but for most work, there's not much that can beat plain Sublime 3.