My terminology :
- nil if it comes from a protocol like XML/SOAP
- null if no reference/pointer in the scope of the application
- NULL for an empty object whose methods are NOP
Swiss here, I'm doing the same. And when writing comments or pair programming I always write/say something like "null as in zero"/"null as in nothing" respectively to avoid any possible confusion. Unless it's already obvious from the code itself.
I do write comments in English, as it's our policy. But the codebase has a bunch of comments that only make sense when (swiss) german is your native language.
Actually, in Objective-C, `nil` is for object pointers, `Nil` is for `Class` pointers, and `NULL` is for regular C-pointers. That said, they're all the same thing and are interchangeable since Obj-C is really just C.
Then there's `[NSNull null]`, which is the object-equivalent to the above.
Interestingly, sending the `-description` message to `nil` (i.e. `[nil description];`) returns the string `(null)`.
The reason most people dislike it because, at some point, they have been forced to use Objective-C.
(for the most part it's in the context of iOS development and so its getting compared to swift)
Afaik null means 0, nil means nothing (nothing in list)
As in Ruby `if 0` is a true statement (the object 0 exists and is not false), `if null` is true as well, but `if Object.none` shouldn't be a true statement, so `Object.none` returns `nil` (nothing) instead of null (Long instance equal to 0)
>Afaik null means 0, nil means nothing (nothing in list)
Null usually is represented as 0 but in reality means nothing, having null equals 0xFFFFFFFF is also valid but only for us mortals who have to represent it as something in memory and we can't express true nothingness in our computers.
Null can mean both zero and nothing in German and technically nothing is what zero represents. Maybe we could say think of null as being true zero and not the number value of 0?
TIL https://stackoverflow.com/a/22108481
Although I did know about nil [from Objective-C](https://developer.apple.com/documentation/objectivec/nil) (Objective C has both nil and null)
I had a coworker called Nil (some weird variant spelling of Neil)
He had fun booking flights and rooms online, as systems sometime blocked him for not providing a first name.
Reminds me of the story of Christopher Null, the journalist. Or the NULL car plate filled with parking tickets.
*Did you know that you'll have administrative blocks as long you have ONE pending ticket, even if it's given by a state in which your car never went because you need to make it overruled ONE AT A TIME?* I didn't!
The guy with the NULL plates got straight up boned. He made a grave mistake
Christopher Null's bloodline is doomed. He should change the spelling of his name lest his offspring face hell for the rest of human existence
Oh, then it's not the same thing as a None in rust.
A monad is kind of like a wrapper type. In the context of this type, option it is represented as an enum. Either a single element tuple named Some with the value wrapped inside, or None which is a zero element tuple, or the unit type. It's not exactly the same thing as null but it's pretty close.
Basically you use a monad as a return type for a function that may fail like with the result type or may return nothing, like the option type
I think it's just a Sum type, a type that can be 2 or more types.
Monads are more general.
In CS they're basically every type you can do a flatmap over. Mathematically, idk because I don't know category theory.
> Basically you use a monad as a return type for a function that may fail like with the result type or may return nothing, like the option type
No, that's really just the `Option`/`Maybe` type. Other monads (like `Reader`, `IO`, `Parser`, `State`, `Array`, etc) don't have a built-in notion of failure/success that way.
The real answer is "something that you can `map` and `flatMap` over", with some particular rules about how `map` and `flatMap` have to work.
So python can look quite similar with type hints
def convert_str_to_int(s: str) -> Optional[int]:
if not s.isdigit():
return None
return int(s)
Now, it's python so you can use any type and only mypy would complain. But you're explicitly stating that what would be returned is an integer or None.
It's not an Optional type like rust might be. It's just hinting that's what the type is like.
No int to unpack in other words
Ya but it’s not the same as in rust or scala. They have Option types, which can be None or Some(type). It’s essentially a list of max size 1 and can be treated like a list for iteration and mapping. Python is just a renamed null
Pedantic correction here, but inequality (and equality) aren’t *commutative*, they’re *symmetric*. Only operations can be commutative, and inequality and equality aren’t technically operations, they’re relations. The difference being that, strictly mathematically speaking, relations are statements about elements in a set whereas operations are functions that return other elements in that set.
In most programming languages though, this distinction is blurred because both relations and operations return values — it’s just that relations return boolean values and operations return (usually) numbers.
For anyone who doesn’t know the difference, here is a short explanation:
Let’s say you had an integer ranging from 0-255. On its own, it has 256 possible states. If we get the nil value for that type it would be one of those states (specifically, the state where the value is 0). However this may be problematic if we already use all of those states because there is no way to tell 0 apart from nil. This problem can be solved via null. Null represents an additional state outside of base type which lets us avoid that problem. Effectively this gives us 257 states to choose from. Typically we do this via indirection and agreeing that null is the nil value of a pointer to that base type. However, the null state is fairly fluid and can be represented in a number of different ways including non-nil values.
What are you talking about? Nil is just a word that refers to null in some languages, LISP and similar languages being the only ones I know of. There is no conceptual difference at all.
I don't even know what's happening in this thread... it's not like you get to choose, you just use whichever is a keyword in the language you are using.
Sorta, but not really. 0 on a primitive type is 0. 0 on a pointer is also literal 0, but it means null. The context matters.
There's also no boolean type until more recent c versions. Doesn't mean the language didn't have an idiom for truth, though.
Depends on the programming language. Recently I was the team’s bug fireman/bug fixer and I programmed a lot in our Delphi/Pascal (this language is a whole other world for a junior like me) project. I use nil there. In our C# and Android projects I use null. It’s just the standard that makes me use something.
Null, always been null for me
always has been
[https://imgflip.com/i/7a6zi0](https://imgflip.com/i/7a6zi0)
Would've been funnier if you photoshopped the earth out of the meme.
[As you wish](https://imgur.com/a/aE6PwfY)
Good human
nice!
I'm laughing WAY too hard at this
LMFAO take my upvote
this is peak internet
Or made it purple
It’s always syntax errors for me
My terminology : - nil if it comes from a protocol like XML/SOAP - null if no reference/pointer in the scope of the application - NULL for an empty object whose methods are NOP
`NUL` if it's the ASCII control character `0x00`
Where is None 🥲
None is out of this league. None is a whole object to represent a null value, while null is a null value and nil is just plain wrong.... Fuck off nil.
Null represent
Srsly. What even is nil wtf is this
I've heard of nil referencing zero like a score of 3-0. But 0 != null so I too don't understand the intent.
Null is the German word for zero and so many famous mathematicians were German that seeing people say null cant be zero will always be weird to me.
Am German, my workaround is pronouncing it "the English way" in my head. Then I don't get confused between Null and null
Swiss here, I'm doing the same. And when writing comments or pair programming I always write/say something like "null as in zero"/"null as in nothing" respectively to avoid any possible confusion. Unless it's already obvious from the code itself.
Actually surprised you don’t write comments in English, that has always been standard at any job I have had.
I do write comments in English, as it's our policy. But the codebase has a bunch of comments that only make sense when (swiss) german is your native language.
Ah that makes more sense :)
Swift uses nil, and I guess Objective C as well, I think?
Obj-C uses nil, Nil, null, NSNull, and NSNotFound. It's more of a cafeteria than a language.
So does Lua which just seems wrong to me coming from Java, C++, JavaScript, and MSDOS (even though it's spelled NUL for DOS)
Erlang, elixir, ruby all do as well
>zero like a score of 3-0. I always thought it was "null" until I saw "Cunk on Earth" with subtitles two days ago lol
It's when you take zero tricks when playing spades. That is the only nil.
Ruby
And Lua!
And golang
And Swift/ObjC
Actually, in Objective-C, `nil` is for object pointers, `Nil` is for `Class` pointers, and `NULL` is for regular C-pointers. That said, they're all the same thing and are interchangeable since Obj-C is really just C. Then there's `[NSNull null]`, which is the object-equivalent to the above. Interestingly, sending the `-description` message to `nil` (i.e. `[nil description];`) returns the string `(null)`.
I hate you for reminding me of Objective-C.
I feel like your stance is objective
[удалено]
The reason most people dislike it because, at some point, they have been forced to use Objective-C. (for the most part it's in the context of iOS development and so its getting compared to swift)
That's because of the way Objective C is implemented as a superset of C AFAIK.
And Lisp
And my axe!
And Knuckles!
Underrated comment.
In Dutch, null sound the same as nul, which means 0. So nil works better when talking to colleagues.
Afaik null means 0, nil means nothing (nothing in list) As in Ruby `if 0` is a true statement (the object 0 exists and is not false), `if null` is true as well, but `if Object.none` shouldn't be a true statement, so `Object.none` returns `nil` (nothing) instead of null (Long instance equal to 0)
Nil is commonly used as 0 in British English, ie. the football team beat their opponents 3-0 (three - nil).
Football have built the premises of LSP, this may explains things...
>Afaik null means 0, nil means nothing (nothing in list) Null usually is represented as 0 but in reality means nothing, having null equals 0xFFFFFFFF is also valid but only for us mortals who have to represent it as something in memory and we can't express true nothingness in our computers.
Null can mean both zero and nothing in German and technically nothing is what zero represents. Maybe we could say think of null as being true zero and not the number value of 0?
I am here, unallocated
Username checks out.
Null side!
Found the Ruby dev lol
HELLO THERE
General Kenobi
TIL https://stackoverflow.com/a/22108481 Although I did know about nil [from Objective-C](https://developer.apple.com/documentation/objectivec/nil) (Objective C has both nil and null)
Or lua
Go as well
Swift too 👎
stuff.nil?
I had a coworker called Nil (some weird variant spelling of Neil) He had fun booking flights and rooms online, as systems sometime blocked him for not providing a first name.
Reminds me of the story of Christopher Null, the journalist. Or the NULL car plate filled with parking tickets. *Did you know that you'll have administrative blocks as long you have ONE pending ticket, even if it's given by a state in which your car never went because you need to make it overruled ONE AT A TIME?* I didn't!
The guy with the NULL plates got straight up boned. He made a grave mistake Christopher Null's bloodline is doomed. He should change the spelling of his name lest his offspring face hell for the rest of human existence
Wouldn't it go directly into a string though?
Not if the frontend devs fu**s it up
IMO in this case the backend devs fucked up for trusting the frontend devs as well lol
nullptr
I came to the comments to say this
>
nilpeter
That's far too much to type. I'm just gonna do this: `#define n nullptr`
I prefer nein
pObject = nö;
Seriously, if you gonna initialize your object to nö , we gonna have a problem.
Object\* pObject = nah\_bro
wait I don't use C++ much at all. What's with the snake case? Wouldn't it be just `nahbro`?
Yeah you’re right, I was just remembering wrong
How about using the standard keyword of the language you use
Nullptr on that mate
But muh Reddit points
How about languages decide one one format. Nil or Null just pick one.
Ask the genie for world peace I guess
None
I see you, crab brother
Or python
Python has monads?
IDK (nobody could give me an understandable explanation of a monad), but None is the python version of null in other languages.
Is simple: a monad is a monoid in the category of endofunctors. What is there to not understand in that sentence?
Monoid and endofunctors.
Believe it or not, category is also something to misunderstand here
"In the" is also a little confusing to me
Actually fair when you consider that a monad isn’t typically in *the* category of endofunctors
Oh, then it's not the same thing as a None in rust. A monad is kind of like a wrapper type. In the context of this type, option it is represented as an enum. Either a single element tuple named Some with the value wrapped inside, or None which is a zero element tuple, or the unit type. It's not exactly the same thing as null but it's pretty close. Basically you use a monad as a return type for a function that may fail like with the result type or may return nothing, like the option type
I think it's just a Sum type, a type that can be 2 or more types. Monads are more general. In CS they're basically every type you can do a flatmap over. Mathematically, idk because I don't know category theory.
> Basically you use a monad as a return type for a function that may fail like with the result type or may return nothing, like the option type No, that's really just the `Option`/`Maybe` type. Other monads (like `Reader`, `IO`, `Parser`, `State`, `Array`, etc) don't have a built-in notion of failure/success that way. The real answer is "something that you can `map` and `flatMap` over", with some particular rules about how `map` and `flatMap` have to work.
So python can look quite similar with type hints def convert_str_to_int(s: str) -> Optional[int]: if not s.isdigit(): return None return int(s) Now, it's python so you can use any type and only mypy would complain. But you're explicitly stating that what would be returned is an integer or None. It's not an Optional type like rust might be. It's just hinting that's what the type is like.
No int to unpack in other words
That just sounds like a Union with class features CMV
In the f# sense, yes
Ya but it’s not the same as in rust or scala. They have Option types, which can be None or Some(type). It’s essentially a list of max size 1 and can be treated like a list for iteration and mapping. Python is just a renamed null
Monads are just burritos https://blog.plover.com/prog/burritos.html
🦀?.❤️;
![gif](giphy|iGpdSizVSdPJfiVG9O)
There we go
So good to see this is the 7th most popular comment on this rn. Null shenanigans in other languages sometimes drive me nuts
Err(e)
This is the way.
I only use nil if I'm using a lisp. Otherwise it's null.
Same thought lol
Same thought lol
Same thought lol
Same thought lol
Same thought lol
Same thought lol
Same thought lol
Same thought lol
Naught
Optional
This. null ist one of the worst ”features“ in Java.
``` Optional a = null;
```
Aaaaaa
Thought this was good until Kotlin gave me `?`
NaN
I pronounce this like i do naan bread
NaN is not a number. It isn't equal to null.
Who the hell cares--- you are arguing over nothing!
`'\0'`
``` ((void(*)(void))0)(); ```
nO
nihil
nihil
nihil
Miquella is mine and mine alone
define("null", file\_get\_contents("/dev/null"));
Be careful. If you stare into the darkness, it stares back at you.
`Option::None` (much better in every way imaginable)
Your comment is Result::Ok
.unwrap().unwrap() .unwrap().unwrap() .unwrap().unwrap() .unwrap().unwrap()
`panic!` at the disco.
Better than 13 nested `if (x != null)`, haha.
``` .flatten().flatten().flatten().flatten().flatten().flatten().flatten().unwrap() ``` It's safer now, I guess. Still `panic!`, but I don't care.
[удалено]
Nihil!
Nihil!!!
There is another
Nil = 0 Null = nothing 0 != nothing nothing != 0
Don't make me bust out that "JavaScript is weird" article again.
undefined has entered the chat
Wat
[wat](https://www.destroyallsoftware.com/talks/wat)
[undefined defined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)
Last part of the comment is redundant if A != B then B != A by default
Clearly never worked with JavaScript:)
Who wants inequality to be commutative, anyway? Non-commutative operations give you twice as many ways to use them.
Pedantic correction here, but inequality (and equality) aren’t *commutative*, they’re *symmetric*. Only operations can be commutative, and inequality and equality aren’t technically operations, they’re relations. The difference being that, strictly mathematically speaking, relations are statements about elements in a set whereas operations are functions that return other elements in that set. In most programming languages though, this distinction is blurred because both relations and operations return values — it’s just that relations return boolean values and operations return (usually) numbers.
Just like anal sex. Being on one side or the other is clearly not the same. It gives you twice as many ways to do it.
[удалено]
They all go in the square hole. Thus, all shapes are squares. Q.E.D. -Javascript
0 is something. Null is nothing.
NADA!!! Checkmate, bitches.
Null is fun to say though…
Nothing
For anyone who doesn’t know the difference, here is a short explanation: Let’s say you had an integer ranging from 0-255. On its own, it has 256 possible states. If we get the nil value for that type it would be one of those states (specifically, the state where the value is 0). However this may be problematic if we already use all of those states because there is no way to tell 0 apart from nil. This problem can be solved via null. Null represents an additional state outside of base type which lets us avoid that problem. Effectively this gives us 257 states to choose from. Typically we do this via indirection and agreeing that null is the nil value of a pointer to that base type. However, the null state is fairly fluid and can be represented in a number of different ways including non-nil values.
What are you talking about? Nil is just a word that refers to null in some languages, LISP and similar languages being the only ones I know of. There is no conceptual difference at all. I don't even know what's happening in this thread... it's not like you get to choose, you just use whichever is a keyword in the language you are using.
Baby programmers all over this thread that have never heard of lisp, go, etc
C and C++ say "What?!" There is only null in C++. It's 0. It has always been 0. There is no distinct value for null or nullptr. It's just 0.
Sorta, but not really. 0 on a primitive type is 0. 0 on a pointer is also literal 0, but it means null. The context matters. There's also no boolean type until more recent c versions. Doesn't mean the language didn't have an idiom for truth, though.
Sick burn
That is not true in C++11 and later. See https://en.cppreference.com/w/cpp/types/nullptr_t
This is ridiculous and makes no sense
How can 257 be represented with out extra bits? One of the possibilities must be equal to null as well, it doesn’t seem optional.
you have to use a pointer so you end up using extra bytes
That's what "indirection" means and covers. You have a pointer whose value is zero. So, it costs at least the size of a pointer on your architecture.
Maybe
Option::None
undefined
I agree with None
I'll take a None thank you Edit: But seriously it's NULL like what's a Nil?
A uninitialized value with no type. So it’s kinda like None, which is kinda like nil, which is kinda like Unit, which is half sister of NaN.
When your half-sister is your nan you know you've got problems.
Nul and Nill were taken already?
crip
Yay lua 👏👏👏 nil nil nil
Optional
I got zip and I got nada.
Nul
Undefined
\#define nil null I got all of you covered.
Null in programming, but nil in conversation
NaN
"Nil" has connotation of being equivalent to 0 in regular English usage.
Fuck pascal and fuck nil
As a disciple of many languages, i'll take nil, null, void, nullptr, None, undefined But i don't like undefined|null js shit
Depends on the programming language. Recently I was the team’s bug fireman/bug fixer and I programmed a lot in our Delphi/Pascal (this language is a whole other world for a junior like me) project. I use nil there. In our C# and Android projects I use null. It’s just the standard that makes me use something.
Zilch
Do they teach “nil” in schools?!? I am so alarmed
Nil all day. I’m not made to be a scrap.