Forum Discussion
Rek
11 years agoVisitor
"Komag" wrote:
How important is it in my coding in all my function headings to add the "As Integer" or "As String" or whatever it's going to be?
So far I've NEVER used this in dozens and dozens of functions, and I've never had a problem (that I'm aware of).
- Is it just for my own benefit/clarity?
- Or is it more useful and important than that?
- Does it force type, such as boxing an intrinsic value? (Am I even saying that right?!)
- Is this something that would help eliminate Type mismatch errors, or could it lead to more of them?
Since brightscript is loosely typed, it shouldn't ever be strictly necessary to include the return types. However, it is good practice to include them where you can since it makes it much easier to identify bugs as you develop. For example: returning invalid instead of a real Integer when method is "as Integer" will crash -- making it clear that the incorrect type was returned from that specific method. Otherwise you could end up seeing the crash in some other code that relies on the poorly behaving function and have to trace it back to the source yourself.