
Web Development with Julia and Genie
Description
Alles über E-Books | Antworten auf Fragen rund um E-Books, Kopierschutz und Dateiformate finden Sie in unserem Info- & Hilfebereich.
All prices
More details
Other editions
Additional editions

Persons
Ivo Balbaert is a lecturer in web programming and databases at CVO Antwerpen, a community college in Belgium. He received a PhD in applied physics from the University of Antwerp in 1986. He worked for 20 years in the software industry as a developer and consultant in several companies, and for 10 years as project manager at the University Hospital of Antwerp. From 2000 onwards, he switched to partly teaching and partly developing software (at KHM Mechelen, CVO Antwerpen). He also wrote an introductory book in Dutch about developing in Ruby and Rails, Programmeren met Ruby en Rails, published by Van Duuren Media. In 2012, he authored a book on the Go programming language, The Way to Go, published by iUniverse. He has written a number of introductory books for new programming languages, notably Dart, Julia, Rust, and Red, all published by Packt.Salceanu Adrian :
Adrian Salceanu is the creator and lead maintainer of Genie Framework. He has over two decades of professional work experience as a web developer and software architect, leading agile teams in developing, scaling, and maintaining business critical, data-intensive web applications. Currently, he is the technical founder and CEO of Genie Cloud, a no-code app development platform built with Genie. Adrian is the author of Julia Programming Projects (published by Packt in 2018) and an enthusiastic JuliaLang open-source contributor. He has two master's degrees, one in Computing, and another in Advanced Computer Science.
Content
- Using Julia Standard Web Packages
- Applying Julia in Various Use Cases on the Web
- Building an MVC ToDo App
- Adding a REST API
- Deploying Genie Apps in Production
- Adding Authentication to Our App
- Developing Interactive Data Dashboards with Genie
1
Julia Programming Overview
Julia is a high-performance, open source computing language, mostly applied to data analysis, machine learning, and other scientific and technical computing applications.
The language combines the ease of use of Python or R with the speed of C and eliminates the need for using two languages to develop data intensive applications. It is as readable and high-level as Python and because of its type inference and optional typing, behaves as a dynamic language. It is also as fast as C, but much more readable. As a new programming language, Julia borrowed some of the best features from other modern languages. For example, like Ruby, it doesn't use semicolons or curly braces for delimiting code; instead, it uses a more Pascal-like syntax, with end to indicate where a code structure stops.
Julia is not a classic object-oriented language like Java; instead, it is more function-oriented, but it also has a struct data type like C. Functions that act on and transform data are the basic building blocks. The language also has built-in parallel computing capabilities and can scale up very easily.
Julia also provides an extensive standard library from the start. The language's usage and popularity are steadily rising; it has been downloaded by users from more than 10,000 companies and is used at over 1,500 universities worldwide (https://juliacomputing.com/media/2022/02/julia-turns-ten-years-old/).
This chapter will touch on the main Julia concepts we will need in web development including types, flow control, functions, packages, and modules. We will introduce some examples relating to the ToDo app project theme for Part 2 of this book.
We'll also show code snippets from the Genie framework that are used in Part 2. We wrap up with a section on how Julia works internally, which makes us better understand Julia's efficacy in web development. By the end of this chapter, your Julia knowledge will be refreshed, and you'll be much better prepared to grasp the rest of the book.
In this chapter, we will cover the following topics:
- Working with Julia
- Types, flow controls, and functions in Julia
- Useful techniques in Julia web development
- Using Julia modules and packages
- How Julia works
- Why Julia is a good fit for web development
Technical requirements
To follow through with all the exercises in this chapter and the rest of the book, you will need the following:
- Access to the command-line terminal on your OS.
- The latest current stable release of Julia installed. Install Julia on your computer by downloading the latest current stable release (v 1.8 or higher) from https://julialang.org/downloads/ or through the cross-platform juliaup tool (https://github.com/JuliaLang/juliaup).
- VS Code: Download it from https://code.visualstudio.com/, preferably v1.66 or higher.
All the code examples in this book have been run on a Windows machine. You may find subtle differences in output if you are using Linux/macOS. Where necessary, command variations for both machines have been specified.
The complete source code for this chapter can be found at https://github.com/PacktPublishing/Web-Development-with-Julia-and-Genie/tree/main/Chapter1.
Working with Julia
In this section, we will set up a standard Julia development environment, and learn how to work with Julia scripts as well as the Read-Eval-Print Loop (REPL). The REPL allows you to work with Julia in an interactive way, trying out expressions, function calls, and even executing whole programs.
You're good to go when typing in julia at the terminal starts up the REPL:
Figure 1.1 - The Julia REPL
Using the REPL to use Julia interactively
Try typing in 256^2, giving the result 65536, or rand(), which gives you a random number between 0 and 1, for example, 0.02925477322848513. We'll use the REPL extensively throughout the book, and the Genie web framework discussed in Part 2 allows you to build your entire web app from the REPL.
Some useful REPL keyboard shortcuts you will use often include the following:
- Ctrl + D: To exit the REPL
- Ctrl + L: To clear the screen
- Ctrl + C: To get a new prompt
- Up and down arrows: To reuse recent commands
To see which folder you are in, type pwd(). To change the current folder, execute cd("path/to/folder").
A feature we'll use a lot in Genie is creating new files from within the REPL with the touch command. For example, to create an empty testset.jl file in an existing folder structure, testing/phase1, enter the following:
julia> touch(joinpath("testing", "phase1", "testset.jl"))The REPL returns testing\\phase1\\testset.jl on Windows and testing/phase1/testset.jl on *nix systems.
The joinpath function constructs the directory path starting in the current folder, and touch creates the file.
Using the package mode to jump-start a project
The Julia ecosystem encompasses thousands of libraries, called packages (see https://julialang.org/packages/), for which Julia has a built-in package manager, Pkg.
The REPL has a special mode for working with packages, which is started by typing ] at julia> prompt, which brings you to package mode: (@v1.8) pkg>.
Some useful commands in this mode to type in after the pkg> prompt are as follows:
- st or status: Gets a list of all the packages installed in your environment.
- add PackageName: Adds a new package (you can add several packages separated by , if needed).
- up or update: Updates all your packages.
- up or update PackageName: Updates a specific package.
- activate .: Activates the current project environment (see the Packages and projects section under Using Julia modules and packages). rm or remove PackageName: Removes a specific package.
- ?: Lists all available commands.
- The backspace key: Exits the pkg> mode.
In the next section, Parsing a CSV file, we will work with a comma-separated values (CSV) file of to-do items. The CSV package can be imported and set up to be used in your Julia REPL by typing the following:
julia> using Pkg julia> Pkg.add("CSV") julia> using CSVThe last line of the preceding command brings the definitions of the CSV package into scope.
Alternatively, from the package mode, use the following:
]: (@v1.8) pkg> add CSVThe preceding command installs all packages CSV depends on and then precompiles them. This way, the project gets a jump-start, because the just-in-time (JIT) compiler doesn't have to do this work anymore.
Using Julia with the VS Code plugin
Julia code can also be saved and edited in files with a .jl extension. Numerous IDEs exist to do that. In this book, we'll use the VS Code platform with the excellent Julia plugin, which provides syntax highlighting and completion, lookup definitions, and plotting among many other features.
A handy way to start VS Code from the terminal prompt is by typing in code.
Search in the Extensions tab for Julia and install it. Then, open up a new file, and type in println("Hi Web World from Julia!"), and save it as hiweb.jl.
Run the program in VS Code with F5 to see the string printed out. Or start the REPL and type the following to get the same...
System requirements
File format: ePUB
Copy protection: Adobe-DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Install the free reader Adobe Digital Editions prior to download (see eBook Help).
- Tablet/smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook before downloading (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (not Kindle).
The file format ePub works well for novels and non-fiction books – i.e., „flowing” text without complex layout. On an e-reader or smartphone, line and page breaks automatically adjust to fit the small displays.
This eBook uses Adobe-DRM, a „hard” copy protection. If the necessary requirements are not met, unfortunately you will not be able to open the eBook. You will therefore need to prepare your reading hardware before downloading.
Please note: We strongly recommend that you authorise using your personal Adobe ID after installation of any reading software.
For more information, see our ebook Help page.
File format: ePUB
Copy protection: without DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Use a reader that can handle the file format ePUB, such as Adobe Digital Editions or FBReader – both free (see eBook Help).
- Tablet/Smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (not Kindle).
The file format ePUB works well for novels and non-fiction books – i.e., 'flowing' text without complex layout. On an e-reader or smartphone, line and page breaks automatically adjust to fit the small displays.
This eBook does not use copy protection or Digital Rights Management
For more information, see our eBook Help page.