Ironman of Languages
If we draw parallel of many popular programming languages to a character in the fictional Marvel universe, Julia will map to Iron Man. In this dispatch we are intended to entertain you with an introduction to the Julia as programming language. We will not waste space, lines and words in pitching the case for the language. You can read well curated articles, blogs, (watch) videos (seriously what is wrong with modern day developers!), guide and tutorials to get the authoritative list of capabilities of Julia. Instead, we get cracking right away not with fun part of the language.
Unicode names
Language as a topic for developers is far to the right in the boring scale. However, we classify it as fun! As you grow to spend more time writing code, language occupies the centre stage. Writing requirements, communicating constraints, decisions and many other aspects of developer’s life. Now you could create Unicode variables in many programming languages. However, in Julia you can use mathematical symbols.
julia > δ = 0.00005
Where “δ” is an infinitesimally small value to use typically as error margin. Did we break the convention of using “ε” for it. Well, we did!
If you are thinking, how did we type this as there is no standard key in the keyboard? We used a trick in REPL. You need to use backslash character followed by tab key in the keyboard. This can be used in the Jupyter notebook too.
You can use more wacky variable names from the Unicode character categories. Julia allows you to pick any combination from the category of Lu/Ll/Lt/Lm/Lo/NI(letters), Sc/So/Sm. The next character could be from categories of Nd/No, Mn/Mc/Me/Sk and Pc. Don’t make us explain what those categories mean. Use one of the many LLM’s.
Not just variables, you could define operators, function names almost everything that constitutes a script or program. Have you imagined a program written in your native mother tongue?
Methods and Functions
Does reading “method” and “function” in the same line confuse you? Probably not. You must be used to the fact that a class can have a method and function. So, there is nothing out of the ordinary in having them in the same English sentence. Let us throw you out of the comfortable world of “I know that”, A function has methods!
Yes, you read it right. In Julia a function can have methods. This brings us to the multi-paradigm world of Julia. It is polymorph. You can use it as object oriented with some limitations and as functional language with lot more freedom. It is also imperative, procedural, parallel (massively), data flow processing, and reactive. Thus, Julia is a multi-paradigm programming language. Now back to function having method!
We will not numb your attention with complex examples. Let us stick with simple ones (that apart we are not paid to give complex examples 😉) – Addition. So, we need to add two numbers.
julia> function Base.:+(a::Int32,b::Int32) = a+b
This is just a function. Now what becomes a method is the following –
julia> function Base.:+(a::Float64, b::Float64) = 0.9a + 3b
Now, we have a method that is more than just function. We have method for the function “+” which is essentially an operator. The method specializes the parameter and makes them accept decimal type values and integer type values. Next stop for us is the weird land of object-oriented paradigm.
Constructor
You will not have a class in Julia. But you do get constructor! Yes!! Don’t strap a booster to your attention and wave ta-ta to it yet. Constructor principally are responsible for building complex type and a function that does same thing in Julia is also known as Constructor. So, you do not have a class but a complex type which is supported in Julia.
struct Weather
Temperature
Pressure
Visibility
end
Now, language gives you the default ability of creating constructor. You can invoke it like this –
julia> weather_today = Weather(29, 105, 3)
julia> weather_today.Temperature
29
You get the drift. You can have type constraints that let you guard the creation, like this –
struct Weather
Temperature
Pressure
Visibility
Weather(t,p,v) = t > 50 ? error(“Global warming!!”) : v > 100 ? error(“Are we all superman!!”) : Weather(t,p,v)
end
Next stop is parallel programming
In popular languages say C++, Java, C# (did we raise eyebrows)! you have the concept of in-process communication and out of process communication. In Julia that is pronounced as parallelism. So, when one builds application that uses in-process communication it is essentially riding on threads to achieve parallelism. In C# the async..await is replaced with wait and fetch keywords.
For those applications that spawns processes it is essentially out-process and becomes distributed processing from Julia’s viewpoint. Ughh! distributed for spawning process? Well the idea is new process gets its own memory addresses and thus can be run withing the same core on the computer where you are running the application or in a remote computer on its cores 😊. This is capability is offered via standard Distributed library. This library is characterised by functions like remotecall, macros like @spawnat, and fetch.
Julia fusses about another core concept – Data movement. Assembly level programming from college days would have prepared you with even variable assignment is data movement. However, in Julia, it is the functions like fetch, @spawnat which constitutes data movement.
If you have endured this long, let us give you the reason we picked this language. Modern day business software could benefit a lot my dynamic programming constructs. We are in a phase where building application is not pivotal. What is game changer is to make knowledge available to many and make it easy to work with ever changing dynamics instead of sub-zero minutes continuous integration of complex app. In the scale of business app ecosystems such scenarios do exist where a dynamically typed, multi-paradigm language could help knowledge workers work with knowledge lot quicker than building an app with fancy UI and managing it through lifecycle.
We have only scratched the surface here. We took a non-conventional introduction to Julia for programmers who know their way around programming languages. You can always build upon this using the modern-day knowledge distribution system – Tutorials, Blogs, Documentation and YouTube videos off course!
--
2dInteresting