Learn OSL

A course in short lessons. Read a little, run the examples, answer a question, solve an exercise, move on.

Every lesson is small and builds on the one before. The examples are live: click into any of them to change the code, and the compiler, running in your browser, checks it as you type.

0 of 24 lessons complete

Start here

  1. Install OSLInstall the compiler, check it works, and set up your editor. About two minutes.
  2. Your first programWrite a program, run it, and turn it into an executable. Meet log, comments and the compiler.

The basics

  1. VariablesName values with variables, give them types, change them, and keep the ones that shouldn't change fixed.
  2. TypesNumbers, text and truth; values that might be missing; converting between types; and naming your own.
  3. StringsJoin, slice, search and reshape text, and build strings from values with templates.
  4. ArraysKeep lists of values, read and change them by position, and transform them with map, filter and friends.
  5. Objects and mapsGroup named values into objects, look things up by key with typed maps, and loop over both.
  6. Control flowMake decisions with if, repeat work with for, loop, while and until, and leave loops early.
  7. Match and switchChoose between many cases with match, which gives a value, and switch, which runs code.

Reusing code

  1. FunctionsName a piece of code, give it parameters and a return type, and call it from anywhere.
  2. LambdasWrite small functions on the spot, pass them around, and let them remember the variables around them.

Your own types

  1. StructsDefine your own value types with named, typed fields, give them methods, and load them from JSON.
  2. EnumsSay that a value is one of a fixed set of cases, carry data with each case, and let match check you've handled them all.
  3. ClassesModel things with identity and changing state, with constructors, private fields, methods and inheritance.
  4. InterfacesDescribe what a value can do, not what it is, and write functions that accept anything that fits.
  5. GenericsWrite one function or type that works for many types, and constrain what those types must support.

Beyond the basics

  1. ErrorsHandle things that can go wrong with result values, catch, and !, and know when to throw or exit.
  2. IteratorsProduce values one at a time with generators, and build lazy chains that only do the work you use.
  3. OperatorsEvery operator in one place, including the two OSL rules that surprise people: left-to-right maths and loose string equality.
  4. Modules and importsSplit a program across files and folders, choose what each file exposes, and use packages from the standard library, Git and Go.
  5. ConcurrencyDo several things at once with async functions, share data safely, pass messages through channels, and run work in parallel.
  6. TestingKeep checks next to your code with test blocks, run them with osl test, and write test files for bigger cases.
  7. Using GoUse any Go package from OSL with a go: import, pass values both ways, and read the Go that OSL generates.
  8. What's nextYou've finished the course. Here's where to go from here.