Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
sjb64
Roku Guru

Brightscript requests

A few items I'd like to see added to BRS. Figured maybe if I list them here, others will join in with ideas, and maybe some will make sense to Roku and be possible to implement without breaking existing code. Some of these have easy work arounds of course, but could be done better in the compiler I think. Some may be there already and I just haven't noticed them, and will appreciate being pointed in the right direction.

Switch / Case, this has come up more than once, even Joel piped in as something he'd like to see if memory serves me right. Using a compile time hash based jump table like C#, a run time check with ranges like TurboPascal/Delphi, or even a brute force walk (syntactic sugar to if else else else...). Any of them would be awesome, and the first one would be much more efficient than the stacked elses we have now.

A tokenize that doesn't eliminate empty values. This would allow better parsing of CSV and other non XML/Json EDI data, either using new function, or adjusting tokenize to have a second arity to all this. We can do this with Regex now but that is rather slow.

A case insensitive string compare, this could be implemented in the base compiler code much more efficiently than us adjusting to lower or upper case before compare.

Compiler constants or aliases, being able to set certain constants that the compiler replaces during compile, avoids cluttering the m. array and the associated runtime costs.

Single line version of for, for each, and while, much like the if variant in BRS, just a personal preference I'd like to see.

An internal 'null' check that handles both "<unitialized>" and invalid. String checking is inefficient anyway, and any internal routine would be much better than the 'return Type(Item)<>"<uninitialized>" and Item<>Invalid' I use and have repeatedly seen in others code.

Dev mode compiler blocks that don't compiie when not in the dev sandbox, avoids runtime checks, even though they admittedly have no real run-time cost.

The ability to preset an array size on associative arrays to avoid progressively resizing for large arrays, like we can on basic arrays. I don't actually know how these are internally implemented, so this might be a meaningless request.

If I was reaching for the unreasonable I'd add...

Multithreading, which I simulate now with a getmessage wrapper method that loops an array of micro-granular state machines to allow background processes, I know this would be a massive restructuring.

Linq, which every c# programmer here knows and I assume appreciates, but that would be rather excessive and in some cases impractical.
0 Kudos
8 REPLIES 8
sjb64
Roku Guru

Re: Brightscript requests

Forgot one...

A values function on associative arrays, like the new keys function. I have a function that does this as I assume many others do too, but this could be done better in an internal function than us scanning the keys and looking up the associated values.

Id say array sorting too but I know there are too many variants. I have shell sorts I use for arrays and for object arrays by field, and NewManLiving recently posted some good quick and insertion sort routines, so this probably would be a quagmire to make a language construct.
0 Kudos
TheEndless
Channel Surfer

Re: Brightscript requests

"sjb64" wrote:
Single line version of for, for each, and while, much like the if variant in BRS, just a personal preference I'd like to see.

This is technically possible using colons...
While True : some simple code : End While

"sjb64" wrote:
An internal 'null' check that handles both "<unitialized>" and invalid. String checking is inefficient anyway, and any internal routine would be much better than the 'return Type(Item)<>"<uninitialized>" and Item<>Invalid' I use and have repeatedly seen in others code.

One could argue that you should never have uninitialized variables in your code, and a runtime error is the correct response, but that's a different discussion.. 😉

"sjb64" wrote:
Multithreading, which I simulate now with a getmessage wrapper method that loops an array of micro-granular state machines to allow background processes, I know this would be a massive restructuring.

This is available as a Task node in the new SceneGraph SDK coming in 7.0.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
sjb64
Roku Guru

Re: Brightscript requests

"TheEndless" wrote:
This is technically possible using colons...
While True : some simple code : End While

Yeah, I use that often, just find it a bit hacky, esp. if there is even the smallest of if statements in the loop, really trips it up

"TheEndless" wrote:
One could argue that you should never have uninitialized variables in your code, and a runtime error is the correct response, but that's a different discussion

Agreed, but that check is one I've see even in code from Roku itself. Again, using a string to compare to seems hacky. Just to be curious changed my code to an invalid check alone and a walkthrough of the app behaved fine, since my code relies heavily on arrays. But still seems safer to have the <uninitialized> since there is no exception handing options in BRS other than Run/Eval. Maybe a point I should have added to my list.

"TheEndless" wrote:
This is available as a Task node in the new SceneGraph SDK coming in 7.0.

Thanks, I'll take a look at that.
0 Kudos
RokuKC
Roku Employee
Roku Employee

Re: Brightscript requests

"sjb64" wrote:
A few items I'd like to see added to BRS.


It's great to see the suggestions and "pain points" called out. Keep 'em coming... 🙂
0 Kudos
TheEndless
Channel Surfer

Re: Brightscript requests

"sjb64" wrote:
"TheEndless" wrote:
One could argue that you should never have uninitialized variables in your code, and a runtime error is the correct response, but that's a different discussion

Agreed, but that check is one I've see even in code from Roku itself.

I have it in my code as well, but don't tell anyone.. 😉 I'm just not convinced there's any legitimate scenario where you could have an uninitialized variable in your code and not want to know about it.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
sjb64
Roku Guru

Re: Brightscript requests

"TheEndless" wrote:
I'm just not convinced there's any legitimate scenario where you could have an uninitialized variable in your code and not want to know about it.

The way you worded that I had no valid argument in my defense. That routine is now no longer in my code, although invalid checks in appropriate places still of course are. It mainly had to do with that background task loop that fires hundreds of times per second and could start on a given state machine before I had initialized it. But you're right, that's on me to manage, which a runtime error would point out any misstep.

But adding an exception handler I'd would like to officially add to my list of requests. Being able to ping my server with a log of error details of any RT errors that happen in the field would be invaluable, even if the routine didn't offer any reentry options, but was only a death throes intercept.
0 Kudos
EnTerr
Roku Guru

Re: Brightscript requests

(re single-line loops)
"sjb64" wrote:
"TheEndless" wrote:
This is technically possible using colons...
While True : some simple code : End While
Yeah, I use that often, just find it a bit hacky, esp. if there is even the smallest of if statements in the loop, really trips it up

That's not hacky at all, it's the honest-to-goodness way to do WHILE/FOR loops. And it works - as long as you don't use IFs - but that's a different story.

The tripping you observed, it's due to broken(ish) "IF" statement. I planted into it when i was trying to do an automated line-by-line profiler - and bitched about it in this thread - viewtopic.php?f=34&t=73411 . The reason behind the mess - i am guessing - is because the difference between 1-line and multi-line `IF` has never been formalized and so it was left to the de-facto/hacky parser implementation. (I likely would have put a bright-line separation between the two `IF` versions, based on whether there is a "THEN" afterwards, i.e. if there is THEN, it's a one-liner - otherwise it's a multi-line. But now is too late because of the existing B/S codebase that uses it every which way).
0 Kudos
sjb64
Roku Guru

Re: Brightscript requests

"EnTerr" wrote:
But now is too late because of the existing B/S codebase that uses it every which way).

Every channel, other than sideloaded, is packaged on the Roku servers. If they ever did want to create a potentially breaking change, they could literally syntax check the change against every known public and private channel in an automated test if they chose to. Would love to see a PC based syntax checker anyway, but they'd end up having to create versions for Windows, Linux, and Mac, which probably just isn't worth it.
0 Kudos