473,549 Members | 2,719 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Static typing

Is there currently any plan to introduce static typing in any future
version of Python? (I'm not entirely sure that "static typing" is the right
term: what I'm talking about is the declaration of types for variables,
parameters and function return values).

I know there was a "types SIG" which introduced several proposals, but it
expired quite a while ago, and I was wondering whether whether some
consensus has been reached on the subject or if it has just been shelved
indefinitely.

--
Remove the spam and filter components to get my e-mail address.

Jul 18 '05 #1
12 2550
Michael Muller wrote:
Is there currently any plan to introduce static typing in any future
version of Python?
AARGGHHHH ! NO !! DON'T DO THAT !!! NEVER AGAIN !!!!

(sorry, uncontrolable nervous reaction... 3 valiums latter... : )

(I'm not entirely sure that "static typing" is the right term: what I'm talking about is the declaration of types for variables,
parameters and function return values).
This is the right term. This is also the wrong thing for Python IMHO.
I know there was a "types SIG" which introduced several proposals, but it
expired quite a while ago, and I was wondering whether whether some
consensus has been reached on the subject


<flame-war-mode='on'>
Yes :
dynamic typing is good a Good Thing(tm),
static typing is Evil(tm) !-)
</flame-war-mode>
Bruno

Jul 18 '05 #2
Michael Muller wrote:
Is there currently any plan to introduce static typing in any future
version of Python?


Seriously, why would you do that ?

Bruno

Jul 18 '05 #3
Bruno Desthuilliers wrote:
Michael Muller wrote:
Is there currently any plan to introduce static typing in any future
version of Python?

Seriously, why would you do that ?


You _might_ want some static typing information as program
documentation or to enable efficient program translation. The
types sig was interested in allowing type annotation where
possible. Remember, the type you might want may be more like
"what protocol must these objects (the ones passing through
this variable) follow" than "what are the construction details
of these objects".

I would like to see interface descriptions describing what
kinds of parameters are required and results produced for
packages that I am considering using. If there were a single
central-python-endorsed form for those descriptions even better.
If the descriptions can be mechanically read, and at least
sometimes mechincally checked (possibly slowly, possibly only
for slow execution), I might use such a system to check a module
before announcing it to the world.

A very old Sun study determined that most variables in a
dynamically typed system (smalltalk, IIRC) are almost always
of the same type.

David Ungar got a fair amount of mileage out of optimizing for
a guessed common case in a protype-driven language where you
couldn't even name types in the language (you make objects
"just like that one except...").

I had a sketch of how to optimize for OODBs using behavior-based
typing. The big trick was to use the DB's knowledge of the classes
in the DB (provided for each instance in the DB) to determine
when there was, at least currently, only one method for the given
function. An environment like that might be able to do much
better at query optimization than any OODB that allows you to
store arbitrary objects and retrieve them based on message calls.

-Scott David Daniels
Sc***********@A cm.Org

Jul 18 '05 #4
In article <ma************ *************** *******@python. org>,
Shane Hathaway <sh***@zope.com > wrote:

Well, here's a pattern I've been trying out for this purpose: use assert
statements at the top of the function.

def foo(bar, baz):
assert isinstance(bar, int)
assert isinstance(baz, str)

I'm quite happy with the pattern, although there are a couple of
negative points that I can think of:

- It's a bit verbose, although that verbosity enables you to perform
bounds checking and operate with other type systems like Zope's interfaces.

- You can't specify the type of the return values this way.


You skipped the crucial negative: it breaks Python's name-based
polymorphism. If someone creates a class that works just like a string
but doesn't derive from the str class, your program breaks for no good
reason.
--
Aahz (aa**@pythoncra ft.com) <*> http://www.pythoncraft.com/

This is Python. We don't care much about theory, except where it intersects
with useful practice. --Aahz
Jul 18 '05 #5
Shane Hathaway:
Well, here's a pattern I've been trying out for this purpose: use assert
statements at the top of the function.

def foo(bar, baz):
assert isinstance(bar, int)
assert isinstance(baz, str)


The Wing IDE will read assertions of the above form and provide more
assistance than with identifiers it knows nothing about:
http://wingide.com/psupport/wingide-...00000000000000
00

Neil
Jul 18 '05 #6
On 07/25/2003 07:36 PM, Neil Hodgson wrote:
Shane Hathaway:

Well, here's a pattern I've been trying out for this purpose: use assert
statements at the top of the function.

def foo(bar, baz):
assert isinstance(bar, int)
assert isinstance(baz, str)

The Wing IDE will read assertions of the above form and provide more
assistance than with identifiers it knows nothing about:
http://wingide.com/psupport/wingide-...00000000000000


Excellent. It's nice to have an idea validated. :-)

Shane
Jul 18 '05 #7
Michael Muller wrote:
Well, it appears that I have inadvertantly trolled c.l.p. I humbly
apologize. I really just wanted to know what the status of the issue
was.
I may be wrong, but I don't think anyone took your question as a troll -
well, I didn't anyway.
FWIW, I do favor the addition of optional static typing for the two
reasons Scott described - interface documentation and optimization.


Interface documentation may be obtained in others ways (docstring for
exemple). And I'm not sure static typing would optimize anything, but
not being a Python (nor anything else) guru, I would not bet my hand on
this...

my 2 cents...

Bruno

Jul 18 '05 #8
Bruno Desthuilliers <bd***********@ removeme.free.f r> wrote in message news:<3f******* *************** *@news.free.fr> ...
FWIW, I do favor the addition of optional static typing for the two
reasons Scott described - interface documentation and optimization.
Interface documentation may be obtained in others ways (docstring for
exemple).


Indeed! As I remember, Jython uses doc strings for typing, when it
presents an API to Java. So it's in the comments, and I think that's
an oddly appropriate place for hints to the compiler.

And I'm not sure static typing would optimize anything, but
not being a Python (nor anything else) guru, I would not bet my hand on
this...


If you mess around with lisp, you can easily see the compiled assembly
language of your functions when you experiment with optional typing.
(By calling the function "disassembl e".) Normally, the compiler spews
a lot of general code because it doesn't know what you've passed in.
But when you promise that you're passing in numbers or something, the
assembly language is much tighter.

Sort of like when someone asks you to move something to a different
house, and you have no idea how big it is. If you were told, "It's
just a pillow," you know that you don't need to order a huge truck or
take any special precautions.
Jul 18 '05 #9
Michael Muller wrote:
In article <3f************ ***********@new s.free.fr>, "Bruno Desthuilliers"
<bd***********@ removeme.free.f r> wrote:
Michael Muller wrote:
Interface documentation may be obtained in others ways (docstring for
exemple).

Yes, and that's the way that I do it now. But the problem with this is
that it's "non-binding": it doesn't impose any programmatic constraints.
Because of this:

- it's hard to enforce automatically (if you want to make sure that all
programmers in your team are using the prescribed argument definition
conventions, you have to parse all the docstrings)


It's a management problem, not a programming language issue.
- there is no global standard (I might use "name: type info" in my
docstring, you might use "type name")
Idem.
- it is hard to guarantee that the documentation is in sync with the code
(if you change the type expectations of a function, you can do so without
changing the documented expectations)
Idem. If your programmers don't care about keeping doc in sync, you're
in trouble whatever the language.
- it makes type errors less obvious (you end up getting an attribute
error when you perform an operation on the value instead of a type error
when you initially abuse the interface) Although, I must say that this is
surprisingly less of a problem in Python than one might expect.
Yep. Type errors are not the most common nor the most annoying bugs. If
only declaring types three times was enough to get bug-free programs...
And I'm not sure static typing would optimize anything, but not being a
Python (nor anything else) guru, I would not bet my hand on this... my 2
cents...

In and of itself, static typing does not optimize anything. In fact, it
could slow things down because you suddenly have to do typechecks all over
the place.

Static typing can be /used/ for optimizations because it allows for
optimized forms of attribute access -


Right.
without it you must do dynamic name
resolution at runtime.
Which is a Good Thing IMHO.
For example, if you want to resolve a method name, you currently have to
look up the method name in the object and its classes. With static
typing, since you know the type of the object at compile time, you can
just reference it in a "vtable" (a virtual function table) associated with
the object.

In short, static typing brings us one step closer to "python compiled to
machine code".


Well... Objective C is compiled to machine code, and still has dynamic
binding (not late binding as in C++), so static typing does not seem
mandatory here.

Anyway, I personnally don't have a compelling need for Python being
compiled into machine code, and just don't want to here about it if it
implies static typing !-)

The only thing that could make sens to me would be a protocol-checking
mechanism, and there are already some.

Bruno

Jul 18 '05 #10

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

Similar topics

467
21249
by: mike420 | last post by:
THE GOOD: 1. pickle 2. simplicity and uniformity 3. big library (bigger would be even better) THE BAD:
15
2650
by: Premshree Pillai | last post by:
How do I force static typing in Python? -Premshree Pillai ===== -Premshree http://www.qiksearch.com/] ________________________________________________________________________ Yahoo! India Insurance Special: Be informed on the best policies, services, tools and more.
8
1811
by: Grzegorz Dostatni | last post by:
I had an idea yesterday. (Yes, I know. Sorry). If we don't need to declare variables as having a certain type, why do we need to import modules into the program? Isn't the "import sys" redundant if all I want is to call "sys.setrecursionlimit(5000)" ? Why couldn't we just try loading the module of a name "sys" to see if it exists and re-try...
19
1655
by: bearophile | last post by:
This is my first post here, I hope this is the right place to talk about such things. I have few comments and notes on the Python language. I've just started to learn it; this is negative because I'm ignorant still, but it's also positive because I can still see details that later probably I'll start to ignore. Some of the functions of...
49
3054
by: bearophileHUGS | last post by:
Adding Optional Static Typing to Python looks like a quite complex thing, but useful too: http://www.artima.com/weblogs/viewpost.jsp?thread=85551 I have just a couple of notes: Boo (http://boo.codehaus.org/) is a different language, but I like its "as" instead of ":" and "->", to have: def min(a as iterable(T)) as T: Instead of:
44
2817
by: John A. Bailo | last post by:
Dr. Dobbs has a /glowing/ article on Ruby on Rails this month. What do you guys think? Can it replace .net, php and java? And be the Open Source OOP web solution that is not bound to Sun or MS? http://media.rubyonrails.org/presentations/pursuitofbeauty.pdf
6
1749
by: Christian Convey | last post by:
Hi guys, I'm looking at developing a somewhat complex system, and I think some static typing will help me keep limit my confusion. I.e.: http://www.artima.com/weblogs/viewpost.jsp?thread=87182 Does anyone know if/when that feature may become part of Python? Thanks very much,
17
4410
by: copx | last post by:
I don't know what to think of the following.. (from the dietlibc FAQ) Q: I see lots of uninitialized variables, like "static int foo;". What gives? A: "static" global variables are initialized to 0. ANSI C guarantees that. Technically speaking, static variables go into the .bss ELF segment, while "static int foo=0" goes into .data. ...
45
1842
by: azrael | last post by:
Hy guys, A friend of mine i a proud PERL developer which always keeps making jokes on python's cost. Please give me any arguments to cut him down about his commnets like :"keep programing i python. maybe, one day, you will be able to program in VisualBasic" This hurts. Please give me informations about realy famous aplications.
0
7520
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...
0
7450
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7957
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...
1
5368
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...
0
5088
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...
0
3500
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3481
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1941
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1059
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.