'year' manga attribute [Implemented]

Status
Not open for further replies.
Voting on this suggestion has been paused.
Contributor
Joined
Jan 19, 2018
Messages
575
In most cases (when dealing with scripting/programming) the default or "null" value of a numeric (int, double, float, etc.) variable/field is 0. While I haven't used PHP in many many years I am pretty sure it treats null values as 0 when it comes to casting them into integer values.

Edit: I should mention its not impossible to have "null" as the value for numeric fields, but it is not the norm
 
Last edited:
Staff
Super Moderator
Joined
Aug 19, 2020
Messages
814
In most cases (when dealing with scripting/programming) the default or "null" value of a numeric (int, double, float, etc.) variable/field is 0. While I haven't used PHP in many many years I am pretty sure it treats null values as 0 when it comes to casting them into integer values.

Edit: I should mention its not impossible to have "null" as the value for numeric fields, but it is not the norm
Makes sense as to how.
Now to the question why 0 instead of null. I see no value in using 0 as default value.
The manga POST and PUT endpoint even accepts null for the 'year' attribute, so why shouldn't the GET endpoint use it too?
And the JSON:API specification specifies multiple times that an api should return null if the value doesn't exist, e.g the link specification.
And when we go further down the rabbit hole we come to the json definition.
RFC 4627 and json.org specifically added null to represent the value of "nothing".
Following what php does because it works in php shouldn't be a thing.
 
Last edited:

rdn

Forum Admin
Staff
Developer
Joined
Jan 18, 2018
Messages
281
why its 0 instead of null wasnt thought out very much, the schema is
Code:
        "year": {
          "type": ["integer", "null"],
          "minimum": 0,
          "maximum": 9999
        },
purely to have a very basic sanity check of not having any negative values in a potentially unsigned field
who would send 0 as a year? idk. if someone sends bad data then there's bad data in it and it should be reported so it can be corrected
 
Staff
Super Moderator
Joined
Aug 19, 2020
Messages
814
Just noticed that I didn't post an update
The api got a stealth update. The year attribute default value is now null
 
Status
Not open for further replies.

Users who are viewing this thread

Top