Re: python newbie: some surprises

2008-05-18 Thread Lie
On May 8, 2:06 pm, v4vijayakumar <[EMAIL PROTECTED]>
wrote:
> When I started coding in python, these two things surprised me.
>
> 1. my code is inconsistently indented with the combination of tabs and
> spaces. Even lines looked intended, but it is not.

The problem is in tab not Python, there is no convention on how many
spaces should tab be treated, python (by default) assumes a tab to be
equal to 8 spaces, but not everyone thinks the same, some code editor
might consider it as 4 spaces or 2 spaces. In most python-oriented
code editor, a tab might be automatically replaced with four spaces.

> 2. python requires to pass "self" to all instance methods

No, python doesn't requires self to be passed to all instance methods,
python passes the "current instance" of a class to the first argument
of a function inside the class, this first argument can be named
anything, although it is traditionally named as self. In other
programming languages, this current instance is implicitly passed (Me
in VB, this in C/C++).

> and I missed ":" often. :)

Not in your smiley though. :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: python newbie: some surprises

2008-05-15 Thread tinnews
Kees Bakker <[EMAIL PROTECTED]> wrote:
> 
> So far, I have seen only one editor that understands the difference between
> TABs and indentation, and that is Emacs.

Most vi clones (and the original vi) do too!  :-)

E.g. in the clone I use (vile) there are independent settings for
tabstop and shiftwidth.  In addition you can tell the editor to change
tabs to spaces (or not) as you wish.

-- 
Chris Green
--
http://mail.python.org/mailman/listinfo/python-list


Re: python newbie: some surprises

2008-05-15 Thread Marco Mariani

Kees Bakker wrote:



So far, I have seen only one editor that understands the difference between
TABs and indentation, and that is Emacs.


Oh, well... in .vimrc:

autocmd FileType python set tabstop=8
autocmd FileType python set softtabstop=4
autocmd FileType python set expandtab

--
http://mail.python.org/mailman/listinfo/python-list


Re: python newbie: some surprises

2008-05-15 Thread Kees Bakker
Gabriel Genellina wrote:

> En Fri, 09 May 2008 10:37:30 -0300, v4vijayakumar <[EMAIL PROTECTED]> 
> escribió:
> 
>> On May 9, 1:48 pm, Bruno Desthuilliers > [EMAIL PROTECTED]> wrote:
>>> v4vijayakumar a écrit :
>>>
>>> > When I started coding in python, these two things surprised me.
>>>
>>> > 1. my code is inconsistently indented with the combination of tabs and
>>> > spaces. Even lines looked intended, but it is not.
>>>
>>> Then you have a problem with your code editor - not with Python.
>>>
>>
>> Editors can not be wrong. :)
>>
>> I think there should be some way to say python compiler, to consider
>> tab and two blank spaces equal, when tab space = 2.
> 
> It already considers tab = 8 spaces, and when invoked with -tt it rejects 
> mixed tabs+spaces. (I would like Python rejected *any* tab used for 
> indenting...)
> There is a tool 'reindent.py' -somewhere on your Python install-, and an 
> indentation checker 'tabnanny.py' (this one in the standard library).
> 

That's one of the reasons why I like Python :-)

Still too many people don't know that you must set a TAB to 8 in
your editor. Anything other than 8 for a TAB will, at some point,
confuse somebody.

Don't confuse indentation with TAB setting.

Many editors are not helpfull either. Pydev, for example, has a setting
for TAB, but it is used for indentation. It is just luck (I think) that
pydev has an option to say that you only want spaces. (Take a look at
the main preferences of Pydev.)

So far, I have seen only one editor that understands the difference between
TABs and indentation, and that is Emacs.
-- 
Kees

--
http://mail.python.org/mailman/listinfo/python-list


Re: python newbie: some surprises

2008-05-10 Thread Gabriel Genellina
En Fri, 09 May 2008 10:37:30 -0300, v4vijayakumar <[EMAIL PROTECTED]> escribió:

> On May 9, 1:48 pm, Bruno Desthuilliers  [EMAIL PROTECTED]> wrote:
>> v4vijayakumar a écrit :
>>
>> > When I started coding in python, these two things surprised me.
>>
>> > 1. my code is inconsistently indented with the combination of tabs and
>> > spaces. Even lines looked intended, but it is not.
>>
>> Then you have a problem with your code editor - not with Python.
>>
>
> Editors can not be wrong. :)
>
> I think there should be some way to say python compiler, to consider
> tab and two blank spaces equal, when tab space = 2.

It already considers tab = 8 spaces, and when invoked with -tt it rejects mixed 
tabs+spaces. (I would like Python rejected *any* tab used for indenting...)
There is a tool 'reindent.py' -somewhere on your Python install-, and an 
indentation checker 'tabnanny.py' (this one in the standard library).

-- 
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: python newbie: some surprises

2008-05-09 Thread J. Cliff Dyer
On Fri, 2008-05-09 at 15:08 +, Yves Dorfsman wrote:
> Gabriel Genellina wrote:
> 
> >> I see the point of the OP. Couldn't the new-line be used as an 
> >> equivalent of   ':', for example, do you find this difficult to read:
> >>
> >> if a == 3
> >>do_something()
> >>
> >>
> >> if a == 3: do_something()
> > 
> > Yes, it could be done, there are no technical reasons to always force to 
> > use ":". But AFAIK the main reasons to keep ":" are internal consistency 
> > (an inner block always starts with ":"; incidentally, that's easier to 
> > handle for editors) and legibility (the ":" stands for itself and has a 
> > meaning)
> 
> Legibility ?
> But one could make the same argument for curly brackets, and we seem to be 
> doing fine without them !
> 
> I have become so used to the power of indenting in python that I keep 
> forgetting the colon, and this is getting worse as I do more python, not 
> better. Maybe I'll write myself a "pre-compiler" that add the colons where 
> the compiler needs them :-)
> 
> 
> Yves.
> http://www.SollerS.ca
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 

Have you considered the following:

if (x == 4 and (y in 
[len(x) for x in
foo if x**2 > 23]
or y < 2) and z.strip().endswith('z') and
remove_first(w))
attach_list(q, r)
reject(x)

A colon on the correct line would help readability quite a bit.

Yeah, I know I made it pretty ugly to begin with, and there are ways to
improve it without the colon, but still, just because it could be
removed doesn't necessarily mean it should.

Cheers,
Cliff

--
http://mail.python.org/mailman/listinfo/python-list


Re: python newbie: some surprises

2008-05-09 Thread Yves Dorfsman

Gabriel Genellina wrote:

I see the point of the OP. Couldn't the new-line be used as an 
equivalent of   ':', for example, do you find this difficult to read:


if a == 3
   do_something()


if a == 3: do_something()


Yes, it could be done, there are no technical reasons to always force to 
use ":". But AFAIK the main reasons to keep ":" are internal consistency 
(an inner block always starts with ":"; incidentally, that's easier to 
handle for editors) and legibility (the ":" stands for itself and has a 
meaning)


Legibility ?
But one could make the same argument for curly brackets, and we seem to be 
doing fine without them !


I have become so used to the power of indenting in python that I keep 
forgetting the colon, and this is getting worse as I do more python, not 
better. Maybe I'll write myself a "pre-compiler" that add the colons where 
the compiler needs them :-)



Yves.
http://www.SollerS.ca

--
http://mail.python.org/mailman/listinfo/python-list


Re: python newbie: some surprises

2008-05-09 Thread v4vijayakumar
On May 9, 1:48 pm, Bruno Desthuilliers  wrote:
> v4vijayakumar a écrit :
>
> > When I started coding in python, these two things surprised me.
>
> > 1. my code is inconsistently indented with the combination of tabs and
> > spaces. Even lines looked intended, but it is not.
>
> Then you have a problem with your code editor - not with Python.
>

Editors can not be wrong. :)

I think there should be some way to say python compiler, to consider
tab and two blank spaces equal, when tab space = 2.
--
http://mail.python.org/mailman/listinfo/python-list


Re: python newbie: some surprises

2008-05-09 Thread Bruno Desthuilliers

Yves Dorfsman a écrit :
(snip)
I see the point of the OP. Couldn't the new-line be used as an 
equivalent of  ':', 



Technically, yes. OTHO, the ':' helps editors doing proper indentation.
--
http://mail.python.org/mailman/listinfo/python-list


Re: python newbie: some surprises

2008-05-09 Thread Bruno Desthuilliers

Yves Dorfsman a écrit :

Mensanator wrote:

2. python requires to pass "self" to all instance methods


Who uses methods?


Is this a joke ?


Very probably.


What are the alternatives ?


Err... functions ?-)

--
http://mail.python.org/mailman/listinfo/python-list


Re: python newbie: some surprises

2008-05-09 Thread Bruno Desthuilliers

v4vijayakumar a écrit :

When I started coding in python, these two things surprised me.

1. my code is inconsistently indented with the combination of tabs and
spaces. Even lines looked intended, but it is not.


Then you have a problem with your code editor - not with Python.


2. python requires to pass "self" to all instance methods


Nope. Python requires that function used as instance methods take the 
instance as first argument (and that functions used as classmethods take 
the class as first argument). It's the method object's duty to actually 
pass the appropriate object to the function. The rational is that it 
allows to built methods above two more generic constructs (namely: 
functions and the descriptor protocol) instead of having to special-case 
them.



and I missed ":" often. :)


Your editor should not indent the next line then. Either you failed to 
correctly configure your editor, or it's broken.

--
http://mail.python.org/mailman/listinfo/python-list


Re: python newbie: some surprises

2008-05-08 Thread Gabriel Genellina
En Fri, 09 May 2008 01:47:49 -0300, Yves Dorfsman <[EMAIL PROTECTED]>  
escribió:


I see the point of the OP. Couldn't the new-line be used as an  
equivalent of   ':', for example, do you find this difficult to read:


if a == 3
   do_something()


if a == 3: do_something()


And surely, it should be easy to parse by the compiler.


Yes, it could be done, there are no technical reasons to always force to  
use ":". But AFAIK the main reasons to keep ":" are internal consistency  
(an inner block always starts with ":"; incidentally, that's easier to  
handle for editors) and legibility (the ":" stands for itself and has a  
meaning)


--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: python newbie: some surprises

2008-05-08 Thread Mensanator
On May 8, 11:47�pm, Yves Dorfsman <[EMAIL PROTECTED]> wrote:
> Mensanator wrote:
> >> 2. python requires to pass "self" to all instance methods
>
> > Who uses methods?
>
> Is this a joke ?

Yes.

> What are the alternatives ?
>
>
>
> >> and I missed ":" often. :)
>
> > Try using something like Seed7, where you have to use "then" with
> > "if" and "do" with "while" and "end" in every block. Maybe you'll
> > come to appreciate significant whitespace and ":".
>
> I see the point of the OP. Couldn't the new-line be used as an equivalent of
> � ':', for example, do you find this difficult to read:
>
> if a == 3
> � �do_something()
>
> if a == 3: do_something()
>
> And surely, it should be easy to parse by the compiler.

If they were to chane it, I wouldn't complain.

I just think it doesn't deserve complaints when
compared to other systems.

>
> Yves.http://www.SollerS.ca

--
http://mail.python.org/mailman/listinfo/python-list

Re: python newbie: some surprises

2008-05-08 Thread Yves Dorfsman

Mensanator wrote:

2. python requires to pass "self" to all instance methods


Who uses methods?


Is this a joke ?
What are the alternatives ?





and I missed ":" often. :)


Try using something like Seed7, where you have to use "then" with
"if" and "do" with "while" and "end" in every block. Maybe you'll
come to appreciate significant whitespace and ":".


I see the point of the OP. Couldn't the new-line be used as an equivalent of 
 ':', for example, do you find this difficult to read:


if a == 3
  do_something()


if a == 3: do_something()


And surely, it should be easy to parse by the compiler.

Yves.
http://www.SollerS.ca
--
http://mail.python.org/mailman/listinfo/python-list


Re: python newbie: some surprises

2008-05-08 Thread Mensanator
On May 8, 2:06 am, v4vijayakumar <[EMAIL PROTECTED]>
wrote:
> When I started coding in python, these two things surprised me.
>
> 1. my code is inconsistently indented with the combination of tabs and
> spaces. Even lines looked intended, but it is not.

You must type inconsistently.

I never had such a problem even when I used to use Notepad.

>
> 2. python requires to pass "self" to all instance methods

Who uses methods?

>
> and I missed ":" often. :)

Try using something like Seed7, where you have to use "then" with
"if" and "do" with "while" and "end" in every block. Maybe you'll
come to appreciate significant whitespace and ":".
--
http://mail.python.org/mailman/listinfo/python-list


Re: python newbie: some surprises

2008-05-08 Thread Martin P. Hellwig

v4vijayakumar wrote:

When I started coding in python, these two things surprised me.

1. my code is inconsistently indented with the combination of tabs and
spaces. Even lines looked intended, but it is not.

Even the standard editor Idle tries to guess the intendation, so this 
was never a problem for me. Though these days I use PyDev a lot.



2. python requires to pass "self" to all instance methods
A lot of editors help you with these 'unnecessary' things by 
auto-completion might be worth looking into one.


and I missed ":" often. :)

Still do after 5 years of python abuse :-)

--
mph
--
http://mail.python.org/mailman/listinfo/python-list


python newbie: some surprises

2008-05-08 Thread v4vijayakumar
When I started coding in python, these two things surprised me.

1. my code is inconsistently indented with the combination of tabs and
spaces. Even lines looked intended, but it is not.

2. python requires to pass "self" to all instance methods

and I missed ":" often. :)
--
http://mail.python.org/mailman/listinfo/python-list