Questions tagged [meta-programming]
Meta-programming is the writing of computer programs with the ability to treat programs as their data. It means that a program could be designed to read, generate, analyze and/or transform other programs, and even modify itself while running.
141
questions
1
vote
2
answers
116
views
Python 3.10+ deconstructing an over engineered solution to better understand how metaclasses work with properties, static methods, and classmethods
TL;DR
This question examines an over-engineered example of python metaclasses and dataclasses to create a LiteralEnum (for validating a stringly-typed keyword ...
8
votes
2
answers
978
views
JVM bytecode instruction struct with serializer & parser
I am writing a java class file parsing & serialization library. As part of that i needed to implement a structure for the JVM bytecode instructions as well as come up with a way to parse & ...
1
vote
3
answers
425
views
Decorator to validate that Python function arguments are positive
I have a list of functions whose parameters in the signature should be validated with the same criteria each time.
...
1
vote
1
answer
47
views
Python colorized debug printer
In Python you can use print(locals()) to print a dictionary of all the local variables, but this has 3 shortcomings:
Double underscore variables will be included ...
1
vote
1
answer
715
views
AutoBind TypeScript decorator
Idea is to have an AutoBind decorator which you could append in front of any method to have it preserve its own this, instead of manually binding it when called.
<...
9
votes
1
answer
746
views
Change arbitrary arguments of function based on their names with a decorator
I ran across an issue that proved to be more complicated than I thought: Changing an arbitrary argument of a function purely based upon its name in Python - possibly via a decorator. I tried to ...
1
vote
0
answers
57
views
Higher-order function to do throttling, written two ways
I have used below method for throttling which is a Higher Order Function (HOF), but find some difficulties to choose which one is better way to write it. Below are both methods.
return of the ...
3
votes
1
answer
161
views
Lightweight interface implementation in Python 3 using abstract classes
Here is my take at a lightweight interface implementation, where I focus on discoverability of suitable classes from strings (for simplicity, class name is used as an id). Each interface has it's own &...
2
votes
1
answer
203
views
How can I make this CSV Importer code better of any code smell?
I wrote this method a few years ago in a Ruby on Rails project, which I think I am not proud of. How can I make this code better to show in-depth professionalism in Ruby?
lib/merchant/web_csv_importer....
1
vote
0
answers
103
views
Metaprogamming elixir for module proxy
I'm working on my first real Elixir application, after dabbling for a few years. In my elixir/phoenix application I have to work with data over an external REST API. For my purposes, I can tolerate ...
1
vote
1
answer
57
views
Ruby: Database Authentication Module
I have created a module that validates the credentials against different databases.
...
3
votes
0
answers
121
views
Yet another reflection library
Tried to do my own implementation of reflection(introspection) for using in my next projects.
Is it optimized at compile time? If no, how can I improve it?
This macro is good interface for adapting ...
6
votes
2
answers
474
views
LazyEnum with validation
Motivation
In the standard Python library enum, a subclass of Enum would create all its members upon class creation. This can ...
1
vote
0
answers
59
views
Simplified Bash getopts flow
I've always found the boilerplate needed to use getopts correctly fairly fiddly and verbose, and was motivated to try to abstract it away. I wanted to try ...
4
votes
1
answer
140
views
A self contained parser generator implementation
This is a recreational project, I was trying to make a parser generator with a grammar inspired from: https://docs.python.org/3/reference/grammar.html
Unfortunately, understanding that specific ...