Python vs Ruby!

A

Adrian Howard

On 21 Aug 2005, at 04:23, Jamey Cribbs wrote:
[snip]
Oops! I should have said, "because a Python lambda can only have
an expression, not a statement...". Here's a quote from the Python
Tutorial: "They are syntactically restricted to a single
expression". And here's a quote from Python's Language Reference:
"Note that functions created with lambda forms cannot contain
statements".
[snip]

Of course Python might not have lambda's much longer. See <http://
www.artima.com/weblogs/viewpost.jsp?thread=98196> for Guido's
comments on why lambda, reduce and friends may soon meet their demise
in Python.

Adrian
 
B

bruno modulix

baalbek said:
You must be kidding! It is Python that has had the object oriented stuff
baked in. Ruby was designed from ground up to be object oriented (every
thing, even a number, even nil, is an object!)

In Python too... Python is no less OO that Ruby, even if the object
models are somewhat different.
 
B

bruno modulix

Alexandru said:
#: Jamey Cribbs changed the world a bit at a time by saying on
8/19/2005 3:18 AM :#


What about lambdas? (afaik python has lambdas

yes, but they are really limited, and nowhere near Smalltalk/Ruby's blocks.
and a notion called maps -
but about the 2nd I am not pretty sure).

You mean "maps" like "mappings" (ie hashtables, dictionnaries, ...) or
"map" like the map(function, sequence) function ? (Python has both anyway)
 
B

bruno modulix

Adrian said:
On 21 Aug 2005, at 04:23, Jamey Cribbs wrote:
[snip]
Oops! I should have said, "because a Python lambda can only have an
expression, not a statement...". Here's a quote from the Python
Tutorial: "They are syntactically restricted to a single
expression". And here's a quote from Python's Language Reference:
"Note that functions created with lambda forms cannot contain
statements".

[snip]

Of course Python might not have lambda's much longer. See <http://
www.artima.com/weblogs/viewpost.jsp?thread=98196> for Guido's comments
on why lambda, reduce and friends may soon meet their demise in Python.

Note that their's a *strong* opposition to this from the FP-addicts part
of the Python community. What is going to happen is probably moving
lisp-like constructs (map, reduce, filter etc) to a module and *replace*
lambda with something much more pythonic.

My 2 cents...
 
B

bruno modulix

William said:
Is something like this difficult in Python?

irb(main):004:0> print "Working..."; calc(); puts "finished."
Working...finished.
Working...
finished.

no much difference except for the newline...
 
W

William James

bruno said:
Working...
finished.

no much difference except for the newline...


"...except for the newline..."

That's the whole point! How do you do it without the newline???
 
N

Nick Albright

If you don't mind a space, you could always do:

If you really don't like even the space, you can do:

Hope this helps!
-Nick

P.S. Any spelling mistakes are not those of the author, as he can't
spell.
 
A

Alex Nedelcu

Jamey said:
plane_tbl.update { |r| r.name == 'P-51' }.set do |r|
r.speed = 405
r.range = 1210
end

This says, for the record where name equals P-51, change the speed to
405mph and the range to 1,210 miles. I couldn't do this with a lambda
in Python.

Jamey

Have you looked at Django: http://www.djangoproject.com/.
Their approach to make a select would go something like:

polls.get_list(
pub_date__year=2005,
pub_date__month=1,
question__startswith="Would",
)

I haven't bothered to look at how they do selects, but take a look
here:
http://www.djangoproject.com/documentation/db_api/

Although I like the Ruby approach, that's nice too.
 
G

gabriele renzi

Nick Albright ha scritto:
If you don't mind a space, you could always do:




If you really don't like even the space, you can do:




Hope this helps!
-Nick

P.S. Any spelling mistakes are not those of the author, as he can't
spell.


you could even do (untested):
print "working...", "" and calc(), "finished."

basically relying on "" being false.
Ok, it's ugly, but hey, the original ruby is ugly too ;)
 
W

William James

The Pythonistas were asked to translate this Ruby code to Python:
print "Working..."; calc(); puts "finished."

This seemingly trivial task turned out to be quite thorny because
Guido frowns upon printing twice without intervening whitespace.

The first attempt by one of Guido's henchmen was a failure.
The second attempt was a failure. The third and fourth
were:

sys.stdout.write( "Working..."); calc(); print "finished."

print "working...", "" and calc(), "finished."


Guido has ways of making life unpleasant for those who refuse to do
as he says.

If you really don't like even the space, you can do:

In other words, are you really sure you don't want to do it Guido's
way?
Better think twice! You know what happens when Guido is displeased!

This example leads one to believe that Guido's Python is almost
as ridgid, as inflexible, and as uncomfortable as a wooden shoe.
It also inspired this revision of Stephen Crane's poem:


Code as I Code

"Code as I code," said Guido,
"Or you are abominably wicked;
"You are a toad."

And after I had thought of it,
I said: "I will, then, be a toad."
 
G

gabriele renzi

William James ha scritto:
<snip>

notice that Guido himself considers print-the-keyword as an error and
wants to remove it ;P
 
B

bruno modulix

William said:
The Pythonistas were asked to translate this Ruby code to Python:
print "Working..."; calc(); puts "finished."

This seemingly trivial task turned out to be quite thorny because
Guido frowns upon printing twice without intervening whitespace.

The first attempt by one of Guido's henchmen was a failure.
The second attempt was a failure. The third and fourth
were:

sys.stdout.write( "Working..."); calc(); print "finished."

print "working...", "" and calc(), "finished."


Guido has ways of making life unpleasant for those who refuse to do
as he says.





In other words, are you really sure you don't want to do it Guido's
way?
Better think twice! You know what happens when Guido is displeased!

This example leads one to believe that Guido's Python is almost
as ridgid, as inflexible, and as uncomfortable as a wooden shoe.
It also inspired this revision of Stephen Crane's poem:


Code as I Code

"Code as I code," said Guido,
"Or you are abominably wicked;
"You are a toad."

And after I had thought of it,
I said: "I will, then, be a toad."

William,

I'm sorry to have to say so, but you're acting like a complete toad
asshole.

Hopefully, I know enough of this communauty not to judge it on your
stupidity. Ruby has nothing to gain in bashing Python - nor Python in
bashing Ruby, but this is not the common attitude on c.l.py (AFAICT,
Ruby is usually considered as a very interesting language by most
pythonistas).

Get a life...
 
N

Nick Albright

<Laugh> Interesting perspective. Couple of thoughts. The only real
difference between the original ruby:

print "Working..."; calc(); puts "finished."

and the 3rd solution:

sys.stdout.write( "Working..."); calc(); print "finished."

Is changing puts to sys.stdout.write(). Which I don't know if is
such a large change/difference. Either way, you have to make two diff
print type calls to get it done.

I found more interesting your comment about why it's so hard. I
honestly took the adding of whitespace after a , in the python print to
be a design issue. It makes prining multiple things very handy, like:

print "Name", first, last

or

print "Pos", x, y, z

It elminiates the need for exta " " in the print line. The flip side
is that you obviously can't print one next to the other. But in your
example, is it really important that you get

Working...finished

vs:

Working... finished

?

If I really want percise output, I tend to use the formated print
anyways.

But to each their own. Just some misc thoughts from a guy passing
through, = )
-Nick
 
G

Greg McIntyre

Joe said:
So, I think the question is: "Why would you
want to use Ruby in a situation where Python is available?"

We use both here at work. Python for the actual project code
(management decision to adopt Python) and Ruby for
supporting/surrounding/supplemental/sysadmin type code.

I find Ruby distinctly better than Python for the following tasks:

- 1-liners from the command line (like you used to use Perl for)
- working with file system paths
- regular expression-intensive text processing
- XML templating (I love XTemplate xtemplate.sf.net & can't find
anything as good for Python)
- working with very large integers (Python 2.4 seems fixed though)
- extending basic types (Array, Hash vs. tuple, list, dict)
- package management (import/require/include, etc.)
- wrapping a C/C++ API (reference counting vs. mark & sweep)
- guessing the right method (homogenous naming scheme, etc.)
- generating internal documentation (RDoc >> pydoc)
- language customisation/metaprogramming
 
J

Joe Van Dyk

Which is better, Python or Ruby?
=20
(ha, just kidding)
=20
I've been fighting the good fight inside a really large corporation
trying to get Ruby on the "approved" list. I've brought this up a
couple times in the past on this list and have got some good
responses.

Well, good news. While Ruby's not on the companywide "approved" list
yet, my group and all other groups that we work with have got an
official "Ruby is ok" exception granted.

So, thanks to all of you!

Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top