Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

8
  • 2
    Ok, maybe it does depend more on the language, but in C#, you would likely do: if (timeout.HasValue) instead of a direct comparison to null. Commented Mar 30, 2012 at 16:59
  • 2
    Null isn't any worse than magic number. With magic numbers, you never know what the magic number is... it could be 0, -1, or something else. null is just null. Commented Mar 30, 2012 at 17:22
  • 9
    Null means absence of value. This is the concept that a lot of magic numbers are intending to express. Being able to use null with a nullable type is a MUCH better solution than picking one arbitrary value from the range of possible values for a data type. Commented Mar 30, 2012 at 17:32
  • 2
    Using "null" as your magic value, if your type has "null," is fine. The important thing is to NAME it, because sure as shootin' the next guy to come along will not know what you meant. Null can mean "infinity," "not yet specified," "bug in the code that created the data structure," or any number of other things. Only a name lets the next coder know that you meant that value to be there, and what behavior you meant it to trigger. Commented Mar 30, 2012 at 17:49
  • 2
    -1: Null is better than a magic number. A magic number can easily be misinterpreted as data. Commented Apr 2, 2012 at 20:25