Julia
Julia was announced in 2012 by Jeff Bezanson, Stefan Karpinski, Viral Shah and Alan Edelman, and version 1.0 came in 2018. It aims to be as easy as Python or MATLAB and as fast as C, and its hybrid nature centres on one idea: multiple dispatch.
Paradigm: Popular Hybrid Languages
What Makes Julia Special
- Multiple dispatch. A function can have many methods, and Julia picks one using the types of all arguments. This replaces most uses of classes and inheritance.
- Types without methods inside. A
structholds data only. Behaviour lives in functions, so you can add methods to types you did not write. - Fast by compilation. Each method is compiled just in time through LLVM for the concrete types it receives, so ordinary Julia code reaches near C speed.
- Array programming built in. Arrays are central, and a dot turns any function into an element-wise one:
area.(shapes). See array-oriented programming. - Functional habits. Functions are first-class,
mapand comprehensions are common, and macros (@time) let code transform code.
Example: Shapes with multiple dispatch
abstract type Shape end
struct Circle <: Shape; r::Float64; end
struct Rect <: Shape; w::Float64; h::Float64; end
area(c::Circle) = π * c.r^2
area(r::Rect) = r.w * r.h
overlap(a::Circle, b::Circle) = "two circles"
overlap(a::Circle, b::Rect) = "circle and rectangle"
overlap(a::Rect, b::Circle) = overlap(b, a)
overlap(a::Shape, b::Shape) = "generic shapes"
shapes = [Circle(1.0), Rect(2.0, 3.0)]
println(map(area, shapes)) # [3.141592653589793, 6.0]
println(overlap(shapes[1], shapes[2])) # circle and rectangle
println(overlap(shapes[2], shapes[1])) # circle and rectangle
println(overlap(shapes[2], shapes[2])) # generic shapes
println(area.(shapes) .* 2) # [6.283185307179586, 12.0]
How It Works
CircleandRectare plain data types that share the abstract typeShape. Neither has methods inside.areahas two methods. Julia selects the right one from the type of its single argument.overlapdepends on two arguments. A Java-style class would dispatch only on the receiver, so this pair logic would need extra code there.- A rectangle with a rectangle has no specific method, so the more general
(Shape, Shape)one runs. area.(shapes)broadcastsareaover the array, and.* 2doubles each result.
History and Where It Is Used
Julia is used in scientific computing, numerical simulation, optimization, data science and machine learning research. Notable packages include DifferentialEquations.jl, JuMP and Flux. It calls C, Fortran and Python libraries directly, so existing code is reusable. The main cost is start-up and first-call compilation time, which the developers keep reducing. See also the full Julia roadmap on this site.