What's Up, Nick?

A blog for ongoing projects both professional and personal.

6th September 2018 1:42 am

Trying Out Julia

Brave New Jule

It’s been a while. Between work and just working on different things I’ve been studying this little coding language I found out about in this news post called Julia. It’s apparently made to combine the best features of various programming languages like C, Python, Ruby and many others.

I’ve downloaded it and have since been poking at the VERY extensive documentation for the language. This post will be going over what I’ve noticed so far, specifically what I’ve liked.

Typing

The first thing to get out of the way is that, like Python, Julia is dynamically typed. This is always nice for beginners but is sometimes a pain for veteran programmers. And while it’s a pretty petty gripe in this age of modern hi-powered computers at under 300$, the number 44 hardly needs to be an Int64 when it really only needs to be an Int8, but Int64 is the default on my x86 machine.

Workaround?

There’s a feature for specifying type but it only works in the local scope of functions. Functions themselves can also be typed, so they can be forced to return an Int8 or something. The only definitive workaround is to specify the number in binary or hex, in which case Julia will give it the absolute minimum type it needs. Again, with computer hardware having memory measured in gigabytes this isn’t exactly a huge issue. The only problem would be with integer division, though Julia seems to default to float values when doing division.

The more I look into Julia the more I like what I see. There’s a lot of quality of life features, just those little syntax touches you always desperately wanted to be in other languages but they never were. Take the power function: In python, raising one number to the power of another number is done using a built-in function:

Python Power

That’s slightly awkward. Typically when typed out, x to the power of y is just x^y. It’s so simple and you want to type that and for it to work but it absolutely won’t. Julia, on the other hand, actually addresses this tiny detail:

Julia Power

Much easier. It’s such a small thing, but it’s these small things that make a difference towards readability. It’s all about making important operations simple, making this not only easy to learn but also just more compact to use.

For another example, take array operations. Arrays have always been a big deal but they’re even more important now with Neural networks and data mining. Being able to more easily code array operations AND read array operation code is a pretty big deal:

Julia Power

Finally, this is another really minor thing but I love this so much: Like C, strings in Julia are treated as an array of characters. However, unlike C, creating strings isn’t such a huge issue. You can make your string like it’s python, then reference characters like it’s a string array in C. Literally the best of both worlds. I imagine this can be a powerful tool for easier argument parsing.

Julia Power

The last thing I want to note before I go into the test program I had made is the functions in Julia. Typically, when a function is called with parameters then the function essentially creates its own copies of those parameters to use in its scope. The only programming language I can really recall having a way to alter the caller’s variables is in C, using pass-by-reference, ie function(&x, &y). Even then, that’s just the function making a copy of the memory address it can edit directly. Julia is different in that it uses pointers by default, meaning that if you don’t want the caller’s variables changed you have to make explicit copies in the function itself.

To me, this is more intuitive to first-time programmers. After all, it makes more sense that variables passed to a function should be the same variables used within that function. Making explicit copies, in my opinion, enhances readability if it’s sometimes easy to forget functions have their own copies that they use.

With that, I had decided to remake my old Knuth arrow code in Julia. Nothing like programming challenges to break into a new language.:

Julia Power

Comparing to the python code it barely looks any different, so it’s very python-like. Still, the power function is much more straightforward, and the end of every if statement is more clearly defined.

Checking the output in powershell, it’s exactly the same as the python program:

Julia Power

I’m really excited to start playing around with Julia, seeing what else I can do with it. If I have any updates as to projects I start in Julia, I’ll be sure to post about it here. As for the future of Julia…I say it’s looking bright. It’s definitely prioritized readability and usability. It’s even compatible with C code, so it’s looking to be a useful tool, especially in our data-science focused world. Julia just hit v1.0 and I’ll be excited to see what features future updates bring. It might not be 100% ready for widespread use, but I think it makes a pretty good learner’s program even at first glance and it has pretty clear priorities. He’s to seeing what it does!

~Nicko

My Github!

Recent Projects: