Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Style question...

Reply
Thread Tools

Style question...

 
 
Anthony Roberts
Guest
Posts: n/a
 
      08-27-2003
If I end indentation levels with "pass" statements, will I **** off people
that have to read my code? eg:

for i in xrange(0,5):
if i:
print i
pass
print i * -1
pass

I ask for two reasons... a) it helps emacs figure it out, and b) I'm more
comfortable ending compound statements with a token.


 
Reply With Quote
 
 
 
 
Peter Hansen
Guest
Posts: n/a
 
      08-27-2003
Anthony Roberts wrote:
>
> If I end indentation levels with "pass" statements, will I **** off people
> that have to read my code? eg:
>
> for i in xrange(0,5):
> if i:
> print i
> pass
> print i * -1
> pass
>
> I ask for two reasons... a) it helps emacs figure it out, and b) I'm more
> comfortable ending compound statements with a token.


Sorry, but yes, I find that ugly. If you're just starting out with
Python, please just give it a shot without that approach for a while
and see whether you become much more comfortable *without* the token
than you ever were with it.

-Peter
 
Reply With Quote
 
 
 
 
Chad Netzer
Guest
Posts: n/a
 
      08-27-2003
On Wed, 2003-08-27 at 15:45, Anthony Roberts wrote:
> If I end indentation levels with "pass" statements, will I **** off people
> that have to read my code? eg:
>
> for i in xrange(0,5):
> if i:
> print i
> pass
> print i * -1
> pass


I do this myself at times, to help emacs. But I'd suggest you not
overdo it. It is more "pythonic" to simply leave the line blank (ie.
vertical whitespace), than have "pass" everywhere.

Pressing backspace once (to undo the auto-indent that emacs gives inside
loops) is less typing than 'pass'. And if you need to reindent large
chunks of code, you are better off using emacs block indent/dedent
feature than relying on "pass" as defacto block delimiter (this has been
my experience)

Also, look into the pindent.py script (included in Python's "Tools"
directory with the distribution), for another way of producing block
closing tokens.

--

Chad Netzer


 
Reply With Quote
 
Sean Ross
Guest
Posts: n/a
 
      08-27-2003
"Anthony Roberts" <anthonyr-at-hotmail-dot-> wrote in message
news:Uva3b.49430$.. .
> If I end indentation levels with "pass" statements, will I **** off people
> that have to read my code? eg:
>
> for i in xrange(0,5):
> if i:
> print i
> pass
> print i * -1
> pass
>
> I ask for two reasons... a) it helps emacs figure it out, and b) I'm more
> comfortable ending compound statements with a token.
>



Hi. I tried to do something like that too, early on. (I recall being
frustrated to find I couldn't just alias "end = pass", and use 'end' as a
block delimiter... heh). I didn't actually want to use 'end' (I like
significant whitespace), I just saw a lot of posts with complaints about
"no-block-delimiter", and I thought, I wonder if you can make one. Well, you
can (of course), but not like that.

Anyway. I think the suggested idiom for people who must have a visible block
delimiter is "# end <keyword>". If you use this, I think emacs can "figure
it out" (I don't know, I don't use emacs, but I think pymode can handle
this), and you can also use Tools/scripts/pindent.py, if you like.

"from pindent.py"
# This file contains a class and a main program that perform three
# related (though complimentary) formatting operations on Python
# programs. When called as "pindent -c", it takes a valid Python
# program as input and outputs a version augmented with block-closing
# comments. When called as "pindent -d", it assumes its input is a
# Python program with block-closing comments and outputs a commentless
# version. When called as "pindent -r" it assumes its input is a
# Python program with block-closing comments but with its indentation
# messed up, and outputs a properly indented version.

[snip]

# Secret feature:
# - On input, a block may also be closed with an "end statement" --
# this is a block-closing comment without the '#' sign.

Hmm. Looks like you can also use "end", or perhaps 'end' . I don't know if
the <keyword> is optional or not, having never used this module.
Anyway, if you use this format, then, if someone doesn't like seeing all
that noise when they read your code, they can strip it out with
"pindent -d". Handy. And, when you read other peoples code, you can clutter
it up nicely with "pindent -c". Best of both worlds, really.

HTH
Sean


 
Reply With Quote
 
Bruno Desthuilliers
Guest
Posts: n/a
 
      08-27-2003
Anthony Roberts wrote:
> If I end indentation levels with "pass" statements, will I **** off people
> that have to read my code? eg:
>
> for i in xrange(0,5):
> if i:
> print i
> pass
> print i * -1
> pass


*yuck*

(oops, sorry...)

Bruno

 
Reply With Quote
 
Anthony Roberts
Guest
Posts: n/a
 
      08-28-2003
> Sorry, but yes, I find that ugly. If you're just starting out with
> Python, please just give it a shot without that approach for a while
> and see whether you become much more comfortable *without* the token
> than you ever were with it.


Well, when in Rome I guess.

Having the closing token at the same indent level as the compound statement
is ugly anyway.


 
Reply With Quote
 
John Roth
Guest
Posts: n/a
 
      08-28-2003

"Anthony Roberts" <anthonyr-at-hotmail-dot-> wrote in message
news:Uva3b.49430$.. .
> If I end indentation levels with "pass" statements, will I **** off people
> that have to read my code? eg:
>
> for i in xrange(0,5):
> if i:
> print i
> pass
> print i * -1
> pass
>
> I ask for two reasons... a) it helps emacs figure it out, and b) I'm more
> comfortable ending compound statements with a token.


Isn't there some kind of emacs plugin, macro or mode that
handles Python? I'm not an emacs person, but I've heard that
there is, and I would expect that it would handle things like
auto-indent for you.

John Roth
>
>



 
Reply With Quote
 
Anthony Roberts
Guest
Posts: n/a
 
      08-28-2003
> Isn't there some kind of emacs plugin, macro or mode that
> handles Python? I'm not an emacs person, but I've heard that
> there is, and I would expect that it would handle things like
> auto-indent for you.


There is, but it can't tell if I want some stuff indented or not.


 
Reply With Quote
 
Anthony Roberts
Guest
Posts: n/a
 
      08-28-2003
> Hi. I tried to do something like that too, early on. (I recall being
> frustrated to find I couldn't just alias "end = pass", and use 'end' as a
> block delimiter... heh). I didn't actually want to use 'end' (I like
> significant whitespace), I just saw a lot of posts with complaints about
> "no-block-delimiter", and I thought, I wonder if you can make one. Well,

you
> can (of course), but not like that.
>
> Anyway. I think the suggested idiom for people who must have a visible

block
> delimiter is "# end <keyword>". If you use this, I think emacs can "figure
> it out" (I don't know, I don't use emacs, but I think pymode can handle
> this), and you can also use Tools/scripts/pindent.py, if you like.


My emacs can't handle it... I think I'm going to subject myself to a bit
more of the Python way to see if I change my mind.


 
Reply With Quote
 
Anthony Roberts
Guest
Posts: n/a
 
      08-28-2003
> *yuck*

LOL!

I'm sorry.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGrid header style inconsistent with sortable column style cedoucette@alum.rpi.edu ASP .Net 0 10-14-2005 12:13 AM
All style tags after the first 30 style tags on an HTML page are not applied in Internet Explorer Rob Nicholson ASP .Net 3 05-28-2005 03:11 PM
Need help with Style conversion from Style object to Style key/value collection. Ken Varn ASP .Net Building Controls 0 04-26-2004 07:06 PM
Javascript Style Switcher that remebers current site style in use Hardeep Rakhra HTML 8 01-15-2004 08:00 PM
Style sheets, include one style within another (not inheritance) foldface@yahoo.co.uk HTML 1 11-24-2003 01:37 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57