Discussion:
[Jython-users] Statically Typed Python/Jython?
j***@gmail.com
2010-01-12 08:18:42 UTC
Permalink
Today I came across this very old post (1/6/2005) of Guido van Rossum
"Optional Static Typing -- Stop the Flames!"
http://www.artima.com/weblogs/viewpost.jsp?thread=87182
which discusses optional static typing of Python. It particularly
interests me because I've been searching for a language that's
statically typed to take advantages of the error checking features
of compilers and IDEs (as well as many other features provided by
IDEs, e.g. refactoring), while also has the power of Python. I'm
not sure if it's eventually implemented or not. I checked Python 2.5
command line options but didn't find anything that's related to
static typing.

However, because of the flexibility of dynamic typing, Python code
is too easy to break (typos typos!). (I know I can always write
more unit tests for my code but I can't be convinced that unit tests
can replace the help of compiler and IDE.) Many times I ended up
rewriting Python projects in Java when they get big.

But Java doesn't really satisfy me because of its verbosity. So
I was on the lookout for a language that has the benefit of both
worlds. I have recently tried Scala for a concise and statically typed
language. It has a very powerful type system and it is much more
concise than Java. However, its syntax looks quite cryptic, especially
for new users. After playing with Scala for a short while, I miss
Python's simple but powerful syntax a lot. And I certainly miss the
"Zen of Python" (http://www.python.org/dev/peps/pep-0020/) a lot.
I believe many others are in the same boat.

After reading GvR's article, I come to think that maybe Jython with
(optional) static typing is the answer, with the added benefit of
running on the powerful JVM platform. I guess at this point this
is no more than wishful thinking but who knows. I understand at
this point improving Python compatibility is the main goal of Jython
development but maybe having a statically typed Jython is even more
useful to developers :)
--
Best regards,
Jack
Alex Grönholm
2010-01-12 08:24:28 UTC
Permalink
Post by j***@gmail.com
Today I came across this very old post (1/6/2005) of Guido van Rossum
"Optional Static Typing -- Stop the Flames!"
http://www.artima.com/weblogs/viewpost.jsp?thread=87182
which discusses optional static typing of Python. It particularly
interests me because I've been searching for a language that's
statically typed to take advantages of the error checking features
of compilers and IDEs (as well as many other features provided by
IDEs, e.g. refactoring), while also has the power of Python. I'm
not sure if it's eventually implemented or not. I checked Python 2.5
command line options but didn't find anything that's related to
static typing.
However, because of the flexibility of dynamic typing, Python code
is too easy to break (typos typos!). (I know I can always write
more unit tests for my code but I can't be convinced that unit tests
can replace the help of compiler and IDE.) Many times I ended up
rewriting Python projects in Java when they get big.
But Java doesn't really satisfy me because of its verbosity. So
I was on the lookout for a language that has the benefit of both
worlds. I have recently tried Scala for a concise and statically typed
language. It has a very powerful type system and it is much more
concise than Java. However, its syntax looks quite cryptic, especially
for new users. After playing with Scala for a short while, I miss
Python's simple but powerful syntax a lot. And I certainly miss the
"Zen of Python" (http://www.python.org/dev/peps/pep-0020/) a lot.
I believe many others are in the same boat.
After reading GvR's article, I come to think that maybe Jython with
(optional) static typing is the answer, with the added benefit of
running on the powerful JVM platform. I guess at this point this
is no more than wishful thinking but who knows. I understand at
this point improving Python compatibility is the main goal of Jython
development but maybe having a statically typed Jython is even more
useful to developers :)
You'll have to wait at least until Jython 3.0, where function argument
names can be accompanied with a type, and function return types can be
declared.
Stefan Behnel
2010-01-12 10:50:52 UTC
Permalink
Post by j***@gmail.com
Today I came across this very old post (1/6/2005) of Guido van Rossum
"Optional Static Typing -- Stop the Flames!"
http://www.artima.com/weblogs/viewpost.jsp?thread=87182
which discusses optional static typing of Python. It particularly
interests me because I've been searching for a language that's
statically typed to take advantages of the error checking features
of compilers and IDEs (as well as many other features provided by
IDEs, e.g. refactoring), while also has the power of Python. I'm
not sure if it's eventually implemented or not.
There's Cython, for one.

http://cython.org

Although I'm not aware of any specific IDE features for Cython code besides
regular syntax support.

To support safe refactorings, however, you will need a lot of type
declarations - simply because you can't know in advance what code will get
refactored in the future. You'd loose a lot of Python's beauties if you go
that route. Personally, I don't think it's worth bothering. The experienced
value of IDEs is highly due to the fact that you can't efficiently write
Java without them. They are less useful if the language itself is efficient.

Also, I think that a "good-enough" type inference mechanism is a lot more
helpful in a language than support for static typing.
Post by j***@gmail.com
However, because of the flexibility of dynamic typing, Python code
is too easy to break (typos typos!). (I know I can always write
more unit tests for my code but I can't be convinced that unit tests
can replace the help of compiler and IDE.)
There are also tools like pylint and pychecker that find loads of potential
bugs in Python code. They do much more than just finding typos.
Post by j***@gmail.com
Many times I ended up
rewriting Python projects in Java when they get big.
Python is often used for rapid prototyping, but the prototypes do not
always go into production. Some really get rewritten after the prototyping
phase, although not always for the better.
Post by j***@gmail.com
After reading GvR's article, I come to think that maybe Jython with
(optional) static typing is the answer, with the added benefit of
running on the powerful JVM platform. I guess at this point this
is no more than wishful thinking but who knows. I understand at
this point improving Python compatibility is the main goal of Jython
development but maybe having a statically typed Jython is even more
useful to developers :)
You can get pretty far with Cython's pure Python syntax (in addition to Py3
function type annotations). Java operations are mostly syntax compatible
with Python anyway, so if you find a way to additionally support generics
in Python type declarations, I don't think you'd need anything more than
that in Jython to support full-fledged typing. Could be a nice optional
feature, and shouldn't be hard to implement.

Stefan
jlist9
2010-01-12 16:50:59 UTC
Permalink
+1 for type inference. It has been proven to work well in Scala, and
it's explicit enough.
Post by Stefan Behnel
Also, I think that a "good-enough" type inference mechanism is a lot more
helpful in a language than support for static typing.
Stefan Behnel
2010-01-12 17:21:44 UTC
Permalink
Post by jlist9
+1 for type inference. It has been proven to work well in Scala, and
it's explicit enough.
... except that it won't work as well as in Scala due to language design
differences. But there's a lot you can do without requiring whole program
analysis. Real-world code rarely hits the "general case" where type
inference can't work at all for Python.

Actually, I would expect that the JIT compiler of a hot-spot JVM would do
quite a bit of runtime optimisation for e.g. virtual method calls anyway (I
assume operators are based on that?), so the benefit for Jython should be
smaller than for CPython (or Cython).

Stefan
Jim Baker
2010-01-12 19:12:53 UTC
Permalink
[This really is a jython-dev topic, so cross posting there...]

Runtime type observation and inference, along with AST analysis, is useful
now, and it's something that any Python implementation can support. This is
just a feature of the Python language, and helps make it a dynamic language.
I don't know the specifics of the various tools like pylint however. Someone
chime in here?

In terms of optimization, Jython gets some support from JIT now, and we
expect more in the future. Operators fully inline on Hotspot, and probably
on other JVMs too. The new invokedynamic bytecode instruction in Java 7
should enable similar inlining for functions, methods, and other names. (We
may even see direct support of this backported to Java 6 JVMs; fingers
crossed.)

There are similar opportunities for optimization across the board in Jython.
For example, we could readily increase regex and pickle performance by
getting rid of the large switch statements and using polymorphic dispatch
instead, which should inline much better.

Unfortunately, Python's frame semantics mean that local variables in Python
code can and do escape. Their consequent boxing means we pay huge memory
allocation costs. Making this go away, along with invokedynamic to make it
less contrived, should make possible writing performant inner loops in
Python with built-in types, instead of resorting to Java. And so on, such as
looking at optimization opportunities for user-defined types, or supporting
better unpacking of function calls, or removing frames entirely.

Typing is necessary for some of these optimizations. One possibility is to
use the gradual typing scheme, in conjunction with an appropriate surface
syntax (I favor decorators). The challenge will be to properly combine this
with the dynamic features of Python. Any support should not rule out using
metaprogramming. This might be a good topic to discuss at the upcoming
summits at PyCon.

Lastly, can any of this typing support be done before 3.x? Sure, since I
don't see it as dependent on 3.x specifically. The Jynx project is a good
example of what can be done with decorators today for expressing type info
to Java.

- Jim
Post by Stefan Behnel
Post by jlist9
+1 for type inference. It has been proven to work well in Scala, and
it's explicit enough.
... except that it won't work as well as in Scala due to language design
differences. But there's a lot you can do without requiring whole program
analysis. Real-world code rarely hits the "general case" where type
inference can't work at all for Python.
Actually, I would expect that the JIT compiler of a hot-spot JVM would do
quite a bit of runtime optimisation for e.g. virtual method calls anyway (I
assume operators are based on that?), so the benefit for Jython should be
smaller than for CPython (or Cython).
Stefan
------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and
easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev
_______________________________________________
Jython-users mailing list
https://lists.sourceforge.net/lists/listinfo/jython-users
--
Jim Baker
***@zyasoft.com
Tim Gilbert
2010-01-12 20:48:21 UTC
Permalink
You might be interested in Boo, a language which is heavily inspired by
Python but which is statically typed (with type inference). Note,
however, that it runs on the CLI / .Net platform, not the JVM. You can
find out more about it at http://boo.codehaus.org/. There's also
another Python derivative language called Reia
(http://wiki.reia-lang.org/) which runs on the Erlang VM, but I can't
tell immediately whether it is statically typed.

Tim
Post by j***@gmail.com
Today I came across this very old post (1/6/2005) of Guido van Rossum
"Optional Static Typing -- Stop the Flames!"
http://www.artima.com/weblogs/viewpost.jsp?thread=87182
which discusses optional static typing of Python. It particularly
interests me because I've been searching for a language that's
statically typed to take advantages of the error checking features
of compilers and IDEs (as well as many other features provided by
IDEs, e.g. refactoring), while also has the power of Python. I'm
not sure if it's eventually implemented or not. I checked Python 2.5
command line options but didn't find anything that's related to
static typing.
However, because of the flexibility of dynamic typing, Python code
is too easy to break (typos typos!). (I know I can always write
more unit tests for my code but I can't be convinced that unit tests
can replace the help of compiler and IDE.) Many times I ended up
rewriting Python projects in Java when they get big.
But Java doesn't really satisfy me because of its verbosity. So
I was on the lookout for a language that has the benefit of both
worlds. I have recently tried Scala for a concise and statically typed
language. It has a very powerful type system and it is much more
concise than Java. However, its syntax looks quite cryptic, especially
for new users. After playing with Scala for a short while, I miss
Python's simple but powerful syntax a lot. And I certainly miss the
"Zen of Python" (http://www.python.org/dev/peps/pep-0020/) a lot.
I believe many others are in the same boat.
After reading GvR's article, I come to think that maybe Jython with
(optional) static typing is the answer, with the added benefit of
running on the powerful JVM platform. I guess at this point this
is no more than wishful thinking but who knows. I understand at
this point improving Python compatibility is the main goal of Jython
development but maybe having a statically typed Jython is even more
useful to developers :)
jlist9
2010-01-15 01:19:14 UTC
Permalink
Thanks, Tim. I just checked out Boo. It looks like exactly what I need,
Python syntax with enhancements, statically typed with type inference,
running on a managed platform that doesn't suffer from GIL, except that
it's only available on the .Net platform. A Java version of Boo, or a Boo
variation of Jython would be exactly what I need :-)

Jack
Post by Tim Gilbert
You might be interested in Boo, a language which is heavily inspired by
Python but which is statically typed (with type inference).  Note,
however, that it runs on the CLI / .Net platform, not the JVM.  You can
find out more about it at http://boo.codehaus.org/.  There's also
another Python derivative language called Reia
(http://wiki.reia-lang.org/) which runs on the Erlang VM, but I can't
tell immediately whether it is statically typed.
Tim
Post by j***@gmail.com
Today I came across this very old post (1/6/2005) of Guido van Rossum
"Optional Static Typing -- Stop the Flames!"
http://www.artima.com/weblogs/viewpost.jsp?thread=87182
which discusses optional static typing of Python. It particularly
interests me because I've been searching for a language that's
statically typed to take advantages of the error checking features
of compilers and IDEs (as well as many other features provided by
IDEs, e.g. refactoring), while also has the power of Python. I'm
not sure if it's eventually implemented or not. I checked Python 2.5
command line options but didn't find anything that's related to
static typing.
However, because of the flexibility of dynamic typing, Python code
is too easy to break (typos typos!). (I know I can always write
more unit tests for my code but I can't be convinced that unit tests
can replace the help of compiler and IDE.) Many times I ended up
rewriting Python projects in Java when they get big.
But Java doesn't really satisfy me because of its verbosity. So
I was on the lookout for a language that has the benefit of both
worlds. I have recently tried Scala for a concise and statically typed
language. It has a very powerful type system and it is much more
concise than Java. However, its syntax looks quite cryptic, especially
for new users. After playing with Scala for a short while, I miss
Python's simple but powerful syntax a lot. And I certainly miss the
"Zen of Python" (http://www.python.org/dev/peps/pep-0020/) a lot.
I believe many others are in the same boat.
After reading GvR's article, I come to think that maybe Jython with
(optional) static typing is the answer, with the added benefit of
running on the powerful JVM platform. I guess at this point this
is no more than wishful thinking but who knows. I understand at
this point improving Python compatibility is the main goal of Jython
development but maybe having a statically typed Jython is even more
useful to developers :)
------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev
_______________________________________________
Jython-users mailing list
https://lists.sourceforge.net/lists/listinfo/jython-users
Marcos Sánchez Provencio
2010-01-15 12:13:00 UTC
Permalink
Hi, you are looking for boojay.
Has anybody tried it?
http://groups.google.com/group/boojay/
Post by jlist9
Thanks, Tim. I just checked out Boo. It looks like exactly what I need,
Python syntax with enhancements, statically typed with type inference,
running on a managed platform that doesn't suffer from GIL, except that
it's only available on the .Net platform. A Java version of Boo, or a Boo
variation of Jython would be exactly what I need :-)
Jack
Post by Tim Gilbert
You might be interested in Boo, a language which is heavily inspired by
Python but which is statically typed (with type inference). Note,
however, that it runs on the CLI / .Net platform, not the JVM. You can
find out more about it at http://boo.codehaus.org/. There's also
another Python derivative language called Reia
(http://wiki.reia-lang.org/) which runs on the Erlang VM, but I can't
tell immediately whether it is statically typed.
Tim
Post by j***@gmail.com
Today I came across this very old post (1/6/2005) of Guido van Rossum
"Optional Static Typing -- Stop the Flames!"
http://www.artima.com/weblogs/viewpost.jsp?thread=87182
which discusses optional static typing of Python. It particularly
interests me because I've been searching for a language that's
statically typed to take advantages of the error checking features
of compilers and IDEs (as well as many other features provided by
IDEs, e.g. refactoring), while also has the power of Python. I'm
not sure if it's eventually implemented or not. I checked Python 2.5
command line options but didn't find anything that's related to
static typing.
However, because of the flexibility of dynamic typing, Python code
is too easy to break (typos typos!). (I know I can always write
more unit tests for my code but I can't be convinced that unit tests
can replace the help of compiler and IDE.) Many times I ended up
rewriting Python projects in Java when they get big.
But Java doesn't really satisfy me because of its verbosity. So
I was on the lookout for a language that has the benefit of both
worlds. I have recently tried Scala for a concise and statically typed
language. It has a very powerful type system and it is much more
concise than Java. However, its syntax looks quite cryptic, especially
for new users. After playing with Scala for a short while, I miss
Python's simple but powerful syntax a lot. And I certainly miss the
"Zen of Python" (http://www.python.org/dev/peps/pep-0020/) a lot.
I believe many others are in the same boat.
After reading GvR's article, I come to think that maybe Jython with
(optional) static typing is the answer, with the added benefit of
running on the powerful JVM platform. I guess at this point this
is no more than wishful thinking but who knows. I understand at
this point improving Python compatibility is the main goal of Jython
development but maybe having a statically typed Jython is even more
useful to developers :)
------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev
_______________________________________________
Jython-users mailing list
https://lists.sourceforge.net/lists/listinfo/jython-users
------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
Jython-users mailing list
https://lists.sourceforge.net/lists/listinfo/jython-users
Loading...