3 Julia’s support for scaling projects

 

This chapter covers

  • Using Julia’s type system
  • Defining multiple methods for a function
  • Working with modules and packages
  • Using macros

In this chapter, you will learn elements of the Julia language that are important when creating larger projects. We start with exploring Julia’s type system. Understanding how type hierarchy works is essential to learning how to define multiple methods for a single function, a topic we started discussing in section 2.4. Similarly, when you use an existing function, you must know how to find out which types of arguments it accepts. Getting an exception because you tried to pass an argument of incorrect type when calling a function is one of the most common errors when working in Julia. To avoid such problems, you must have a good understanding of how Julia’s type system is designed.

When you define methods for a function, you can restrict the types of arguments they accept. This feature makes your Julia programs faster, allows you to catch bugs more easily, and makes it easier to understand how the code works.

If your projects grow larger, you will need to use third-party functionalities provided as packages or organize your source code into modules. In this chapter, you will learn how to do that with Julia.

3.1 Understanding Julia’s type system

3.1.1 A single function in Julia may have multiple methods

3.1.2 Types in Julia are arranged in a hierarchy

3.1.3 Finding all supertypes of a type

3.1.4 Finding all subtypes of a type

3.1.5 Union of types

3.1.6 Deciding what type restrictions to put in method signature

3.2 Using multiple dispatch in Julia

3.2.1 Rules for defining methods of a function

3.2.2 Method ambiguity problem

3.2.3 Improved implementation of winsorized mean

3.3 Working with packages and modules

3.3.1 What is a module in Julia?

3.3.2 How can packages be used in Julia?