Today's programming silliness
Oct. 20th, 2023 05:33 pmToday's programming silliness: creating a function with 16 parameters.
And then creating a second function with 39 parameters to call the first one.
The worst part: I think it makes the code more readable!
And then creating a second function with 39 parameters to call the first one.
The worst part: I think it makes the code more readable!
no subject
Date: 2023-10-22 02:04 am (UTC)no subject
Date: 2023-11-01 10:39 pm (UTC)It's a chunk of code converting from one struct to another, where there's a half-dozen fields repeated twice, and then that entire block is repeated twice with a few more fields. It should be nested types, and indeed it is in a C# version - but this function is in C where it's all flat structs with awkward bit packing. So the 16-parameter function has pointers to the fields to read from the input struct, pointers to the fields to write in the output struct, and a handful of constants for flags. Then the 39-parameter function takes all that times two, and calls the 16-parameter function twice. Then the top-level code calls that 39-parameter function twice.
It does at least mean it's easy to scan through and see "this is reading part A1, this is reading part A2, etc" and then have the conversion logic in one place. The other way I could think of is copy'n'paste four times and hope I've updated everything!
no subject
Date: 2023-11-02 05:28 am (UTC)