473,416 Members | 1,732 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,416 software developers and data experts.

noob question

Hello,

Very new to python, so a noob question. When I've written stuff in
JavaScript or MEL in the past, I've always adopted the variable naming
convention of using a $ as the first character (no, I don't use perl,
never have). Not possible in python. What are some good options that
people commonly use so that they can easily and quickly identify
variable with just a glance? When I was writing stuff in SoftImage
XSI/JScript, many of the examples in the SDK used just a leading lower
case o, but I'd like somethign that's more visible. I'm not a super
advanced user and am just starting out in python (pretty much just
working my way through Learning Python, at around page 160 or so).
Seems like an _extremely_ elegent language that is very easy to read, so
I suppose it's not really as much of an issue as it is with other
languages. Still, I would like to see what other people do and what are
some good ideas for this kind of thing.

Thank you for any and all ideas.

cheers,

-Matt

Jul 19 '05 #1
10 2079
Matt Hollingsworth <ma**@maudit.net> writes:
What are some good options that people commonly use so that they can
easily and quickly identify variable with just a glance?


Use an editor that has a Python syntax highlighting mode, for example
Emacs with python-mode, Vim, or the IDLE IDE that comes with Python.

--
Björn Lindström <bk**@stp.ling.uu.se>
Student of computational linguistics, Uppsala University, Sweden
Jul 19 '05 #2
To recognize variables that you have assigned, just look for
assignment. If your code is readible, and you know it well, you
shouldn't need the $ sign in front of everything.

Jul 19 '05 #3
Hi Matt,
I also am almost a newbie (in Python) and my approach to variable
naming
follows more or less the Hungarian Type Notation Defined.
To better explain, I use one char or two (in small case) as a prefix of
the name of
the variable (starting in capital letters).
The prefix identifies the "type" of variable. My choice of such
prefixes is (a short example):
s string (sStringVariable)
l list (lFileLines)
n numeric (nNumericVariable)
and so on...
Bye.

Jul 19 '05 #4
On Sat, 25 Jun 2005 22:06:08 -0700, Matt Hollingsworth wrote:
Hello,

Very new to python, so a noob question. When I've written stuff in
JavaScript or MEL in the past, I've always adopted the variable naming
convention of using a $ as the first character (no, I don't use perl,
never have). Not possible in python. What are some good options that
people commonly use so that they can easily and quickly identify
variable with just a glance?


Learn the language rather than relying on magic symbols.

I don't understand why you would need to have a special naming convention
to identify variables. Magic symbols just get in the way, especially in a
language like Python where everything is an object. (Except keywords and
operators, I suppose.)

Eg, when you do something like this:

myInstance = MyClass(something)
print myInstance.method(somethingelse)

everything except "print" is an object. Or rather, a name that references
an object.

Python doesn't really have variables as such. It has names and objects.
Most of the time, you can think of names as being like variables.

Can anyone think of some good, easy to understand examples of where
Python's name/object model differs from the variable/value model?
--
Steven.

Jul 19 '05 #5
"Matt Hollingsworth" <ma**@maudit.net> wrote in message
news:ma**************************************@pyth on.org...
Very new to python, so a noob question. When I've written stuff in JavaScript or MEL in the past, I've always adopted the variable naming convention of using a $ as the first character (no, I don't use

perl,

Can I ask why you did that?
Did someone tell you to or did you hit on the idea yourself?
Do you really find it useful? I mean do you often in your
Python coding find a problem with identifying your variables?

I'm curious because one of the things I like most about Python
is the fact I don't need to mess up my programs with spurious
characters like $ etc. And I never have any problem identifying
variables etc in my code. (The same is true of Object Pascal
in Delphi, my other favourite language).

The only place I've ever found Hungarian notation useful was
in C which is a weird mix of static typing and no-typing,
and there the prefix code gives a clue as to what kind of
value you might expect to find. But when I moved to C++ I
dropped the prefixes because they added no value.

In Python Hungarian notation is meaningless since variables
aren't typed anyway.

So I am curious as to why anyone would feel the need to introduce
these kinds of notational features into Python. What is the
problem that you are trying to solve?
--
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


Jul 19 '05 #6
Alan Gauld wrote:
In Python Hungarian notation is meaningless since variables
aren't typed anyway.


in real-life Python code, variables tend to be 'typed' in the hungarian
sense:

http://msdn.microsoft.com/library/en...hunganotat.asp

"/.../ the concept of 'type' in this context is determined by
the set of operations that can be applied to a quantity. The
test for type equivalence is simple: could the same set of
operations be meaningfully applied to the quantities in
questions? If so, the types are thought to be the same.
If there are operations that apply to a quantity in exclusion
of others, the type of the quantity is different."

</F>

Jul 19 '05 #7
On Mon, 27 Jun 2005 07:14:07 +0000, Alan Gauld wrote:
The only place I've ever found Hungarian notation useful was
in C which is a weird mix of static typing and no-typing,
and there the prefix code gives a clue as to what kind of
value you might expect to find. But when I moved to C++ I
dropped the prefixes because they added no value.

In Python Hungarian notation is meaningless since variables
aren't typed anyway.


Not quite true. Objects are typed in Python:

py> type('')
<type 'str'>
py> type(1)
<type 'int'>

but names ("variables", almost) can be dynamically changed from one type
to another:

py> x = 1 # x starts as an int
py> x = '~' # now it is a string
py> x = [1] # and now a list

Even though names can refer to an object of any type, the actual
objects themselves are always strongly typed: "hello" is always a
string, {} is always a dict, and so on.

The best use of Hungarian notation is the original use, as introduced in
the application development team at Microsoft (before the operating system
team got their hands on it, and broke it).

Rather than prefixing variable names with the type which the compiler
already knows (eg "sName" for a string, "iAge" for an integer), the
original use of Hungarian notation was to use a prefix which explains what
the data is for: the "type" of object, but not types which compilers
understand.

Here are some good uses for Hungarian notation:

ixCurrent = 0 # ix~ means index into a list or array
cFound = 0 # c~ means a count
dxObject = object.width() # d means difference

No compiler in the world can tell that adding the width of an object in
pixels to the count of how many objects were found gives a meaningless
result. But a human programmer should immediately see the bug in:

ixHam = dxEgg + cTomato

even if they don't remember what Ham, Egg and Tomato represent.

Remember that space probe a few years back that crashed into Mars because
some NASA engineer forgot to convert metric to imperial or vice versa?
That sort of mistake is easy to make when you have something like this:

initialSpeed = 3572.8 # feet per second
# ~~~
# five pages of code
# ~~~
deceleration = 3.5 # metres per second squared
# ~~~
# five more pages of code
# ~~~
timeNeeded = initialSpeed/deceleration

Now imagine seeing this line instead:

timeNeeded = iInitialSpeed/mDeceleration

With just a glance you can see that there needs to be a conversion from
imperial (i~) to metric (m~) or vice versa, or else your $20 billion
dollar space probe turns the engines off too early and becomes a $20
billion hole in the ground.

The history and justification for Hungarian notation is explained here:

http://www.joelonsoftware.com/articles/Wrong.html
--
Steven.

Jul 19 '05 #8
Alan Gauld wrote:
The only place I've ever found Hungarian notation useful was
in C which is a weird mix of static typing and no-typing,
and there the prefix code gives a clue as to what kind of
value you might expect to find. But when I moved to C++ I
dropped the prefixes because they added no value. In Python Hungarian notation is meaningless since variables
aren't typed anyway.


Unfortunately, the original concept of Hungarian is often misunderstood,
as shown by the article pointed out by Konstantin.

Reinhold
Jul 19 '05 #9
qw******@yahoo.it wrote:
Hi Matt,
I also am almost a newbie (in Python) and my approach to variable
naming
follows more or less the Hungarian Type Notation Defined.


which is seen as a bad practice anywhere outside Win32...

http://mindprod.com/jgloss/unmainnaming.html
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Jul 19 '05 #10
Steven D'Aprano <st***@REMOVETHIScyber.com.au> wrote in message news:<pa****************************@REMOVETHIScyb er.com.au>...
Can anyone think of some good, easy to understand examples of where
Python's name/object model differs from the variable/value model?


a = b = [ 1 ]

a and b are _not_ two variables, each with [ 1 ] as value, but just two
names for the same object (a list). In other variable-based languages,
the above is equivalent to:

a = [ 1 ]
b = [ 1 ]

in Python it is not.

..TM.
Jul 19 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dave Williams | last post by:
First off...total noob to VB. So far have learned a lot in 1.5 days and feel fairly comfortable at throwing screens up. However, I want to start writing forms that revolve around an access...
1
by: davestrike | last post by:
I am a noob to sql and asp programming. I am working on a db for the gaming squad I am a member of. One of the pages I created is a roster list of all the squad members. Part of this roster is...
3
by: We need more power captain | last post by:
Hi, I know less than a noob, I've been asked to do some compiles in VC++ 6 without knowing too much at all. (I'm a COBOL program normally so this is all too much for me) I open VC++6, open...
8
by: Ivan Shevanski | last post by:
Alright heres another noob question for everyone. Alright, say I have a menu like this. print "1. . .Start" print "2. . .End" choice1 = raw_input("> ") and then I had this to determine what...
2
by: Chris Dunaway | last post by:
I was looking over some asp.net code and saw this asp:Image control: <asp:Image ImageUrl="~/images/logo.gif" runat="server" ID="Image1"/> What does the tilde (~) mean in the ImageUrl...
2
by: Dan McCollick | last post by:
Hi All, Noob question that I can not seem to figure out: I am trying to implement a screenscraper to pull data from two seperate websites, here is some test code so far: public static void...
0
by: AndyW | last post by:
Hey folks. I am trying to get a soap wsdl service working and have a bit of a noob php programming question for it. I'm using PHP 5.x btw. I have written a soap server that contains a...
6
by: Lang Murphy | last post by:
I'm baaaaack... some of you answered a question I had last week. Only problem is: I'm a dope who doesn't understand most of what y'all posted. Raw noob when it comes to .Net and C#. So I'm going...
1
by: SCRIPT KEEPER | last post by:
Hello, I am a complete noob and just starting off with csharp so I apologize for my basic question. I am wanting to start powershell from inside a batch script and then to pass the powershell args...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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,...
0
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...

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.