Julia for Beginners
Julia for Beginners
From Romans to Rockets
Erik Engheim
Leanpub
2020 Sixty North AS
Preface
I began programming as a teenager with fun books containing comic book strips with wizards and turtles. I read magazines that showed me how to make my own simple games or make silly stuff happen on the screen. I had fun.
But when I went to university, books started talking about bank accounts, balances, sales departments, employees and employers. I wondered if my life as a programmer would mean putting on a gray suit and writing code handling payroll systems. Oh the horror!
At least half of my class hated programming with a passion. I could not blame them. Why did programming books have to be so boring, functional and sensible?
Where was the sense of adventure and fun? Fun is underrated. Who cares if a book is silly and has stupid jokes if it makes you learn and enjoy learning?
That is one of the reasons I wrote this book. I wanted the reader to enjoy learning programming. Not through cracking jokes, but by working through programming examples that are interesting or fun to do.
I promise you, there will be no examples modeling a sales department. Instead we will simulate rocket launches, pretend to be Caesar sending a secret message to his army commanders using old Roman encryption techniques, as well as simulating a beautiful old handheld mechanical calculator, the Curta, and many other things.
The second important reason I wanted to write this book is because people keep telling me: Julia? Isnt that a language only for science and scientists?
Julia has had major success in this area, which is why the Julia community today is full of brainy people working on hard problems such as developing new drugs, modeling the spread of infectious diseases, climate change or the economy.
But no, you dont need to be a genius or a scientists to use Julia. Julia is a wonderful general purpose programming language for everyone! I am not a scientist and I have enjoyed using it for over 7 years now. With Julia you will find that you can solve problems more quickly and elegantly than you have done in the past. And as a cherry on top, computationally intensive code will run blisteringly fast.
Introduction
Software is everywhere around us. Every program you see on your computer, smart phone or tablet has been made by someone, who wrote code in a programming language.
But that isnt the only places youll find software. You may think of a computer as box that sits on your desk or a laptop computer, but there are tiny computers we call micro controllers inside almost any kind of technical device we use. In cars for instance, these little computers figure out how much gasoline needs to be injected into the engine cylinder.
A Falcon 9 booster coming in for landing.
Have you ever seen the Falcon 9 rocket land at sea on a barge by firing its rocket engines right before it smashes into the deck? There are numerous computers inside this rocket keeping track of how fast the rocket is going, how far it is from the ground and exactly how much thrust it has to apply, and for how long, to avoid crashing.
All of these computers run programs that somebody wrote.
Programs are written in many different programming languages. People sometimes ask me what the best programming language is. There is no best language! It is like asking what the best car is. Some cars are better for certain things than others. Ferraris are good at going really fast, but not good at transporting your IKEA furniture. But most of the time, car choices come down to personal preferences and personality. Programming languages are the same. It is both about the job, but also about how you like to work.
The Julia Programming Language
I have chosen to teach you to the Julia programming language. Why did I pick this language, when there are hundreds of others to chose from, some which are much better known?
- It is a fun language! The language plays on your team instead of against you.
- Easy to learn. Some languages languages require you do learn a myriad of details before you get to do anything at all. Julia lets you learn one small thing at a time.
- Powerful. You can get a lot done with very small amounts of code.
- Batteries included. Dont you hate it when you unpack a cool new thing and it doesnt work, because batteries are sold separately? A lot of programming languages are like that, but not Julia.
- Fast. You can write code that runs slow in any language, but Julia gives you the ability to write very high performance code.
Overview
The chapters in this book are meant to be read in sequence, and build upon each other. However not every single chapter needs to be read.
This book tries to balance the needs of three different kinds of readers:
- The beginner, with minimal programming experience. For this reason the first chapters try to keep things simple and assume limited prior knowledge of common programming concepts.
- The experienced developer who wants to move faster and have more in depth coverage of material specific to Julia. For this reason, later chapters will assume more prior knowledge of various programming concepts.
- The curious technology enthusiast. Some chapters go into more technical and historical details, which some readers may find fascinating or interesting. However these chapters cover material which may not be strictly necessary to master Julia.
The inspiration for this organization is my own experience reading technology and science books for fun. Sometimes you want to learn something fast and get to the meat quickly. Other times you enjoy immersing yourself with geeky details.
- . We cover how to install Julia, setup tools to work with Julia and a basic introduction to the Julia programming environment.
- . What makes a computer different from a mere calculator? Exploring the ability to automate complex number calculations using a programming language.
- . We make a simple program to allow somebody to practice multiplication. This ties together reading input from the user and writing out messages.
- . We work through an example of how to convert Roman numerals to decimal numbers by using an important data structure called a dictionary.
- Is an introduction to the binary number system, binary operations and how to work with integers in different representations. Go through how a microprocessor does arithmetic.
- . We explain the Julia type system and how it ties in with multiple dispatch.
- by building a space rocket in code.
- . Julia has type annotations, so what makes Julia a dynamic language, and how is it different from a statically typed language such as C/C++, Java or C#?
- of different number types.
- . How to represent objects which are not found, missing or undefined in Julia.
- . Working with text strings. What is Unicode and UTF-8 encoding?
- . Shared abilities for different types of object collections and how you make your own.
- . Creating sets, set operations and what makes a set different from an array.
- . Use Julia like a spreadsheet, or how to work with multi-dimensional arrays. A simple introduction to linear algebra.
- using affine transformation matrices (2D arrays) to simulate movement and rotation of a space rocket. A geometric look at matrices, vectors and points.