Closed dougsyer closed 8 years ago
@dougsyer: I'm strongly of the opinion that None is a better default value for all properties. This is the only way for me to tell whether I've never successfully modeled a property's value, or if the value is actually "" or 0 or 0.0. I think there's a big difference between those two cases. I realize that bugs are sometimes caused by this, but I think it's preferable to have and fix those bugs than it is to show a value of 0 when in fact there's no value at all. That's actively misleading.
I do think having ApplyDataMap check types, and possibly do type coercion is a good idea.
Yes I know what you are talking about, I typically will leave something as empty string if its not a super important property and I know that its possible that it wont be modeled. if it is an important property then i'll set some kind of text tag like "Missing" or "Not Modeled". to make it a bit more structured. But I understand why you would want to check if a field is None..
One question through, if i have an integer field and i dont set a default. if that sets it as None, when the field is modeled as an integer, will it really be set as an integer or will it be a string saved in a field defined as an int? I made the mistake once also of having a DEFAULTS setting an empty string value then i overrode it on a property and set it to None and oops...yeah that gave me the None string..i think sometimes i subconsciously try to make my life harder..
yeah ive saved the wrong type a bunch of time now and looking back i found that some wierd issues i was having with older zenpacks were caused by me defining string and setting a numeric or vice versa (ugh). I'm not sure that if you move a device out of its python class that it clears the device level properties you defined also so ive run into that I think to.
Currently if you set the type to int and don't set a default value, you get the default of None. Since we don't currently do any type coercion at least when applying datamaps from modeling, the type of the value will remain NoneType until you model it. At which time it will become the type of the value in your ObjectMap. So if you make the value an int in your ObjectMap, that's what it'll be.
I think that the "default" value should be initialized as follows by default:
String: empty string "" Int: 0 Float: 0.0
I know in old style zenpack development you would never declare a property as string, int, float and initialize it as None..if you look at any older zenpacks that isnt done.. If you set the default as None you are also putting more reliance on your api layer and javascript to interpret None correctly...which will cause issues. Ive seen in zenoss before doing inspects in my javascript..
It seems a waste for me to manually have to set the default value on every string int and float field.
The advantage to None i think is that in development you can change types without as may side effects.
As a correlary to this..the apply data map should really check types. I know thats kind of an anathema having types but you end up having to do do type checking or conversion anyways as soon as you do anyhing involving calculations..better imo to check it on the way in imo..
Inknow its sometimes safer to set everything as string but if you have users editing things that are intended to be ints then you either have to set it as int and have the xtype set to int or you have to write type checking or conversion code sometimes in several places..