On Jun 26, 2013, at 16:25, Joshua Landau <joshua.landau.ws@gmail.com> wrote:
On 27 June 2013 00:17, Andrew Barnert <abarnert@yahoo.com> wrote:
In case it's not obvious how ridiculous it is to extrapolate MISRA-C to other languages…
I went through the 127 rules in MISRA-C 1998. About 52 of them could be extrapolated to Python. Of those, 20 make some sense; the other 32 would be either ridiculous or disastrous to apply in Python. (In fact, much the same is true even for more closely-related languages like C++ or JavaScript.)
If you're curious about the details, see http://stupidpythonideas.blogspot.com/2013/06/misra-c-and-python.html.
"67. rcm: Don't rebind the iterator in a for loop."
That sounds quite sane to me...
Why? In C, the loop iterator is a mutable variable; assigning to it changes the loop flow. for (i=0; i!=10; ++i) { if (i % 2) { i = 0; } printf("%d\n", i); } That looks like it should alternate even numbers with 0's, up to 10. But it actually produces an infinite loop of 0's. Very confusing. In Python, the loop iterator is just a name for a value; assigning to it does not change that value or affect the flow in any way; it just gives you a convenient name for a different value. for i in range(10): if i % 2: i = 0 print i That looks like it should alternate even numbers with 0's, up to 10. And that's exactly what it does. Obviously this is a silly toy example, but there's plenty of real code that does this kind of thing.