What is the purpose of null?

后端 未结 25 2583
别那么骄傲
别那么骄傲 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:19

    I usually think of 'null' in the C/C++ aspect of 'memory address 0'. It's not strictly needed, but if it didn't exist, then people would just use something else (if myNumber == -1, or if myString == "").

    All I know is, I can't think of a day I've spent coding that I haven't typed the word "null", so I think that makes it pretty important.

    In the .NET world, MS recently added nullable types for int, long, etc that never used to be nullable, so I guess they think its pretty important too.

    If I was designing a lanaguage, I would keep it. However I wouldnt avoid using a language that didn't have null either. It would just take a little getting used too.

提交回复
热议问题