Skip to content

Classes? #103

Closed as not planned
Closed as not planned
@FAReTek1

Description

@FAReTek1

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};
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions