matrixebiz
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2016
06:16 AM
Brightscript Sub and Function Routine
Hello, just wondering the difference between a Sub routine and a Function routine.
Are Sub routines always ran in the code automatically and a Function routine needs to be called upon within the code?
Or do you always have to call upon them both within the code script for them to run? Thx
Are Sub routines always ran in the code automatically and a Function routine needs to be called upon within the code?
Or do you always have to call upon them both within the code script for them to run? Thx
18 REPLIES 18

squirreltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2016
08:05 AM
Re: Brightscript Sub and Function Routine
"matrixebiz" wrote:
Or do you always have to call upon them both within the code script for them to run? Thx
Yes. The difference is that a function can return something.
Kinetics Screensavers
EnTerr
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2016
11:16 AM
Re: Brightscript Sub and Function Routine
sub is just a special case of function.
Sub is a function that does not return a value (formally, its return type is "as void"). Also, from what i remember you cannot have an anonymous/lambda sub literal:
Consider "sub" as a shortcut when writing procedures/subroutines.
Sub is a function that does not return a value (formally, its return type is "as void"). Also, from what i remember you cannot have an anonymous/lambda sub literal:
myFun = function(): ? "fun": end function ' can haz '
mySub = sub(): ? "sub": end sub ' cannot haz '
Consider "sub" as a shortcut when writing procedures/subroutines.

Komag
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2016
11:30 AM
Re: Brightscript Sub and Function Routine
Maybe I'm missing some usefulness, but I don't have a single sub, only Functions, with some "AS VOID" where needed. Is there a benefit to using sub?
belltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2016
11:33 AM
Re: Brightscript Sub and Function Routine
"Komag" wrote:
Maybe I'm missing some usefulness, but I don't have a single sub, only Functions, with some "AS VOID" where needed. Is there a benefit to using sub?
No benefit that I can see. I very rarely use subs, except for main(), which I don't expect to ever return a value.
EnTerr
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2016
11:50 AM
Re: Brightscript Sub and Function Routine
Indeed. Sub is syntax sugar like "don't" - you "do not" have to use the short form 🙂
renojim
Community Streaming Expert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2016
02:17 PM
Re: Brightscript Sub and Function Routine
It's much quicker to type Sub/End Sub than Function ... as void/End Function. 😄
Roku Community Streaming Expert
Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.
I am not a Roku employee.
Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.
I am not a Roku employee.

marcelo_cabral
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2016
08:54 AM
Re: Brightscript Sub and Function Routine
As a retro-developer (there is such word ?) that worked with Visual Basic 1.0 up to VB.Net I also use Sub a lot, when there is no return value I just think there is no point to write a Function "as void"
🙂
🙂
EnTerr
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2016
09:29 AM
Re: Brightscript Sub and Function Routine
Guys, you do know that in B/S declaring the return and arguments types is largely in the "good manners" category and does not speed up the code, right?
Just checking 🙂
Just checking 🙂
NND
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2016
10:42 AM
Re: Brightscript Sub and Function Routine
You can declare sub with return value and use it as a function. One real difference is the one mentioned by EnTerr, no anonymous subs.