ewx: (geek)
[personal profile] ewx

From time to time I and colleagues find ourselves extending some function in C in a way that requires extra arguments. Often this happens in a context where it's impractical to change all the callers (for instance, because some of them are in customer code) so the extended version of the function gets a new name and the original name just calls that with some default value of the new arguments.

For instance I might go from this:

int refine_glorp(glorp *g) {
  /* refinement */
}

…to this:

int refine_glorp(glorp *g) {
  return refine_glorp_ex(g, 0);
}

int refine_glorp_ex(glorp *g, int arg) {
  /* extended refinement, based on arg */
}

Is there a well-known name for this transformation?

A colleague who did this a week or so ago started out with 'decapitation' but changed his mind to 'recapitation' on the grounds that he was really adding a second head to the function rather than removing one. But neither of us knew if there was already a name for this.

(no subject)

Date: 2015-11-09 08:30 am (UTC)
From: [identity profile] bellinghman.livejournal.com
In C? Haven't a clue. But I'll note that it's quite a common pattern in C++, though there the overloaded function would have the same name as the original even as the original passes along its parameter.

(And I'm not aware of its name in C++ either)

(no subject)

Date: 2015-11-09 07:16 pm (UTC)
From: [identity profile] armb.livejournal.com
Or just add the new argument with a suitable default value in the declaration so existing calls remain valid.

(no subject)

Date: 2015-11-09 08:15 pm (UTC)
ext_8103: (Default)
From: [identity profile] ewx.livejournal.com
That's an ABI change though, limiting the contexts in which it will work a bit.

(no subject)

Date: 2015-11-09 08:58 am (UTC)
From: [identity profile] jorallan.livejournal.com
I don't know, but I'd like to as I've done lots of this (well, in C# so I don't need to have two different names) while trying to get unit tests into some legacy code...

(no subject)

Date: 2015-11-09 09:11 am (UTC)
simont: A picture of me in 2016 (Default)
From: [personal profile] simont
No, I don't know of any standard name for this either. But I kind of want to come up with a gratuitously pretentious functional-style name, based on it being precisely the inverse operation to partial function application.

(no subject)

Date: 2015-11-09 06:43 pm (UTC)
From: [identity profile] krabbe.livejournal.com
Would you call it... *sunglasses* an impartial function application?

(no subject)

Date: 2015-11-09 08:13 pm (UTC)

(no subject)

Date: 2015-11-09 08:13 pm (UTC)
ext_8103: (Default)
From: [identity profile] ewx.livejournal.com
Partial deapplication, then?

(no subject)

Date: 2015-11-09 08:21 pm (UTC)
From: [identity profile] krabbe.livejournal.com
According to a dictionary I found on the Internet (http://dictionary.reference.com/browse/ap-), the "ap" prefix is related to "apo-", as in "aphelion". So it'd be a partial function periplication? Or, going with the more mundane "ad-" source, a partial explication?

Language makes sense, right?

(no subject)

Date: 2015-11-09 08:28 pm (UTC)
ext_8103: (Default)
From: [identity profile] ewx.livejournal.com
I like partial periplication l-)

(OED thinks application is ap- from ad- + p rather than the apo- version, but why would anyone let that get in the way?)

(no subject)

Date: 2015-11-09 11:02 pm (UTC)
From: [identity profile] bellinghman.livejournal.com
Well, there's already Currying, so why not Chutneying?

(Yes, I know that Curry was a person's name.)

(no subject)

Date: 2015-11-10 08:16 am (UTC)
From: [identity profile] lethargic-man.livejournal.com
In the style of biochemistry, which took the technique for analysing DNA invented by Professor Southern (https://en.wikipedia.org/wiki/Southern_blot) and extended it to Northern blots (https://en.wikipedia.org/wiki/Northern_blot) for RNA, Western blots (https://en.wikipedia.org/wiki/Western_blot) for protein, North-western blots (https://en.wikipedia.org/wiki/Northwestern_blot) for RNA-protein interactions and, I see from Wikipedia, that Eastern blotting (https://en.wikipedia.org/wiki/Eastern_blot), Middle-Eastern blotting, Far-Eastern blotting (https://en.wikipedia.org/wiki/Far-Eastern_blotting) and Far-Western blotting (https://en.wikipedia.org/wiki/Far-western_blotting) exist too.

(no subject)

Date: 2015-11-10 08:16 am (UTC)
From: [identity profile] lethargic-man.livejournal.com
Well, so much for waiting a day in the hopes of learning the actual name of this technique from the comments...

(no subject)

Date: 2015-11-26 11:22 pm (UTC)
From: [identity profile] gareth-rees.livejournal.com
This is an anti-pattern rather than a pattern. If the function as originally defined was missing one parameter, then there's a good chance it's missing another parameter, so that in the future you will find yourself needing to introduce refine_glorp_ex_ex. Better to design the new function so that it is more future-proof, for example instead of taking an int as the second argument, it could take an array of options.

(no subject)

Date: 2015-11-27 09:15 am (UTC)
ext_8103: (Default)
From: [identity profile] ewx.livejournal.com
I'm not looking for a name for "new function with an extra int argument and the old one becomes a wrapper", I'm looking for a name for "new function with an extra argument and the old one becomes a wrapper".
Indeed most of the examples in our code use an indefinitely extensible approach.

(no subject)

Date: 2015-11-27 11:52 am (UTC)
From: [identity profile] gareth-rees.livejournal.com
That's the thing about using made-up examples — it's hard to know which features are salient and which are accidental.

The Windows API suffers from this anti-pattern: a typical example is VirtualAllocExNuma (https://msdn.microsoft.com/en-us/library/windows/desktop/aa366891.aspx), which adds a node argument to VirtualAllocEx (https://msdn.microsoft.com/en-us/library/windows/desktop/aa366890.aspx), which adds a process argument to VirtualAlloc (https://msdn.microsoft.com/en-us/library/windows/desktop/aa366887.aspx). You'd think that when they came to extend it a second time they would have recognized the anti-pattern.

(no subject)

Date: 2015-11-27 12:36 pm (UTC)
From: [identity profile] uon.livejournal.com
I do this a lot, often as new requirements come in from users. It occurred to me (as I went through it again today) that it's rather like moulting: the original function grows a little bit, and sheds an outer layer.

November 2025

S M T W T F S
      1
2345678
91011121314 15
1617 181920 2122
23242526272829
30      

Most Popular Tags

Expand Cut Tags

No cut tags