"null" is a value or a state in which the property is located?

Asked

Viewed 140 times

2

When checking if a property/variable/object is null(o), are we checking its value or state? For example, if I have the object Quadrilátero with the properties LadoA and LadoB it will not be possible to access the properties of this object until it is instantiated. When it comes to variables, if I have a variable that is populated by a database data and it returns null she’ll be worth it null, then nullin this case is a value and not a state in which the variable is ? Briefly my question is whether nullis a value?

1 answer

5


A database does not return null. A method from any library you are using can return null and you can store this value in a variable. Not all languages allow this, but I understand you’re talking about one that allows it. Not all libraries use this way of indicating that nothing was possible to return from the database. This is a error code.

The question starts from a false premise that a value and a state are distinct things. In fact the value is the state of the variable at that time. So null is both.

null is a value that is said to be of his own kind, a type whose value can only be null. There are languages that conceptualize a little different, but it’s never very different from this, some even use another name like nil or none. Anyway it’s usually the absence of value valid. Note that it is not exactly absence of value as it is said informally.

In some languages the value null can only be used in reference types since the reference is null and therefore prevents accessing a valid object. In types by value there is no way to represent nullity directly (you can create a composite type).

In static typing languages we can say that this is a breach of typing since a variable can have two different types of data, one is the valid value, the object of its type, and the other is a null which is basically a value of another kind.

Then a variable (or property) has a valid or invalid value (null), and is in valid or invalid status (specified by null). It’s just a semantic discussion at best.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.