# Did Julia community do something to improve its correctness?

**URL:** <https://discourse.julialang.org/t/did-julia-community-do-something-to-improve-its-correctness/102515>\
**Category:** General Usage\
**Created:** [August 5, 2023, 7:16am UTC](https://discourse.julialang.org/t/did-julia-community-do-something-to-improve-its-correctness/102515 "2023-08-05T07:16:42Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [August 5, 2023, 6:28pm UTC](https://discourse.julialang.org/t/did-julia-community-do-something-to-improve-its-correctness/102515/21 "2023-08-05T18:28:44Z")

</div>

Yeah. This one is kind of horrifying.

---

<div class="post-metadata">

**Author:** ![larsh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/larsh/32/51866_2.png) [@larsh](https://discourse.julialang.org/u/larsh)\
**Post date:** [August 5, 2023, 6:32pm UTC](https://discourse.julialang.org/t/did-julia-community-do-something-to-improve-its-correctness/102515/22 "2023-08-05T18:32:47Z")

</div>

> [@ufechner7](#):
>
> The main difference between Matlab and Julia with respect to correctness is that Matlab does not have a public issue tracker…

Matlab (sort of) do have it, it is found here:  
[https://www.mathworks.com/support/bugreports](https://www.mathworks.com/support/bugreports)

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [August 5, 2023, 6:40pm UTC](https://discourse.julialang.org/t/did-julia-community-do-something-to-improve-its-correctness/102515/23 "2023-08-05T18:40:16Z")

</div>

Thanks for adding it to the 1.10 milestone…

---

<div class="post-metadata">

**Author:** ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)\
**Post date:** [August 5, 2023, 6:40pm UTC](https://discourse.julialang.org/t/did-julia-community-do-something-to-improve-its-correctness/102515/24 "2023-08-05T18:40:43Z")

</div>

Thanks for linking all of those, its good to know exactly what people mean in these discussions.

Yes probably there are problems with Julia Base from being both comprehensive and _internally_ composable more than is often possible. Your problem of the reversed filter iteration is again that we can compose too many things together. It would be interesting to know if you can do anything like that at all in other languages.

With your issues with `sum!` etc over aliasing arrays, I think I _assumed_ that or anything like it would break somehow or be undefined. But I can see that this would seem pretty weird if you expected otherwise:

```julia
julia> x = [1, 2, 3]
3-element Vector{Int64}:
 1
 2
 3

julia> sum!(x, x)
3-element Vector{Int64}:
 0
 0
 0

julia> y = [1, 2, 3]
3-element Vector{Int64}:
 1
 2
 3

julia> sum!(x, y)
3-element Vector{Int64}:
 1
 2
 3

```

Given I assumed that wouldn’t work, I wouldn’t personally class it as a huge correctness bug - so I’m not sure how clear the definitions we are using are.

---

<div class="post-metadata">

**Author:** ![Ininterrompue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ininterrompue/32/5594_2.png) [@Ininterrompue](https://discourse.julialang.org/u/Ininterrompue)\
**Post date:** [August 5, 2023, 6:41pm UTC](https://discourse.julialang.org/t/did-julia-community-do-something-to-improve-its-correctness/102515/25 "2023-08-05T18:41:45Z")

</div>

> [@jakobnissen](#):
>
> The cultural shift may be happening, but I don’t really any impact of it yet.

> [@adienes](#):
>
> Undefined behavior exposed to the user open for 3 years, which I had to basically beg to get on the 1.10 milestone and was later removed  
> [`map!` resulting in undefined values · Issue #36235 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/36235)

Within this link:

> “I don’t think it needs to be release blocking, as the bug has been open for years without too many people noticing.”

I appreciate that this specific example adienes linked to is being fixed, but it’s comments like these that do not make me optimistic of a cultural shift.

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [August 5, 2023, 6:55pm UTC](https://discourse.julialang.org/t/did-julia-community-do-something-to-improve-its-correctness/102515/26 "2023-08-05T18:55:57Z")

</div>

> [@Raf](#):
>
> It would be interesting to know if you can do anything like that at all in other languages.

well, no, and that’s the point. I think `reverse(::Filter)` should be entirely removed 🙂 and `reverse(::Zip)` should error unless all of its constituent iterators are known to have the same finite length

---

<div class="post-metadata">

**Author:** ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)\
**Post date:** [August 5, 2023, 7:04pm UTC](https://discourse.julialang.org/t/did-julia-community-do-something-to-improve-its-correctness/102515/27 "2023-08-05T19:04:40Z")

</div>

Totaly. As I was getting at many of these bugs exist because you cant do these things in other languages - and that makes comparisons with other languages difficult.

Its also a problem to fix because removing it is a breaking change, and some people may productively use `reverse(::Filter)` with pure iterators!

As you mentioned we can hope that analysis can catch these at some point, but its hard. Maybe a docs warning is the best we have in the short term.

---

<div class="post-metadata">

**Author:** ![ImreSamu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/imresamu/32/20677_2.png) [@ImreSamu](https://discourse.julialang.org/u/ImreSamu)\
**Post date:** [August 5, 2023, 7:13pm UTC](https://discourse.julialang.org/t/did-julia-community-do-something-to-improve-its-correctness/102515/28 "2023-08-05T19:13:27Z")

</div>

Is there any way to make Julia “bounty” issues ( ~related to correctness ) more visible to the community?

- Where can I contribute to support a particular JuliaLang issue bounty?
  - adding my 10 - 100 - … $

- Where can I see the existing bounties?
- Is it possible to integrate with Github issues? For example, can we create a **“Bounty”** label ( in the [JuliaLang/julia](https://github.com/JuliaLang/julia) repo ) to highlight its importance?

For reference, “bounty” based development is emphasized in the tinygrad repository - as a “bounty-locked” label:

- [Pull requests · tinygrad/tinygrad · GitHub](https://github.com/tinygrad/tinygrad/pulls?q=is%3Apr+is%3Aopen+label%3A%22bounty+locked%22)

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [August 5, 2023, 7:32pm UTC](https://discourse.julialang.org/t/did-julia-community-do-something-to-improve-its-correctness/102515/29 "2023-08-05T19:32:21Z")

</div>

> [@Raf](#):
>
> Totaly. As I was getting at many of these bugs exist because you cant do these things in other languages - and that makes comparisons with other languages difficult.

I mean, that seems like a totally unholdable claim. Nothing about “lazy filtering object” is unique to Julia, so why should it not be possible or be difficult to do in another language? To be quite honest, this just sounds like dodging the issue of “we didn’t think about that failure case” (which I take to be the core issue Yuri was originally getting at - undocumented/unexpected but quite obvious failure & edge cases).

> [@Raf](#):
>
> Its also a problem to fix because removing it is a breaking change, and some people may productively use `reverse(::Filter)` with pure iterators!

The Julia semver stability guarantee has pretty much always been “if it’s in the manual, it’s API”. I’d be VERY surprised if this thing actually existing was guaranteed. That doesn’t change the fact that people may expect it to exist, but that’s precisely the issue - what _is_ actually part of semver and supposed to work is not at all well defined in Julia today, leading to the sorts of correctness issues/unexpected bugs that people complain about all the time (rightly so!).

> [@Raf](#):
>
> As you mentioned we can hope that analysis can catch these at some point, but its hard. Maybe a docs warning is the best we have in the short term.

No amount of static analysis can compensate for a lack of documentation of core functionality, or contradicting documentation about semantics in type hierarchies.

- [Document memory model of Per-field atomics · Issue #46739 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/46739)
- [`Ptr` doesn't observe the supertype semantics of `Ref` · Issue #49004 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/49004)
- [Properly crash/report error when writing to full filesystem · Issue #44535 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/44535)
- [Document the behavior of `lastindex([])` · Issue #42998 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/42998)

and these are just some of the ones I personally filed. I’m not in the habit of keeping a list of these kinds of issues, but I do try to file them when I stumble across them.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [August 5, 2023, 7:38pm UTC](https://discourse.julialang.org/t/did-julia-community-do-something-to-improve-its-correctness/102515/30 "2023-08-05T19:38:13Z")

</div>

> [@adienes](#):
>
> I can conclude, though, that ModelingToolkit must not be depending on the correctness of reverse iterators or aliasing `map!`-like functions!

Yup, and that’s easy to audit:

[https://github.com/search?q=org%3ASciML+sum!&type=code](https://github.com/search?q=org%3ASciML+sum%21&type=code)

[https://github.com/search?q=org%3ASciML+prod!&type=code](https://github.com/search?q=org%3ASciML+prod%21&type=code)

[https://github.com/search?q=org%3ASciML+map!&type=code](https://github.com/search?q=org%3ASciML+map%21&type=code)

All of our `sum!`, `prod!` (not even used), and `map!` look fine. And the uses of `reverse!` are on Array or Tuple with no Filter, so that seems fine.

[https://github.com/search?q=org%3ASciML+reverse&type=code&p=1](https://github.com/search?q=org%3ASciML+reverse&type=code&p=1)

Of course it should be improved anyways, but this is why I object to the phrase of “packages”. This shows about \>100 of some of the most used packages in Julia do not touch the aforementioned issues. `prod!` doesn’t even show up in the source code. One should qualify what exactly is the issue in every instance, because many areas of Julia are doing fundamentally different things.

But not only that, qualifying what exactly is the issue is a constructive way to help get it fixed.

> [@adienes](#):
>
> BUT, of the bugs in my Python or C++ code, the chance that it is an issue with the language itself is usually negligible, and it is almost always user-error. This is something that can be caught via peer review (or just self-review). When the language itself has a bug, reviews are not as effective a safeguard, as both sets of eyes might expect the same (correct) behavior, and it can take a very long time to realize what has actually gone wrong.

This is because those languages don’t include their major math libraries. numpy and PETSc have all sort of bugs and you hear about them during conference talks all of the time. The large the support surface the longer it takes to stabilize. Python is in a particularly weird position where its standard libraries tend to be so gimped that people tend to use many standard library replacements, which tend to be less supported and have quite a few bugs, and so I’m not sure how that’s any better.

> **[PEP 594 – Removing dead batteries from the standard library | peps.python.org](https://peps.python.org/pep-0594/)**
>
> Python Enhancement Proposals (PEPs)

Notably, the built in password and login libraries in Python are known to have security issues so they aren’t recommended and it’s been this way since 2008 or something like that. You’re taught as a beginning user to just avoid those modules, so therefore it’s safe? 🤷 So people will define Python as safe by simply moving the boundary to not include those modules (which may end of life in 2028). Julia just has a different looking standard library since it’s historically been focused towards different developers, but in just the same way as you go further into the weeds you’ll find things less supported.

The larger the surface, the more there is to do.

---

<div class="post-metadata">

**Author:** ![bertschi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bertschi/32/33462_2.png) [@bertschi](https://discourse.julialang.org/u/bertschi)\
**Post date:** [August 5, 2023, 7:44pm UTC](https://discourse.julialang.org/t/did-julia-community-do-something-to-improve-its-correctness/102515/31 "2023-08-05T19:44:54Z")

</div>

Maybe I just got used to such quirks in dynamic languages, as all of them seem to have issues where silently wrong results can be returned. Here one example from R and Python each, that had bitten me in the past:

- **R** : Recycling of vectors with non-matching length
- **Python** : Before numpy made the switch to `@`, it had `W * x` mean matrix multiplication when `W` is a `Matrix`, but element-wise multiplication when `W` is an `Array`.

Just for fun, I checked the reverse filter example using `std::ranges` in C++20. Using the stateful predicate it compiles fine and then segfaults.There are very few compilers out there that warn about impure functions – mainly Haskell and some experimental effect systems. Basically, I only trust the Haskell compiler to a good extend (have not tried Rust though) – C++ is a lost case (compiled or not).

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [August 5, 2023, 7:48pm UTC](https://discourse.julialang.org/t/did-julia-community-do-something-to-improve-its-correctness/102515/32 "2023-08-05T19:48:21Z")

</div>

> [@bertschi](#):
>
> it compiles fine and then segfaults

that’s interesting, thanks for trying it! still, I would prefer a (loud) segfault over getting the wrong answer

---

<div class="post-metadata">

**Author:** ![bertschi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bertschi/32/33462_2.png) [@bertschi](https://discourse.julialang.org/u/bertschi)\
**Post date:** [August 5, 2023, 7:56pm UTC](https://discourse.julialang.org/t/did-julia-community-do-something-to-improve-its-correctness/102515/33 "2023-08-05T19:56:51Z")

</div>

Me too, but unfortunately we don’t always get it. At least in my experience, Julia has not been worse than other dynamic languages in that regard.  
I’m not saying these issues should not be fixed though … the less quirks and corner cases the better. Not just for that reason, I like the principled approach of Haskell stating laws that have to hold for its generic types, i.e., type classes. Guess that also Julia could benefit if required properties of its implicit interfaces could be easily tested, e.g., using [PropCheck](https://github.com/Seelengrab/PropCheck.jl) or something similar.

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [August 5, 2023, 8:11pm UTC](https://discourse.julialang.org/t/did-julia-community-do-something-to-improve-its-correctness/102515/34 "2023-08-05T20:11:32Z")

</div>

> [@bertschi](#):
>
> Maybe I just got used to such quirks in dynamic languages, as all of them seem to have issues where silently wrong results can be returned. Here one example from R and Python each, that had bitten me in the past:
> 
> - **R** : Recycling of vectors with non-matching length

That’s an API quirk, not a correctness bug – R is designed to do that intentionally. The Julia examples like `reverse(zip(` are incorrect implementations of [documented behavior](https://github.com/JuliaLang/julia/issues/25583#issuecomment-1635017695). Having a compiler check the documented assumptions is a nice feature but it’s not very useful if the implementation assumptions aren’t actually part of the documented interface in the first place.

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [August 5, 2023, 8:30pm UTC](https://discourse.julialang.org/t/did-julia-community-do-something-to-improve-its-correctness/102515/35 "2023-08-05T20:30:38Z")

</div>

The problem with the topic of Julia and correctness was how it lumped many issues with varying degrees of relevance into One Thing newcomers have to consider. It’s not. Newcomers care about whether they can write practical code that gives the correct results; yes they can, which is why we get more of the subsequent questions of “how do I optimize this”. Newcomers care about whether they can pick up packages that work properly; yes they can, and like any other language it depends on how actively maintained the package is.

It’s not particularly helpful for newcomers to be bombarded by bugs in corner cases or composition with little-used packages. For example, while I do agree that aliasing should be handled instead of silent, we know not to alias with reducing operations _in practice_, and we would never reduce over none of the dimensions, specifically `sum!(copy(a), a)` gives the same result as `sum(a;dims=())` or `copy(a)`. This is irrelevant to a newcomer who wants to Do Something. I get that people can be frustrated by problems in areas with little attention or demand, but that’s an issue for any language and it shouldn’t be a reason to avoid a language that is proven useful.

---

<div class="post-metadata">

**Author:** ![bertschi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bertschi/32/33462_2.png) [@bertschi](https://discourse.julialang.org/u/bertschi)\
**Post date:** [August 5, 2023, 8:31pm UTC](https://discourse.julialang.org/t/did-julia-community-do-something-to-improve-its-correctness/102515/36 "2023-08-05T20:31:21Z")

</div>

> [@jar1](#):
>
> That’s an API quirk, not a correctness bug – R is designed to do that intentionally.

Technically correct, but it has a similar effect to program rather defensively when using it.

> [@jar1](#):
>
> The Julia examples like `reverse(zip(` are incorrect implementations of [documented behavior](https://github.com/JuliaLang/julia/issues/25583#issuecomment-1635017695). Having a compiler check the documented assumptions is a nice feature but it’s not very useful if the implementation assumptions aren’t actually part of the documented interface in the first place.

`reverse(zip(` I would also expect to work. `filter` with an impure predicate probably not, but it does not seem to be documented what can be assumed in that case.

---

<div class="post-metadata">

**Author:** ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)\
**Post date:** [August 5, 2023, 9:26pm UTC](https://discourse.julialang.org/t/did-julia-community-do-something-to-improve-its-correctness/102515/37 "2023-08-05T21:26:26Z")

</div>

If you look at the example in the issue, the mutable functor in question is user-defined:

> <https://github.com/JuliaLang/julia/issues/50440>
>
> From docstring of \`reverse\` 
> \> \`reverse(itr)\` is an iterator over the
> same col…lection but in the reverse order.
> 
> yet consider
> \`\`\`
> julia\> mutable struct RollingMax
> m
> end
> 
> julia\> function (rm::RollingMax)(x)
> if x \> rm.m
> rm.m = x
> return true
> else
> return false
> end
> end
> 
> julia\> arr = rand(10);
> 
> julia\> Iterators.filter(RollingMax(0), arr) |\> collect
> 5-element Vector{Float64}:
> 0.20543016348395104
> 0.40777744342276
> 0.6118207748963927
> 0.6765659450947831
> 0.8719846507332757
> 
> julia\> Iterators.filter(RollingMax(0), arr) |\> Iterators.reverse |\> collect
> 2-element Vector{Float64}:
> 0.839252025474182
> 0.8719846507332757
> \`\`\`
> 
> personally I think \`reverse(f::Filter)\` should just be removed; it cannot be implemented correctly without knowing the purity of the predicate. another option is to add a warning in the docs? or maybe a third option is to somehow dispatch \`reverse\` only when \`flt\` can be proven pure---not sure how this is technically possible though.

And passed into `Iterators.filter` and `Iterators.reverse`.

As I’ve mentioned above statements like “seems like a totally unholdable claim” don’t help this conversation… we do actually want to know in what language you can both

1. do that easily  
and
2. it correctly handles the distinction between a pure function and an impure function

Then we have a clear comparison to make, and maybe something to learn from

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [August 5, 2023, 9:35pm UTC](https://discourse.julialang.org/t/did-julia-community-do-something-to-improve-its-correctness/102515/38 "2023-08-05T21:35:43Z")

</div>

> [@adienes](#):
>
> I think `reverse(::Filter)` should be entirely removed 🙂

I thought that the thing with composability was that `reverse(filter(...))` would work _without_ there being any explicit such method.

So either this particular example is not a composability issue, or you can’t really remove this, except by writing a method saying it’s not implemented (oh, and do those cause the most deliciously discombobulating error messages).

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [August 7, 2023, 3:39am UTC](https://discourse.julialang.org/t/did-julia-community-do-something-to-improve-its-correctness/102515/39 "2023-08-07T03:39:39Z")

</div>

Split this topic on August 7, 2023, 3:39am UTC

45 posts were split to a new topic: [On the behavior of reversed iterators](https://discourse.julialang.org/t/on-the-behavior-of-reversed-iterators/102543)

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [August 6, 2023, 10:27pm UTC](https://discourse.julialang.org/t/did-julia-community-do-something-to-improve-its-correctness/102515/85 "2023-08-06T22:27:33Z")

</div>

This is becoming a post on `reverse`, perhaps this post should be split?

[Previous page](https://discourse.julialang.org/t/did-julia-community-do-something-to-improve-its-correctness/102515.md?page=1)

[Next page](https://discourse.julialang.org/t/did-julia-community-do-something-to-improve-its-correctness/102515.md?page=3)
