Re: [PATCH 19/22] sequencer: support cleaning up commit messages
- From
Jakub Narębski <jnareb@gmail.com>
- Date
- Sep 1, 2016, 23:31 UTC
- Message-ID
- <80a779a5-70d3-64dc-d206-41c47e1c69f5@gmail.com>
- In-Reply-To
- <alpine.DEB.2.20.1609011543290.129229@virtualbox>
Hello Johannes,
W dniu 01.09.2016 o 15:56, Johannes Schindelin pisze:
> On Thu, 1 Sep 2016, Jakub Narębski wrote:
Show 16 quoted lines
>> It's a pity that emulation of named parameters in C requires
>> relying on designated inits from C99
>>
>> typedef struct {
>> double pressure, moles, temp;
>> } ideal_struct;
>>
>> #define ideal_pressure(...) ideal_pressure_base((ideal_struct){.pressure=1, \
>> .moles=1, .temp=273.15, __VA_ARGS__})
>>
>> double ideal_pressure_base(ideal_struct in)
>> {
>> return 8.314 * in.moles*in.temp/in.pressure;
>> }
>>
>> ... ideal_pressure(.moles=2, .temp=373.15) ...Forgot to add citation:
[1] Ben Klemens "21st Century C: C Tips from the New School", 2nd Ed. (2014),
O'Reilly Media, chapter 10. "Better Structures", subsection
"Optional and Named Arguments"> > Yeah, that looks unwieldy ;-) >
Declaration needs some trickery, but use is much, much more readable (if we cannot use sensibly named variables for passing arguments):
ideal_pressure() ideal_pressure(.temp=373.15) ideal_pressure(.moles=2) ideal_pressure(.moles=2, .temp=373.15)
It is even better if there are large amount of parameters:
res = amortization(.amount=200000, .inflation=3,
.show_table=0, .extra_payoff=100)vs
double amortize(double amt, double rate, double inflation, int months,
int selloff_month, double extra_payoff, int verbose,
double *interest_pv, double *duration, double *monthly_payment);But we can't use it in Git, anyway
-- Jakub Narębski