By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,285 Members | 1,647 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,285 IT Pros & Developers. It's quick & easy.

Declaring variables

P: n/a
I looked in the language but did not find a switch for requiring
variables to be declared before use.

Is such an option available?

Thanks,

jvh

May 16 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
On 2007-05-16, HMS Surprise <jo**@datavoiceint.comwrote:
I looked in the language but did not find a switch for requiring
variables to be declared before use.
Still trying to write Pascal, eh? ;)
Is such an option available?
No.

However, there are utilities to "proofread" your code should
you have a desire for that:

http://www.logilab.org/pylint
http://pychecker.sourceforge.net/

--
Grant Edwards grante Yow! What I need is a
at MATURE RELATIONSHIP with a
visi.com FLOPPY DISK ...
May 16 '07 #2

P: n/a

No haven't had to endure Pascal. Mostly C/C++, Tcl, and assembler. Oh
yeah, and a (thankfully) short stint of Ada.

But I glad to hear of the proofing tools. Working a lot of data parsed
from web pages and the developer there a different naming convention
from what I am accustomed so sometimes I introduce a new variable
unintentionally.
Thanks,

jvh

May 16 '07 #3

P: n/a
On May 16, 9:57 am, HMS Surprise <j...@datavoiceint.comwrote:
I looked in the language but did not find a switch for requiring
variables to be declared before use.

Is such an option available?

Thanks,

jvh
You do have to declare a variable before use. You do so by assigning
it a value. You can't use a variable before it has been assigned. In
some ways this is less ambiguous than even C where you can declare a
variable without assigning a value. Also note that this caries the
type information, since the variable is of whatever type was assigned
to it. The only thing it doesn't do is give a unique flag that says
"hey this is where I'm declared", although I suppose you could do that
with a comment.

Matt

May 16 '07 #4

P: n/a
Matimus wrote:
On May 16, 9:57 am, HMS Surprise <j...@datavoiceint.comwrote:
>I looked in the language but did not find a switch for requiring
variables to be declared before use.

Is such an option available?

Thanks,

jvh

You do have to declare a variable before use. You do so by assigning
it a value. You can't use a variable before it has been assigned. In
some ways this is less ambiguous than even C where you can declare a
variable without assigning a value. Also note that this caries the
type information, since the variable is of whatever type was assigned
to it. The only thing it doesn't do is give a unique flag that says
"hey this is where I'm declared", although I suppose you could do that
with a comment.
Strictly, the variable has no type at all (and strictly your "variables"
are actually names bound to values in a namespace, and it's the values
that are typed).

We shouldn't ignore the fact that declarations unambiguously say "the
programmer intends to use such-and-such a name for a value of a specific
type". Contrast this with a Python program where one path makes an
assignment (binding) to a name while another path doesn't, resulting in
a later NameError.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
------------------ Asciimercial ---------------------
Get on the web: Blog, lens and tag your way to fame!!
holdenweb.blogspot.com squidoo.com/pythonology
tagged items: del.icio.us/steve.holden/python
All these services currently offer free registration!
-------------- Thank You for Reading ----------------

May 17 '07 #5

P: n/a
On May 16, 6:48 pm, Matimus <mccre...@gmail.comwrote:
On May 16, 9:57 am, HMS Surprise <j...@datavoiceint.comwrote:
I looked in the language but did not find a switch for requiring
variables to be declared before use.
Is such an option available?
Thanks,
jvh

You do have to declare a variable before use. You do so by assigning
it a value. You can't use a variable before it has been assigned.
Yes this is where the problem arises. This is a gross
oversimplification , but is where I typically find problems.

jh
#~~~~~~~~~~~~~~~~~~~~~~
createdIncidentId = 0
..
..
..
#attempt to change varialbe
createdIncidentID = 1
..
..
..
if createdIncidentId == 1:
...

May 17 '07 #6

P: n/a
HMS Surprise schrieb:
>
#~~~~~~~~~~~~~~~~~~~~~~
createdIncidentId = 0
.
.
.
#attempt to change varialbe
createdIncidentID = 1
.
.
.
if createdIncidentId == 1:
...
test.py is your code above

$ pychecker -v test.py
Processing test...

Warnings...

test.py:7: Variable (createdIncidentID) not used
Gregor
May 17 '07 #7

P: n/a
On 2007-05-16, HMS Surprise <jo**@datavoiceint.comwrote:
No haven't had to endure Pascal. Mostly C/C++, Tcl, and assembler.
I must have you mixed up with somebody else who recently
mentioned having Pascal as their first real language.

--
Grant Edwards grante Yow! It's OKAY -- I'm an
at INTELLECTUAL, too.
visi.com
May 17 '07 #8

P: n/a
On May 17, 9:34 am, Grant Edwards <gra...@visi.comwrote:
On 2007-05-16, HMS Surprise <j...@datavoiceint.comwrote:
No haven't had to endure Pascal. Mostly C/C++, Tcl, and assembler.

I must have you mixed up with somebody else who recently
mentioned having Pascal as their first real language.

--
Grant Edwards grante Yow! It's OKAY -- I'm an
at INTELLECTUAL, too.
visi.com
That's OK. I am easily mixed up.

May 17 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.