Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Classes? #103

Open
FAReTek1 opened this issue Feb 23, 2025 · 1 comment
Open

Classes? #103

FAReTek1 opened this issue Feb 23, 2025 · 1 comment

Comments

@FAReTek1
Copy link

FAReTek1 commented Feb 23, 2025

As a user of goboscript I have found the struct system very convenient for handling objects with multiple values. However, these often go into functions which can get very messy - especially the struct that represents a complex number.

Since goboscript compiles to scratch code, an implementation of OOP would be quite inefficient in the scratch editor. This is why I suggest classes in goboscript that behave exactly like a struct with associated methods (procs/functions). This means that the classes will not be able to directly support attribute assignment unless held in a variable (just like structs).

But what about normal OOP..? In the future, it could be possible to support a conventional (and slow) OOP system using JSON and a list which acts as memory, allowing for object creation/deletion.

theoretical code:

class Complex {
    real, imag;
    
    func add(self, Complex other) Complex { # self is implicitly complex
        return Complex{real: self.real + other.real, imag: self.imag + other.imag};
    }
}
@FAReTek1 FAReTek1 changed the title Classes Classes? Feb 23, 2025
@FAReTek1
Copy link
Author

Another extremely useful feature that could build upon this is operator overloading. This would make the complex numbers issue extremely clean

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant