pjforde1978
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2019
04:38 PM
roSGNode subclass type reflection
I've created a UrlNode, which is a ContentNode with a feed_url field added.
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?
<?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?
5 REPLIES 5
destruk
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2019
05:37 PM
Re: roSGNode subclass type reflection
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".
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
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2019
06:04 PM
Re: roSGNode subclass type reflection
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.
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
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2019
07:00 PM
Re: roSGNode subclass type reflection
Profiler is here -
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.
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
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2019
08:42 PM
Re: roSGNode subclass type reflection
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.
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
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2019
01:09 AM
Re: roSGNode subclass type reflection
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!
In my original example, calling node.subtype() on my UrlNode component would return "UrlNode".
https://sdkdocs.roku.com/display/sdkdoc/ifSGNodeDict
Case closed!