by xiphias2 · 5y ago · 0 comments
I think that Union types do more harm than good (why would you want a function to return Union of int and float instead of compile error? It totally slows down the program)
Array{Number} is totally different from Array{:<Number}, and shouldn’t be allowed, as it is inefficient.
1-based indexing was a mistake, and I have seen it emitting inefficient code in the PTX compiler.
But the worst and hardest part is the rule/heuristic for multiple dispatch: it’s so complex, that it isn’t even documented. It should probably throw more errors and be predictable instead of trying to be so smart.
The most software I write, the more I am convinced that 1-based indexing is what most languages should be using, either the exception being the very specific use-case of needing to track offsets by hand for some reason. 1-based indexing is so much easier to reason about, but zero based indexing is seen as “the one true way” due its ubiquity, and not because it’s actually better.
> and I have seen it emitting inefficient code in the PTX compiler.
Have you raised this with the devs? This seems like something worth raising as an issue.
In Julia, this will pick a random value from an array: rand([3, 4, 5, 1])
While this picks a value from a range: rand(1:10)
Much more straightforward to read IMHO. Where I prefer 0-based index is when dealing with coordinate systems and memory locations.
What's wrong with rand(a)?
At the same time if you look at TIOBE, 0 based indexing won.
The biggest problem for me was porting numerical code from Ruby: the syntax is so similar to Julia, that I didn’t have much to do, but porting 0 based code to 1 based was the biggest work actually.
I’m sure it’s painful to port code from R or Marlab if it’s 0 based, but that will need to happen anyways.
Though for intentional uses of unions, most of the time I use a union of a success type or an error type, or a union of a type and null, or a union of type and missing. They could all be special cases, but I don't see the point of not being just one mechanism.
In a language without union types, you'd just have two fields for both cases, and you'd have to check everywhere that you're handling both cases and that you can't get into broken situations where both or neither fields are set. Union types give you peace of mind there.
If your type system has a different way of turning one type into two different (but isomorphic) types (for example by wrapping them in records with a single field), you can simulate sum types with union types. Hence union types are more general than sum types.
However, in my experience you (almost?) always want sum types anyways. In this case union types being the basic construction tends to be a disadvantage because the basic construct it usually more convenient and therefore gets used. Union types tend to work fine for a while and once you realize that sum types would be better, you have quite a bit of refactoring to do.
I understand why this is the case and I don't have an issue generally with it, but considering that I know Python well, and know how to speed up Python using numba, pythran or cython, I don't see what I would gain by investing in Julia.
Instead I've now decided to learn Rust, as it fills a different niche and I can use it for writing python modules for some of my bottleneck code.
Plus, I think people forget that Python now works pretty well on Windows, and I don't think the same can be necessarily said for Julia. In my University, we support a lot of people on Windows with Python packages - particularly outside of traditonally HPC type areas.
As a final thing - on one occasion last year, I tried to integrate a Julia interpreter into an application - something Python does really well on all platforms. I found that copying the code from the website example verbatim did not work on Windows, didn't appear to have done for the best part of a year, and wasn't in the testing framework. I've just checked and it's still not resolved.
As far as your comment about “awkwardness”, the key point for me was when I actually started to understand/embrace multiple dispatch as a programming paradigm. If you try to write Julia like in a an imperative or oo or etc. style, it may work, but will be clunky and quite possibly full of type instabilities. But if you write Julia in a “dispatch-oriented” paradigm then it really is just as performant and elegant as advertised, IMO.
I think Swift with the best bits of Julia would be the perfect general purpose language.
Some people think multiple dispatch is a killer feature but in langauges like Swift, extensions are a much neater approach.
My issue with python is speed, but I will probably end up implementing what I want/need in rust and call that from python.
Like what?
> or the huge bottleneck of unpacking (star operator in python)
In what sense is unpacking a bottleneck?
That happens because it gets splatted into a tuple with N elements, which in Julia has a type parameter for every element - i.e. a generic type Tuple{N1, N2, N3 ... N} with as many type parameters as there are elements in the iterable. And the compiler has a hard time working with an instance of a type with e.g. 10,000 parameters.
@time v = [(1:10_000)...]; -> 0.000639 seconds
f(args...) = sum(args)
@time f(v...); -> 0.001039 secondsPerformance wise, I can't recall the exact scenario though.
Rest of this I disagree with, but this one I just don't understand. Why is it wrong that it's totally different?
Edit: missed a word which changed the meaning of my question
There is a distinction, because e.g. `Array{Int32}` is a subtype of the latter, but not the former (because the former is a concrete types that does not have subtypes).
Array{:<Number} is when LLVM gets the exact type at compile time and can optimize the code using SSE instructions.
You have a factor of 10 between execution, and if you are not experienced, you don't understand why your code is slow and why the garbage collector kicks in so hard.