MISRA new rule suggestion

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
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 ?


Re: MISRA new rule suggestion
Quoted text here. Click to load it

I think it would be better to disallow two identifiers whose only
difference is by underscores, just like it's a bad idea to have separate
identifiers distinguished only by small or capital letters.  Thus
"time_left" would be fine, as long as you don't also have a "TimeLeft",
just as having "TimeLeft" and "timeLeft" would be a bad idea.

Re: MISRA new rule suggestion
Quoted text here. Click to load it

"under-under-loop"

Quoted text here. Click to load it

"time-under-left"

-- Dave Tweed

Re: MISRA new rule suggestion


Quoted text here. Click to load it

Following Mr pre-decremented Tweed's suggestion, I am going to have to
start using the following

_Milkwood
_score
_pass
_pants

Ian


Re: MISRA new rule suggestion

Quoted text here. Click to load it

..well as _ is often called an  "Underscore", that one could causeeven  more
confusion....



Re: MISRA new rule suggestion

Quoted text here. Click to load it
more confusion....

And probably a little mis_standing.



Re: MISRA new rule suggestion
writes
Quoted text here. Click to load it

Captain Over,
Captain Under,
Captain Done?

(apologise to Airplane part Deaux :-)
--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills  Staffs  England     /\/\/\/\/
We've slightly trimmed the long signature. Click to see the full one.
Re: MISRA new rule suggestion
Quoted text here. Click to load it

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
We've slightly trimmed the long signature. Click to see the full one.
Re: MISRA new rule suggestion
Quoted text here. Click to load it


I will show the MISRA-C team tomorrow.  We are half way through one of
our 2 day meetings.... We need a diversion at tea time :-)
--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills  Staffs  England     /\/\/\/\/
We've slightly trimmed the long signature. Click to see the full one.
Re: MISRA new rule suggestion

Quoted text here. Click to load it

Having variable names such as L00P, LO0P are much more of a problem
than an underscore. Varaibles starting with an underscore should not
be used in user apps in anycase. They are supposed to be for the
compiler implementor.

Regards
  Anton Erasmus


Re: MISRA new rule suggestion

Quoted text here. Click to load it
[...]
Quoted text here. Click to load it

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
--
Change is inevitable, progress is not.

Re: MISRA new rule suggestion
Quoted text here. Click to load it
Is that lint it using the MISRA-C conformance filter?

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills  Staffs  England     /\/\/\/\/
We've slightly trimmed the long signature. Click to see the full one.
Re: MISRA new rule suggestion

[...]
Quoted text here. Click to load it
[...]
Quoted text here. Click to load it

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.

Re: MISRA new rule suggestion
Quoted text here. Click to load it

Me too.


V2 is 141 rules. A complete re-write, re-organise and re-number.

Quoted text here. Click to load it

Whilst it is not perfect a lot of people who know what they are doing
seem to rate it.

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills  Staffs  England     /\/\/\/\/
We've slightly trimmed the long signature. Click to see the full one.
Re: MISRA new rule suggestion

Quoted text here. Click to load it

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".

Re: MISRA new rule suggestion
I guess this discussion is really about C, but as long
as I was mentioning how winning it is that names  in Lisp
use hyphens (not underscore) for spaces, I thought I'd
also pass along the recollection that COBOL also does.

Some sample Lisp names:

ENQUEUE-MESSAGE-CHANNEL-BUFFER
WITHOUT-INTERRUPTS
STOP-82C54-PERIODIC-TIMER
SCSI-MODE-SENSE-BLOCK-DESCRIPTOR-BLOCK-LENGTH
MAYBE-WAKEUP-DMA-SUPERVISOR
CHANNEL-ENABLE-68562-RECEIVER
IS-PLAN-FOR-CONJUNCTIVE-SUBGOALS
PARENT-INFERIORS
BUBBLE-MUNG-REGION-ARRAY
REAL-COMPLEX-W
RV-FFT-IMAG-INDEX-ARRAYS

Some sample COBOL names:

LINE-NO
REPLENISH-REPORT-HEADING
UNITS-ON-HAND

Pretty much the same!  People (for the last 20 years) usually
write Lisp source code in lowercase, though, although the
case doesn't matter.  Lisp predates COBOL.

Re: MISRA new rule suggestion
<SNIP>
Quoted text here. Click to load it

Well, in Forth we use the dash convention often too.
I have defined the word _ as "push a don't care value to the
stack". Its prononciation is "don't care". Forth uses any number
of weird character combinations, but the prononciation is
known:
*/mod  "star-slash-mod"
+!     "plus-store"
$^     "string-index"

Not only the founder, Chuck Moore, insists that words are
pronouncable, he prefers them to form sentences.

Further most Forth's are case-insensitive, although I don't really
like that.

Quoted text here. Click to load it

Groetjes Albert.

--
--
Albert van der Horst,Oranjestr 8,3511 RA UTRECHT,THE NETHERLANDS
Economic growth -- like all pyramid schemes -- ultimately falters.
We've slightly trimmed the long signature. Click to see the full one.
Re: MISRA new rule suggestion
On 20 Jun, in article
Quoted text here. Click to load it

Having seen other replies, I wonder whether some people think of rules
in isolation.

Quoted text here. Click to load it

Makes basic assumption that all people only create variables using English
to describe the function/variable/constant.....

Quoted text here. Click to load it

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.

Quoted text here. Click to load it

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          | snipped-for-privacy@pcserviceselectronics.co.uk
<http://www.pcserviceselectronics.co.uk/ PC Services
We've slightly trimmed the long signature. Click to see the full one.
Re: MISRA new rule suggestion


Quoted text here. Click to load it

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.

Quoted text here. Click to load it

Is that a cultural problem ? In this case it is beyond hope;)

Quoted text here. Click to load it

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.

Quoted text here. Click to load it


Re: MISRA new rule suggestion
Quoted text here. Click to load it

Globals? What globals? (I avoid global variables at all costs. I'm hoping
you mean function names.)

Quoted text here. Click to load it

I dislike cryptic variable names (e.g. ct_lhw) intensely. Common sense would
suggest a compromise, e.g. WidgetCountLH.

Steve
http://www.fivetrees.com



Site Timeline