A case for "real" multiline comments

Cameron Simpson cs at zip.com.au
Thu Apr 19 00:29:19 EDT 2012


On 18Apr2012 22:07, Jordan Perr <jordan at jperr.com> wrote:
| I came across this case while debugging some Python code that contained an
| error stemming from the use of multiline strings as comments. The code
| contained a very long list of objects, and I had commented out some of the
| objects using the multiline string.

You are aware that a string is not a comment?

| This caused a string to be appended to
| the list instead of ignoring the section. Consider the following code:
| 
| list = [
| Object1(arg),
| """
| Object2(arg),
| Object3(arg),
| """
| Object4(arg)
| ]
| 
| Real multiline comments would produce [Object1, Object4]. The list, in
| fact, contains [Object1, "Object2, Object3", Object4]. I can't really see a
| good way to get around this without true multiline comments.

I'd just do this:

  list = [
  Object1(arg),
  ## Object2(arg),
  ## Object3(arg),
  Object4(arg)
  ]

Multiple lines of single line comments. Frankly, I find this much easier
to see (all the disabled lines are delineated with nice bright comment
markers, and the beginning and end of the comment (were it a multiline
comment) can't disappear off my screen.

I would say you've made a case _against_ multiline coments.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

Sam Jones <samjones at leo.unm.edu> on the Nine Types of User:

Frying Pan/Fire Tactician - "It didn't work with the data set we had, so I
                             fed in my aunt's recipe for key lime pie."
Advantages:     Will usually fix error.
Disadvantages:  'Fix' is defined VERY loosely here.
Symptoms:       A tendancy to delete lines that get errors instead of fixing
                them.
Real Case:      One user complained that their program executed, but didn't
                do anything.  The scon looked at it for twenty minutes before
                realizing that they'd commented out EVERY LINE.  The user
                said, "Well, that was the only way I could get it to compile."



More information about the Python-list mailing list