Implications of not including NULL in a language?

后端 未结 10 1358
广开言路
广开言路 2020-12-28 19:38

I know that NULL isn\'t necessary in a programming language, and I recently made the decision not to include NULL in my programming language. Declaration is done by initial

10条回答
  •  感动是毒
    2020-12-28 19:54

    We use nulls all the time in our application to represent the "nothing" case. For example, if you are asked to look up some data in the database given an id, and no record matches that id: return null. This is very handy because we can store nulls in our cache, which means we don't have to go back to the database if someone asks for that id again in a few seconds.

    The cache itself has two different kinds of responses: null, meaning there was no such entry in the cache, or an entry object. The entry object might have a null value, which is the case when we cached a null db lookup.

    Our app is written in Java, but even with unchecked exceptions doing this with exceptions would be incredibly annoying.

提交回复
热议问题