-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
Description
I know and love the Null Object Pattern, but there are a few situations where containsKey() is a better choice.
For example, when you are checking if a member exists, but that member is a zero, then the if statement will evaulate to false:
if (input["tank_level"]) {
float level = input["tank_level"];
wm.setTankLevel(level);
}I know there is the .is<> syntax, but semantically it is not nearly as clear as containsKey and is a lot more verbose.
if (input["tank_level"].is<JsonVariantConst>()) {
float level = input["tank_level"];
wm.setTankLevel(level);
}It seems completely arbitrary to force the user to use one syntax over the other when you could simply provide access to both.