4 ms·
julia seems to be positioned as a kind of matlab / r replacement. but i'm finding it works very well as a faster python, for the kind of programs i am writing
by andrewcooke 13y ago
julia seems to be positioned as a kind of matlab / r replacement. but i'm finding it works very well as a faster python, for the kind of programs i am writing in my free time (learning about / analysing block ciphers, most recently).
its big idea is multiple dispatch, like clos (oo-lisp) multimethods. where you would define an "underscores" method in python (ie to extend the language for a new class), in julia you define appropriate functions for that type - the cute thing being that the new type doesn't have to be the first parameter.
so, for example, the equivalent of
class Foo:
def __repr__(self):
...
would be
function show(io, f::Foo)
...
end
and the end result is something that has more of a FP flavor than python. it's very appealing.
if you're looking for a "dynamic scripting" language that takes some of the good bits from static typing, and has decent performance, it's worth a try.
- PuercoPop 13y agoI think another big advantage of CLOS that Julia took is that you can dispatch on the type of not just the first argument but on the combination of the types of all the arguments
- StefanKarpinski 13y agoMultiple dispatch is very powerful paradigm and Julia takes it a good bit further even than CLOS. There's a good comparison of Julia and CLOS in terms of parametric types and dispatch in Julia's Wikipedia entry: https://en.wikipedia.org/wiki/Julia_(programming_language)#Language_features https://en.wikipedia.org/wiki/Julia_(programming_language)#L... It also compares with Dylan and Fortress, which are the other major non-research multiple dispatch languages. The unique combination of features that Julia has is 1. a fully dynamic type system (code with type annotations is still dynamically typed) 2. functions are all generic by default, including all the built-ins and operators 3. support for parametric types that you can dispatch on. This combination of features working smoothly together turns out to be very powerful, especially when designed so that you don't have to talk about types except when you want to.
- rcthompson 13y ago> Dylan and Fortress, which are the other major non-research multiple dispatch languages What about R with S4 classes?
- StefanKarpinski 13y agoFair point, although R's multiple dispatch barely counts as a language feature at all, but is really more of a standard add-on library (read on). All S4 is doing is using a hash table keyed by method signatures to look up which function body to call. You don't even need any syntactic support since "defining a generic function" is just a matter of defining a function that does a hash lookup and then applies that function to its arguments. R doesn't provide any syntactic support for adding methods to generics – you literally have to give it a vector of strings of argument class names. Since you can do all of this in any language – even C – it's arguable that multiple dispatch isn't really part of "the R language" at all, but rather "the R system" happens to ship with a standard implementation of hash-based multiple dispatch and a few of the built-in function like "show" and "plot" are defined using it. Due to not being a deep language feature, S4 lacks some crucial abilities. It doesn't support any sort of type hierarchy besides the special "ANY" class. Without the ability to define a type hierarchy and program to abstract types, most of the power of multiple dispatch evaporates. Even though it is technically an implementation detail, I've found that performance is a critical feature for multiple dispatch to really come into its own. R's S4 dispatch has been described as "slower than S3" [1] – and S3 dispatch is not exactly fast. Unless really basic things like + and array indexing can be generic and usably fast, you're not really cooking with gas. [1] http://www.r-project.org/conferences/useR-2004/Keynotes/Leisch.pdf http://www.r-project.org/conferences/useR-2004/Keynotes/Leis...
- rcthompson 13y agoThanks for the explanation. What do you mean by "It doesn't support any sort of type hierarchy"? I've contributed to a package that defines some S4 methods on a base class and relies on that implementation being called on derived classes as well.