Skip to main content

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.

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 ...
SumNeuron's user avatar
  • 271
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 & ...
p0sa's user avatar
  • 81
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. ...
SeF's user avatar
  • 199
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 ...
Caridorc's user avatar
  • 27.5k
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. <...
Ilija Ivic's user avatar
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 ...
s-m-e's user avatar
  • 273
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 ...
xkeshav's user avatar
  • 131
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 &...
Roman Susi's user avatar
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....
Afolabi Olaoluwa's user avatar
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 ...
Segfault's user avatar
  • 141
1 vote
1 answer
57 views

Ruby: Database Authentication Module

I have created a module that validates the credentials against different databases. ...
Rajkaran Mishra's user avatar
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 ...
Vladyslav Mozhvylo's user avatar
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 ...
user141240's user avatar
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 ...
dimo414's user avatar
  • 417
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 ...
Jeacom's user avatar
  • 125

15 30 50 per page
1
2 3 4 5
10