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.

learn more… | top users | synonyms

4
votes
1answer
52 views

Class decorator in Python to set variables for the constructor

I personally don't like the boilerplate of most __init__ methods: self.a = a self.b = b ... So I thought this would be a nice ...
0
votes
1answer
22 views

Generic Int conversion to scalar

I'm new to Scala and I'm trying to write a generic function to convert from Int to any scalar. For example: ...
7
votes
1answer
88 views

Removing XML Doc Comment Nodes

I recently wrote a code fix to handle many of the C# and VB.NET compiler diagnostics that was merged into Roslyn. Because it handles both, I implemented it as an abstract class with only the sections ...
2
votes
2answers
30 views

Memoizing decorator with retries - now with backoff added! (Part 3)

A continuation of Memoizing decorator with retries, part 2, and related to http://codereview.stackexchange.com/a/133493/47529. I liked my decorator before, but especially in my original use case of a ...
5
votes
3answers
81 views

Memoizing decorator with retries, part 2

A while ago I asked this question Memoizing decorator that can retry and then promptly forgot about it. I more recently saw Python decorator for retrying w/exponential backoff and wanted to add ...
2
votes
1answer
101 views

Python decorator for retrying w/exponential backoff

This is my first decorator in Python! I found some of it on the internet but have tweaked it to our needs. Here is the couple concerns of mine: Multiple python version compatibility Is grabbing ...
3
votes
1answer
59 views

Lombokython - Automatic __eq__, __hash__, __repr__

I recently decided to code some in Python after coding in Java using lombok for quite some time. However, I got bit real hard when I forgot to implement __eq__, ...
2
votes
2answers
343 views

Classes for reading XML from a file

Basically, all I have to do is read some xml from a file. And I have a working solution, although I am not sure that it is the best way of going about doing things, as I have only recently started ...
4
votes
1answer
65 views

Code Explorer View Models

Continuing the series of Code Explorer posts, here is the collection of view models for the tree nodes: This is the interface for nodes with a declaration. ...
7
votes
1answer
100 views

Code Explorer Commands

Rubberduck's Code Explorer was recently redesigned from scratch: Anything from modern features, such as virtual folders (limitation of the VBE--it doesn't support real folders), to ancient features ...
3
votes
2answers
59 views

Decorator that supplies arguments to functions

I have assignment to generate argument based decorator I wrote like this. ...
2
votes
1answer
37 views

Method to act on parameter or from iterable if not parameters are passed

The scenario is as follows. The API of my program will allow the user to perform some method on a particular element (let's say a tuple from a database). If this parameter is not passed to the ...
2
votes
0answers
39 views

Dynamically create instance variables from a list of classes

I have a situation, where I want to add many classes as instance variables of another class, plus perform some action on each class. The purpose is to have an 'app' with many 'views', to represent <...
5
votes
1answer
124 views

Detect and Fix Switching over an Enum Without Handling all Members

VSDiagnostic's latest refactoring and code fix detects when a switch does not contain case statements for each of the ...
2
votes
1answer
65 views

Print Trace Debugger

Notice: The original library has since been replaced by: https://github.com/JohnReedLOL/scala-trace-debug See my Scala print trace debugger. This project is used for lightweight debugging sort of ...
3
votes
2answers
73 views

Decorator to convert a function's result into the desired units

I tried to collect some of my formulas inside classes so that I didn't need to browser the names of the functions anymore but only determine which Quantity I want to calculate and then check which ...
4
votes
2answers
57 views

Dynamically generated attribute accessors in Perl

In my spare time I'm working at a perl library, which is the lightweight implementation of a package I did some time ago. In the previous iteration I used Moose as object-oriented framework, as ...
3
votes
1answer
43 views

caching decorator

I came up with a caching decorator for pure functions. Is it ok? Could it be better/simpler/faster? ...
4
votes
2answers
177 views

Custom array indexing

Note that this code is not going to be used for anything, it's more of a thought experiment. I've been seeing a lot of NumPy code lately and noticed that they use a custom indexing process, presumably ...
6
votes
4answers
152 views

Unit Testing the Duck

I recently reinstated the unit tests in Rubberduck. Previously, our parser was a synchronous parser, with everything running in sequence, and we could just request a parse result. Now, however, it ...
6
votes
1answer
146 views

Add Missing XML Doc Parameters

This is an analyzer and code fix for VSDiagnostics that detects when a doc comment on a method does not have all parameters listed. When the user tells it to provide the fix, it adds a ...
5
votes
1answer
65 views

Convert Procedure to Function

My latest inspection for Rubberduck determines whether a procedure should be a function by checking whether it has a single ByRef parameter (either explicit or ...
5
votes
1answer
153 views

login_required decorator in Flask

I have 2 Flask apps (different projects) that work together . One implements some API which uses tokens for auth. The second one consumes the API and makes a web interface for it. Now I have a login ...
11
votes
1answer
87 views

Extract Interface

One of the latest refactorings for Rubberduck is Extract Interface. This refactoring will take a class, display all public members, and allow you to select which members you wish to include in your ...
6
votes
1answer
79 views

Implement Interface Refactoring

The latest refactoring for Rubberduck is Implement Interface. This refactoring will check whether the active class fully implements the selected interface by comparing the definitions. It knows the ...
10
votes
1answer
74 views

Move Closer To Usage

One of my latest refactorings for Rubberduck is Move Closer To Usage. The refactoring will take a field and move it just above the reference to it only if it is used in a single method, or take a ...
6
votes
1answer
74 views

The Realtor-duck: Encapsulating Fields with Properties

The latest new refactoring for our friend Rubberduck is Encapsulate Field: This image, for the sake of brevity, shows the result of the refactoring and the UI together. The three properties below ...
8
votes
1answer
69 views

Climbing the Totem Pole - Local Variables Become Parameters

Along with the Introduce Field refactoring, I wrote an Introduce Parameter refactoring. I actually wrote this refactoring first, but due to a bug in the parser/resolver, I was unable to fully test it ...
17
votes
4answers
3k views

You are Promoted, You are Promoted, We All are Promoted!​

My latest refactoring for Rubberduck is called Introduce Field - it promotes a local variable to a private field. The three overridden Refactor() methods are the ...
1
vote
1answer
82 views

Simplifying Rails Validation [closed]

I have four fields a, b, c, and d. All of them must be populated if any of them have a value. So what I want to do is validate that they are all populated, if any of them have a value. I'm trying ...
5
votes
1answer
317 views

Using Rails concerns for validation in models

This is my first Rails project. I have read about concerns which are a great tool, but I am confused about how I should redesign my models. Some models have similar fields, but the validations are ...
3
votes
1answer
101 views

Compile-time wildcard pattern matching

I was in need of a function that could check a string against a certain pattern at compile-time. The pattern can contain any of the commonly known wildcards: ?, * and +. ...
7
votes
2answers
167 views

Strict types decorator (works only with Python 3.5)

I wrote a decorator which makes Python 3.5 raise exceptions if the arguments that are passed to a type-hinted function are of the wrong type. ...
12
votes
1answer
277 views

Remove Empty Argument Lists from Attributes

I converted a C# analyzer for removing empty argument lists from attributes to be a C# and VB.NET analyzer: ...
9
votes
1answer
263 views

Brainfuck Printer Generator

Given a text, this program will output a Brainfuck program, that when executed will print the text back. Writing Brainfuck in this style to print a sentence is pretty straightforward. Iterate over ...
8
votes
2answers
172 views

Putting everything in its place

A new diagnostic has seen the light of day! This one will alert you when you have a string.Format() call where the formatting placeholders are in the wrong order. ...
4
votes
2answers
180 views

Tool to Add Access Modifiers to Code

Working on VSDiagnostics, I implemented a tool that adds the default access modifiers to C# code. An example use would be starting with this: static class Foo { } ...
4
votes
0answers
72 views

Creating companion classes that are `inherited` onto any sub-classes

The idea for the code I have written came about due to the acts_as_versioned gem which automatically nests a Version class onto ...
5
votes
1answer
154 views

Descriptor class with advanced (inspect/metaclass) functionality

Having answered this question over on Programmers.SE, I found myself wondering how much effort it would be to write a descriptor that can automatically figure out what the 'destination' attribute ...
11
votes
2answers
372 views

Memoizing decorator that can retry

I have some tasks that I'd like to memoize because they connect to a rather slow network and have to wait for the data. Unfortunately this network can be a little finnicky and we get occasional ...
7
votes
1answer
93 views

Game loop decorator for Pygame

I've built a simple decorator that wraps a function in a general Pygame game loop. It also allows for the programmer to set the tick rate. ...
1
vote
4answers
585 views

Python Decorator - inspecting function argument values

Some of my functions use a "fail_silently" flag. It is used in the following way: ...
3
votes
1answer
32 views

user_interface module

As writing code to handle error-checked input or to present functions to execute to the user is boring and error-prone, I wrote a module to automate these tasks: ...
10
votes
1answer
263 views

Try-except decorator for classmethods

This question is related to the Cactus Text Game Engine. For easy error handling in Cactus, we've put together this small decorator. Essentially, the decorator wraps any class method in a ...
7
votes
1answer
424 views

Automatic flowchart generator

I wanted to see graphically what my programme was doing so I wrote this automatic flowchart generator: ...
3
votes
2answers
316 views

Building a chain of responsibility in Ruby to apply transformators on an object

I try to make a middleware stack system in the rack way (but not for HTTP request). Here is the main class: ...
3
votes
1answer
117 views

Meta-class to allow inspection of all __slots__of a class

If classes provide __slots__ and at the same time inherit from another class also providing __slots__, there is no ...
3
votes
2answers
121 views

Synchronous and asynchronous motor movement

I am working on an API that is mostly intended to be used interactively/little scripts. There are some classes with methods that could act slightly differently depending on the intention of the user, ...
2
votes
1answer
459 views

Memoization of Fibonacci using generic Int => Int helper

I'm trying to understand memoization using Scala. I took the Fibonacci sequence as an example because of the high cost of recursively computing numbers in the sequence without memoization. ...
9
votes
2answers
199 views

Find arity of a rebol function

I needed a way to find the number of arguments a function or operation in Rebol accepts (the functions arity). I could not find any direct support for this in the language, so I made my own ...