473,769 Members | 6,337 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

multiline comments

At the risk of flogging a dead horse, I'm wondering why Python doesn't have
any multiline comments. One can abuse triple-quotes for that purpose, but
that's obviously not what it's for and doesn't nest properly. ML has a
very elegant system for nested comments with (* and *).

Using an editor to throw #s in front of every line has limitations. Your
editor has to support it and you have to know how to use that feature. Not
exactly intuitive or easy for novices to pick up. Also a pain if your
preferred editor is python/perl/sh-agnostic.

Saying coders shouldn't use multiline comments to disable code misses the
point. Coders will comment out code regardless of the existence of
multiline comemnts. There has to be a better argument for leaving them out.

Keeping the language small and simple is desirable, but it's not an
absolute. A little syntactic sugar like 'for x in s' makes code easier to
read than 'for i in len(s): x = s[i]'. So what are the tradeoffs involved
with nested multiline comments? I'd like to understand the reasoning
behind keeping them out.
Apr 19 '06 #1
40 4640
Edward Elliott wrote:
At the risk of flogging a dead horse, I'm wondering why Python doesn't
have any multiline comments. One can abuse triple-quotes for that
purpose, but that's obviously not what it's for and doesn't nest
properly. ML has a very elegant system for nested comments with (* and *).

Using an editor to throw #s in front of every line has limitations.
Your editor has to support it and you have to know how to use that
feature. Not exactly intuitive or easy for novices to pick up. Also a
pain if your preferred editor is python/perl/sh-agnostic.

Saying coders shouldn't use multiline comments to disable code misses
the point. Coders will comment out code regardless of the existence of
multiline comemnts. There has to be a better argument for leaving them
out.

Keeping the language small and simple is desirable, but it's not an
absolute. A little syntactic sugar like 'for x in s' makes code easier
to read than 'for i in len(s): x = s[i]'. So what are the tradeoffs
involved with nested multiline comments? I'd like to understand the
reasoning behind keeping them out.


I think the absence of multiline comments is like the requirement for
indentation. It enforces good habits. Better is to make your multiple
lines a function and comment out the function call.

James

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
Apr 19 '06 #2
James Stroud <js*****@ucla.e du> writes:
Edward Elliott wrote:
At the risk of flogging a dead horse, I'm wondering why Python
doesn't have any multiline comments. [...]

Using an editor to throw #s in front of every line has
limitations. Your editor has to support it and you have to know
how to use that feature. Not exactly intuitive or easy for
novices to pick up. Also a pain if your preferred editor is
python/perl/sh-agnostic.


I think the absence of multiline comments is like the requirement
for indentation. It enforces good habits. Better is to make your
multiple lines a function and comment out the function call.


And/or switch to an editor that can perform editing operations on a
range of lines.

--
\ Q: "I've heard that Linux causes cancer..." Torvalds: "That's |
`\ a filthy lie. Besides, it was only in rats and has not been |
_o__) reproduced in humans." -- Linus Torvalds |
Ben Finney

Apr 19 '06 #3

Edward Elliott wrote:
At the risk of flogging a dead horse, I'm wondering why Python doesn't have
any multiline comments. One can abuse triple-quotes for that purpose, but
that's obviously not what it's for and doesn't nest properly. .... Saying coders shouldn't use multiline comments to disable code misses the
point. Coders will comment out code regardless of the existence of
multiline comemnts. There has to be a better argument for leaving them out.


i beg to differ: you'd be surprised how much effect can little
inconveniences have.

want to comment block of code? use tripple-quotes. does not nest? ahhh,
maybe it's time to get rid of that block you commented out a month ago
"just in case the new code doesnt work".

that gives you incentive to tidy up. don't be a code slob... don't
leave a mess forever ;-)

Apr 19 '06 #4
"Atanas Banov" <en****@gmail.c om> writes:
Edward Elliott wrote:
Saying coders shouldn't use multiline comments to disable code
misses the point. Coders will comment out code regardless of the
existence of multiline comemnts. There has to be a better
argument for leaving them out.


i beg to differ: you'd be surprised how much effect can little
inconveniences have.

want to comment block of code? use tripple-quotes. does not nest?
ahhh, maybe it's time to get rid of that block you commented out a
month ago "just in case the new code doesnt work".


Indeed. Using revision control means never needing to comment out
blocks of code.

If your revision control system is so inconvenient to use that you'd
rather have large blocks of commented-out code, it's time to start
using a better RCS -- perhaps a distributed one, so you can commit to
your own local repository with abandon while trying out changes.

--
\ "I saw a sign: 'Rest Area 25 Miles'. That's pretty big. Some |
`\ people must be really tired." -- Steven Wright |
_o__) |
Ben Finney

Apr 19 '06 #5
Atanas Banov wrote:
want to comment block of code? use tripple-quotes. does not nest? ahhh,
maybe it's time to get rid of that block you commented out a month ago
"just in case the new code doesnt work".

that gives you incentive to tidy up. don't be a code slob... don't
leave a mess forever ;-)


And when the section I want to comment out contains a legit doc string in
the middle, triple-quotes won't work. There are valid reasons to nest
comments which have nothing to do with laziness or sloppy code.

Forcing programmers to write clean code with syntax is like teaching a pig
to sing: it wastes your time and annoys the pig. Good coding is a state of
mind, not a parser option.
Apr 19 '06 #6
Ben Finney wrote:
And/or switch to an editor that can perform editing operations on a
range of lines.


I'm not unsympathetic to this point of view, as I would feel hamstrung
without my vim. It's more that I object to the paternalism of telling
people they have to use such an editor. There are times when notepad is
all that's available.

On top of that, the expressive power of nested comments seems greater than
an endless string of ^#s. Sometimes it's just easier to see what's going on.
Apr 19 '06 #7
Ben Finney wrote:
Indeed. Using revision control means never needing to comment out
blocks of code.


Typing (* and *) on a few line will always be quicker, easier, and less
confusing than any rcs diffs/restores. Once you delete the code you can no
longer see it or add pieces back in without retrieving it from an external
store. I'm not saying nested comments solve every problem, just that there
exists a certain (perhaps small) class of problems they solve particularly
well.

Personally, I rarely leave code commented out beyond a single coding
session. But my particular coding habits aren't relevant here.
Apr 19 '06 #8
In article <wZ************ *******@newssvr 21.news.prodigy .com>,
Edward Elliott <no****@127.0.0 .1> wrote:
ML has a
very elegant system for nested comments with (* and *).


Which, if you mistype an opening or closing comment symbol, can lead to
some very mysterious syntax errors.
Apr 19 '06 #9
Edward Elliott wrote:
Ben Finney wrote:
Indeed. Using revision control means never needing to comment out
blocks of code.
Typing (* and *) on a few line will always be quicker, easier, and
less confusing than any rcs diffs/restores. Once you delete the code
you can no longer see it or add pieces back in without retrieving it
from an external store. I'm not saying nested comments solve every
problem, just that there exists a certain (perhaps small) class of
problems they solve particularly well.


Would you care to name a few languages which support nested block
comments? There really aren't many: ML as you mentioned; Standard Pascal
doesn't permit nesting of comments but *some* implementations do allow it.

Want to comment out a block of code in C++? The only (nearly) reliable way
is to insert single-line comments down the block. You can't use a block
comment if there are any other block comments inside the code you want to
block out.

The danger of block comments is that if you forget to close the comment
you can accidentally comment out a large part of your code. With support
from the editor (coloured highlighting of comments) this isn't so bad,
but then if you have a decent editor you don't need the block comments
anyway as you will be able to comment/uncomment a block in your editor.

Doc strings will usually work as an alternative, especially since you
have a choice of two flavours of triple quoted strings, so if you use
one for docstrings the other is always free for your temporary block
comments.
Forcing programmers to write clean code with syntax is like teaching a
pig to sing: it wastes your time and annoys the pig.


This pig gets much more annoyed having to maintain code which has large
chunks of unneeded commented out code left over from some other programmer,
or which has completely messed up indentation.
Apr 19 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3154
by: FLEB | last post by:
I like PHP for its excellent inline integration into standard HTML files, but I like Perl for its quick-moving syntax and simpler data-processing. To resolve this deep-seated inner turmoil (oh, the drama) I've been trying to think of good ways to get Perl code to run inline in a PHP script. Here are a few of my ideas. If anyone has any further ideas, resources, or knows of someone else who's solved this already, please do tell... 1.) The...
32
3166
by: Elliot Temple | last post by:
Hi I have two questions. Could someone explain to me why Python is case sensitive? I find that annoying. Also, why aren't there multiline comments? Would adding them cause a problem of some sort? Thanks, Elliot
4
10939
by: Uwe Ziegenhagen | last post by:
Hello, my fellows and me implement a c++ tool that is able to divide blank/tab separated files into <number>, <text>, <c-singlelinecomment> and <multilinecomment>. So far it's not working bad, we have just one problem if I call the a.exe that gcc compiles with the following textfile (./a.exe < test.txt) he does not match the multiline comments correctly. *test.txt contains:
2
1677
by: pothik05 | last post by:
I have a multiline textbox (with scrollbar) on a form. I add lines to the textbox at runtime. If the number of lines crosses the visible area in the textbox, I want the scrollbar to scrolldown. I tried selectionstart but it is not working. Any comments will be appreciated.
1
7402
by: Laser Lu | last post by:
Hi, all, I'm now writing a program to compress JavaScript code. One puzzle is how to write a regular expression to find out and remove all the redundent blank spaces. However, those blank spaces that are in the comments should be kept intact. I've tried to write some Regexs, and I list them here for your information: regex = new Regex(@"/\**?\*/"); // pattern used to match a multiline comment block regex = new Regex(@"//*\n"); //...
2
4734
by: JohnMSyrasoft | last post by:
Hi, wondering if I'm missing something before I log a minor bug to the VS2005 feedback page. In VB6, you could span multiple lines with comments by using a line continuation character as in 'this is the beginning of my _ comment which continues down to this line In VS05, the 2nd line doesn't appear commented unless the apostrophe is explicitly included.
0
1202
by: Dan Sikorsky | last post by:
I have labels and associated multiline textboxes on a panel that's disabled for the purpose of presenting lengthy readonly comments. Using this method, the textbox scrollbars don't work; the user must click in the textbox and 'arrow down' to see the lengthy comment. How can I get the scrollbars to work? Enabling the panel, and setting the textbox readonly property works, but I have to manage the forecolor and backcolor of the textbox...
4
3072
by: anilga | last post by:
Hi , I am a starter with perl on windows. I need to match commented lines like below /* comments * comments comments */ Whats the exact reg exp in windows perl script to use for this.
29
5979
by: s0suk3 | last post by:
I was shocked a while ago when a discovered that in Python you can't do a multiline assignment with comments between the lines. For example, let's say I want to assign a bunch of variables to an initial, single value. In C or a similar language you would do: CONSTANT1 = /* This is some constant */ CONSTANT2 =
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10050
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.