|
|
|
|
|
by bbkane
265 days ago
|
|
Does anyone have good examples of the "metaprograms (programs that make/analyse a program" he's referring to? Making these types of programs relatively easy in Go (with stdlib ways to manipulate source code) has been a huge boon to the ecosystem (golangci-lint linters, code gen tools). I'd love to see examples of what that looks like in Odin |
|
That's a little tricky because almost anything can be a metaprogram. They're basically used when something could be "simplified" by writing a DSL, but you don't want to invent a whole new language (but you're going to anyway).
But some examples off the top of my head:
- For HTTP routers: HTTP methods (GET/POST/PATCH/DELETE/QUERY) are used when requesting a route. Instead of setting up the boilerplate of registering a url route and handling the different possible http method calls, a developer might want to use a more ergonomic macro to handle all the setup. (e.g. @<HTTP method>(<string of url>, <lamda function that returns a string that is sent back to the browser>)
- For MVC Frameworks (Same thing for MVVM, MVCL, MV*, etc... frameworks): Making a Model, View and Controller Macro that takes a name and a function and hooks it up to the application.
- For standards implementations: Adding special/non-standard bounds checking that is only calculated during compile time and removed from runtime for performance purposes (e.g. This int can only be between the ranges of -12 <-> 378 and 10621 <-> 11012)
- For game design: This level can only be solved by following the specified sequence. During the compile/build step, a proofer is run that ensures that the conditions for solving the level still hold. That way if someone adds a teleport item later in development, it doesn't break earlier levels.
- For testing: To mark a test case for a function