Hacker News new | ask | show | jobs
by konstmonst 2337 days ago
I think a lot of misra rules are bullshit and not account for improvements in computer science.

- goto is useful for error handling and when you have to double break

- function pointers are useful and easy to read state machines and also for functional programming, which is sometimes easier to comprehend and produces better patterns

- "Restrict functions to a single printed page." in my experience does not work. I would rather partition functions by topic or by level of "zoom"/abstraction

- "Use a minimum of two runtime assertions per function." that doesn't really say anything useful imho. Use as much as experience tells you too.

I agree with the rest

3 comments

I think your fourth rule is better stated along the lines of requiring constraints on both input and output (Performance?)

a la

bool noNaNs(float[] test); bool isSorted(inout float[]); float[] sort(float[] input) in(input.noNaNs) out(o; o.isSorted) { return input; }

Not sure about goto, I'm not sure what I prefer between goto or a while loop and a very big switch statement (let's say) to implement a lexer.

Yes goto in C is perfectly safe. Far as I've been able to discern 1970's computer scientists believed they could prove things about program iff they restricted the language features. Problem is, you basically can't and goto in structured languages isn't an impediment. See also the rules against using continue and multiple returns.

Personally I can't see how function pointers are worse than languages pushing return addresses onto the same fucking stack they push data.

Restrict functions to a single page sounds like a home work assignment rule that's been cargo culted into a standard. Functions should do one logical thing and nothing more or LESS.

The two runtime assertions might make sense for a space craft where cosmic rays are randomly flipping bits. Don't make much sense otherwise. My theory is functions that modify state should barf hard when told to do something stupid. Functions that don't should return an error.

That's fine. You don't have to use every rule, you just have to express why you're choosing not to use them. That's why they're separated into categories.