public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: John Richard Moser <nigelenki@comcast.net>
To: Jakob Oestergaard <jakob@unthought.net>
Cc: Denis Vlasenko <vda@port.imtp.ilyichevsk.odessa.ua>,
	linux-kernel@vger.kernel.org
Subject: Re: [RFC] Bug zapper?  :)
Date: Tue, 10 Aug 2004 11:19:43 -0400	[thread overview]
Message-ID: <4118E78F.8070301@comcast.net> (raw)
In-Reply-To: <20040810083553.GB27443@unthought.net>



Jakob Oestergaard wrote:
> On Mon, Aug 09, 2004 at 07:09:55PM -0400, John Richard Moser wrote:
> ...
> 
>>Now, we could try another approach at this, below.
>>
>>/* get_food(char **a)
>>* Gets the current food.
>>*
>>* INPUT:
>>*  - char **a
>>*    Pointer to a pointer for the outputted food.
>>* OUTPUT:
>>*  - Return
>>*    none.
>>*  - *a
>>*    Set to a copy of the current food.
>>* PROCESS:
>>*  - Set '*a' to a newly allocated block of memory containing a copy
>>*    of the current food (global_food)
>>* STATE CHANGE:
>>*  none.
>>*/
> 
> ...
> 
> There's just more to it than this.
> 
> Even in the almost "self explanatory" example you gave, even with your
> suggested style of commenting, there are still problems:
> 
> Your comments do not describe who's responsible for allocating/freeing
> which memory areas the various pointers point at.
> 

Then my comment above is bad.  Should add that it frees the old block.

> Your get_food() function will cause a write at address 0 if malloc()
> fails.
> 

My code is bad probably.  I should return if malloc() fails.

> So, you have provided some good examples that no particular commenting
> style is going to solve the common problems that all larger C software
> projects face to some extent (memory management and error handling).
> 

Memory managment is annoying.  I'm working on a reference counting 
scheme on the side; but that's a fair bit of overhead.  I've never been 
able to argue that reference counting is less overhead than manual mm; 
but I've also never been able to argue that trying to guess if you can 
free memory based on your program's internal state is less overhead than 
reference counting.

There's places where this is inappropriate, and places where it's 
appropriate.  Inside the kernel, though, I can't imagine where it'd be 
appropriate.   . . . yeh this is a bad idea, isn't it?  :p


> ...
> 
>>These comment blocks are *MUCH* more verbose.
> 
> 
> Agreed  :)
> 
> 
>>They describe the process 
>>loosely, but do give enough information to allow understanding without 
>>questions.
> 
> 
> That's where I disagree.
> 
> They do provide an illusion of knowledge though (for example, you did
> not mention the built-in segfault mechanism, that was a hidden feature).
> 

The function isn't made to segfault; segfaulting is what happens when 
you screw up your code.  :)

I guess it should describe INPUT, OUTPUT, PROCESS, STATE CHANGE, and 
ERRORS :/

> 
>>The large amount of extra commentary is worth it, IMHO.
> 
> 
> Comments are good.  Frequent comments are very good - if they are
> correct and actually helpful.
> 
> I view it this way; if code is not commented, the only explanation is
> that the author didn't feel it was worth commenting.  Code that is not
> worth even a comment, should be removed from whatever project it is in,
> to be replaced by something actually worth commenting.   (no, I'm not
> bashing any particular part of the Linux kernel or anything like that -
> this is my personal view for projects that I'm involved in).
> 
> However; comments are NOT a substitute for all the other aspects
> required for good and reliable code.
> 

Readable.  Don't guess what the code does.

> Comments are one little part of the larger puzzle.  Ignoring their
> importance is inexcusable - but they are not the magic silver bullet all
> by themselves either.
> 

Of course not.  The goal I was aiming for was to create an extremely 
structured documentation scheme in the hopes that it would provide a 
great deal of ease in understanding what a function does.  "if you don't 
understand what it does, don't fuck with my code"

> 
> My 0.02 Euro
>  (as someone working on another large project that actually needs
>   to run reliably)
> 

-- 
All content of all messages exchanged herein are left in the
Public Domain, unless otherwise explicitly stated.


  reply	other threads:[~2004-08-10 15:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-09 20:07 [RFC] Bug zapper? :) John Richard Moser
     [not found] ` <200408100042.37159.vda@port.imtp.ilyichevsk.odessa.ua>
2004-08-09 23:09   ` John Richard Moser
2004-08-10  0:58     ` Bernd Eckenfels
2004-08-10  1:55       ` Tommy Reynolds
2004-08-10  2:47     ` Rik van Riel
2004-08-10  3:13       ` John Richard Moser
2004-08-10  8:35     ` Jakob Oestergaard
2004-08-10 15:19       ` John Richard Moser [this message]
2004-08-10 21:43         ` Bernd Eckenfels
2004-08-10 21:30 ` V13
2004-08-10 23:35   ` John Richard Moser
2004-08-11  4:50   ` Bernd Eckenfels
  -- strict thread matches above, loose matches on Subject: below --
2004-08-10 21:13 Nick Warne

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4118E78F.8070301@comcast.net \
    --to=nigelenki@comcast.net \
    --cc=jakob@unthought.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vda@port.imtp.ilyichevsk.odessa.ua \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox