Book Image

Julia Programming Projects

By : Adrian Salceanu
Book Image

Julia Programming Projects

By: Adrian Salceanu

Overview of this book

Julia is a new programming language that offers a unique combination of performance and productivity. Its powerful features, friendly syntax, and speed are attracting a growing number of adopters from Python, R, and Matlab, effectively raising the bar for modern general and scientific computing. After six years in the making, Julia has reached version 1.0. Now is the perfect time to learn it, due to its large-scale adoption across a wide range of domains, including fintech, biotech, education, and AI. Beginning with an introduction to the language, Julia Programming Projects goes on to illustrate how to analyze the Iris dataset using DataFrames. You will explore functions and the type system, methods, and multiple dispatch while building a web scraper and a web app. Next, you'll delve into machine learning, where you'll build a books recommender system. You will also see how to apply unsupervised machine learning to perform clustering on the San Francisco business database. After metaprogramming, the final chapters will discuss dates and time, time series analysis, visualization, and forecasting. We'll close with package development, documenting, testing and benchmarking. By the end of the book, you will have gained the practical knowledge to build real-world applications in Julia.
Table of Contents (19 chapters)
Title Page
Copyright and Credits
Dedication
About Packt
Contributors
Preface
Index

Choosing an IDE


An IDE is very important when working with a programming language. A powerful source code editor, code completion, and a good linter and debugger can significantly influence the learning curve and the productivity of using a language. You will be happy to learn that there are some very good IDE and editor options for Julia—and chances are you'll find your favorite one among these.

The IDE choices reflect the pragmatism of the language as a whole. From choosing LLVM as the compiler to providing efficient ways for calling functions from other languages, to using git and GitHub to power the package manager, the Julia core team takes a don't reinvent the wheel approach. Following the same line of thinking, the Julia community has built powerful IDEs upon existing industry established editors, such as Atom and Visual Studio Code.

Juno (Atom)

Juno (http://junolab.org) is the most advanced Julia IDE and the de facto editor of choice for Julia professionals. It is based on the Atom editor and it can be considered the official development tool, being also distributed with the previously mentioned JuliaPro distribution.

To get it, either download and install JuliaPro from https://juliacomputing.com/products/juliapro.htmlor do a manual install of Atom and the required plugins.

If you choose the manual install, first you need to download Atom from https://atom.io. Once it's up and running, go to the Settings pane (you can use the shortcut Ctrl/cmd and ,) and then go to the Install panel. Type uber-juno into the search box and press Enter. Next, click the install button on the package with the same name. Atom will pick it up from here, installing all the required Atom and Julia packages.

Once configured, the IDE options will be available in Atom's menu, under Packages > Julia. Various panes can also be enabled from here, to list variables, visualize plots, or search the documentation.

For further information, check out http://junolab.org and https://github.com/JunoLab/uber-juno/blob/master/setup.md.

Visual Studio Code

Visual Studio Code is a cross-platform extendable editor from Microsoft. It is available for all the big three platforms at https://code.visualstudio.com. Once installed, run it and from the menu click View > Extensions or use the shortcut Shift and Ctrl/cmd and X. Search for julia and install the Julia extension from julialang.

The Julia support in Visual Studio Code is not (yet) as powerful as Juno, but if you prefer it, it makes for a great coding experience, providing syntax highlighting, code completion, hover help, evaluation of Julia code, linting, code navigation, and more. Visual Studio Code is also snappier and uses fewer resources than Atom, which makes it an appealing option when running on a less powerful workstation (although Atom has greatly improved in this regard with recent versions).

The extension might need a bit of help figuring out where it can find the Julia binary. If that is the case, you'll get an informative error message, asking you to set the julia.executablePath configuration option. This should point to the julia binary, and depends on your operating system and the way you installed Julia (see the previous section for details on the installation).

To set the configuration, go to Preferences > Settings (Ctrl/cmd and ,) and in the right pane, the one used to overwrite the defaults, add the following:

"julia.executablePath": "/path/to/your/julia/folder/bin/julia" 

IJulia (JuliaBox)

We already mentioned JuliaBox (https://www.juliabox.com) in the previous section—it allows creating, editing, and running IJulia Jupyter notebooks in the cloud. IJulia can also be installed on the local development machine.

IJulia is a Julia language backend for the Jupyter interactive environment (also used by IPython). It allows us to interact with the Julia language using Jupyter/IPython's powerful graphical notebook, which combines code, formatted text, math, and multimedia in a single document.

Although IJulia/Jupyter is not really an IDE, nor a classical editor, it is a powerful environment for editing and executing Julia scripts, and it's especially popular for data science and scientific computing. Let's take a few moments to set it up.

Start a new Julia REPL and execute the following:

julia> using Pkg
julia> Pkg.add("IJulia")

This will install the IJulia package, while also adding a required minimal Python and Jupyter distribution called Miniconda. This Python distribution is private to Julia (not in your PATH). Once finished, continue by executing the following:

julia> using IJulia
julia> notebook()

This will open the home page of your local Jupyter install in your default browser, at http://localhost:8888/tree. From the toolbar choose New > Julia 1.0.0 (or whatever version you are currently running) to create a new notebook. You can now create rich documents using embedded executable Julia code.

Note

There's another way of running IJulia as a desktop app, through Interact. You can download it and give it a try at https://nteract.io/desktop.

If you're new to Jupyter, it's worth learning more about it. Go check it out at http://jupyter.org.

Note

You can also find IJulia notebooks for each chapter in this book in the chapter's support file repository. The notebooks will allow you to go through the code we're writing, step by step. For instance, you can find the code for this chapter at https://github.com/PacktPublishing/Julia-Programming-Projects/blob/master/Chapter01/Chapter%201.ipynb. You can download it on your computer and open it with the local IJulia installation, or upload it to JuliaBox through their Google Drive integration.

Other options

The preceding choices are the most common IDE and editor options for Julia. But there are a few more out there.

For the vim enthusiasts, there's also julia-vim (https://github.com/JuliaEditorSupport/julia-vim).

If you prefer Emacs, you'll be pleased to know that Julia supports it as well https://github.com/JuliaEditorSupport/julia-emacs.

If you'd rater go with one of the IDEs provided by JetBrains (like IntelliJ IDEA), you'll be happy to hear that a plugin is available, at https://plugins.jetbrains.com/plugin/10413-julia

Finally, there is also support for Sublime Text, available at https://github.com/JuliaEditorSupport/Julia-sublime. The plugin provides a good Julia editing experience, supporting syntax highlighting, code completion, and jumping to definition, among other things.