gpsd-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

why so many different ways to check valid attributes/values?


From: Beta Tester
Subject: why so many different ways to check valid attributes/values?
Date: Sat, 2 Jul 2022 11:20:57 +0200

i just wondering if it wouldn't be nicer for gpsd-client developer/users to 
have only one single way to check if attribute values are valid or not.
at least in python, i see at the moment five different situation that you have 
to care to check if attribute values are valid.
you have to check:
- if an attribute exists in a dictionary or not. you can handle in normal 
python style e.g., `value_or_default = dict.get(key, default=None)`.
- if the `PACKET_SET` flag is set to see if the report you got has any kind of 
valid data at all
- if the attribute, you are interested in, is one, that has a `..._SET` flag 
that has to be checked, e.g., 'is_valid = ((gps.valie & ..._SET) == ..._SET)'.
- if a float value is a finite value or if it is "NAN" or another infinite 
extreme. that you have to check with `is_valid = math.isfinite(value)`.
- if `SKY` satellites `el`, `az`, `ss` values are `-999` to see if they are 
invalid.
did i forgot oter checks to list?

why not just handling the a `dict` or `json` object like: all attribute values 
that exists in the container are valid - anything else that is missing is not 
valid.
so you simply can use in all cases the `dict` or `json` object's own `.get(key, 
default=None)` method to cover all different situation above in one way.

at least under python that would be the most "natural" way to cover all checks 
in a well known way, without the need to study deeply docs and source code.

or give the gpsd-client developer/user a single method to hand, to do the all 
different checks in one - something like `gps.get_value_or_default(key, 
default=None)` or `dictwrapper.get_value_or_default(key, default=None)`.

the situation now is, you have to figure out which attribute you are interested 
in has which set of diffeent checks you have to cover.
this is very confusing und painful to collect all the informations you need.

i don't know if this suggestion above will apply to the C-implementation as 
well - if there is also the informations available as a dictionary or json 
object that is accessable like a dictionary with a nice way to get an key value 
or a default value, when the attribute does not exists.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]