If class X has only one line in initialize
extendsClass.initialize();
Can I omit definition X.initialize() and system calls extendsClass.initialize() itself?
always a few bytes less in code...
If class X has only one line in initialize
extendsClass.initialize();
Can I omit definition X.initialize() and system calls extendsClass.initialize() itself?
always a few bytes less in code...
That's what I do, actually in most places i don't call the parent class' constructor even when I do have some code in initialize
There is a bit difference between your an my case :)
- I don't want to put new class initialize()
- You don't want to call extendsClass.initialize() - that is safe only you are sure that based class do nothing in initialize
If doing "extends" on standard CIQ class, I ALWAYS call initialize() on the parent. Your not sure what the parent is doing and that could change in the future (it has in the past!). With Eclipse (I've not checked with VS Code) it would flag cases where you didn't init the parent.
Not worth the risk to save a small number of bytes today
no.. no...
classic:
class PSXGlanceView extends UII.GlanceView
{
function initialize()
{
GlanceView.initialize();// of course should be
}
function onUpdate(dc)
{
//....
}
}
app
function getGlanceView()
{
return [new PSXGlanceView()];
}
want to save a few bytes so write without initialize
class PSXGlanceView extends UII.GlanceView
{
function onUpdate(dc)
{
//....
}
}
I would always have initialize() and init the Parent. Like I said it's bitten apps in the past.
We don't talk here how should be but how have to do be due to memory limits.
12bytes is worth the risk
If you are worried about 12 bytes today, you need to look for ways to save much more in your app other than ignoring basic things in the language.
If this bites you in the future, no forum threads or bug reposts, right? You'll just fix it!!
Yes, in my case every bytes is very important due to limit of 28kb in glance, when system load into memory unnecessary 8kB and after compilation with new sdk it eating additional 5.5kB...
Unfortunately you will also have to change code in future if e.g. ciq will add parameter to initialize some system thing because you don't have it now!
I only ask is according my example: does system in line
return [new PSXGlanceView()];
calls
GlanceView.initialize();
even I don't have in class PSXGlanceView extends UII.GlanceView function initialize()
What Jim meant is that in theory it's possible that today AppBase.initialize doesn't do anything but there will be a new firmware version on some devices where it'll do and then we'll be in trouble.
But this is not the case IMHO when you remove your class' initialize completely, because then IMHO it'll call the parent's initialize automatically. (but maybe this is wishful thinking because of how it works in other languages...)
I recall that is not the case in Monkey C. It's not automatic.
I do recall sometime in the last 8 years, on some class I was extending and I didn't initialize the parent it caused problems, but I don't recall the specific class or the SDK it started with. That's why today I always init the parent. Maybe Garmin optimization will strip it out if it's not needed, but I don't make that decision myself.
There are safe ways to save 12 bytes, but skipping this isn't one of them.