Lambda the Ultimate

inactiveTopic Comments on Comments
started 3/1/2002; 3:29:50 PM - last post 3/7/2002; 12:57:03 PM
Chris Rathman - Comments on Comments  blueArrow
3/1/2002; 3:29:50 PM (reads: 2667, responses: 14)
Comments on Comments
Comments are those things which get in the way of the coding process and turn a simple 5 line function into a 2 page long novella. :)

Lots of effort seems to be geared towards formalism in proving the correctness of programs. Yet, when it comes to comments, there's usually little formal structure. Sure, some languages have ad hoc standards, where certain meta tags are used to extract to an html file, etc... but these are not really part of the formal language definition, and there's no enforcement mechanism to speak of.

Wondering if the language researchers have put any thought into making comments a bit easier to maintain and digest?
Posted to Software-Eng by Chris Rathman on 3/1/02; 3:33:21 PM

michael mceniry - Re: Comments on Comments  blueArrow
3/1/2002; 8:21:55 PM (reads: 1869, responses: 0)
(diatribe at http://pokey.itsc.uah.edu/~mmceniry/odd/2002/03/01.html#a73)

It's one thing to enforce form (javadoc, style checkers). It's pretty much the same to provide tools (IDEs) that make it easier to follow a form than not. Only peer review (ie, "Pride of Workmanship") can really provide that extra bit of encouragment to a comment author. Just because a chunk of XML is valid doesn't mean that the values are correct. At least code can have automated tests.

In any case, some software engineering efforts (um, sorry, no references handy) have focused on formalising requirements language, primarily for mathematical proofs of correctness of requirements and, as you mention, code. Perhaps those could be used for comments as well.

scruzia - Re: Comments on Comments  blueArrow
3/1/2002; 9:09:22 PM (reads: 1876, responses: 0)
I always thought literate programming was the "right" way to go about writing programs. Unfortunately:

- comp.programming.literate has only the FAQ, no active participation.

- when I suggested to the author of the "syntax across languages" page http://merd.net/pixel/language-study/syntax-across-languages.html that his "comments" section should have *some* mention of literate programming, at least in the form that Haskell's ".lhs" files encourage, he decided that this was somehow outside of the realm of syntax, outside of the scope of his page.

- most programmers are too lazy and too focused on the immediate problem to write clear natural language descriptions of what they intend for their code to do.

Ehud Lamm - Re: Comments on Comments  blueArrow
3/2/2002; 8:50:06 AM (reads: 1832, responses: 0)
If the code and the comments disagree, then both are probably wrong. -- Norm Schryer, Bell Labs (quoted in More Programming Pearls by Jon Bentley)

Luke Gorrie - Re: Comments on Comments  blueArrow
3/2/2002; 9:13:31 AM (reads: 1834, responses: 0)
Interesting topic, terrible article! :-)

My $0.02 says that Lisp's docstrings, `describe', `apropos', and so on are great and that other systems should use them too.

Chris Rathman - Re: Comments on Comments  blueArrow
3/2/2002; 11:53:06 PM (reads: 1818, responses: 0)
Interesting topic, terrible article!
From a theoretical standpoint, there wasn't much to recommmend the article. It was mostly a matter of pragmatics or common sense - things that most programmers know. Mostly the article was about implementation, of which LtU is not necessarily interested. The article was more a springboard about discussing how programming languages might aide the process the commenting code - so I really didn't discuss the article per se.

My $0.02 says that Lisp's docstrings, `describe', `apropos', and so on are great and that other systems should use them too.
I think that these comment structures represent an improvement over totally free form comments, but I think they are still only a beginning. Oddly enuf, many people have complained about how difficult it is to comment out Lisp code, so maybe the constructs represent counter attempts to overcome the inherent deficiencies in the free form comments in the language.

Personally, I think the solution to the problem comes by limiting each and every function to 5 to 25 lines of code (think smalltalk). If one limits a function/method to a minumum, then one does not need to comment each and every line. Indeed, I think that if one gives any comment to anything other than the overall level of the function, then one has not factored the function properly.

So to those that would give comment that one should write comments within the function pertaining to the exact nature of the specifics of the function, I eould say that you have written functions that are way too complex. A function should do one thing - and it should do it well.

It's one thing to enforce form (javadoc, style checkers). It's pretty much the same to provide tools (IDEs) that make it easier to follow a form than not. Only peer review (ie, "Pride of Workmanship") can really provide that extra bit of encouragment to a comment author
One problem I see is that code is a document with many different consumers. On the one hand, we have the readers that want to simply know the external references (contracts) that are present within the code. On the other hand, we have the programmers that want to know how the code goes about fulfilling that contract - wishing to know whether the code is truthful, or whether it is lying about that contract. In addition, there is the end user that just wants the dang software works.

The point is that the code is read for different purposes by different people. The code may correctly convey information to the machine but its usefulness in the long term is determined by the META-information contained in the comments in the code that are neither compiled nor verified.

Daniel Dittmar - Re: Comments on Comments  blueArrow
3/4/2002; 2:31:14 AM (reads: 1770, responses: 0)
IBM's cleanroom method makes extensive use of comments: - part of the code review is that comments and code match - comments should be formal whenever possible, which seems to mean that they use some form of pidgin smalltalk. More on this in the book 'Toward Zero-Defect Programming', although I'm sure that there are some web resources as well.

Worth mentioning is also the Object Contraint Language, an often neglected part of UML, which strives to be some form of language independent Design by Contract. I guess all specification languages could wind up in special comment sections (provided they can be expressed in ASCII).

Franck Arnaud - Re: Comments on Comments  blueArrow
3/4/2002; 4:13:31 AM (reads: 1766, responses: 0)
Eiffel has header comments which are part of the language spec and extracted by documentation tools. It's not perfect but it's more than ad-hoc: there are no tags inside the comments, it's the location of the comment within the syntax which distinguishes the formal comments from inline comments which are ignored by documentation tools.

Also design by contract, despite its limitations, goes some way towards making what would be comments in other languages executable (and typed) constructs.

Ehud Lamm - Re: Comments on Comments  blueArrow
3/4/2002; 12:36:56 PM (reads: 1742, responses: 2)
I prefer to limit comments to things that cannot (and should not) be part of the code itself- things like design decisions and imlplications, change logs etc. Other than that I prefer languages that are both expressive enough and readable enough to allow the programmer to explain himself via the code. Notice that these are two criteria. For example, adding contracts to the language allows you to specify the contractual obligations of software components inside the language. Finding a readable contract notation is a more problematic issue.

One language design issue concerns adding language constructs that cannot be checked or enforced by the translator. Many find such constructs problematic. This is one reason why some prefer comments over annotations that are part of the code but are not checked. Contracts are again a useful example, since contract are used to specify properties that are only checked during runtime, as opposed to static properties specified using type systems. The problem becomes even more extreme when you consider properties that cannot be checked effectively even during runtime, like being deadlock free and other temporal properties. Should these be specified as code, or as comments? Personally, I prefer formal, executable, notations. I concede that this can be problematic, and implies adding to the complexity of the programming language.

Ehud Lamm - Re: Comments on Comments  blueArrow
3/7/2002; 1:27:48 AM (reads: 1740, responses: 0)
Lest we forget assertions which are -- like contracts -- enforceable comments.

Chris Rathman - Re: Comments on Comments  blueArrow
3/7/2002; 10:51:46 AM (reads: 1637, responses: 1)
But then how do we ensure that the comments which are associated with contracts and assertions are correct? Must be some twist on Godel's Thereom. :-)

scruzia - Re: Comments on Comments  blueArrow
3/7/2002; 12:57:03 PM (reads: 1637, responses: 0)
Ehud writes:
One language design issue concerns adding language constructs that cannot be checked or enforced by the translator. Many find such constructs problematic. [...] Personally, I prefer formal, executable, notations. I concede that this can be problematic, and implies adding to the complexity of the programming language.

A bit of support for Ehud's point of view here: Alex Martelli writes voluminously, passionately, articulately, repeatedly, and convincingly (to me, anyway) about this subject in comp.lang.python ... a GooJa search for

compiler express group:comp.lang.python author:Martelli
led me to these paragraphs (each a part of a much longer posting):

July 2001
Subject: Re: not safe at all
http://groups.google.com/groups?selm=9ioonl0jgu%40enews4.newsguy.com

I'd like a language that just lets me state as little or as much as I know and want to express unambiguously -- then the compiler in turn can generate as little or as much static or dynamic typing as it knows how to generate and/or it's directed to generate by options or whatever, but meanwhile I HAVE expressed my design intent in my sources -- *NOT* in possibly-ambiguous comments, but in formal, unambiguous language that MAY, depending on the state of compiler technology, turn out to help direct the compiler to generate appropriate code.

August 2001
Subject: typing system vs. Java
http://groups.google.com/groups?selm=9ke6n409mj%40enews3.newsguy.com

When expressing design intentions in a formal language, I get a *CHANCE* that they will be checked, at least partially, or used for optimization purposes and other inferences. [...] [Expressing these *formally* makes them:]
  • totally unambiguous [...]
  • potentially checkable [...]
  • potentially usable for inferences [...], to get higher-performing code
The first point always holds and it's a key one. Second and third are just possibilities (with current Python technology, for assert, the second does hold, the third one doesn't), but the point is: once the construct is in the language, and therefore in those application programs that might live for the next 20 or 40 years, compiler technology may improve and actually take advantage of what today are just 'potentials', aka possibilities.

November 2000
Subject: Re: Programming Habits in Python
http://groups.google.com/groups?selm=8vlia101jd9%40news2.newsguy.com

What I'd really like is a set of ways to _express_ every possible constraint/expectation that I may consider to be highly relevant for my application -- whether the compiler is able to check it statically, dynamically, or not at all (or, conversely, whether fruitful optimizations may be gained by the compiler relying on my assertions) are secondary issues... the key is that the language lets me STATE things, then, as technology develops, some of them may come in handy, and anyway in the meantime human readers and maintainers are better placed than if the assertions were in comments, in separate docs, or totally absent.

Ehud Lamm - Re: Comments on Comments  blueArrow
3/8/2002; 7:52:26 AM (reads: 1664, responses: 0)
I don't follow. The point is that instead of comments you code the specification as contracts and assertions. You can use comments for things that are outside this scope, of course.