473,378 Members | 1,391 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Declaring variables

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
8 3385
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

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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Stefanie | last post by:
Hi, I have a question about declaring variables for writing data to a file for random access. I have two string variables declared in a module (user-defined types). The point is that for one of...
2
by: Oliver Corona | last post by:
I am wondering if anyone has any insights on the performance benefit (or detriment) of declaring local variables instead of referencing members. Is allocating memory for a new variable more...
2
by: ross.oneill | last post by:
Hi, I am having trouble with a simple task of declaring a variable. Is this possible? Here is what I want to do. DECLARE start_date date; DECLARE end_date date; SET start_date =...
1
by: ColinWard | last post by:
Hi guys. I have a question about declaring variables. I do a lot of re-querying of controls in my database and I use the Set statement with a variable set to the name of the control to tell the...
5
by: param | last post by:
Declaring struct as static is creating problem with newer version of CC compiler 5.7 in solaris. e.g. static struct new_str { int a; int b; };
6
by: Mark A. Sam | last post by:
Hello, I am using Visual Web Developer 2005 Express. I want to declare a varible, using Visual Basic as the language and can't get anywhere. For example Public Test1 as String I'll get en...
3
by: jbeteta | last post by:
Hello, I have a problem declaring variables. I need to create an object oRpte as ReportClass on WebForm1.aspx and be able to use its value on WebForm2.aspx. For declaring the property oRpte()...
2
by: TARUN | last post by:
I have a question about declaring the Global.ascx: In VS.NET I create a Solution, and there are 4 projects under it. They are put under 4 folders, but web pages would be called across the 4...
8
by: SM | last post by:
I've always wonder if there is diference when declaring and initializing a varible inside/outside a loop. What's a better practice? Declaring and initializing variables inside a loop routine,...
6
by: =?Utf-8?B?QUw=?= | last post by:
Hi I usually stick to the convention of not declaring variables in my bodies of "loops" (including foreach) ie int x; for (int i = 0; i < 10; i++) {
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.