Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a term for this concept, and does it exist in a static-typed language?
    primarykey
    data
    text
    <p>Recently I started noticing a repetition in some of my code. Of course, once you notice a repetition, it becomes grating. Which is why I'm asking this question.</p> <p>The idea is this: sometimes you write different versions of the same class: a raw version, a locked version, a read-only facade version, etc. These are common things to do to a class, but the translations are highly mechanical. Surround all the methods with lock acquires/releases, etc. In a dynamic language, you could write a function which did this to an instance of a class (eg. iterate over all the functions, replacing them with a version which acquires/releases a lock.).</p> <p>I think a good term for what I mean is 'reflected class'. You create a transformation which takes a class, and returns a modified-in-a-desired-way class. Synchronization is the easiest case, but there are others: make a class immutable [wrap methods so they clone, mutate the clone, and include it in the result], make a class readonly [assuming you can identify mutating methods], make a class appear to work with type A instead of type B, etc.</p> <p>The important part is that, in theory, these transformations make sense at compile-time. Even though an ActorModel&lt;T&gt; has methods which change depending on T, they depend on T in a specific way knowable at compile-time (ActorModel&lt;T&gt; methods would return a future of the original result type).</p> <p>I'm just wondering if this has been implemented in a language, and what it's called.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload