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
The basics
- VariablesName values with variables, give them types, change them, and keep the ones that shouldn't change fixed.
- TypesNumbers, text and truth; values that might be missing; converting between types; and naming your own.
- StringsJoin, slice, search and reshape text, and build strings from values with templates.
- ArraysKeep lists of values, read and change them by position, and transform them with map, filter and friends.
- Objects and mapsGroup named values into objects, look things up by key with typed maps, and loop over both.
- Control flowMake decisions with if, repeat work with for, loop, while and until, and leave loops early.
- Match and switchChoose between many cases with match, which gives a value, and switch, which runs code.
Reusing code
Your own types
- StructsDefine your own value types with named, typed fields, give them methods, and load them from JSON.
- 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.
- ClassesModel things with identity and changing state, with constructors, private fields, methods and inheritance.
- InterfacesDescribe what a value can do, not what it is, and write functions that accept anything that fits.
- GenericsWrite one function or type that works for many types, and constrain what those types must support.
Beyond the basics
- ErrorsHandle things that can go wrong with result values, catch, and !, and know when to throw or exit.
- IteratorsProduce values one at a time with generators, and build lazy chains that only do the work you use.
- OperatorsEvery operator in one place, including the two OSL rules that surprise people: left-to-right maths and loose string equality.
- Modules and importsSplit a program across files and folders, choose what each file exposes, and use packages from the standard library, Git and Go.
- ConcurrencyDo several things at once with async functions, share data safely, pass messages through channels, and run work in parallel.
- TestingKeep checks next to your code with test blocks, run them with osl test, and write test files for bigger cases.
- Using GoUse any Go package from OSL with a go: import, pass values both ways, and read the Go that OSL generates.
- What's nextYou've finished the course. Here's where to go from here.