rokucommunity / rokucommunity/brighterscript
Proposal: Add class type
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 208
- Forks
- 68
- Avg merge
- 8h 39m
- Merged PRs (30d)
- 39
Description
The Problem
There's currently no built-in way to distinguish a brighterscript class from other classes or plain assocarrays. We can manually add our own "type" property, but have to do that for every class we ever create.. and on teams with multiple members, that's also left to memory and easy to forget
Proposal
This is a similar problem that JavaScript prototypes have (which are very similar to brighterscript classes). A potential pattern that we could mirror was added in ES6:
JS ES6 solved this by adding the constructor.name property
For Brighterscript, the simplest way to add this might look like:
(transpiled)
function __exampleClass_builder()
instance = {}
instance._isClass = true
instance._name = "exampleClass"
return instance
end function
function exampleClass(args)
instance = __exampleClass_builder()
instance.new(args)
return instance
end function
Value-Add
This opens up room for developers to use simple utils like [the following] to differentiate classes from eachother and other objects
function isClass (value)
return isAssocArray(value) and (true = value._isClass)
end function
function isClassOf (value, classType)
return isClass(value) and (value._name <> invalid) and (value._name = classType)
end function
Closing Remarks
Open to discussion/suggestions on what this should look like for Brighterscript. Once there's consensus, I don't mind doing the PR
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The proposal names no implementation files, tests, or compiler entry points. First establish consensus on the class representation and type-detection behavior, then locate the BrighterScript class transpilation path and define tests that distinguish class instances from plain associative arrays.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100