473,688 Members | 3,186 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3410
On 2007-05-16, HMS Surprise <jo**@datavoice int.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...@datavoice int.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...@datavoice int.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.blogs pot.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...@datavoice int.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
oversimplificat ion , but is where I typically find problems.

jh
#~~~~~~~~~~~~~~ ~~~~~~~~
createdIncident Id = 0
..
..
..
#attempt to change varialbe
createdIncident ID = 1
..
..
..
if createdIncident Id == 1:
...

May 17 '07 #6
HMS Surprise schrieb:
>
#~~~~~~~~~~~~~~ ~~~~~~~~
createdIncident Id = 0
.
.
.
#attempt to change varialbe
createdIncident ID = 1
.
.
.
if createdIncident Id == 1:
...
test.py is your code above

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

Warnings...

test.py:7: Variable (createdInciden tID) not used
Gregor
May 17 '07 #7
On 2007-05-16, HMS Surprise <jo**@datavoice int.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.co mwrote:
On 2007-05-16, HMS Surprise <j...@datavoice int.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
6331
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 them i can't define (hard coded) a fixed length because the application is reading data from another file (In that file they have the same lenght). Is it possible to use the lenght i obtain from reading that other file to declare my variable or...
2
2134
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 efficient than repeatedly referencing the member in a loop? Maybe using a string isn't the best example, but hopefully you get the idea! * example (referencing member):
2
54017
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 = '2005-01-01'
1
2426
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 program which control to requery. This makes it easy to requery controls on a different form. However, up until today, I was dimming a new local variable for each control I wanted to deal with ( E.G. Dim cbxctl as control) and then setting that...
5
2227
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
3511
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 error saying to change Public to Dim. When I do, it will say that Test1 is an unused local variable.
3
2261
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() on WebForm1.aspx, I use "Public Property" and I declare variable _oRpte as Friend Shared. That's my problem. If I don't declare _oRpte as Friend Shared, I can't use WebForm1.oRpte() on other webpage. If I declare _oRpte as Friend Shared, I can use...
2
2057
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 projects. For example, web page Page1 in Project1 will redirect to web page Page2 in Project2 which will further redirect to Page3 in project3 and Page4 in Project4 and finally back to Page1. In each web page, some session variables, such as...
8
7510
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, like this: for(var i=0; i<list; i++) { var name = list; }
6
2982
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
8590
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8782
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8786
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7621
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6453
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5807
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2215
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.