What is the purpose of null?

后端 未结 25 2505
别那么骄傲
别那么骄傲 2020-12-07 22:24

I am in a compilers class and we are tasked with creating our own language, from scratch. Currently our dilemma is whether to include a \'null\' type or not. What purpose do

25条回答
  •  一整个雨季
    2020-12-07 23:05

    What purpose does null provide?

    I believe there are two concepts of null at work here.

    The first (null the logical indicator) is a conventional program language mechanism that provides runtime indication of a non-initialized memory reference in program logic.

    The second (null the value) is a base data value that can be used in logical expressions to detect the logical null indicator (the previous definition) and make logical decisions in program code.

    Do you have any thoughts, especially for or against null?

    While null has been the bane of many programmers and the source of many application faults over the years, the null concept has validity. If you and your team create a language that uses memory references that can be potentially misused because the reference was not initialized, you will likely need a mechanism to detect that eventuality. It is always an option to create an alternative, but null is a widely known alternative.

    Bottom line, it all depends upon the goals of your language:

    1. target programming audience
    2. robustness
    3. performance
    4. etc...

    If robustness and program correctness are high on your priority list AND you allow programmatic memory references, you will want to consider null.

    BB

提交回复
热议问题