# Something about nothing

**URL:** <https://discourse.julialang.org/t/something-about-nothing/40001>\
**Category:** New to Julia\
**Created:** [May 22, 2020, 11:07pm UTC](https://discourse.julialang.org/t/something-about-nothing/40001 "2020-05-22T23:07:03Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![pauljurczak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauljurczak/32/921_2.png) [@pauljurczak](https://discourse.julialang.org/u/pauljurczak)\
**Post date:** [May 22, 2020, 11:07pm UTC](https://discourse.julialang.org/t/something-about-nothing/40001/1 "2020-05-22T23:07:04Z")

</div>

I’m learning Julia from the manual and really enjoying the process. Occasionally I try to do something weird and useless with a new learned concept. Here is an example of it:

```julia
julia> nothing == nothing
true

```

Nice, as expected.

```julia
julia> nothing <= nothing 
ERROR: MethodError: no method matching isless(::Nothing, ::Nothing)

```

I understand why, but this is logically incorrect.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [May 22, 2020, 11:26pm UTC](https://discourse.julialang.org/t/something-about-nothing/40001/2 "2020-05-22T23:26:02Z")

</div>

What’s logically incorrect? Do you expect `nothing` to be no equal to anything or do you expect it to have an order?

If you are talking about `<=` must include `==` then no, one of them is talking about ordering while the other is not. They are used i completely different context. OTOH, if `<=` works I would expect `==` to work though.

* * *

Another way to say it, this is **not** math and the way different operators and concepts are overloaded is not going to be completely the same as math. FWIW, math has it’s own inconsistency in many concepts anyway depending on the field. A programming language is also going to make decisions based on what people **should** use, rather than what could possibly be made work. Throwing an error in cases where one of the answer could be given can often be good for catching errors.

---

<div class="post-metadata">

**Author:** ![pauljurczak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauljurczak/32/921_2.png) [@pauljurczak](https://discourse.julialang.org/u/pauljurczak)\
**Post date:** [May 22, 2020, 11:35pm UTC](https://discourse.julialang.org/t/something-about-nothing/40001/3 "2020-05-22T23:35:17Z")

</div>

> [@yuyichao](#):
>
> What’s logically incorrect

a \<= b is equivalent to a \< b or a == b, therefore `nothing <= nothing` should be true. Not a big problem, though. I understand that it would be a bit cumbersome to implement.

---

<div class="post-metadata">

**Author:** ![kevinczimmerman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevinczimmerman/32/13040_2.png) [@kevinczimmerman](https://discourse.julialang.org/u/kevinczimmerman)\
**Post date:** [May 22, 2020, 11:51pm UTC](https://discourse.julialang.org/t/something-about-nothing/40001/4 "2020-05-22T23:51:55Z")

</div>

Let’s just go with this,

> [@pauljurczak](#):
>
> equivalent to a \< b or a == b

The problem still exists, the error says

> ERROR: MethodError: no method matching isless(::Nothing, ::Nothing)

The first condition cannot be evaluated.

---

<div class="post-metadata">

**Author:** ![pauljurczak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauljurczak/32/921_2.png) [@pauljurczak](https://discourse.julialang.org/u/pauljurczak)\
**Post date:** [May 22, 2020, 11:58pm UTC](https://discourse.julialang.org/t/something-about-nothing/40001/5 "2020-05-22T23:58:20Z")

</div>

Yes, that’s why I wrote I understand the source of this error. A fix is to implement `isless(::Nothing, ::Nothing)`, which returns `false`.

---

<div class="post-metadata">

**Author:** ![kevinczimmerman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevinczimmerman/32/13040_2.png) [@kevinczimmerman](https://discourse.julialang.org/u/kevinczimmerman)\
**Post date:** [May 23, 2020, 12:03am UTC](https://discourse.julialang.org/t/something-about-nothing/40001/6 "2020-05-23T00:03:35Z")

</div>

Ah yes. I am sorry that I missed that part. Since I wrote that I’ve continued to think about it. Yeah, it’s interesting that you can define equality for any thing you want but it doesn’t necessarily imply that it should be able to be ordered. I guess maybe that’s the point that @yuyichao was making.

---

<div class="post-metadata">

**Author:** ![pauljurczak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauljurczak/32/921_2.png) [@pauljurczak](https://discourse.julialang.org/u/pauljurczak)\
**Post date:** [May 23, 2020, 12:10am UTC](https://discourse.julialang.org/t/something-about-nothing/40001/7 "2020-05-23T00:10:05Z")

</div>

Except in this case we have a type `Nothing` with only one element `nothing`, if I understand correctly. For degenerate case like this, `<`, `>` can always return `false`. Multiple dispatch could be used to define it this way for single element types.

Another option is to apply equality test first, before ordering test in operators like `<=` or `>=`.

---

<div class="post-metadata">

**Author:** ![johnmyleswhite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnmyleswhite/32/31_2.png) [@johnmyleswhite](https://discourse.julialang.org/u/johnmyleswhite)\
**Post date:** [May 23, 2020, 12:24am UTC](https://discourse.julialang.org/t/something-about-nothing/40001/8 "2020-05-23T00:24:36Z")

</div>

Probably worth reading this Wikipedia article and then explaining why you want Nothing to be ordinal rather than nominal: [Level of measurement - Wikipedia](https://en.wikipedia.org/wiki/Level_of_measurement)

---

<div class="post-metadata">

**Author:** ![pauljurczak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauljurczak/32/921_2.png) [@pauljurczak](https://discourse.julialang.org/u/pauljurczak)\
**Post date:** [May 23, 2020, 12:36am UTC](https://discourse.julialang.org/t/something-about-nothing/40001/9 "2020-05-23T00:36:21Z")

</div>

I think the problem is orthogonal to ordinal/nominal dichotomy. The set has only one element, which is equal to itself and ordering can’t be defined on such a set. So it is a degenerate case of nominal, if you have to use this classification. The way `<=` is implemented now, is equivalent to: (is equal and the type is ordered) or is smaller. I prefer the simpler: is equal or is smaller.

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [May 23, 2020, 1:02am UTC](https://discourse.julialang.org/t/something-about-nothing/40001/10 "2020-05-23T01:02:38Z")

</div>

Curious as to what you’d have to say about this case:

```julia
julia> 1 + im == 1 + im
true

julia> 1 + im <= 1 + im
ERROR: MethodError: no method matching isless(::Complex{Int64}, ::Complex{Int64})

```

I think that the programmer typing `<=` implies that they believe that ordering is defined for the types on which they’re operating.

This leads me to believe that throwing a method error here is good. It serves the purpose of catching bugs or misconceptions that the programmer may have.

* * *

Another way of phrasing it would be this:

You claim that it’s logically correct to say that

> [@pauljurczak](#):
>
> a \<= b is equivalent to a \< b or a == b, therefore `nothing <= nothing` should be true.

but I think you gloss over something important. `a < b` is _undefined_ in this case. It’s **not** that

```julia
(a < b) == false

```

it’s that `a < b` is a statement without meaning, so claiming that

```julia
(nothing < nothing) or (nothing == nothing)

```

should evaluate to `true` is wrong, in my opinion because

```julia
undefined or true

```

is _not_ the same thing as `true`.

---

<div class="post-metadata">

**Author:** ![pauljurczak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauljurczak/32/921_2.png) [@pauljurczak](https://discourse.julialang.org/u/pauljurczak)\
**Post date:** [May 23, 2020, 2:30am UTC](https://discourse.julialang.org/t/something-about-nothing/40001/11 "2020-05-23T02:30:09Z")

</div>

> [@Mason](#):
>
> This leads me to believe that throwing a method error here is good. It serves the purpose of catching bugs or misconceptions that the programmer may have.

That’s probably the best justification of having it as is. I was trying to find a compelling case where it would be really useful and I couldn’t find any.

---

<div class="post-metadata">

**Author:** ![pauljurczak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauljurczak/32/921_2.png) [@pauljurczak](https://discourse.julialang.org/u/pauljurczak)\
**Post date:** [May 23, 2020, 2:42am UTC](https://discourse.julialang.org/t/something-about-nothing/40001/12 "2020-05-23T02:42:16Z")

</div>

> [@Mason](#):
>
> you gloss over something important. `a < b` is _undefined_ in this case

I paid attention to this. My suggestion relied on a property of single element sets, which are strictly totally ordered ([Total order - Wikipedia](https://en.wikipedia.org/wiki/Total_order)).

---

<div class="post-metadata">

**Author:** ![Ian\_Slagle](https://avatars.discourse-cdn.com/v4/letter/i/b5a626/32.png) [@Ian\_Slagle](https://discourse.julialang.org/u/Ian_Slagle)\
**Post date:** [May 23, 2020, 2:42am UTC](https://discourse.julialang.org/t/something-about-nothing/40001/13 "2020-05-23T02:42:43Z")

</div>

I wonder if this is the reason `<=` goes to `(x < y) | (x == y)` rather than `(x == y) | (x < y)`, since I would imagine (perhaps falsely), that equality is implemented for more types than comparators?

But (and maybe I’m missing something here, perhaps in the distinction between missing/undefined), it seems that the three-valued logic implicit in using `|` there, isn’t the same as what’s indicated here:

> [@Mason](#):
>
> should evaluate to `true` is wrong, in my opinion because
> 
> ```julia
> undefined or true
> 
> ```
> 
> is _not_ the same thing as `true` .

because `missing | true` returns `true`

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [May 23, 2020, 2:54am UTC](https://discourse.julialang.org/t/something-about-nothing/40001/14 "2020-05-23T02:54:39Z")

</div>

> [@Ian\_Slagle](#):
>
> But (and maybe I’m missing something here, perhaps in the distinction between missing/undefined), it seems that the three-valued logic implicit in using `|` there, isn’t the same as what’s indicated here:

Right, I purposefully wrote `undefined` there rather than `missing`, which is meant for cases where you could imagine that there is a valid value, but that value is missing. That is not what’s going on here, and the Julia object which best represents the point I was trying to make would be `MethodError`, because an operation `<` was applied to types for which it is not defined.

However, Paul’s point about total order for a singleton set is well taken, though we agree it does not appear to be useful in practice.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 23, 2020, 7:26am UTC](https://discourse.julialang.org/t/something-about-nothing/40001/15 "2020-05-23T07:26:36Z")

</div>

> [@pauljurczak](#):
>
> My suggestion relied on a property of single element sets, which are strictly totally ordered

I am wondering what practical application you imagine for ordering singleton sets.

Also, a lot of methods for `::Nothing` are undefined _on purpose_. The implicit message is that if you want it to behave like a number (to a certain extent), you should really be using `missing`. `MethodError`s in this context are a feature, not a bug.

---

<div class="post-metadata">

**Author:** ![pauljurczak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauljurczak/32/921_2.png) [@pauljurczak](https://discourse.julialang.org/u/pauljurczak)\
**Post date:** [May 23, 2020, 2:17pm UTC](https://discourse.julialang.org/t/something-about-nothing/40001/16 "2020-05-23T14:17:02Z")

</div>

As I wrote earlier, I don’t see a compelling application. The best I could find is a case of vectors with elements of ordered type or `nothing`. Such vectors would be conveniently comparable even if elements at the same index happen to be `nothing`. There are of course dangers of such approach.

I’m not proposing anything in this post. I’m just learning a new language and this was something I wanted to find more about.

---

<div class="post-metadata">

**Author:** ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)\
**Post date:** [May 23, 2020, 2:44pm UTC](https://discourse.julialang.org/t/something-about-nothing/40001/17 "2020-05-23T14:44:40Z")

</div>

> [@pauljurczak](#):
>
> The best I could find is a case of vectors with elements of ordered type or `nothing` . Such vectors would be conveniently comparable even if elements at the same index happen to be `nothing`

As others have said, if you end up with this type of vector, there’s a good chance you’re using `nothing` when you should actually be using `missing` (or possibly `NaN` if you’re working with floats). Among the many great discussions on this topic, I put John Miles White’s issue [post here](https://github.com/JuliaLang/julia/pull/19034#issuecomment-255247516) among the top. Might be a bit tough since some of the language (eg Nullable) are out of date, but the whole discussion is great

Edit: wrong link

---

<div class="post-metadata">

**Author:** ![pauljurczak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauljurczak/32/921_2.png) [@pauljurczak](https://discourse.julialang.org/u/pauljurczak)\
**Post date:** [May 23, 2020, 3:58pm UTC](https://discourse.julialang.org/t/something-about-nothing/40001/18 "2020-05-23T15:58:20Z")

</div>

> [@kevbonham](#):
>
> you should actually be using `missing`

It looks more appropriate, but I’m at Chapter 14 and haven’t gotten to that part yet. 😀

---

<div class="post-metadata">

**Author:** ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)\
**Post date:** [May 23, 2020, 5:15pm UTC](https://discourse.julialang.org/t/something-about-nothing/40001/19 "2020-05-23T17:15:01Z")

</div>

Fair enough 🙂. Once you get there, report back and let us know if the behavior of `nothing` makes sense in that context.

I found it challenging at first because a lot of programming languages muddle these different concepts. Coming from python, where an empty list, `Nothing` and `False` could all have the same meaning, I struggled with some programming patterns - “Why not just figure out what I mean, julia?!” But over time I’ve come to really appreciate the separation of these concerns, and the need to be explicit in dealing with the correct type.

---

<div class="post-metadata">

**Author:** ![yha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yha/32/3502_2.png) [@yha](https://discourse.julialang.org/u/yha)\
**Post date:** [May 23, 2020, 7:48pm UTC](https://discourse.julialang.org/t/something-about-nothing/40001/20 "2020-05-23T19:48:44Z")

</div>

> [@pauljurczak](#):
>
> The best I could find is a case of vectors with elements of ordered type or `nothing` . Such vectors would be conveniently comparable even if elements at the same index happen to be `nothing` .

This actually works already, because comparison of vectors only compares the corresponding element’s ordering when they’re not `isequal`.

```julia
julia> [1,nothing,1] < [1,nothing,2]
true

```

[Next page](https://discourse.julialang.org/t/something-about-nothing/40001.md?page=2)
