EmbeddedRelated.com
Forums

MISRA new rule suggestion

Started by Rob June 20, 2005
In article <42b71238.13946546@news.aioe.org>, Dave Hansen
<iddw@hotmail.com> writes
>On 20 Jun 2005 01:51:47 -0700, "Rob" <mr_horton@yahoo.com> wrote: > >>Ok, I admit this is just a personal preference of mine but I just >>wondered if anyone else felt the same way. So here comes the suggested >>rule >[...] >>Is it me or do I seem to have a dislike of _'s ? > >It's just you. > >Actually, I think most of MISRA (and most other coding "standards") >could be replaced with one simple rule: "Lint your d*mn code." > >Regards, > > -=Dave
Is that lint it using the MISRA-C conformance filter? -- \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/ /\/\/ chris@phaedsys.org www.phaedsys.org \/\/\ \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
David Tweed wrote:
> Rob wrote: > >> (1) __loop. Well, how are you supposed to drop that into polite >> conversation? > > "under-under-loop"
You're not. It is an identifier reserved for the implementor. If you are trying to use it you are wrong. -- Some informative links: news:news.announce.newusers http://www.geocities.com/nnqweb/ http://www.catb.org/~esr/faqs/smart-questions.html http://www.caliburn.nl/topposting.html http://www.netmeister.org/news/learn2quote.html
On Mon, 20 Jun 2005 23:40:23 +0100, Chris Hills <chris@phaedsys.org>
wrote:

>In article <42b71238.13946546@news.aioe.org>, Dave Hansen ><iddw@hotmail.com> writes
[...]
>>Actually, I think most of MISRA (and most other coding "standards") >>could be replaced with one simple rule: "Lint your d*mn code."
[...]
>Is that lint it using the MISRA-C conformance filter?
If your lint policy says so. Otherwise, no. FWIW, I've been using PC-lint from Gimpel for almost 20 years. It has saved my posterior more times than I care to count (or admit). I've been using (required to use on selected projects) the MISRA-bull guidelines (V1 -- I haven't seen V2 yet) for about 4 years. The only thing it's saved me is attempting to explain to the customer why it's unnecessary -- They can just check off the MISRA box on their list and go away happy. Regards, -=Dave -- Change is inevitable, progress is not.
"Rob" <mr_horton@yahoo.com> writes:

> Ok, I admit this is just a personal preference of mine but I just > wondered if anyone else felt the same way. So here comes the suggested > rule > > "Never use characters that cannot be pronounced" > > Here are some highly contrived examples: > > (1) __loop. Well, how are you supposed to drop that into polite > conversation? What if you have another variable called loop. How do you > verbally differentiate between the two of them? > > (2) time_left so how could you tell it apart from TimeLeft? > > Is it me or do I seem to have a dislike of _'s ?
I would say it's just you, because you really want to pronounce all of those things "time left", but none of them are actually spelled that way. I suppose you could pronounce "TimeLeft" by runningthewords together, to make it clear that it was a run-together word. But that doesn't tell you whether it's timeLeft, TimeLeft, or some other random spelling. And you could pronounce "__loop" as "double-under loop", but then I wonder how you are going to pronounce "__double_under_loop". And you could combine them: "__DOUBLE_Underloop". There's no easy way to pronounce those. In some languages, programmers do use all those different conventions at once. What a mess! The programming language that I usually work in (Lisp) uses a different set of conventions. First of all, case doesn't matter. If you say "UNDER" or "under" it means the same thing, so we don't bother with run-together words and worrying about the case. And although you could use underscore, nobody does, because we can use dash ("-"), which reads more naturally. I make this claim, because nobody is ever instructed not to use underscore. They know that they could, and many of the older programmers came from languages (like PL/I) where that's you always did. And yet nobody --- in particular, no newbies -- ever even suggest using underscores. I think the only reason this is not done in other languages is the infix subtraction problem. So we would always just write "time-left", pronounced "time left".
On 20 Jun, in article
     <1119257507.051249.148300@g47g2000cwa.googlegroups.com>
     mr_horton@yahoo.com "Rob" wrote:
>Ok, I admit this is just a personal preference of mine but I just >wondered if anyone else felt the same way. So here comes the suggested >rule
Having seen other replies, I wonder whether some people think of rules in isolation.
>"Never use characters that cannot be pronounced"
Makes basic assumption that all people only create variables using English to describe the function/variable/constant.....
>Here are some highly contrived examples: > >(1) __loop. Well, how are you supposed to drop that into polite >conversation? What if you have another variable called loop. How do you >verbally differentiate between the two of them? > >(2) time_left so how could you tell it apart from TimeLeft?
That is a different issue to you underscores example which if anything is a rule of making each name not having minor variations due to case or single punctuation characters.
>Is it me or do I seem to have a dislike of _'s ?
Probably just you, as I particular hate groupings like the following LeftHandedWidgetCount LeftHandedWidgetCountMax LeftHandedWidgetCountMin LeftHandedWidgetCountStep LeftFootedWidgetCount LeftFootedWidgetCountMax LeftFootedWidgetCountMin LeftFootedWidgetCountStep LeftFootedWalkingCount LeftFootedWalkingCountMax LeftFootedWalkingCountMin LeftFootedWalkingCountStep Which when combined in complex statements make following the flow prone to errors of auto assumption when reading. Having seen some code that because the compiler can support long names you end up with very long names because you can. This is like phone numbers, there comes a point where it is difficult to remember all the long sequences when the sequences get too long. -- Paul Carpenter | paul@pcserviceselectronics.co.uk <http://www.pcserviceselectronics.co.uk/> PC Services <http://www.gnuh8.org.uk/> GNU H8 & mailing list info <http://www.badweb.org.uk/> For those web sites you hate
In article <42b876d7.105237593@news.aioe.org>, Dave Hansen
<iddw@hotmail.com> writes
>On Mon, 20 Jun 2005 23:40:23 +0100, Chris Hills <chris@phaedsys.org> >wrote: > >>In article <42b71238.13946546@news.aioe.org>, Dave Hansen >><iddw@hotmail.com> writes >[...] >>>Actually, I think most of MISRA (and most other coding "standards") >>>could be replaced with one simple rule: "Lint your d*mn code." >[...] >>Is that lint it using the MISRA-C conformance filter? > >If your lint policy says so. Otherwise, no. > >FWIW, I've been using PC-lint from Gimpel for almost 20 years. It has >saved my posterior more times than I care to count (or admit).
Me too.
>I've been using (required to use on selected projects) the MISRA-bull >guidelines (V1 -- I haven't seen V2 yet) for about 4 years.
V2 is 141 rules. A complete re-write, re-organise and re-number.
>The only >thing it's saved me is attempting to explain to the customer why it's >unnecessary -- They can just check off the MISRA box on their list and >go away happy.
Whilst it is not perfect a lot of people who know what they are doing seem to rate it. -- \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/ /\/\/ chris@phaedsys.org www.phaedsys.org \/\/\ \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Paul Carpenter wrote:
> On 20 Jun, in article > <1119257507.051249.148300@g47g2000cwa.googlegroups.com> > mr_horton@yahoo.com "Rob" wrote: > >Ok, I admit this is just a personal preference of mine but I just > >wondered if anyone else felt the same way. So here comes the suggested > >rule > > Having seen other replies, I wonder whether some people think of rules > in isolation.
MISRA C rules sound like common sense when you have been through tricky bugs, We try to follow them as far as possible. lint is ok but it is not a bad idea to have coding rules in order to plan your coding in advance. lint helps to ensure you did it right.
> >"Never use characters that cannot be pronounced" > > Makes basic assumption that all people only create variables using English > to describe the function/variable/constant..... > > >Here are some highly contrived examples: > > > >(1) __loop. Well, how are you supposed to drop that into polite > >conversation? What if you have another variable called loop. How do you > >verbally differentiate between the two of them? > > > >(2) time_left so how could you tell it apart from TimeLeft? > > That is a different issue to you underscores example which if > anything is a rule of making each name not having minor variations due > to case or single punctuation characters. > > >Is it me or do I seem to have a dislike of _'s ?
Is that a cultural problem ? In this case it is beyond hope;)
> Probably just you, as I particular hate groupings like the following > > LeftHandedWidgetCount > LeftHandedWidgetCountMax > LeftHandedWidgetCountMin > LeftHandedWidgetCountStep > LeftFootedWidgetCount > LeftFootedWidgetCountMax > LeftFootedWidgetCountMin > LeftFootedWidgetCountStep > LeftFootedWalkingCount > LeftFootedWalkingCountMax > LeftFootedWalkingCountMin > LeftFootedWalkingCountStep
I once saw a sound advice, that you use the long names for globals and the short names for locals. Something like for(CounterOfLeftHandedWidget=0; ...) is overkill. for (ct_lhw=0; ...) is easier to read. You don't get lost in noise. If you have only a few local variables in your function it is not necessary to have long names.
> Which when combined in complex statements make following the flow > prone to errors of auto assumption when reading. Having seen some > code that because the compiler can support long names you end up > with very long names because you can. > > This is like phone numbers, there comes a point where it is > difficult to remember all the long sequences when the sequences > get too long. > > -- > Paul Carpenter | paul@pcserviceselectronics.co.uk > <http://www.pcserviceselectronics.co.uk/> PC Services > <http://www.gnuh8.org.uk/> GNU H8 & mailing list info > <http://www.badweb.org.uk/> For those web sites you hate
"Lanarcam" <lanarcam1@yahoo.fr> wrote in message 
news:1119435835.256492.263110@g43g2000cwa.googlegroups.com...
> I once saw a sound advice, that you use the long names for > globals and the short names for locals.
Globals? What globals? (I avoid global variables at all costs. I'm hoping you mean function names.)
> Something like for(CounterOfLeftHandedWidget=0; ...) is > overkill. for (ct_lhw=0; ...) is easier to read. You don't > get lost in noise. If you have only a few local variables > in your function it is not necessary to have long names.
I dislike cryptic variable names (e.g. ct_lhw) intensely. Common sense would suggest a compromise, e.g. WidgetCountLH. Steve http://www.fivetrees.com
Rob wrote:
>
... snip ...
> > Is it me or do I seem to have a dislike of _'s ?
I seem to be one of the very few who agree with you. I think it is a consequence of extreme laziness, and thus reluctance to use the shift key. -- Some informative links: news:news.announce.newusers http://www.geocities.com/nnqweb/ http://www.catb.org/~esr/faqs/smart-questions.html http://www.caliburn.nl/topposting.html http://www.netmeister.org/news/learn2quote.html
"Paul Carpenter" <paul$@pcserviceselectronics.co.uk> wrote in message

> Probably just you, as I particular hate groupings like the following > > LeftHandedWidgetCount > LeftHandedWidgetCountMax > LeftHandedWidgetCountMin > LeftHandedWidgetCountStep > LeftFootedWidgetCount > LeftFootedWidgetCountMax > LeftFootedWidgetCountMin > LeftFootedWidgetCountStep > LeftFootedWalkingCount > LeftFootedWalkingCountMax > LeftFootedWalkingCountMin > LeftFootedWalkingCountStep
In a situation like that, one should also check the (implementation-specific) significant initial character length. In the examples above, if the compiler only recognizes the first 16 characters, then LeftHandedWidgetCount and LeftHandedWidgetCountMax refer to the same variable.