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.
2
votes
1answer
36 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
34 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
96 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
60 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
63 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
34 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
37 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
70 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
134 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 ...
5
votes
1answer
90 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
62 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
83 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
81 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
67 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
65 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 ...
16
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
72 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 ...
4
votes
1answer
126 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
86 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
123 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
174 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
234 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
159 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
133 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:
...
4
votes
0answers
69 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
123 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 ...
10
votes
2answers
283 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 ...
6
votes
1answer
77 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
304 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
31 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
183 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 ...
6
votes
1answer
336 views
Automatic flowchart generator
I wanted to see graphically what my programme was doing so I wrote this automatic flowchart generator:
...
3
votes
2answers
230 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
104 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
96 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
286 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
180 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 ...
2
votes
0answers
69 views
Making a default value a property
I recently asked a question on StackOverflow, looking for a way to more easily turn a class attribute into a @property, but only if no other value has been provided ...
5
votes
1answer
162 views
Creating 2D vectors
I've made a little mechanism for creating 2-D vectors in Lua. Vectors have two components i and j, and support addition, dot ...
3
votes
0answers
68 views
Extracting dynamic behaviors of state machines to modules
This is my initial class. (I am not trying to reinvent state-flows again, just practicing)
As you can see straight forward, it dynamically generates methods like .recommend,.recommend!, ...
4
votes
1answer
208 views
Enums for measurement units, with possible circular dependency
I have some enums that define measurement information, such as volume, mass, distance etc...
They are defined as such:
...
2
votes
0answers
258 views
Efficient compile-time directed graph
During my research in Rigid Body Dynamics, (where Contact Graphs are used to solve the contact problem) I came across the question if it is possible to define at compile time a directed graph (class) ...
4
votes
1answer
183 views
Dictionary with restricted keys
I'm currently building some software that works with systemd unit files, and I've been trying to improve how we construct the unit files.
This is all running in Python 3.4
This first block is the ...
2
votes
2answers
652 views
Failing fast by raising an exception with a custom message
This is a script that utilizes lazy exception throwing. What I do is decorate a function that might throw an exception to throw an exception with a formatted string.
...
12
votes
2answers
796 views
Wait, is that variable ever assigned?
One of the inspections we wanted to implement in Rubberduck for the next release, is one that finds all unassigned variables in a VBA project.
Implementing this inspection has been ...complicated ...
18
votes
3answers
352 views
Rubberduck's “Extract Method” refactoring implementation
With the ANTLR-powered parser, I was able to reimplement all code inspections from the last release build, and the rest of the inspections on the road map are now implementable.
Code inspections ...
5
votes
2answers
923 views
Java MVC model for large scale GUI using annotations
I'm trying to make a good MVC model using annotations, which I will use it in a large scale GUI project. I want to respect the maximum of rules and guidelines, and be able to decorrelate every parts ...
0
votes
1answer
113 views
Python decorator for optional arguments decorator
I want my Python decorators to have optional arguments and not be called when not necessary.
The accepted answer in here doesn't accept named arguments, and I don't want to add boilerplate code ...