Did Julia community do something to improve its correctness?

Yes, of course:

julia> function sum!(a,b)
           for i in eachindex(a,b)
               a[i] = a[i] + b[i]
           end
           return a
       end
sum! (generic function with 1 method)

julia> x = [1,2,3];

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

At the same time, I also think that the importance of such an issue is overrated. Anyone really uses a mutating function like that without checking the result?

Important libraries like numpy and other are full of gotchas, and while I think that bug should be fixed in a good way (not only by documentation), I find hardly believable that someone writing some complex math and working out performance tuning (to arrive at trying to use this) would have a program with a hidden bug like that.

By the way, can someone explain this?

In [1]: import numpy as np

In [2]: a = np.array([1,2,3])

In [3]: sum(a,a)
Out[3]: array([7, 8, 9])

Seems that sum is not intended to sum two arrays (one thing is the array being summed, the other I didn’t understand from the documentation. Fair enough, but I think it makes my point: I do not trust my intuition about what a function should do… not here, not with any other language.

8 Likes