News for hackers. Stuff that matters.
Re:Calculus with Julia by FabHK on Saturday May 18, 2024 @11:07PM (#40403910)
I used to miss "OOP" in Julia. The funny thing about the dot notation is that it makes the limitations of single dispatch seem natural. Once you get used to multiple dispatch and its benefits, the dot notation seems limiting.

`x.plus(y)` dispatches based on (runtime) type of x (polymorphism) (single dispatch), and might call different functions based on the (compile time) type of y (function overloading)

In Julia, it would be `plus(x, y)`, and it can dispatch based on the runtime type of both x and y (or determine the correct method to call at compile time already, if the types of x and y can be determined then).

Re:Calculus with Julia by adastra22 on Sunday May 19, 2024 @03:09AM (#40404878)
Virtual method dispatch isn’t always a good thing though. It’s a tradeoff and typically you really want one or the other. C++ makes both available for that reason, although C++’s syntax is horrible.
Re:Calculus with Julia by jakobnissen on Sunday May 19, 2024 @04:26AM (#40405290)
It's multiple dispatch though, not virtual dispatch. If I understand correctly, virtual dispatch means the method is picked at runtime. In Julia, the compiler is able to pick the correct method at compile time, even when dispatching on all arguments of the function.
Re:Calculus with Julia by samatman on Sunday May 19, 2024 @09:53AM (#40406982)
This is correct, but it's important to realize that compile time continues during runtime.

Julia's execution model is quite distinctive, and it does take a thorough understanding of how it plays out to get native-code speeds out of it.