Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Misuse of <tab>

Reply
Thread Tools

Re: Misuse of <tab>

 
 
John Roth
Guest
Posts: n/a
 
      07-30-2003

"Gisle Vanem" <> wrote in message
news:3f27f0e3$...
> I'm a .py newbie and fascinated by the simplicity of formatting.
> No need for {} as in Perl etc. But the misuse of <tab> that many
> .py writers do makes it hard to understand how a script operates.
>
> E.g.
>
> def main():
> terminate = 0
> def foo():
> line = sys.stdin.readline()
> <tab> try:
> bar()
> except:
> terminate = 1
>
> main()
>
> Now, with an editor with different tab-settings it's difficult to see

where
> the try statement belongs. In 'def main()' or in 'def foo()' ?
> I'm confused, please enlighten me.


You're quite right - mixing spaces and tabs when indenting is
not the thing to do. In fact, it's warned against in a number of
places. The recommended practice is to use spaces, and
avoid tabs completely.

I think you'll find that all the modules in the standard library
use spaces exclusively.

John Roth
>
> --gv
>
>



 
Reply With Quote
 
 
 
 
max
Guest
Posts: n/a
 
      07-30-2003
> You're quite right - mixing spaces and tabs when indenting is
> not the thing to do. In fact, it's warned against in a number of
> places. The recommended practice is to use spaces, and
> avoid tabs completely.
>
> I think you'll find that all the modules in the standard library
> use spaces exclusively.

The problem with spaces is that you need to do 5 times the work of a tab
to get decent-looking indentation .

 
Reply With Quote
 
 
 
 
John J. Lee
Guest
Posts: n/a
 
      07-30-2003
max <> writes:
[...]
> The problem with spaces is that you need to do 5 times the work of a
> tab to get decent-looking indentation .


Get an editor.


John
 
Reply With Quote
 
Cliff Wells
Guest
Posts: n/a
 
      07-30-2003
On Wed, 2003-07-30 at 10:25, max wrote:

> The problem with spaces is that you need to do 5 times the work of a tab
> to get decent-looking indentation .


Or you get a decent editor that inserts 4 spaces when you hit tab and
erases 4 spaces when you hit backspace.

--
Cliff Wells, Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 (800) 735-0555


 
Reply With Quote
 
Asun Friere
Guest
Posts: n/a
 
      07-31-2003
"Keith Jones" <> wrote in message news:<>.. .
> On Wed, 30 Jul 2003 17:25:05 +0000, max wrote:
>
> > The problem with spaces is that you need to do 5 times the work of a tab
> > to get decent-looking indentation .

>
> Not if you have a good editor.. Use vim or emacs. In vim, try :h sts (I
> think, or :h softtabstop) ...it would suck to have to type
> <space><space><space><space> all the time, but you don't.


If you use vim remember to put 'set expandtab' (or if you wanna be
fancy 'au BufRead,BufNewFile *.py set expandtab' ) into your .vimrc
(or .exrc) file. This way you can use '[Ctrl]-[T]' and '[Ctrl]-[D]'
to in- and un-dent in insert mode, as well as '>>' and '<<' in command
mode, without fear of hard tabs being inserted. (Though the way vi(m)
mixes tabs and spaces is consistent enough that you wouldn't usually
get into any trouble with it.)
 
Reply With Quote
 
James Graves
Guest
Posts: n/a
 
      07-31-2003
Asun Friere <> wrote:

>If you use vim remember to put 'set expandtab' (or if you wanna be
>fancy 'au BufRead,BufNewFile *.py set expandtab' ) into your .vimrc
>(or .exrc) file. This way you can use '[Ctrl]-[T]' and '[Ctrl]-[D]'
>to in- and un-dent in insert mode, as well as '>>' and '<<' in command
>mode, without fear of hard tabs being inserted. (Though the way vi(m)
>mixes tabs and spaces is consistent enough that you wouldn't usually
>get into any trouble with it.)


That's handy. I had known about 'set expandtab' for a while, but I
wanted to figure out how to use it for just Python.

And now I don't have to.

Thanks,

James Graves
 
Reply With Quote
 
Asun Friere
Guest
Posts: n/a
 
      08-01-2003
"Keith Jones" <> wrote in message news:<>.. .
> > If you use vim remember to put 'set expandtab' (or if you wanna be fancy
> > 'au BufRead,BufNewFile *.py set expandtab' ) into your .vimrc (or .exrc)
> > file. This way you can use '[Ctrl]-[T]' and '[Ctrl]-[D]' to in- and
> > un-dent in insert mode, as well as '>>' and '<<' in command mode,
> > without fear of hard tabs being inserted. (Though the way vi(m) mixes
> > tabs and spaces is consistent enough that you wouldn't usually get into
> > any trouble with it.)

>
>
> Oh, yeah, forgot to mention expandtab; I did not know about >>, <<,
> Ctrl+T, and Ctrl+D, however; so thanks for those. I had mapped <tab> and
> <s-tab> to : s/^/ /<cr> and : s/^ /<cr> for command mode, which I
> guess I won't have to use anymore.


[ctrl]-[t] and [ctrl]-[d] also exist in vanilla vi, but are much more
nicely implemented in vim. In vi you have to make sure you are at the
front of the line, or else you indent will be inserted into your line
(which is hardly ever what you would want). In vim it doesn't matter
where in the line your cursor is, the commands will move the line as a
unit, much like your mappings would.

I should perhaps also mention the very useful ex versions of this
command as well. ie '>' for a single indent, '>>' for two indents,
'<<<' for three dedents, etc, which like ex commands generally are
especially useful when you want to move a bunch of lines at a time.

Thanks for that resource file listing, that is going to up a whole new
vista of vim/python usage for me.
 
Reply With Quote
 
Asun Friere
Guest
Posts: n/a
 
      08-01-2003
(James Graves) wrote in message news:<bgbqmu$ksv$>...

> That's handy. I had known about 'set expandtab' for a while, but I
> wanted to figure out how to use it for just Python.


Note how Keith Jones, in the following post, achieves the same:

au FileType python set et

I wasn't aware of the 'FileType' setting, but it has the advantage of
working with files which vim recognises as python source, but which
don't necessarily end in 'py'. Nice!
 
Reply With Quote
 
Robin Munn
Guest
Posts: n/a
 
      08-12-2003
Keith Jones <> wrote:
> On Wed, 30 Jul 2003 17:25:05 +0000, max wrote:
>
>> The problem with spaces is that you need to do 5 times the work of a tab
>> to get decent-looking indentation .

>
> Not if you have a good editor.. Use vim or emacs. In vim, try :h sts (I
> think, or :h softtabstop) ...it would suck to have to type
><space><space><space><space> all the time, but you don't.


Don't forget the "smarttab" option (:h smarttab). My .vimrc looks like:

set shiftwidth=4
set expandtab
set smarttab

OK, if you want to be precise about it, *part* of my .vimrc looks like
the above.

--
Robin Munn <> | http://www.rmunn.com/ | PGP key 0x6AFB6838
-----------------------------+-----------------------+----------------------
"Remember, when it comes to commercial TV, the program is not the product.
YOU are the product, and the advertiser is the customer." - Mark W. Schumann
 
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
Page won't validate -- misuse of A element? Michael Laplante HTML 3 05-18-2006 10:38 PM
Re: Misuse of XML namespaces; call for help in marshalling arguments Peter Flynn XML 2 08-09-2004 10:23 PM
Misuse of namespaces, help is summoning arguments Simon North XML 0 08-05-2004 11:52 AM
Employer misuse Marko Microsoft Certification 0 09-25-2003 06:09 AM
Re: Hotmail and Computer Misuse anthonyberet Computer Support 39 08-11-2003 10:32 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