If I end indentation levels with "pass" statements, will I piss 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. 17 1915
Anthony Roberts wrote: If I end indentation levels with "pass" statements, will I piss 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
Anthony Roberts wrote: If I end indentation levels with "pass" statements, will I piss 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
"Anthony Roberts" <an*************************@nospam.com> wrote in message
news:Uv*******************@news1.calgary.shaw.ca.. . If I end indentation levels with "pass" statements, will I piss 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
On Wed, 2003-08-27 at 15:45, Anthony Roberts wrote: If I end indentation levels with "pass" statements, will I piss 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
> 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. :)
"Anthony Roberts" <an*************************@nospam.com> wrote in message
news:Uv*******************@news1.calgary.shaw.ca.. . If I end indentation levels with "pass" statements, will I piss 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
> 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.
> 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.
> *yuck* :(
LOL!
I'm sorry. :)
Anthony Roberts wrote: What's the keystroke for that?
C-c < and C-c >.
--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ Nobody's on nobody's side
\__/ Florence, _Chess_
On Wed, 2003-08-27 at 19:06, Erik Max Francis wrote: Anthony Roberts wrote:
There is, but it can't tell if I want some stuff indented or not.
Sure it can. Hit tab or backspace.
I think the problem is that people learn to reindent chunks of code by
the following technique:
<arrow down>
<TAB>
<arrow down>
<TAB>
..
..
..
This has the unfortunate consequence of breaking your code when you hit
multiply indented loops, nested functions, function or loop boundaries,
etc.
However, by sticking 'pass' at the end of loops, emacs's python-mode
will assume a dedent and preserve the indenting at boundaries.
But, this technique will STILL fail on multiply nested loops, etc.
(emacs does it's best, but it cannot mind read) So it is a terrible
habit to get into, because it WILL cause you problems if relied upon
blindly.
So, it is better to NOT rely on the 'pass' crutch, and instead rely on
the python mode operations for reindenting blocks of code (which Eric
provided; surely this is becoming a FAQ)
So, to Anthony, if you are using the TAB key to indent blocks of code,
and relying on 'pass' to make it easier, just be aware that this
technique is NOT robust.
--
Chad Netzer <cn*****@sonic.net>
Chad Netzer wrote: But, this technique will STILL fail on multiply nested loops, etc. (emacs does it's best, but it cannot mind read) So it is a terrible habit to get into, because it WILL cause you problems if relied upon blindly.
So, it is better to NOT rely on the 'pass' crutch, and instead rely on the python mode operations for reindenting blocks of code (which Eric provided; surely this is becoming a FAQ)
Agreed. If you're going to write code in a particular language, you
should fully embrace the language and its style, or move on to something
that you feel more comfortable with. These kind of crutches will only
serve to bite you later -- they aren't panaceas, and you may forget to
use them or be hobbled when interacting with someone else's code (where
you're not going to convince others to use your crutches). There's also
an indirect effect; if I'm reading someone else's Python code, and, say,
see someone using semicolons as statement delimiters on every line, I'm
not exactly going to be struck with a great deal of confidence.
--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ Don't ever get discouraged / There's always / A better day
\__/ TLC
> C-c < and C-c >.
Thanks. :)
BTW: I've had your website bookmarked since 2001 because a number of the
things there are useful and cool.
> I think the problem is that people learn to reindent chunks of code by the following technique:
Yup. In emacs, it is robust for C and C decendants. Indent region can do it
to entire files.
It's good for structural modifications when you want to change some outer
loop that ends up changing the indent/nesting level of some inner loop.
In Java, which is where I really started to lean of that feature heavily, it
comes with so *many* data structure classes that even though they mostly
share interfaces, you still come up with a cleaner way later on and go back
to change it. I'm finding Python is more a matter of "for x in
<whatever>:"...
But I still change my mind sometimes. :)
> Agreed. If you're going to write code in a particular language, you should fully embrace the language and its style, or move on to something that you feel more comfortable with. These kind of crutches will only serve to bite you later -- they aren't panaceas, and you may forget to use them or be hobbled when interacting with someone else's code (where you're not going to convince others to use your crutches). There's also an indirect effect; if I'm reading someone else's Python code, and, say, see someone using semicolons as statement delimiters on every line, I'm not exactly going to be struck with a great deal of confidence.
It sits better with me if I have a good idea why I'm doing it.
Anthony Roberts wrote: BTW: I've had your website bookmarked since 2001 because a number of the things there are useful and cool.
:-).
--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ I'll tell them that their daddy was / A good man
\__/ India Arie
"Anthony Roberts" <an*************************@nospam.com> writes: C-c < and C-c >.
Thanks. :)
It's worth doing "C-h m" and "C-c ?" and reading the results, too.
Cheers,
mwh
--
In case you're not a computer person, I should probably point out
that "Real Soon Now" is a technical term meaning "sometime before
the heat-death of the universe, maybe".
-- Scott Fahlman <se*@cs.cmu.edu> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: David MacQuigg |
last post by:
I have what looks like a bug trying to generate new style classes with
a factory function.
class Animal(object): pass
class Mammal(Animal): pass
def newAnimal(bases=(Animal,), dict={}):...
|
by: Christopher Benson-Manica |
last post by:
If you had an unsigned int that needed to be cast to a const myClass*,
would you use
const myClass* a=reinterpret_cast<const myClass*>(my_val);
or
const myClass* a=(const myClass*)myVal;
...
|
by: amerar |
last post by:
Hi All,
I can make a page using a style sheet, no problem there. However, if I
make an email and send it out to my list, Yahoo & Hotmail totally
ignore the style tags. It looks fine in...
|
by: amerar |
last post by:
Hi All,
I posted a question about style sheets, and why certain email clients
were ignoring them. Someone suggested placing them inline. I did
this and get better results, but not what I...
|
by: KvS |
last post by:
Hi all,
I'm pretty new to (wx)Python so plz. don't shoot me if I've missed
something obvious ;). I have a panel inside a frame, on which a Button
and a StaticText is placed:
self.panel =...
|
by: rahul8143 |
last post by:
hello,
what is difference between sizeof("abcd") and strlen("abcd")? why
both functions gives different output when applied to same string
"abcd".
I tried following example for that.
#include...
|
by: jamilur_rahman |
last post by:
What is the BIG difference between checking the "if(expression)" in A
and B ? I'm used to with style A, "if(0==a)", but my peer reviewer
likes style B, how can I defend myself to stay with style A...
|
by: pocmatos |
last post by:
Hi all,
While I was programming 5 minutes ago a recurring issue came up and
this time I'd like to hear some opinions on style. Although they are
usually personal I do think that in this case as...
|
by: Claus Mygind |
last post by:
I want to move some style setting into a javaScript function so I can make them variable but I get "invalid assignment left-hand side" error?
see my question at the bottom of this message.
It...
|
by: MatthewS |
last post by:
I've seen the question raised several times here, but apparently never
answered. Since PyInstance_Check returns False for new-style class
instances, is there a standard procedure for testing this...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
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,...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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,...
| |