News for hackers. Stuff that matters.
Re:Rules for Developing Safety-Critical Code (2006) [pdf] by msla on Friday October 18, 2019 @10:03AM (#21291417)
Some functions are complicated, some are simple, some are very simple. C makes you write out more of the very simple ones by hand.

For example, imagine a very simple bytecode interpreter: In C, you need a function to dispatch all of your bytecodes to the correct implementation functions with the right arguments. In Common Lisp, this is a prime target for a macro to turn a configuration file into actual code using fill-in-the-blanks boilerplate iterated a few times. In C, you have to write the switch statement by hand, which leads to writing a function as long as the number of individual bytecodes your interpreter knows about. Exceeding sixty lines is entirely possible assuming formatting directives are adhered to such that you can't bunch statements up on a single line. However, that switchyard function is the simplest way to write that code; breaking it up would only make things needlessly complicated and harder to check.

Re:Rules for Developing Safety-Critical Code (2006) [pdf] by Gibbon1 on Friday October 18, 2019 @11:28AM (#21292181)
That's my opinion as well. A function should have a one job and do that one job. Not two jobs, not five jobs and usually worse 3/16ths a job because some line limit rule.

The line limit rule sounds to me like a CS professors homework assignment instruction that escaped into the workplace.

Re:Rules for Developing Safety-Critical Code (2006) [pdf] by AnimalMuppet on Friday October 18, 2019 @01:29PM (#21293300)
In C, you could do that with an array of pointers to functions, and just index into the array. (The functions would need to know their own number of arguments, though, and consume them from the byte stream. But I think I prefer that to the dispatcher knowing the number of arguments that each function consumes.)
Re:Rules for Developing Safety-Critical Code (2006) [pdf] by msla on Friday October 18, 2019 @01:55PM (#21293567)
That would defeat some static analysis, so I can see it being disallowed by a careful style guide.
Re:Rules for Developing Safety-Critical Code (2006) [pdf] by scatters on Friday October 18, 2019 @11:27AM (#21292168)
Well - in C, you can use macros as well as in Lisp. Classically, you'd use X-Macros, requiring a separate file to hold the list of bytecodes; in the modern style you can use Boost.Preprocessor to operate on preprocessor data structures.
Re:Rules for Developing Safety-Critical Code (2006) [pdf] by saghm on Friday October 18, 2019 @04:07PM (#21294671)
You can use Boost in C? Is this something that's commonly done? I thought Boost was for C++
Re:Rules for Developing Safety-Critical Code (2006) [pdf] by AlotOfReading on Friday October 18, 2019 @04:31PM (#21294833)
Boost.Preprocessor is the only part usable from C, though I wouldn't generally recommend using it.
Re:Rules for Developing Safety-Critical Code (2006) [pdf] by Mikhail_Edoshin on Sunday October 20, 2019 @02:31AM (#21302585)
And exactly such a function exists in CPython, the main implementation of Python :) It's about 2000 lines of code, as far as I remember.