General Purpose Julia
I decided to use Julia Programming Language after experiencing many issues while trying to write a decent command line app to interact with…
I decided to use Julia Programming Language after experiencing many issues while trying to write a decent command line app to interact with Ycashd. I started off writing in python3 and I have to say python is a great language, but it has many drawbacks. My particular problem: executing shell commands. Julia gets often gets categorized as a data science language, but this is simply not true, Julia is a very powerful general purpose language that is easy to understand, but often poorly documented.
In python3 a shell command goes something like this: subprocess.run(“your_process_here”). You can also use subprocess.popen(), but it’s all basically the same. After many painstaking nights, I was finally able to get [some of] the commands I wanted to run. After this, I experienced two more problems, first dealing with nested dictionaries which come from parsing json data returned by ycashd (when you’re not used to this sort of thing, python is kind of a pain in the butt), and the other, shell=TRUE. According to just about everything ever I’ve read, you are NEVER supposed to use shell=TRUE.
Stuff for Julia kept showing up in my feed and after all my frustration, I decided to try it. I didn’t download the latest binary, I simply opened bash and ran sudo apt-get install julia. I figured, I probably won’t have any users at all, but if I do, installing the default version from Ubuntu’s package manager will be the easiest route for them. As the language has been rapidly growing, this was a mistake, always grab the newest stable build.
So I began writing ycash.jl. It is a simple wrapper for using the full node ycash-cli inside of the REPL (Read-Evaluate-Print-Loop). Out of the box, Julia allows for shell commands in the following syntax:
run(`your_shell_command_here`)
Or if you need the output:
read(`your_shell_command_here`, String).
In python3, this would be:
subprocess.check_output(“your_command_here”) and depending on what you’re doing, (from my experience) this does not always work.
The first command I ran after using Julia’s builtin cd() function:
run(`./ycash-cli z_gettotalbalance`). It worked on the first try at about the same speed of its python equivalent… 1 second-ish?
The real magic starts to show not in the syntax, but after you run any piece of code a second time. The REPL rather than reinterpreting code the second time you run it, compiles it on the first run, and runs it as bytecode afterward. A Julia command will execute around 20 times the speed of the python counterpart the first run!!! After experiencing this, I began to understand their slogan, “Walks like python, runs like C.”
Julia’s package manager, Pkg, is probably the easiest one I have ever dealt with. Pkg.add(“name_of_package”) and boom! You’ve installed a dependency. This makes scripting a cinch. You have a script that uses a few external dependencies? Just write a function:
function build_deps()
Pkg.add(“dep1")
Pkg.add(“dep2")
end
How easy is that? Your script now gives the option to build all dependencies without having to walk the user through a build process because you just automated it! How about adding a non-Julia package to your program?
function build_ycashd()
run(`git clone https://github.com/ycashfoundation/ycash.git`)
cd("ycash")
run(`./zcutil/build.sh -j4`)
end
This code automates the process of building ycashd from source. No looking at setup guides, just set it and forget it.
Julia’s Data Science Stereotype
A lot of people believe that Julia is a language made strictly for data science. These people are wrong.
I think a huge reason for this also has to do with documentation. Documentation in Julia is incredibly sparse and sometimes very cryptic. In fact, can be downright awful. That being said, some of the best Julia documentation comes from people who are in fact Data Scientists. Julia is also evolving at a rapid pace, which means sometimes when you do find a solution written for something written perhaps a year ago, that solution you found on Google might not work in modern Julia. If you are writing Julia code, more often than not, you will be unable to Google your way out of a stuck point, you WILL have to code your way out.
If this is a problem to you, uninstall Julia right now. Julia is like an unfinished, but very liveable house. Sometimes you move in but you’ve still gotta put some drywall up.
Have a look here:
https://julialang.org/downloads/
When you’re finished, click on the older releases. Julia 1.5.4 was released in March of 2021. As of April 2022, the current stable release is 1.7.2. If this rapid development keeps up, I will not be surprised if we wind up with 2.0.0 at some point this year.
For proper comparison, python 3.0 was released in 2008. In October of 2021, python 3.10 was released. Let that sink in a little bit. Is it hard to wrap your head around? This sort of rapid innovation means that even if documentation is there, it could be obsolete in just a few months!


