472,374 Members | 1,367 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,374 software developers and data experts.

Colons, indentation and reformatting. (2)

I was just perusing a Wikipedia entry on the "off side rule" at
http://en.wikipedia.org/wiki/Off-side_rule .
It says that the colon in Python is purely for readability, and cites
our FAQ entry
http://www.python.org/doc/faq/genera...ns-required-fo...
Jan 9 '07 #1
9 1514

Paddy wrote:
I was just perusing a Wikipedia entry on the "off side rule" at
http://en.wikipedia.org/wiki/Off-side_rule .
It says that the colon in Python is purely for readability, and cites
our FAQ entry
http://www.python.org/doc/faq/genera...ns-required-fo...
.
However, near the top of the Alternatives section, it states that for C
type, curly braces using languages:
"An advantage of this is that program code can be automatically
reformatted and neatly indented without fear of the block structure
changing".

Thinking about it a little, it seems that a colon followed by
non-indented code that has just been pasted in could also be used by a
Python-aware editor as a flag to re-indent the pasted code.
How would you re-indent this?

if x>0: print x

>
Tell me it is not so, or I will be editing the Wikipedia page I think.

- Paddy.
Jan 9 '07 #2
"Paddy" <pa*******@netscape.netwrote in message
news:11**********************@i15g2000cwa.googlegr oups.com...
>I was just perusing a Wikipedia entry on the "off side rule" at
http://en.wikipedia.org/wiki/Off-side_rule .
It says that the colon in Python is purely for readability, and cites
our FAQ entry
http://www.python.org/doc/faq/genera...ns-required-fo...
.
However, near the top of the Alternatives section, it states that for C
type, curly braces using languages:
"An advantage of this is that program code can be automatically
reformatted and neatly indented without fear of the block structure
changing".

Thinking about it a little, it seems that a colon followed by
non-indented code that has just been pasted in could also be used by a
Python-aware editor as a flag to re-indent the pasted code.

Tell me it is not so, or I will be editing the Wikipedia page I think.

- Paddy.
No, the ambiguity comes in when you have a nested construct within another
nested construct. Here is some (fake) code where all the indentation was
lost after pasting through a badly-behaved newsreader (this is NOT real
code, I know that it wont really run, I'm just trying to demonstrate the
indentation issue):

while x:
a = 100
if b 3:
a += 1
b += 1

Here are some valid indented versions:

while x:
a = 100
if b 3:
a += 1
b += 1

while x:
a = 100
if b 3:
a += 1
b += 1

while x:
a = 100
if b 3:
a += 1
b += 1

while x:
a = 100
if b 3:
a += 1
b += 1

The colons alone are not sufficient to tell us which is correct.

-- Paul
Jan 9 '07 #3

me********@aol.com wrote:
Paddy wrote:
I was just perusing a Wikipedia entry on the "off side rule" at
http://en.wikipedia.org/wiki/Off-side_rule .
It says that the colon in Python is purely for readability, and cites
our FAQ entry
http://www.python.org/doc/faq/genera...ns-required-fo...
.
However, near the top of the Alternatives section, it states that for C
type, curly braces using languages:
"An advantage of this is that program code can be automatically
reformatted and neatly indented without fear of the block structure
changing".

Thinking about it a little, it seems that a colon followed by
non-indented code that has just been pasted in could also be used by a
Python-aware editor as a flag to re-indent the pasted code.

How would you re-indent this?

if x>0: print x
If pasted as a line , after a line *ending with* a colon then indent it
w.r.t. previous line.
if pasting full lines after such a line then first pasted line cannot
be indented more than this line; if it is then flag for re-indenting
pasted block either equal too or less than this line.

- Paddy.

Jan 9 '07 #4

Paul McGuire wrote:
"Paddy" <pa*******@netscape.netwrote in message
news:11**********************@i15g2000cwa.googlegr oups.com...
I was just perusing a Wikipedia entry on the "off side rule" at
http://en.wikipedia.org/wiki/Off-side_rule .
It says that the colon in Python is purely for readability, and cites
our FAQ entry
http://www.python.org/doc/faq/genera...ns-required-fo...
.
However, near the top of the Alternatives section, it states that for C
type, curly braces using languages:
"An advantage of this is that program code can be automatically
reformatted and neatly indented without fear of the block structure
changing".

Thinking about it a little, it seems that a colon followed by
non-indented code that has just been pasted in could also be used by a
Python-aware editor as a flag to re-indent the pasted code.

Tell me it is not so, or I will be editing the Wikipedia page I think.

- Paddy.
No, the ambiguity comes in when you have a nested construct within another
nested construct. Here is some (fake) code where all the indentation was
lost after pasting through a badly-behaved newsreader (this is NOT real
code, I know that it wont really run, I'm just trying to demonstrate the
indentation issue):

while x:
a = 100
if b 3:
a += 1
b += 1

Here are some valid indented versions:

while x:
a = 100
if b 3:
a += 1
b += 1

while x:
a = 100
if b 3:
a += 1
b += 1

while x:
a = 100
if b 3:
a += 1
b += 1

while x:
a = 100
if b 3:
a += 1
b += 1

The colons alone are not sufficient to tell us which is correct.

-- Paul
Won't the following rules work when pasting complete Python statements
and complete lines, after other lines in an editor:

lets call the line after which the block is to be pasted the paste
line, and the original indent of the first line of the copied block to
be pasted the copy indent.

If the paste line ends in a colon then the copy indent must be greater
than the paste line indent, or the copy block should be re-indented on
pasting to make it so.
If the paste line does not end in a colon then the copy block indent
should be equal too or less than the paste line indent. If this is not
the case then the user should be asked wether to re-indent the copy
block to be equal to, or de-dented w.r.t. the paste line indent prior
to pasting.

- Paddy.

Jan 9 '07 #5
Won't the following rules work when pasting complete Python statements
and complete lines, after other lines in an editor:

lets call the line after which the block is to be pasted the paste
line, and the original indent of the first line of the copied block to
be pasted the copy indent.

If the paste line ends in a colon then the copy indent must be greater
than the paste line indent, or the copy block should be re-indented on
pasting to make it so.
If the paste line does not end in a colon then the copy block indent
should be equal too or less than the paste line indent. If this is not
the case then the user should be asked wether to re-indent the copy
block to be equal to, or de-dented w.r.t. the paste line indent prior
to pasting.

Could be done that way - but is it a killer feature? I doubt it, but
maybe you convince somebody to implement it.

Yet it certainly doesn't justify a wikipedia edit - the FAQ entry is
right, and there is no way of auto-indenting python code that for some
reason suffered from indention mix-up.

Diez
Jan 9 '07 #6

OK, whilst colons are not sufficient to re-format a completely
mis-indented file. I'm thinking that they are sufficient for
reformatting most pasted code blocks when refactoring say?
- Paddy.

Jan 9 '07 #7
"Paddy" <pa*******@netscape.netwrote in message
news:11**********************@38g2000cwa.googlegro ups.com...
>
If this is not
the case then the user should be asked wether to re-indent the copy
block to be equal to, or de-dented w.r.t. the paste line indent prior
to pasting.
How would the user know this? Every dedent is ambiguous, since there is no
punctuation to indicate it.

-- Paul
Jan 9 '07 #8
On 8 Jan 2007 23:57:29 -0800, Paddy <pa*******@netscape.netwrote:
>
OK, whilst colons are not sufficient to re-format a completely
mis-indented file. I'm thinking that they are sufficient for
reformatting most pasted code blocks when refactoring say?
Let's put it this way: if the formatter can assume the original code is
valid (i.e. has the intended indentation) then it can do all kinds of nifty
things to it.

Personally, I'm happy with what Emacs' python-mode offers: suggested indents
as I type, and a command to indent/de-dent the highlighted block one step.

/Jorgen

--
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.dyndns.org R'lyeh wgah'nagl fhtagn!
Jan 9 '07 #9

"Jorgen Grahn" <gr********@snipabacken.dyndns.org>wrote:
On 8 Jan 2007 23:57:29 -0800, Paddy <pa*******@netscape.netwrote:

OK, whilst colons are not sufficient to re-format a completely
mis-indented file. I'm thinking that they are sufficient for
reformatting most pasted code blocks when refactoring say?

Let's put it this way: if the formatter can assume the original code is
valid (i.e. has the intended indentation) then it can do all kinds of nifty
things to it.
This is true - and I think it will only fail if the "entry" point in the pasted
code is "further to the right" than where it has to fit in to the original
code - i.e. if you "run out of space" to the left. - but in that case
you really are hacking, and you are in urgent need of some slashing...

- Hendrik

Jan 10 '07 #10

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

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
0
by: Draz | last post by:
I have some XML extended language that generates output. Everything works ok. I have created additional xsl templates for reformatting strings, mathematical calculations and reformatting numbers....
3
by: Chris Lane | last post by:
Hi, This is super annoying FrontPage like behavior. Does anybody know how I can stop the Visual Studio.NET IDE from reformatting my HTML? Thank You
7
by: Lloyd Sheen | last post by:
I know I have seen a way to stop the terrible reformatting that VS 2003 IDE does. Beyond that is MS going to do a better (could not do a worse) job of auto formatting. Every change I make to...
6
by: Abhishek Srivastava | last post by:
Hello All, I am developing a page which has a complex layout. This layout cannot be made using VS alone, so I have to go into the html view and edit the html myself. The problem is that...
2
by: Paddy | last post by:
i was just perusing a Wikipedia entry on the "off side rule" at http://en.wikipedia.org/wiki/Off-side_rule . It says that the colon in Python is purely for readability, and cites our FAQ entry...
6
by: Grant Robertson | last post by:
I am relatively new to XML, though I have taught myself a lot in the past month. I keep seeing namespace names with multiple colons in them such as: "urn:oasis:names:tc:entity:xmlns:xml:catalog"...
26
by: machineghost | last post by:
First off, let me just say that as someone with no DBA training whatsoever, any help I can get with this issue will be very, very much appreciated. My company recently migrated our database from...
19
by: Eric S. Johansson | last post by:
Almar Klein wrote: there's nothing like self interest to drive one's initiative. :-) 14 years with speech recognition and counting. I'm so looking to my 15th anniversary of being injured next...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...
0
by: F22F35 | last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...

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.