Karl Zylinski | Understanding the Odin Programming Language (v. 1.6 / 1.10) (2024) [PDF, EPUB, HTML]
Автор: Karl Zylinski
Издательство: Самиздат
Жанр: Компьютерная литература
Язык: Английский
Формат: PDF, EPUB, HTML
Качество: Изначально электронное (ebook)
Иллюстрации: Отсутствуют
Описание:Do you want to learn the Odin Programming Language and demystify low-level programming?
Understanding the Odin Programming Language teaches both basic and advanced concepts. You'll learn about variables, constants, procedures, manual memory management, parametric polymorphism, data-oriented design, and much more.
A programming language is a tool. By understanding your tools, you will become a better craftsperson. Therefore, on top of how to write Odin code, this book also provides explanations of why things work the way they do.
The target audience is anyone with some programming experience. Odin is a simple yet powerful language, making it a great introduction to low-level programming, regardless of your programming background.
1. Introduction
Why learn Odin?
Language overview
Why write a book?
How to read the book
Installing the Odin compiler
If you get stuck
Acknowledgements
Copyright notice
Let's go!
2. Hellope! A tiny program
Compile and run the code
Line-by-line
What does the period in odin run . mean?
Compile without running
No need for semicolons
Where is the code inside core:fmt?
Compile a single Odin source file
There's much more!
3. Variables and constants
Declaring variables and assigning values
Another variable type and casting
Something strange?
Constants
Type inference defaults
Constants of explicit type
Benefits of Untyped Types
Basic types summary
Untyped Types summary
Video
4. Some additional basics
Procedure parameters and return values
If statements
Loops
Fixed arrays
All together
5. Making new types
Structs
Structs within structs
using on struct fields
using and "parenting"
No methods
Enums and switch
Switch
Explicit enum numbering
Backing type
Unions
The zero value of a union
The union's tag
Maybe
Raw union: C-style unions
Struct variants using unions
Using unions for state machines
6. Pointers
A procedure that modifies an integer
nil: the zero value of a pointer
A pointer to a struct
Copying a pointer and the address of a pointer
Under the hood: Addressables
7. Procedures and scopes
Default parameter values and named arguments
Example: Allocator parameter with default value
Multiple return values
Named return values
Nested procedures and captured variables
Parameters are always immutable
Don't use pointer parameters for the sake of optimization
Pointer and immutable reference aliasing
Explicit overloading
Run procedures on startup and shutdown
The scope and the stack
Scopes within scopes
defer: Making things happen at end of scope
Don't overuse defer
8. Fixed-memory containers
Fixed arrays revisited
Where does the memory live?
Blowing up the stack
Vectors and array programming
Passing fixed arrays to procedures
Enumerated arrays
Small_Array: A pseudo-growing fixed-memory array
9. Introduction to manual memory management
What is manual memory management?
Dynamic arrays
Creating a dynamic array and appending items
Deallocating a dynamic array
Removing items
Preallocated dynamic arrays
Under the hood: append and Raw_Dynamic_Array
Exercise: Understanding Dynamic Arrays
Dynamically allocated variables
Example: Dynamically allocated struct
Example: Dynamically allocated fixed array
The default allocator: context.allocator
The heap allocator
The WASM allocator
The separation of pointer and allocated memory
free and delete
Temporary allocator
Placing the free_all
"Scripts" that allocate memory
10. More container types
Slices: A window into part of an array
Creating a slice
Slice internals
Slice example: Considering 10 elements at a time
Prefer to pass slices
Slices with their own memory
Slice literals
Maps
Creating and destroying maps
Maps and allocations
Iterating maps
When to use maps
Making a set using a map
Custom iterators
11. Strings
String literals
Iterating and indexing strings
Grapheme clusters
Construct strings using fmt
Construct strings using string builder
What's a string internally?
Deallocating strings that are mixed with string constants
String constants
Combining string constants
Why does the slice operator count bytes?
Interfacing with Windows strings
12. Implicit context
context.allocator
Setting context.allocator vs passing explicit allocators
context.temp_allocator
context.assertion_failure_proc
context.logger
context.random_generator
context.user_ptr and context.user_index
How the context is passed
13. Making manual memory management easier
Tracking memory leaks
Setting up the tracking allocator
How does it work?
Making memory leak reports clearer
Arena allocators
No individual deallocations
Choosing an arena allocator
Growing virtual memory arena
Static virtual memory arena
Fixed buffer arena
Debugging memory mistakes
Improving your understanding
14. Parametric polymorphism: Writing generic code
Procedures with polymorphic parameters
Explicitly passing a type to a procedure
Parametric polymorphism with structs and unions
The unified concept of parametric polymorphism
Specialization
Specialization and distinct types
Video
15. Bit-related types
Binary representation of integers
Bit sets
The bits inside the bit_set
Force backing type
bit_set using letters and numbers
Bit fields
When to use bit sets and bit fields
16. Error handling
Errors using bool
Errors using enum
Errors using union
or_return
#optional_allocator_error
#optional_ok
17. Package system and code organization
What is a package?
Creating a package
The package name
Make sure your packages are independent
Breaking cyclic dependencies using callbacks
File and package private
Making your own collections
Video
18. You (probably) don't need a build system
Compiling your program
Importing packages
Importing non-Odin libraries
Caveats
Platform specific code
Compiling multiple binaries
More complicated build setups
Summary
19. Reflection and Run-Time Type Information (RTTI)
Example: Enum member from string
Case study: Enum dropdown menu
When to not use reflection
Learning more about reflection
20. Data-oriented design
Avoid doing many small heap allocations
Performance differences when iterating
How much faster is it?
Problem: Pointers get invalidated when the array grows
Structure of arrays (SoA)
How much faster is SoA?
When do I use SoA arrays?
Conclusion and further reading
21. Making C library bindings (Foreign Function Interface)
The C library
The Odin bindings
Testing our bindings
More examples
Video
22. Debuggers
VS Code
RemedyBG
RAD Debugger
23. Odin features you should avoid
using on variables and parameters
any type
Dynamic literals
24. A tour of the core collection
Reading and writing files (core:os)
Read and write structs as JSON (core:encoding/json)
Virtual memory arena allocators (core:mem/virtual)
Working with strings (core:strings)
Using the logger (core:log)
Start a new thread (core:thread)
Do things periodically (core:time)
Linear algebra math operations (core:math/linalg)
Create random numbers and shuffle arrays (core:math/rand)
C types and using the C standard library core:c and core:c/libc
Opening a window using the Windows API core:sys/windows
Load symbols from a dynamic library core:dynlib
25. Libraries for creating video games
Make a game using raylib vendor:raylib
Write platform-independent rendering code using SOKOL
Write rendering code using vulkan (vendor:vulkan)
Create 2D game physics using Box2D (vendor:box2d)
26. A few more things...
#load and #load_directory
@rodata
Matrices
Quaternions
Struct tags
WASM
Variadic procedures
deferred_X attributes
Making libraries compile cleanly
Code generation
27. Where to find more Odin resources
28. Thanks for reading!
29. Appendix A: Handle-based array
30. Appendix B: Using only fixed arrays
31. Appendix C: gui_dropdown from CAT & ONION
32. Appendix D: Box2D and raylib
33. About the author
Скриншоты:
Время раздачи: с 10 до 20 (минимум до появления первых 3-5 скачавших)