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?
Mar 8 '06
18 2172
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
> (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
msoulier <ms******@gmail .com> 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.
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
On 9 Mar 2006 07:21:00 -0800
"msoulier" <ms******@gmail .com> 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 (ha*****@Anansi Spaceworks.com)
Anansi Spaceworks http://www.AnansiSpaceworks.com
On Thu, 09 Mar 2006 18:02:27 -0600, Terry Hancock wrote: On 9 Mar 2006 07:21:00 -0800 "msoulier" <ms******@gmail .com> 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.
On Sat, 11 Mar 2006 10:23:56 +1100
"Steven D'Aprano" <st***@REMOVETH IScyber.com.au> wrote: On Thu, 09 Mar 2006 18:02:27 -0600, Terry Hancock wrote:
On 9 Mar 2006 07:21:00 -0800 "msoulier" <ms******@gmail .com> 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 (ha*****@Anansi Spaceworks.com)
Anansi Spaceworks http://www.AnansiSpaceworks.com
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 */
In article <11************ *********@v46g2 000cwv.googlegr oups.com>,
"Jonathan Gardner" <jg******@jonat hangardner.net> 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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tim Parkin |
last post by:
Terry Ready said:
> YUCK< YUCK< YUCK.
> <snip>
> The pollenation site is one of the worst I have seen. The mockup page
> has teeny type that IE will not enlarge.
> <snip>
> I care that the site remain physically readable and that it remain a
> vehicle for information rather than childish egos.
> <snip>
> Using IE6, I need a magnifying glass
|
by: mike420 |
last post by:
I think everyone who used Python will agree that its syntax is
the best thing going for it. It is very readable and easy
for everyone to learn. But, Python does not a have very good
macro capabilities, unfortunately. I'd like to know if it may
be possible to add a powerful macro system to Python, while
keeping its amazing syntax, and if it could be possible to
add Pythonistic syntax to Lisp or Scheme, while keeping all
of the...
|
by: Adam Barr |
last post by:
For a book I am working on, I have written a brief (9 page) summary
of Python. The intent of this is that an experienced programmer who
did
not know Python would be able to get enough information to read and
understand Python programs. It is not meant to be a 100% complete
summary of the language, but everything in there should be correct.
If anyone is interested, please feel free to read it and send me
comments. Note that the material...
|
by: Guido van Rossum |
last post by:
After many rounds of discussion on python-dev, I'm inviting public
comments for PEP 343. Rather than posting the entire PEP text here,
I'm inviting everyone to read it on line
(http://www.python.org/peps/pep-0343.html) and then post comments on a
Wiki page I've created for this purpose
(http://wiki.python.org/moin/WithStatement).
I think this is a good one; I hope people agree. Its acceptance will
obsolete about 4 other PEPs! (A sign...
|
by: Zhang Weiwu |
last post by:
Hello. This is problem puzzled me a long time. I wish to organize some
block elements and let them flow one after each other like text.
Think about a album, I wish the album have 12 thumbnails, each one has a
comment line under the picture. And I wish when the screen size is big,
this thumbnails arrange 3 rows, 4 columns; if the browser window is
smaller, arranges 4 rows, 3 columns; if it's even smaller, 6 rows with 2
columns. If there...
| |
by: lorinh |
last post by:
Hi Folks,
I'm trying to strip C/C++ style comments (/* ... */ or // ) from
source code using Python regexps.
If I don't have to worry about comments embedded in strings, it seems
pretty straightforward (this is what I'm using now):
cpp_pat = re.compile(r"""
/\* .*? \*/ | # C comments
|
by: Robert |
last post by:
After failing on a yield/iterator-continuation problem in Python (see
below) I tried the Ruby (1.8.2) language first time on that construct:
The example tries to convert a block callback interface
(Net::FTP.retrbinary) into a read()-like iterator function in order to
virtualize the existing FTP class as kind of file system. 4 bytes max
per read in this first simple test below. But it fails on the second
continuation with ThreadError after...
|
by: MartinRinehart |
last post by:
Tomorrow is block comment day. I want them to nest. I think the reason
that they don't routinely nest is that it's a lot of trouble to code.
Two questions:
1) Given a start and end location (line position and char index) in an
array of lines of text, how do you Pythonly extract the whole block
comment? (Goal: not to have Bruno accusing me - correctly - of writing
C in Python.)
2) My tokenizer has a bunch of module-level constants...
|
by: Richard |
last post by:
Again, new to DB2. Trying to do something I can do in Sybase ASE.
In any Sybase SQL script I can use /* */ to comment out a block of
code.
In the DB2 9.0 SQL Reference Manual V1 it says:
Comments: SQL comments are either bracketed (introduced by /* and end
with */) or simple (introduced by two consecutive hyphens and end with
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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...
|
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...
|
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...
|
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();...
|
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |