By Arturo Cuya
@arturo__cuyaBrighterScript is a superset of the BrightScript language. It adds modern features that end up being compiled into vanilla BrightScript code. And if you’re not using it yet, you’re really missing out on a great technology.
This post aims to summarize what BrighterScript brings to the table and provides a roadmap for effectively convincing management of its merits.
🤩 Stay ‘til the end to get a free resource that will guarantee the success of your migration journey.
The BrighterScript project is mainly composed of three parts:
bsc
) that transpiles the language to BrightScript, making it compatible with any Roku devicebsc
) which allows any editor that supports LSP (like VSCode) to provide syntax highlighing, completions, go-to-definition, errors, etc.Let’s do a recap of some of the great language features BrighterScript offers.
Template literals are string literals that can have embedded expressions and also capture newlines.
name = "Cap. Demoux"
text = `hello ${name}`
poem = `once upon a time
there was a really long text
that spanned across 3 lines`
Managing script tags in component XML files can be tedious and time consuming. BrighterScript provides the import
statement, which can be added to the top of your .bs
files. The XML file that invokes this script will have <script>
tags injected based on the import
statements.
import "pkg:/source/lib.bs"
sub init()
print someFunctionFromLib()
end sub
Do I really need to mention why this is great?
user = doLogin()
authStatus = user <> invalid ? "logged in" : "not logged in"
The null-coalescing operator evaluates and returns the value of the left-hand expression if it does not evaluate to invalid; otherwise it evaluates and returns the value of the right-hand expression.
value = getUserName() ?? "anonymous"
BrighterScript Enums are a way to define a set of named constants, sharing many similarities to their implementations in other languages such as TypeScript and C#.
enum Direction
Up
Down
Left
Right
end enum
sub move(direction)
if (direction = Direction.Up)
? "going up"
else if (direction = Direction.Down)
? "sinking down"
else
' ...
end if
end sub
Traditional BrightScript supports object creation, but these can get a bit complicated at times. These objects are also difficult to track from a type-checking perspective, as their shape can morph over time. In BrighterScript, you can declare actual classes, and compile them into pure BrightScript which can be used on any Roku device.
class HttpService
function createRequest(method, url, args)
return ...
end function
function get(url, queryParams = {})
return m.createRequest("GET", url, { params: queryParams })
end function
end class
class UsersService extends HttpService
private url = "https://myapp.com/users"
function getUsers()
return m.get(m.url)
end function
end class
Full BrighterScript reference
Roku development is usually tied to big media companies. Only these big players have enough content to justify developing for the Roku platform. This is great because we as developers are greatly appreciated by the job market, but a big company usually moves slow. It wouldn’t be surprising if your company is not quite the early adopter in terms of new and *gasp* open source technologies.
So here are some tips to sell BrighterScript to your manager:
The last thing you want is to share a PR with every .brs
file transformed into a .bs
file and thousands of line changes. There are some small things that you can incorporate into your project without modifying a single file of your source code.
One of these things is adding a linter and formatter to your project. This will let you define a set of style guidelines that you and your team will have to follow. If there are any inconsistencies, your project won’t compile. This will save you an enormous amount of time during PR reviews because there will be no time wasted in style preference discussions.
Scaffolding a new project with linting & formatting.Probably there are some general coding requirements you and your team want to comply to, like:
BrighterScript doesn’t only provides us with additional syntax, but also lets us define our own custom compile-time rules that will determine if the program should compile. These include code annotations, custom diagnostics, AST modifications, etc.
BrighterScript plugin referenceThis is my last tip, and probably the most important one. A good manager is never really against you, they just see the work you do from a different perspective. A matter of costs and benefits; pros and cons. This is why higher-ups have a disdain for adopting new technologies: It’s hard to measure the pros and cons when you can’t see how it will benefit the product you’re making. So we need to help them take the decision from their own perspective.
One tool to achieve this is a SWOT diagram of Strengths, Weaknesses, Opportunities and Threats related to the decision you’re about to make. When creating these diagrams, it’s important to also remark how do you plan to deal with the Weaknesses and Threats of your assessment.
I’ve successfully used this tool to propose the integration of many new technologies to my team. Today I want to share it with you, for free, so that you too can improve your developer experience with BrighterScript.
Want a proven method to convince your manager? Seize this FREE 18-page slideshow:
For absolute beginners, this course is meant to set you in the right path to make use of modern tools and best practices from day one. Subscribe to the newsletter to get notified when it's available.
Use these tools to 10x your workflows. Free and open source forever.