Julia as a Second Language

Book description

Learn the awesome Julia programming language by building fun projects like a rocket launcher, a password keeper, and a battle simulator.

Julia as a Second Language covers:

  • Data types like numbers, strings, arrays, and dictionaries
  • Immediate feedback with Julia’s read-evaluate-print-loop (REPL)
  • Simplify code interactions with multiple dispatch
  • Sharing code using modules and packages
  • Object-oriented and functional programming styles

Julia as a Second Language introduces Julia to readers with a beginning-level knowledge of another language like Python or JavaScript. You’ll learn by coding engaging hands-on projects that encourage you to apply what you’re learning immediately. Don’t be put off by Julia’s reputation as a scientific programming language—there’s no data science or numerical computing knowledge required. You can get started with what you learned in high school math classes.

About the Technology
Originally designed for high-performance data science, Julia has become an awesome general purpose programming language. It offers developer-friendly features like garbage collection, dynamic typing, and a flexible approach to concurrency and distributed computing. It is the perfect mix of simplicity, flexibility and performance.

About the Book
Julia as a Second Language introduces Julia by building on your existing programming knowledge. You’ll see Julia in action as you create a series of interesting projects that guide you from Julia’s basic syntax through its advanced features. Master types and data structures as you model a rocket launch. Use dictionaries to interpret Roman numerals. Use Julia’s unique multiple dispatch feature to send knights and archers into a simulated battle. Along the way, you’ll even compare the object-oriented and functional programming styles–Julia supports both!

What's Inside
  • Data types like numbers, strings, arrays, and dictionaries
  • Immediate feedback with Julia’s read-evaluate-print-loop (REPL)
  • Simplify code interactions with multiple dispatch
  • Share code using modules and packages


About the Reader
For readers comfortable with another programming language like Python, JavaScript, or C#.

About the Author
Erik Engheim is a writer, conference speaker, video course author, and software developer.

Quotes
Helped kickstart my use of Julia for serious projects. It’s a solid review of the core language features that doesn’t get bogged down on programming fundamentals you already know.
- Jonathan Owens, GE Global Research

Everything you need to learn Julia.
- Amanda Debler, Schaeffler Technologies

Julia for seasoned programmers.
- Kevin Cheung, Carleton University

Perfect for anyone who needs to learn Julia but doesn’t know where to start.
- Simone Sguazza, University of Applied Sciences and Arts of Southern Switzerland

Table of contents

  1. inside front cover
  2. Julia as a Second Language
  3. Copyright
  4. dedication
  5. contents
  6. front matter
    1. preface
    2. acknowledgments
    3. about this book
      1. Who should read this book?
      2. How this book is organized
      3. About the code
      4. liveBook discussion forum
      5. Other online resources
    4. about the author
    5. about the cover illustration
  7. Part 1 Basics
  8. 1 Why Julia?
    1. 1.1 What is Julia?
      1. 1.1.1 Pros and cons of statically and dynamically typed languages
    2. 1.2 Julia combines elegance, productivity, and performance
    3. 1.3 Why Julia was created
      1. 1.3.1 Scientists need the interactive programming that dynamically typed languages offer
      2. 1.3.2 Developers in other fields also need the interactivity a dynamically typed language offers
    4. 1.4 Julia’s higher performance solves the two-language problem
    5. 1.5 Julia is for everyone
    6. 1.6 What can I build with Julia?
      1. 1.6.1 Julia in the sciences
      2. 1.6.2 Nonscience uses of Julia
    7. 1.7 Where Julia is less ideal
    8. 1.8 What you will learn in this book
    9. Summary
  9. 2 Julia as a calculator
    1. 2.1 The Julia command line
    2. 2.2 Using constants and variables
      1. 2.2.1 Assigning and binding values to variables
      2. 2.2.2 Using the ans variable
      3. 2.2.3 What is a literal coefficient?
    3. 2.3 Different number types and their bit length in Julia
      1. 2.3.1 Writing numbers using different number formats
    4. 2.4 Floating-point numbers
      1. 2.4.1 Performing operations on integers and floating-point numbers
    5. 2.5 Defining functions
      1. 2.5.1 Storing function definitions in a file
      2. 2.5.2 Working with functions in the REPL
      3. 2.5.3 Functions everywhere
      4. 2.5.4 Functions to work with numbers
    6. 2.6 How to use numbers in practice
    7. Summary
  10. 3 Control flow
    1. 3.1 Navigation and trigonometry
    2. 3.2 Boolean expressions
      1. 3.2.1 Compound statements
    3. 3.3 Looping
      1. 3.3.1 Flowchart
      2. 3.3.2 Making a mathematical table for the sine function
      3. 3.3.3 Range objects
      4. 3.3.4 For loops
    4. 3.4 Multiline functions
      1. 3.4.1 Implementing the sine trigonometric function
    5. 3.5 Implementing factorial
    6. 3.6 Factorial with recursion
    7. 3.7 If statements
      1. 3.7.1 If-else statements
      2. 3.7.2 Elseif clause
    8. 3.8 Throwing exceptions to handle errors
    9. 3.9 Control flow vs. data flow
    10. 3.10 Counting rabbits
      1. 3.10.1 Base case
      2. 3.10.2 Iteration vs. recursion
      3. 3.10.3 To return or not return
    11. Summary
  11. 4 Julia as a spreadsheet
    1. 4.1 Analyzing pizza sales
    2. 4.2 Different types of arrays
    3. 4.3 Performing operations on arrays
    4. 4.4 Working with the statistics module
    5. 4.5 Accessing elements
    6. 4.6 Creating arrays
    7. 4.7 Mapping values in an array
    8. 4.8 Introducing characters and strings
    9. 4.9 Storing pizza data in tuples
    10. 4.10 Filtering pizzas based on predicates
      1. 4.10.1 Combining higher-order functions
    11. 4.11 Mapping and reducing an array
      1. 4.11.1 Sine table with map and reduce
    12. 4.12 Counting matches with Boolean arrays
    13. Summary
  12. 5 Working with text
    1. 5.1 Making a pretty pizza sales table
      1. 5.1.1 Print, println, and printstyled
      2. 5.1.2 Printing multiple elements
      3. 5.1.3 Printing multiple pizzas
      4. 5.1.4 Align with lpad and rpad
      5. 5.1.5 Adding lines
    2. 5.2 Printing a trigonometric table
    3. 5.3 Reading and writing pizza sales to CSV files
      1. 5.3.1 Writing pizza sales to a file
      2. 5.3.2 Reading pizza sales from a file
    4. 5.4 Interacting with the user
    5. Summary
  13. 6 Storing data in dictionaries
    1. 6.1 Parsing Roman numerals
    2. 6.2 Using the Dict type
    3. 6.3 Looping over characters
    4. 6.4 Enumerating values and indices
    5. 6.5 Explaining the conversion process
    6. 6.6 Using dictionaries
      1. 6.6.1 Creating dictionaries
      2. 6.6.2 Element access
    7. 6.7 Why use a dictionary?
    8. 6.8 Using named tuples as dictionaries
      1. 6.8.1 When do you use a named tuple?
      2. 6.8.2 Tying it all together
    9. Summary
  14. Part 2 Types
  15. 7 Understanding types
    1. 7.1 Creating composite types from primitive types
    2. 7.2 Exploring type hierarchies
    3. 7.3 Creating a battle simulator
      1. 7.3.1 Defining warrior types
      2. 7.3.2 Adding behavior to warriors
      3. 7.3.3 Using multiple dispatch to invoke methods
    4. 7.4 How Julia selects method to call
      1. 7.4.1 Contrasting Julia’s multiple dispatch with object-oriented languages
      2. 7.4.2 How is multiple dispatch different from function overloading?
    5. Summary
  16. 8 Building a rocket
    1. 8.1 Building a simple rocket
    2. 8.2 Maintaining invariants in your code
    3. 8.3 Making objects with constructor functions
    4. 8.4 Differences between outer and inner constructors
    5. 8.5 Modeling rocket engines and payloads
    6. 8.6 Assembling a simple rocket
    7. 8.7 Creating a rocket with multiple stages and engines
    8. 8.8 Launching a rocket into space
    9. Summary
  17. 9 Conversion and promotion
    1. 9.1 Exploring Julia’s number promotion system
    2. 9.2 Understanding number conversion
    3. 9.3 Defining custom units for angles
      1. 9.3.1 Defining angle constructors
      2. 9.3.2 Defining arithmetic operations on angles
      3. 9.3.3 Defining accessors to extract degrees, minutes, and seconds
      4. 9.3.4 Displaying DMS angles
      5. 9.3.5 Defining type conversions
      6. 9.3.6 Making pretty literals
      7. 9.3.7 Type promotions
    4. Summary
  18. 10 Representing unknown values
    1. 10.1 The nothing object
    2. 10.2 Using nothing in data structures
      1. 10.2.1 What is a parametric type?
      2. 10.2.2 Using union types to end the wagon train
    3. 10.3 Missing values
    4. 10.4 Not a number
    5. 10.5 Undefined data
    6. 10.6 Putting it all together
    7. Summary
  19. Part 3 Collections
  20. 11 Working with strings
    1. 11.1 UTF-8 and Unicode
      1. 11.1.1 Understanding the relation between code points and code units
    2. 11.2 String operations
      1. 11.2.1 Converting from camel case to snake case
      2. 11.2.2 Converting between numbers and strings
      3. 11.2.3 String interpolation and concatenation
      4. 11.2.4 sprintf formatting
    3. 11.3 Using string interpolation to generate code
    4. 11.4 Working with nonstandard string literals
      1. 11.4.1 DateFormat strings
      2. 11.4.2 Raw strings
      3. 11.4.3 Using regular expressions to match text
      4. 11.4.4 Making large integers with BigInt
      5. 11.4.5 MIME types
    5. Summary
  21. 12 Understanding Julia collections
    1. 12.1 Defining interfaces
    2. 12.2 Propellant tank interface example
    3. 12.3 Interfaces by convention
    4. 12.4 Implementing engine cluster iteration
      1. 12.4.1 Making clusters iterable
    5. 12.5 Implementing rocket stage iteration
      1. 12.5.1 Adding support for map and collect
    6. 12.6 Comparison of linked lists and arrays
      1. 12.6.1 Adding and removing elements
    7. 12.7 Utility of custom types
    8. Summary
  22. 13 Working with sets
    1. 13.1 What kind of problems can sets help solve?
    2. 13.2 What is a set?
      1. 13.2.1 Comparing properties of sets and arrays
    3. 13.3 How to use set operations
    4. 13.4 How to use sets in your code
    5. 13.5 Searching for products using set operations
      1. 13.5.1 Defining and using enumerations
      2. 13.5.2 Creating test data to perform queries on
      3. 13.5.3 Searching for screws
      4. 13.5.4 Putting screw objects into sets
      5. 13.5.5 Looking up screws using dictionaries
    6. 13.6 Search in bug tracker using sets
    7. 13.7 Relational databases and sets
    8. Summary
  23. 14 Working with vectors and matrices
    1. 14.1 Vectors and matrices in mathematics
    2. 14.2 Constructing a matrix from rows and columns
    3. 14.3 The size, length, and norm of an array
    4. 14.4 Slicing and dicing an array
    5. 14.5 Combining matrices and vectors
    6. 14.6 Creating matrices
    7. Summary
  24. Part 4 Software engineering
  25. 15 Functional programming in Julia
    1. 15.1 How does functional programming differ from object-oriented programming?
    2. 15.2 How and why you should learn to think functionally
    3. 15.3 Avoid deeply nested calls with function chaining
      1. 15.3.1 Understanding anonymous functions and closures
      2. 15.3.2 Using the pipe operator |>
      3. 15.3.3 Conveniently produce new functions using partial application
    4. 15.4 Implementing Caesar and substitution ciphers
      1. 15.4.1 Implementing the Caesar cipher
      2. 15.4.2 Implementing substitution ciphers
    5. 15.5 Creating a cipher-algorithm-agnostic service
    6. 15.6 Building an encryption service using object-oriented programming
    7. 15.7 Building an encryption service using functional programming
      1. 15.7.1 Defining a functional Caesar cipher
      2. 15.7.2 Defining a functional substitution cipher
      3. 15.7.3 Implementing a functional password-keeper service
    8. Summary
  26. 16 Organizing and modularizing your code
    1. 16.1 Setting up a work environment
      1. 16.1.1 Using a package in the REPL
      2. 16.1.2 How modules relate to packages
    2. 16.2 Creating your own package and module
      1. 16.2.1 Generating a package
      2. 16.2.2 Adding code to your package
    3. 16.3 Modifying and developing a package
    4. 16.4 Tackling common misconceptions about modules
    5. 16.5 Testing your package
    6. Summary
  27. Part 5 Going in depth
  28. 17 Input and output
    1. 17.1 Introducing Julia’s I/O system
    2. 17.2 Reading data from a process
    3. 17.3 Reading and writing to a socket
    4. 17.4 Parsing a CSV file
      1. 17.4.1 Loading rocket engine data
      2. 17.4.2 Saving rocket engine data
    5. Summary
  29. 18 Defining parametric types
    1. 18.1 Defining parametric methods
    2. 18.2 Defining parametric types
    3. 18.3 Type safety benefits from parametric types
    4. 18.4 Performance benefits from parametric types
    5. 18.5 Memory benefits of parametric types
    6. Summary
  30. Appendix A. Installing and configuring the Julia environment
    1. A.1 Downloading Julia
    2. A.2 Installing Julia
    3. A.3 On Linux
      1. A.3.1 On macOS
      2. A.3.2 On Windows
    4. A.4 Configuring Julia
      1. A.4.1 On Linux and macOS
      2. A.4.2 On Windows
    5. A.5 Running Julia
    6. A.6 Julia REPL Modes
    7. A.7 Installing third-party packages
  31. Appendix B. Numerics
    1. B.1 Different number types and their bit lengths
    2. B.2 Overflow and signed and unsigned numbers
    3. B.3 Floating-point numbers
  32. index
  33. inside back cover

Product information

  • Title: Julia as a Second Language
  • Author(s): Erik Engheim
  • Release date: April 2023
  • Publisher(s): Manning Publications
  • ISBN: 9781617299711