What language are Julia packages written in?

What language are Julia packages written in ?

Julia

13 Likes

Welcome @Kronos! To elaborate a bit on what @jling said, almost all Julia packages are written in Julia. This is one of the biggest strengths of the language: because it is so performant, there is no divide between the user-friendly scripting language and its “under the hood” implementation (as there is with Python/C). You can easily find your favorite packages on GitHub and read the source code, which is actually a great way to learn Julia programming techniques and best practices.

25 Likes

To add another data point here, I was able to contribute to Julia’s source code within only a few months of learning Julia. I programmed in Python for years before switching to Julia. Never was able to add functionality to Python or Python packages.

Either way, welcome to the community @Kronos ! :wave:

8 Likes

Well, this is not exactly true. I don’t have a statistic, but there are also many packages that are wrappers for C++ and Fortran libraries, e.g. QML.jl or Gtk.jl or Dierckx.jl.

But new packages for Julia are usually written in Julia which is different from Python where you have to write packages that shall be fast in C++ or Fortran because they will be slow if you write them in Python.

1 Like

Even wrapper packages could only include Julia code that invokes the other library via ccall or similar.

That’s pretty tautological, and the same would be true for nearly every language.

I don’t think that that is true. Maybe I wasn’t clear. If I want to call a C library from Go, then I have to write the wrapper code in C as cgo comments. AFAIK, Lua has no ccall equivalent and a wrapper requires actual new C code. When I used Java, when I created wrappers I had to write new C code using the JNI interface. I’m unaware of the state of Python lately, but it used to require wrapper C code, but that could be done with SWIG.

1 Like

Oh interesting! Thanks for all the counterexamples. Sure enough, my knowledge here is cursory at best.

So then what are the languages with native interop facilities? I think R?

1 Like

I used to use Jython from a Java application. Because Jython was written in Java, the Python code could access any Java class in the application without any special wrappers as long as the ClassLoader permitted that access. I think other JVM languages, such as Groovy, JRuby, and Clojure, have similar capabilities.

1 Like

Even if you have an analogue of ccall (e.g. Python ctypes or Lua FFI), in other dynamic languages you often have to write “vectorized” wrappers in a lower-level language for performance reasons, because fine-grained calls are too expensive.

For example, my earliest contribution to Julia was to interface my C library for complex erf-related functions. I had already written interfaces to this code from Matlab, Python, Octave, and Scilab, so I figured I might as well write glue for the weird language from the guy down the hall from me. Because these are special functions that take a single scalar in and return a single scalar out, however, in all the other languages I had to implement a low-level “vectorized” interface in C, to apply the function elementwise to a whole array of numbers at once, as otherwise it would be impossible to use efficiently. I was delighted to learn that, in Julia, I could implement a zero-overhead interface with only a single line of Julia code (per C function), and I could even wrap multiple functions at once with an @eval metaprogramming loop.

19 Likes

Interesting. FWIW, LuaJIT is an alternative implementation of Lua, not the original from PUC Rio.

Thank you :slight_smile:

1 Like