Solve lack of generics with metaprogramming
Metaprogramming (MP) is about writing code that writes code. In MP, we write programs that treat programs, even themselves, as input data. Our MP will read, analyze, transform, and generate code.
Maybe we can use MP to fix what's missing in Go due to its lack of support for generics?
Maybe. First, let's get a better understanding of what MP is about.
Here are some examples:
- Lexers, parsers, interpreters, and compilers
- Domain-Specific Languages (DSLs)
- Aspect-Oriented Programming (AOP)
- Attributes (.NET)
- Annotations (Java)
- Generics (.NET, Java)
- Templates (C++)
- Macros (C)
- method_missing (Ruby)
- Reflection (Go, C#, Ruby)
There are several types of MP.
Programs that support the eval
function can generate new code by concatenating strings that represent executable commands. Note: this can pose security risks and is generally not a best practice.
Some languages, such as LISP, can change their own application code based on state information, which provides the flexibility...