Classes for luau module

Also how do you think I could make it better than this MiddleClass module

Maybe, I would love to see the article where they say that, because everything I have read says they WANT it to do that in the future but currently it does not.

Can you give me examples of what you want to happen

Well you could convert it to luau, first, and see where it could benefit from the new things luau can do.

I suggest even if you don’t do that, you should give it a good long look because the guy who made it is pretty emaculate in his coding and he may do some things in some ways you didn’t think about.

I’ve been using the thing for years, and I just recently learned how to properly create an interface (“extend”) which is like a mixtable, for it. That allows for no inheritance or inheritance based on implementation.

I have fancied the idea of updating it to luau typed myself, but atm I still feel a way about typed.

I feel like it its finiky in how you can pass type references to other scripts. It can be unreliable at times for that. Aka, I can’t have a centraliy defined typing that automatically is caught by the intellesense when I require it elsewhere or when I instanciate the class. That being said, I could spend more time on seeing if I am just missing some new tricks they have added. But when I have played with it, it tends to be really finiky if I am not basically re-hard type referencing it every time.

Another thing it has built in checking of "am I a class, or am I a classof, you can look at some of that documentation there for a lot of good built ins for it.

It auto tracks all your construction of class names, so you don’t have a name collision automatically.

It also has a very straight forward implementation for if you want it to flow through a parent construction phase, or if you want the subclass to ignore it.

Again, I could go on and on, when I was figuring out stuff early on, a few years ago, I tried out a TON of different class modules that are out there, and its just the cleanest I have found.

That being said, if you can solve some of that type aspecting of it, that would be awesome. I would love if when I type defined a function for the function that the instatiations of it would automatically get the intellsense for it.

As I have said, outside of what I have read, the intellesense is like the biggest thing with it all.

Native stuff is very specific in it’s uses, and its for computation and raw math like things mostly.

I have not heard or seen anything about Strict typing improving performance to any significant degree.

“Luau compiler currently doesn’t use type information to do further optimizations, however early experiments suggest that we can extract further wins. Because we control the entire stack (unlike e.g. TypeScript where the type information is discarded completely before reaching the VM), we have more flexibility there and can make some tradeoffs during codegen even if the type system isn’t completely sound. For example, it might be reasonable to assume that in presence of known types, we can infer absence of side effects for arithmetic operations and builtins - if the runtime types mismatch due to intentional violation of the type safety through global injection, the code will still be safely sandboxed; this may unlock optimizations such as common subexpression elimination and allocation hoisting without a JIT. This is speculative pending further research”

From the current documentation

With the recent updates and the new upcoming type solver, this old documentation will also be updated soon.

1 Like

Cool, can’t wait to see !! It stands that eventually it should offer performance increases eventually since the whole point is to help with allocation and inference to help the compiling, but we shall see!!

That is exciting to hear, it will be interesting to see how much of a boost it gives to outweigh the overhead for the work with it.

I’ve been using strict typing for the past few months, and I’ve run some benchmarking using Boatbomber’s Benchmarker, and without me making any updates to it, it has gotten faster. (Not using any APIs)

Also, I apologize, I am not a super high frequency on the development forums and I did not recognize your status here. And my tism goes off when people say things that don’t match documentation to persuade someone to do something that perhaps don’t need to do.

So my apologize on the doc hard siting you there. My bad.

1 Like

Just locally or using a lot of exporting? And have you figured out a more reliable format of returning from a module in a way that infers the typing so that I don’t have to hard reReference every time.

CraneStyle is my dicord, hit me up, would love to compare. I have done a little type script work as I edge into it, but some of my experiments have been quite frustrating.

The one you linked is even more recent than mine is! I’ve forgotten just how long ago I’ve made my module. I do quite like how it includes public and private fields, but I don’t like how they’ve been implemented. It feels very clunkly to define those fields and I wish they were written better. This does give me some ideas for if I ever revive my class system… Maybe some day?

This implementation made by @ChatGGPT use fenv to create non-local variables which should be avoided in practice and reconsidering what I mentioned earlier about how types could be added, any benefit they could provide wouldn’t work here as fenv breaks type-safety.

Maybe I am dumb but I still don’t get what you guys mean by type annotation for classes

How would this look like???

Any environment modification disables optimizations. So yeah that’s true.

How so? You should make a feature request or an issue on the guy’s GitHub page if you have any feedback for it.

class.rbxm (1.7 KB)

Ok guys new small update now it lets you do

class {
    ...
}

Maybe what they’re talking about is like when you do

class "Person" {
	constructor = function()
		this.name = "Unknown"
		this.age = 0
		print("Person created: " .. this.name .. ", Age: " .. this.age)
	end,
	greet = function()
		print("Hello, my name is " .. this.name)
	end
}

local john = new(Person)()
john.name = "John"
john.age = 30
john:greet() <- there’s an autocomplete when you’re trying to write greet

I dont think you are able to make dynamic type annotations, if im wrong please correct me

There shouldn’t be, I tried many solutions but none worked so far for my own class module. You have to do it manually unfortunately.

Yeah, I’ve tried making it before too and haven’t found any solutions, I really hope roblox adds a way for dynamic type annotations

1 Like