Re: why no block comments in Python?
Warby wrote: ...and I forgot to mention that the output of grep and diff is far more understandable in the absence of block comments! Which is why people do this /anyway/. (Kind of makes block comments pointless, doesn't it? /* This is a * really * really * long * block comment */ -- http://mail.python.org/mailman/listinfo/python-list
Re: why no block comments in Python?
In article [EMAIL PROTECTED], Jonathan Gardner [EMAIL PROTECTED] wrote: Warby wrote: ...and I forgot to mention that the output of grep and diff is far more understandable in the absence of block comments! Which is why people do this /anyway/. (Kind of makes block comments pointless, doesn't it? /* This is a * really * really * long * block comment */ Habit left over from the C days. It was the only way of making a block comment stand out visually. C++ has // comments, just like Python has #, but old habits die hard. -- http://mail.python.org/mailman/listinfo/python-list
Re: why no block comments in Python?
On Thu, 09 Mar 2006 18:02:27 -0600, Terry Hancock wrote: On 9 Mar 2006 07:21:00 -0800 msoulier [EMAIL PROTECTED] wrote: (and if you don't, you can quickly comment out regions by putting them inside a triple-quoted string.) Although that will use up memory, as opposed to a comment. Not really. Unless it is the first string in the block (class, function, module), it won't be assigned to anything, and will be immediately garbage-collected. It may consume space in the pyc file, I'm not sure. I don't believe this is true. Unassigned strings other than the doc string are not compiled into the code: def f(x): ... this is a doc string ... but this isn't ... return hello world ... dis.dis(f) 4 0 LOAD_CONST 1 ('hello world') 3 RETURN_VALUE 4 LOAD_CONST 2 (None) 7 RETURN_VALUE Strangely enough, this is a local optimization that appears to have been done only for strings: def g(): ... 45 ... return 55 ... dis.dis(g) 2 0 LOAD_CONST 1 (45) 3 POP_TOP 3 4 LOAD_CONST 2 (55) 7 RETURN_VALUE 8 LOAD_CONST 0 (None) 11 RETURN_VALUE So you should feel free to use strings (triple-quoted or otherwise) as documentation in your functions. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: why no block comments in Python?
On Sat, 11 Mar 2006 10:23:56 +1100 Steven D'Aprano [EMAIL PROTECTED] wrote: On Thu, 09 Mar 2006 18:02:27 -0600, Terry Hancock wrote: On 9 Mar 2006 07:21:00 -0800 msoulier [EMAIL PROTECTED] wrote: (and if you don't, you can quickly comment out regions by putting them inside a triple-quoted string.) Although that will use up memory, as opposed to a comment. Not really. Unless it is the first string in the block (class, function, module), it won't be assigned to anything, and will be immediately garbage-collected. It may consume space in the pyc file, I'm not sure. I don't believe this is true. Unassigned strings other than the doc string are not compiled into the code: [bytecode analysis snipped] Cool. I thought that was probably true, but didn't want to guess. Cheers, Terry -- Terry Hancock ([EMAIL PROTECTED]) Anansi Spaceworks http://www.AnansiSpaceworks.com -- http://mail.python.org/mailman/listinfo/python-list
Re: why no block comments in Python?
Terry Hancock wrote: I'm thinking this might be a use-case for the new support for doctests in a separate file. Having doctests in their own file is (IMHO) a majorly under appreciated feature of doctest. The ability to do either nice user (as in developer) docs with known good examples or well documented not-meant-for-documentation unit/functional/integration tests is terrific. -- Benji York -- http://mail.python.org/mailman/listinfo/python-list
Re: why no block comments in Python?
(and if you don't, you can quickly comment out regions by putting them inside a triple-quoted string.) Although that will use up memory, as opposed to a comment. Still, it's simple enough in an editor like Vim or Emacs to highlight a region, and define a macro to add/remove #s. Any Python IDE should certainly have this capability. Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: why no block comments in Python?
msoulier [EMAIL PROTECTED] wrote: (and if you don't, you can quickly comment out regions by putting them inside a triple-quoted string.) Although that will use up memory, as opposed to a comment. I can't imagine a realistic scenario where the amount of memory wasted by triple-quoting out code could possibly be significant. I'll also repeat what I said before -- good software engineering practice demands that you remove dead code completely. Commenting something out for a quick test during development is OK, but once it reaches the production stage, get rid of it. It'll still live in your revision control system. -- http://mail.python.org/mailman/listinfo/python-list
Re: why no block comments in Python?
msoulier wrote: (and if you don't, you can quickly comment out regions by putting them inside a triple-quoted string.) Although that will use up memory, as opposed to a comment. Doesn't seem so: def f(): ... docstring ... another string ... a = 42 ... yet another string ... f.func_code.co_consts ('docstring', 42, None) Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: why no block comments in Python?
On 9 Mar 2006 07:21:00 -0800 msoulier [EMAIL PROTECTED] wrote: (and if you don't, you can quickly comment out regions by putting them inside a triple-quoted string.) Although that will use up memory, as opposed to a comment. Not really. Unless it is the first string in the block (class, function, module), it won't be assigned to anything, and will be immediately garbage-collected. It may consume space in the pyc file, I'm not sure. Of course, I don't think anyone would advocate leaving such things in production code where the memory use would be an issue anyway. The whole point of block-commenting code out is to temporarily delete it without having to use your version control system to get it back. You only do that when you have strong feeling you're going to need to put it back in. -- Terry Hancock ([EMAIL PROTECTED]) Anansi Spaceworks http://www.AnansiSpaceworks.com -- http://mail.python.org/mailman/listinfo/python-list
Re: why no block comments in Python?
John Salerno wrote: I'm still tyring to figure out what Pythonic means, and I have a feeling the answer to my question may fall into that category. Are block comments somehow unpythonic? only in the sense that python don't have them. but they're pretty pointless, if you have a modern editor. (and if you don't, you can quickly comment out regions by putting them inside a triple-quoted string.) /F -- http://mail.python.org/mailman/listinfo/python-list
Re: why no block comments in Python?
Fredrik Lundh [EMAIL PROTECTED] wrote: you can quickly comment out regions by putting them inside a triple-quoted string.) Except that triple-quotes don't nest. I do agree, however, with the idea that any decent editor should be able to comment out a block of code faster than I can type this sentence. -- http://mail.python.org/mailman/listinfo/python-list
Re: why no block comments in Python?
Roy Smith wrote: you can quickly comment out regions by putting them inside a triple-quoted string.) Except that triple-quotes don't nest. ''' ...except when they do ''' /F -- http://mail.python.org/mailman/listinfo/python-list
Re: why no block comments in Python?
It's clear that if you have a modern editor, block comments are unnecessary because it is trivial to add a # to the start of each line of a block, but that doesn't really answer your question. It explains why you might not always need block comments but doesn't explain why you shouldn't use them (especially in a primitive editor). The danger with block comments is that there is no way to tell that the code you're looking at has been commented out unless you can see the start or end of the comment block. If you have a modern editor, it probably changes the color of all commented out code to eliminate confusion. But if you have a primitive editor it does not. Also, even people who use modern editors sometimes browse source code using a plain text viewer (less/more). Eliminating block comments eliminates uncertainty. :) -- http://mail.python.org/mailman/listinfo/python-list
Re: why no block comments in Python?
...and I forgot to mention that the output of grep and diff is far more understandable in the absence of block comments! -- http://mail.python.org/mailman/listinfo/python-list
Re: why no block comments in Python?
Warby wrote: The danger with block comments is that there is no way to tell that the code you're looking at has been commented out unless you can see the start or end of the comment block. If you have a modern editor, it probably changes the color of all commented out code to eliminate confusion. But if you have a primitive editor it does not. That makes sense. If you have a modern editor, you don't need blocks. If you don't have one, blocks don't help. :) -- http://mail.python.org/mailman/listinfo/python-list
Re: why no block comments in Python?
Warby [EMAIL PROTECTED] wrote: Eliminating block comments eliminates uncertainty. :) An even better way to eliminate uncertainty is to eliminate the code. Commenting out is fine for a quick test during development. Once the code is committed, the dead code should be eliminated completely. -- http://mail.python.org/mailman/listinfo/python-list
Re: why no block comments in Python?
On Wednesday 08 March 2006 12:42 pm, Warby wrote: The danger with block comments is that there is no way to tell that the code you're looking at has been commented out unless you can see the start or end of the comment block. If you have a modern editor, it probably changes the color of all commented out code to eliminate confusion. But if you have a primitive editor it does not. Also, even people who use modern editors sometimes browse source code using a plain text viewer (less/more). No doubt some Emacs zealot will say something snarky at this point, ;-) but it's also true that Vi (or gvim anyway) will occasionally get confused by very long block comments or triple-quoted strings, causing the syntax-color to get out of synch. I recently started running into this problem when I started using doctest tests. There's probably a smarter way to do this, but I was putting several of them in a module docstring, and it gets to be a 100+ lines or so of doctest plus explanations. I'm thinking this might be a use-case for the new support for doctests in a separate file. Or maybe I just need to see if I can move the tests into individual object docstrings. -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com -- http://mail.python.org/mailman/listinfo/python-list
Re: why no block comments in Python?
I have found that some editors colourize text based on parsing a section of text around what is visible. Long, multi-line comments or strings might not then get colored correctly. Personally, I do use block comments in other languages but maybe they should not exist in finished code for reasons already given by others, readabiity! Cheers, Paddy. -- http://mail.python.org/mailman/listinfo/python-list