Variable declarations + pyflakes

I have recently been talking to friends/colleagues about their reasons for not using python for large projects (say from a thousand lines of code and with at least three people contributing). One of the problems that comes up time and again is the difficulty in debugging python code and in particular the simple sounding job of catching typos. One specific suggestion is the following. Make variable declaration compulsory. For example. var foo = 15 [...] var foo = 10 should return an error. Similarly

The email below was sent before it was finished. var foo = 15 [...] var foo = 10 should return an error. foo = 15 should return an error if foo was not declared before. The second answer of http://programmers.stackexchange.com/questions/15468/what-are-the-drawbacks-... (with 60 votes) has some more details of a very similar suggestion. Is it possible for use pyflakes with some suitably defined annotation to do something equivalent? Getting python devs to accept the suggestion for the core python language more not be at all plausible. Raphael On 27 May 2013 14:05, Raphael Clifford <drraph@gmail.com> wrote:
I have recently been talking to friends/colleagues about their reasons for not using python for large projects (say from a thousand lines of code and with at least three people contributing). One of the problems that comes up time and again is the difficulty in debugging python code and in particular the simple sounding job of catching typos. One specific suggestion is the following.
Make variable declaration compulsory. For example.
var foo = 15 [...] var foo = 10
should return an error.
Similarly

Wouldn't static type-inferencing of Python give the same benefits, without forcing programmers to write "Java-like" declarations? Type inferencing would catch potential uninitialized variables, calling non-existent methods, etc. ... and combined with a tool like lib2to3 could be used to automatically insert type annotations into the code. On 27 May 2013 06:09, Raphael Clifford <drraph@gmail.com> wrote:
The email below was sent before it was finished.
var foo = 15 [...] var foo = 10
should return an error.
foo = 15
should return an error if foo was not declared before.
The second answer of
http://programmers.stackexchange.com/questions/15468/what-are-the-drawbacks-... (with 60 votes) has some more details of a very similar suggestion.
Is it possible for use pyflakes with some suitably defined annotation to do something equivalent? Getting python devs to accept the suggestion for the core python language more not be at all plausible.
Raphael
On 27 May 2013 14:05, Raphael Clifford <drraph@gmail.com> wrote:
I have recently been talking to friends/colleagues about their reasons for not using python for large projects (say from a thousand lines of code and with at least three people contributing). One of the problems that comes up time and again is the difficulty in debugging python code and in particular the simple sounding job of catching typos. One specific suggestion is the following.
Make variable declaration compulsory. For example.
var foo = 15 [...] var foo = 10
should return an error.
Similarly
code-quality mailing list code-quality@python.org http://mail.python.org/mailman/listinfo/code-quality

Raphael Clifford <drraph@gmail.com> writes: I did not closely follow the previous conversation, please forgive me if I'm off topic.
Is it possible for use pyflakes with some suitably defined annotation to do something equivalent? Getting python devs to accept the suggestion for the core python language more not be at all plausible.
Well, it might be interesting if pyflakes or some similar tool was able to make sense out of a few: assert isinstance(argument-identifier, some-class) statements at the beginning of a function. That would be not only valid Python, but meaningful code whenever executed, as it would ascertain the sanity of function arguments. Such "assert insinstance()" could be sprankled in other places as well for pyflakes to recognize, but I'm not sure it would not become fairly complex to process them all correctly and make proper/useful inferences. The drawback is that this would slow down the execution when used in frequently used, smallish functions. One might argue that assertions might be all turned into noops by using -O on the python call, but I do not buy this argument: turning off all assertions is like activating a kind of unsafe-mode, which people would not do in practice. François

On 27/05/13 21:40, François Pinard wrote:> Raphael Clifford <drraph@gmail.com> writes:
Is it possible for use pyflakes with some suitably defined annotation to do something equivalent? Getting python devs to accept the suggestion for the core python language more not be at all plausible.
Well, it might be interesting if pyflakes or some similar tool was able to make sense out of a few:
assert isinstance(argument-identifier, some-class)
But then code fails with valid values that are not instances of some-class. Duck typing would not work anymore. It's like static typing but with more typing. Ciao, Marc 'BlackJack' Rintsch -- “A man should never be ashamed to own he has been in the wrong, which is saying, in other words, that he is wiser today than he was yesterday.” -- Jonathan Swift
participants (4)
-
François Pinard
-
Marc 'BlackJack' Rintsch
-
Peter Ludemann
-
Raphael Clifford