Your Digital Media Has Never Looked So Good

 
pjforde1978
Topic Author
Posts: 15
Joined: Mon Mar 25, 2019 1:26 pm

roSGNode subclass type reflection

Sun Mar 31, 2019 4:38 pm

I've created a UrlNode, which is a ContentNode with a feed_url field added.

<?xml version="1.0" encoding="utf-8" ?>
<component name="UrlNode" extends="ContentNode">
  <interface>
    <field id="feed_url" type="string" />
  </interface>
</component>


When I iterate over my list of ContentNodes, I would like to be able to figure out if I'm looking at a ContentNode or a UrlNode. When I print out the object, it tells me that it is a <Component: roSGNode:UrlNode> but when I print out type(object) it tells me that it's an roSGNode.

Assuming that we can all agree that testing (object.feed_url <> invalid) would be cheating, how can I determine the subclass of an roSGNode?
 
destruk
Posts: 2710
Joined: Sat Dec 18, 2010 4:58 pm

Re: roSGNode subclass type reflection

Sun Mar 31, 2019 5:37 pm

What I would do here is check the last few characters of the url itself.  If it's an mp4 then it's progressive video, mp3 audio, hls, or html or php or asp.
That way you aren't extending the content node which has quite an impact on larger content sets.  When you do need to have a few extra fields, it's preferable (IMO) to use existing fields you are not utilizing like "album".
 
pjforde1978
Topic Author
Posts: 15
Joined: Mon Mar 25, 2019 1:26 pm

Re: roSGNode subclass type reflection

Sun Mar 31, 2019 6:04 pm

That's an answer I was not expecting. I see that you've made over 2500 posts, so I don't quickly discard your opinion. That said, I would like to benefit from your experience by digging a little deeper.

What's your confidence level regarding the performance impacts of subclassing in BrightScript? Is there a number of child objects where it starts to become problematic?

Is the impact lessened, increased or similar if you use addField() to add a slot dynamically vs formally subclassing via an additional XML file?

Does BrightScript have profiling mechanisms to test these hypotheses on working hardware with incrementally larger iterations? Usually, these sorts of problems have a curve.

Ultimately, my reason for asking is deeper understanding. As I suggested at the end of my post, I could also just test object.feed_url <> invalid and move on, but that feels gross and leads to special cases in your codebase whereas most languages have a mechanism for reflecting on polymorphic class meta-information. A urlNode is a contentNode but the opposite is not necessarily true.
 
destruk
Posts: 2710
Joined: Sat Dec 18, 2010 4:58 pm

Re: roSGNode subclass type reflection

Sun Mar 31, 2019 7:00 pm

Profiler is here -
https://sdkdocs.roku.com/display/sdkdoc/BrightScript+Profiler

AddField is preferred as referenced here on the wiki pages
  • Node creation, especially of inherited components, can be expensive. It is suggested that "AddFields" be used instead of "Extends" for such components.
https://sdkdocs.roku.com/display/sdkdoc/Best+Practices+for+Data+Management

By inference, if you don't need to add a field to the existing contentnode item, and simply appropriate an existing field for your own purposes, that is quicker.
 
pjforde1978
Topic Author
Posts: 15
Joined: Mon Mar 25, 2019 1:26 pm

Re: roSGNode subclass type reflection

Sun Mar 31, 2019 8:42 pm

Thanks for the amazing answers.

I'm still surprised that there's no capacity for reflection but tonight I also realized that there's no || assignment operator either. Every language has its idiosyncrasies.
 
pjforde1978
Topic Author
Posts: 15
Joined: Mon Mar 25, 2019 1:26 pm

Re: roSGNode subclass type reflection

Thu Apr 25, 2019 1:09 am

As it happens, roSGNode has an ifSGNodeDict interface that provides a subtype() function that returns the information I was looking for.

In my original example, calling node.subtype() on my UrlNode component would return "UrlNode".

https://sdkdocs.roku.com/display/sdkdoc/ifSGNodeDict

Case closed!

Who is online

Users browsing this forum: No registered users and 4 guests