By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,089 Members | 1,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,089 IT Pros & Developers. It's quick & easy.

Python vs. Io

P: n/a
Io (www.iolanguage.com) is a new programming language that's purely
object-oriented (but with prototypes), has a powerful concurrency
mechanism via actors, and uses an extremely flexible syntax because
all code is a modifiable message tree. Like Python, it is dynamically
typed, has a very clean syntax, produces short code, and is
excruciatingly slow (on the same level as eachother). Io has a unique
syntax combining Lisp's idea of functions for flow control with
traditional function syntax and smalltalk-like syntax to get slots of
objects. Io has no keywords and everything, even multiple lines of
code, can be used as an expression. Even as a beginner to Io, I was
able to write something in just 43 lines to let you do something like
this (and more) in Io:

each((key, value) in map(x=1, y=2, z=3),
write(key, ": ", value, "\n")
)

Neither the each function nor the map function were built in (Io has
other mechanisms for that kind of thing, but they are less efficient).
Can anyone show me how to so much as alias "for" to "each" in Python
or allow block syntax at all without hacking the C source code?

Io doesn't use __methods_with_this_annoying_syntax__ because nothing
is supposed to be for internal use only and there are only about three
functions that would cause a problem if overridden.

For embedding, Io doesn't have to use Py_ALL_CAPS, instead it just
uses IoCamelCase, which looks much better. Interfaces to C are much
more object oriented.

Many users of Io (myself included) have switched over from Python for
these reasons.

I guess there are still the obvious advantages of Python over Io,
including
*large community
*more bindings to stuff
*strict coding conventions
*inflexible so everything is the same
*no need to close blocks
But unless there are other problems, the first two go away soon
(considering that Io was first created just two years ago). The last
three are somewhat trivial and may even be to Io's advantage.

Daniel Ehrenberg
Jul 18 '05 #1
Share this Question
Share on Google+
20 Replies


P: n/a

"Daniel Ehrenberg" <Li************@yahoo.com> wrote in message
news:71*************************@posting.google.co m...
Can anyone show me how to so much as alias "for" to "each" in Python
Without getting into the language wars, I think what you're looking
for is called the Visitor Pattern (Design Patterns: GOF). It's actually
trivial to implement as long as you're not looking for built-in support.

Something like this works quite well in any object where you want
to implement a visitor over a collection:

class aCollection:
def visit(self, instance):
for x in self._collection:
instance.visitor(x)
return instance.result()

The final call is a little more than the bare visitor pattern, but it
allows the visitor instance to pass back a result so you can use
it in expressions.

A visitor then looks like this:

class fubar:
def __init__(self):
self.whatever = 0
def visitor(self, value):
self.whatever += value
def result(self):
return self.whatever

and you use it like this:

ohWow = aCollection.visit(fubar())

Unlike a block in, for example, Ruby, a visitor instance
can be pre-initialized, it can have multiple methods and
it can persist after being passed against the collection.

Of course, you can use more complex data structures as well,
see the compiler stuff for examples of the visitor pattern used
over the Python Abstract Syntax Tree.

The visitor pattern is also very useful for file system
navigation; I use it consistently.

John Roth

Daniel Ehrenberg

Jul 18 '05 #2

P: n/a
John Roth wrote:
"Daniel Ehrenberg" <Li************@yahoo.com> wrote in message
news:71*************************@posting.google.co m...

Can anyone show me how to so much as alias "for" to "each" in Python

Without getting into the language wars, I think what you're looking
for is called the Visitor Pattern (Design Patterns: GOF). It's actually
trivial to implement as long as you're not looking for built-in support.


I think Daniel's example is a little bit more complicated than that. It
resembles more closly the lisp-ish macros that were discussed to death a
while ago.

Note that in his code:
each((key, value) in map(x=1, y=2, z=3),
write(key, ": ", value, "\n")
)

key and value are variable names that get used inside the function call.

Here is my pythonic(?) version, however it requries a lambda to bind the
variable names.

def map(**kw):
return kw.items()

def each(seq, func):
for v in seq:
apply(func, v)

from sys import stdout
write = stdout.write

each(map(x=1,y=2,z=3),
lambda key, value: write("%s: %s\n"%(key, value)))

Brian

Jul 18 '05 #3

P: n/a
At some point, Li************@yahoo.com (Daniel Ehrenberg) wrote:
Io (www.iolanguage.com) is a new programming language that's purely
object-oriented (but with prototypes), has a powerful concurrency
mechanism via actors, and uses an extremely flexible syntax because
all code is a modifiable message tree. Like Python, it is dynamically
typed, has a very clean syntax, produces short code, and is
excruciatingly slow (on the same level as eachother). Io has a unique
syntax combining Lisp's idea of functions for flow control with
traditional function syntax and smalltalk-like syntax to get slots of
objects. Io has no keywords and everything, even multiple lines of
code, can be used as an expression. Even as a beginner to Io, I was
able to write something in just 43 lines to let you do something like
this (and more) in Io:

each((key, value) in map(x=1, y=2, z=3),
write(key, ": ", value, "\n")
)

Neither the each function nor the map function were built in (Io has
other mechanisms for that kind of thing, but they are less efficient).
Can anyone show me how to so much as alias "for" to "each" in Python
or allow block syntax at all without hacking the C source code?
Hey, if I wanted to to, I could add functions and all that that would
make Python look like Lisp, or IO, or whatever.

But, why? If I wanted to write Lisp or Io, I'd use those.

Your example I'd write in Python as

for key, value in dict(x=1, y=2, z=3):
print '%s: %s\n" % (key, value)

I didn't have to write 43 lines of support code, and it's also two
lines. I don't think "this isn't builtin" is a selling point -- you
need a critical mass of builtins to make a language useful.
Io doesn't use __methods_with_this_annoying_syntax__ because nothing
is supposed to be for internal use only and there are only about three
functions that would cause a problem if overridden. For embedding, Io doesn't have to use Py_ALL_CAPS, instead it just
uses IoCamelCase, which looks much better. Interfaces to C are much
more object oriented.
Ok, these two points are window-dressing: minor spelling and
punctuation issues (which seems to be what most language wars are about).

Heck, use boost::python for C++ interfaces; those function names are
even shorter. Or use pyrex to generate wrappers, writing them in a
Pythonesque language.
Many users of Io (myself included) have switched over from Python for
these reasons.

I guess there are still the obvious advantages of Python over Io,
including
*large community
*more bindings to stuff
Yep. That's a *big* difference, I'd say.
*strict coding conventions
*inflexible so everything is the same
Can you elaborate a bit on why Python is inflexible? I find Python to
be extremely flexible.
*no need to close blocks
But unless there are other problems, the first two go away soon
(considering that Io was first created just two years ago). The last
three are somewhat trivial and may even be to Io's advantage.


Python is 14 years old, and it's still working on global domination;
Io's got some catching up to do :-)

--
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca
Jul 18 '05 #4

P: n/a
On Thu, 29 Jan 2004 17:21:19 -0500, co**********@physics.mcmaster.ca
(David M. Cooke) wrote:
At some point, Li************@yahoo.com (Daniel Ehrenberg) wrote:
[snip-a-lot]
For embedding, Io doesn't have to use Py_ALL_CAPS, instead it just
uses IoCamelCase, which looks much better. Interfaces to C are much
more object oriented.
Ok, these two points are window-dressing: minor spelling and
punctuation issues (which seems to be what most language wars are about).

Heck, use boost::python for C++ interfaces; those function names are
even shorter. Or use pyrex to generate wrappers, writing them in a
Pythonesque language.
Many users of Io (myself included) have switched over from Python for
these reasons.

I guess there are still the obvious advantages of Python over Io,
including
*large community
*more bindings to stuff


Yep. That's a *big* difference, I'd say.


Using any language (other than a Lisp) which is sufficiently powerful
mostly comes down to personal preference regarding syntax. Library and
community support will of course grow for new languages if enough
people find it 'fits their minds' better than anything previously
available.
*strict coding conventions
*inflexible so everything is the same


Can you elaborate a bit on why Python is inflexible? I find Python to
be extremely flexible.


If inflexibility means not being able to arbitrarily change the
syntax, then I'm all for it, because it does help consistency and
readability, which I like very much in my programs, especially when
not working on them alone... Python seems to have found a good middle
ground between strictness and dynamism.
If I wanted a 'flexible' language, I'd use Lisp, or Forth.
--
Christopher
Jul 18 '05 #5

P: n/a
Daniel Ehrenberg wrote:
Neither the each function nor the map function were built in (Io has
other mechanisms for that kind of thing, but they are less efficient).
Can anyone show me how to so much as alias "for" to "each" in Python
or allow block syntax at all without hacking the C source code?
No, you cannot introduce new special forms (i.e., statement syntax) in
Python without modifying the Python interpreter itself.

There are two major camps in language design. One says that you should
be able to modify the language itself to your will, and the other says
that this gets rapidly confusing and you shouldn't. They're simply
different camps, and the two camps won't agree. Furthermore, the
ability to convert a language from the second camp to the first is not
without difficulty; such things usually have to be designed into the
language from the scratch, or you end up with a very complicated process
of creating hygienic macros.

This is a situation where Io is in the first camp and Python is in the
second. They simply don't have equivalent goals; Python emphasizes
transparency and readability more than customizability and flexibility,
whereas Io does the opposite.
Io doesn't use __methods_with_this_annoying_syntax__ because nothing
is supposed to be for internal use only and there are only about three
functions that would cause a problem if overridden.

For embedding, Io doesn't have to use Py_ALL_CAPS, instead it just
uses IoCamelCase, which looks much better. Interfaces to C are much
more object oriented.


These are really stylistic objections, as are the other objections you
list below. That's completely fine, of course; you should choose a
language that jives with your personal sense of language style. But
language designers need to make decisions, and those decisions are
necessarily going to eliminate some styles of programming, while
emphasizing others.

You're in a situation where it sounds like Io jives with your sense of
style more than Python. That's perfectly fine, and I know from my own
research that Io is a neat little language (though I haven't really used
it for anything substantial yet). But you can't expect other languages
to bend to your personal will and personal sense of style, particularly
when it means necessarily violating someone else's corresponding senses.

Io and Python have quite different fundamental approaches to language
design, and so it's not surprising that there are going to be
irreconcilable differences.

--
__ Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
/ \ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
\__/ The only completely consistent people are the dead.
-- Aldous Huxley
Jul 18 '05 #6

P: n/a
Daniel Ehrenberg wrote:
Io (www.iolanguage.com) is a new programming language that's purely
object-oriented (but with prototypes), has a powerful concurrency
mechanism via actors, and uses an extremely flexible syntax because
all code is a modifiable message tree.


I long to live in a world where Python is considered a crufty incumbent
legacy language that is forced on unwilling programmers by Pointy Haired
Bosses. First, it would mean that Python has vanquished languages that
programmers like less. Second, it would mean that the up-and-coming
languages are so unbelievably cool and elegant that they make Python
look like a lumbering dinosaur.

Thanks for reminding me that that that day was once unfathomably far in
the future and now seems almost around the corner!

But when I look closer at IO it seems to me that the day is not as near
as I hope. If you wish to hasten I urge you to:

* finish the IO tutorial
* distribute windows binaries of IO
* make IO compilers to C and Java available
* make bindings to popular windowing toolkits
* make bindings to Java, .NET, COM, SOAP, XML-RPC etc.
* use IO in a production context so that the rest of us can have faith
in its stability
* implement MySQL and Oracle bindings
* publish some books on IO
* point me to some documentation on how to launch and kill processes in IO

If this were all done tomorrow I might be tempted to jump over to IO but
I would be amazed if it were all done even two years from now.

Also, an observation: IO's syntactic simplicity looks to me to be both a
blessing and a curse.

Paul Prescod

Jul 18 '05 #7

P: n/a
As other posts have indicated, this is not the io-user-list. While
you probably have good, purely academic intentions with your post,
this is not the correct forum. Create an io-vs-python list somewhere
and I'm sure you'll get a few subscribers. :)

--

Jonathan Daugherty
http://www.cprogrammer.org

"It's a book about a Spanish guy called Manual, you should read it."
-- Dilbert

Jul 18 '05 #8

P: n/a
Daniel Ehrenberg wrote:
Perhaps it isn't more flexible. On the other hand, it does allow anyone
to read your code and know that there isn't any magical syntax that is
usable on one Python x.y installation, that isn't on another.


As mentioned by Sean Ross, I was talking about Python x.y compatibility
with other copies of version x.y. With the way you describe IO, it
encourages people to customize flow control and syntax. Such
customization does not necessarily increase readability, usability, or
write-once-run-anywhere with IO version u.v. It may also fragment the
language in the long run into different camps; those that like the slim
version, and those that like a version with every modification they can
find.

- Josiah
Jul 18 '05 #9

P: n/a
Paul Prescod wrote:

....snip...
First, if I had invented Python I would not have bothered to buck the
trend of using curly braces. Hardly anyone chooses Python because of
that feature and some are turned off by it.

....snip...
Not that this invalidates your point, as I still fall into the category of
'hardly anyone'; but, the indentation-identified block is precisely the
reason I first tried Python. Having used Occam for many years, I was very
pleased to find a language that recognized the superiority of that style.
--Andy
Jul 18 '05 #10

P: n/a
Li************@yahoo.com (Daniel Ehrenberg) wrote in message news:<71*************************@posting.google.c om>...
Can anyone show me how to so much as alias "for" to "each" in Python
or allow block syntax at all without hacking the C source code?


I think the point is, why on earth would you want to do something like
that? If you want a language you can use to make programs that make
no sense to anyone but the author, Perl should be more than sufficient
for your needs.
Jul 18 '05 #11

P: n/a
On 29 Jan 2004 13:01:06 -0800, Li************@yahoo.com (Daniel
Ehrenberg) wrote:

....
Can anyone show me how to so much as alias "for" to "each" in Python
or allow block syntax at all without hacking the C source code? ....Many users of Io (myself included) have switched over from Python for
these reasons.

If you've switch from Python to Io, what will you do with the answers
to these questions? Use them for good or evil? Will you switch back
from Io to Python?
--dang
Jul 18 '05 #12

P: n/a
On Sun, 01 Feb 2004 13:47:20 -0800, Paul Prescod <pa**@prescod.net> wrote:
First, if I had invented Python I would not have bothered to buck the
trend of using curly braces. Hardly anyone chooses Python because of
that feature and some are turned off by it.


I have to admit that the indentation feature turned me off at first, but
having used Python for a while now, I find that method superior to the
curly braces approach. Much more DWIM.
Jul 18 '05 #13

P: n/a
"Paul Prescod" <pa**@prescod.net> wrote in message
news:ma***************************************@pyt hon.org...
First, if I had invented Python I would not have bothered to buck the
trend of using curly braces.
I suppose I am hardly anyone else, since that it exactly what
attracted me to Python. In fact, I will take partial responsibility
for the indentaion syntax in IBM's ISPF mini-language - it's a
preferance of long standing with me.

Now that I actually have a significant language using them, I
can see that there are a couple of things they make more
difficult, statement syntax embedded within expressions being
one. The other is a rather esoteric issue with clauses like
elif, else and except.

John Roth

Paul Prescod

Jul 18 '05 #14

P: n/a
al************@comcast.net (A. Lloyd Flanagan) wrote in message news:<e8**************************@posting.google. com>...
Li************@yahoo.com (Daniel Ehrenberg) wrote in message news:<71*************************@posting.google.c om>...
Can anyone show me how to so much as alias "for" to "each" in Python
or allow block syntax at all without hacking the C source code?
I think the point is, why on earth would you want to do something like
that? If you want a language you can use to make programs that make
no sense to anyone but the author, Perl should be more than sufficient
for your needs.


The point is that implementing your own "for" is something you can't
do in Python very nicely, so it's a proof that Io can achieve
genuinely higher abstraction levels on this part. Implementing
"for" again with a new name probably wouldn't make anyone
happy, but such power opens a set of tricks and idioms to
be used in real code to solve real problems, that wouldn't
be possible in Python without kludgy syntax.

Here's a normal loop:

bar = 0
for x in range(10):
bar += x

Here's the same using a custom loop:

bar = [0]
def temp(x):
bar[0] += x
for_each(range(10), temp)

That is just so damn ugly. I want to be able to define (e.g.)

bar = 0
for_each(x, range(10)):
bar += x

Now tell me which of these two lowermost forms looks
better and makes more sense? For examples that don't
just make aliases of existing syntax, see the
Lisp vs Python thread that was here a few months ago
(sorry, can't remember it's topic name).

BTW, Python can be used to make programs that make
no sense as well. (due to Ulf Bartelt:)

print (lambda Ru,Ro,Iu,Io,IM,Sx,Sy:reduce(lambda x,y:x+y,map(lambda y,
Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,Sy=Sy,L=lambda yc,Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,i=IM,
Sx=Sx,Sy=Sy:reduce(lambda x,y:x+y,map(lambda x,xc=Ru,yc=yc,Ru=Ru,Ro=Ro,
i=i,Sx=Sx,F=lambda xc,yc,x,y,k,f=lambda xc,yc,x,y,k,f:(k<=0)or (x*x+y*y=4.0) or 1+f(xc,yc,x*x-y*y+xc,2.0*x*y+yc,k-1,f):f(xc,yc,x,y,k,f):chr(

64+F(Ru+x*(Ro-Ru)/Sx,yc,0,0,i)),range(Sx))):L(Iu+y*(Io-Iu)/Sy),range(Sy
))))(-2.1, 0.7, -1.2, 1.2, 30, 80, 24)

The real question is if the language *allows* a sensible
programmer to write clear, understandable code even in hard
problem domains.

But this is nothing but my humble opinion without actually
knowing anything about Io.. Maybe it isn't that good. I wasn't
really arguing for Io but for better abstractions.
Jul 18 '05 #15

P: n/a
John Roth wrote:
"Paul Prescod" <pa**@prescod.net> wrote in message
news:ma***************************************@pyt hon.org...
First, if I had invented Python I would not have bothered to buck the
trend of using curly braces.

I suppose I am hardly anyone else, since that it exactly what
attracted me to Python. In fact, I will take partial responsibility
for the indentaion syntax in IBM's ISPF mini-language - it's a
preferance of long standing with me.


There are certainly costs and benefits to the Python way. And we've been
over them many times. ;)

I'm just saying that from a language popularity point of view,
"different" is usually perceived as "worse" unless it is really vastly
better.

Paul Prescod

Jul 18 '05 #16

P: n/a
> If you've switch from Python to Io, what will you do with the answers
to these questions? Use them for good or evil? Will you switch back
from Io to Python?
--dang


If there are good enough responses, I'll use Python. I just wanted to
know a reason why Python is better. Also, these responses might be
used to make Io better (since it's a young language).

Daniel Ehrenberg
Jul 18 '05 #17

P: n/a
> I think the point is, why on earth would you want to do something like
that? If you want a language you can use to make programs that make
no sense to anyone but the author, Perl should be more than sufficient
for your needs.


Nobody uses Perl because they like its illegibility, they think (for
some reason) that it's more powerful.
As for the flexibility of Io, there's a big difference between
flexibility and illegibility. Whenever a new, more powerful
programming language comes out, everybody says it's too flexible.
Fortran people were saying that about C, C people were saying it about
C++ and Java, and C++ and Java people are still saying it about
Python. Dynamic typing? That's so error-prone, they say. Flexible
block syntax? Code is "illegible", you say.

Daniel Ehrenberg
Jul 18 '05 #18

P: n/a
> If there are good enough responses, I'll use Python. I just wanted to
know a reason why Python is better. Also, these responses might be
used to make Io better (since it's a young language).

Daniel Ehrenberg


From your responses, you seem to prefer a /flexibility/ in IO syntax
and semantics that will never be attainable in Python.

Python isn't about allowing different syntax or semantics, it is about
having a reasonable set of syntax and semantics along with a reasonable
object, class, module and package structure, resulting in a language
that allows the vast majority of algorithms, data structures, and
/ideas/ to be implemented in a way that is both easy to write and to
understand.

I would say something similar about IO, but I don't know what it is
about (and I am too turned off by its syntax to find out).

Using metaphors; when you have a hammer, everything looks like a nail.
Me? I've got 3 hammers: Python, C/C++, Lisp. I have not yet met a nail
that wasn't properly pounded with my Python hammer. Nails:
data processing
databases
sockets (both async with asyncore and sync with threads)
gui development
data structure implementation
prototyping
etc.

Now, a few of those could easily be hammered with either C/C++ or Lisp,
but I wouldn't have been able to built the apartment complexes with
C/C++ or Lisp that I was able to with Python.
What you are asking us, conceptually, is what hammer you should use.
The hell if we care what hammer you use, we hang out here because /we/
enjoy using the Python hammer. Of course it would be nice for you to
use the Python hammer and give to the community, but I'm sure the IO
community feels the same way - so whatever you want, I'm sure it will be
fine.

- Josiah
Jul 18 '05 #19

P: n/a
Daniel Ehrenberg wrote:
Whenever a new, more powerful
programming language comes out, everybody says it's too flexible.
Fortran people were saying that about C, C people were saying it about
C++ and Java, ...


C people were saying that about Java?

Look, you like Io better than Python. Fine. You're not going to be
convincing others that you're right by simply repeating it over and over
again. Io and Python cater to different styles; if your personal style
is more in sync with Io, then so be it. But someone whose personal
style is more in sync with Python than Io is simply not going to be
swayed by your largely stylistic arguments.

--
__ Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
/ \ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
\__/ I just want to create my own life. I can just be me.
-- Ekene Nwokoye
Jul 18 '05 #20

P: n/a
Daniel Ehrenberg wrote:
If there are good enough responses, I'll use Python. I just wanted to
know a reason why Python is better. Also, these responses might be
used to make Io better (since it's a young language).


Why is difference necessarily better or worse? Sometimes different is
just different and whether that's better or worse is a subjective
judgement call on which there will be no general consensus.

--
__ Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
/ \ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
\__/ I just want to create my own life. I can just be me.
-- Ekene Nwokoye
Jul 18 '05 #21

This discussion thread is closed

Replies have been disabled for this discussion.