4 ms·
Ruby and Python are basically Perl with superficial differences? How in the world did you come to that conclusion? I don't think I have ever seen anyone make th
by DanielStraight 17y ago
Ruby and Python are basically Perl with superficial differences? How in the world did you come to that conclusion? I don't think I have ever seen anyone make that argument before.
- jrockway 17y agoI can only explain in terms of an experiment: Write an algorithm (or app) in your favorite language of the three. Then port it to a different one of those three. Now port to Common Lisp or Haskell, and see how your code feels different. I find that Ruby/Python/Perl basically let you write the same program with different syntax. "$self->foo" instead of "@foo". I find that Haskell changes the way you actually program. Example: Nobody (except me) uses a type like Haskell's Error monad in Perl; they use exceptions. (Similarly, look for a "web framework" in Perl/Python/Ruby. Perl has Catalyst. Python has Django. Ruby has Rails. They are all different, true, but the idea is the same. If three people each started the same project on those various frameworks, the end result, code-wise, would be very similar.)
- btilly 17y agoWhile you will have that experience with a lot of code, there are some concepts that don't translate so easily. As an experiment port this Ruby to Perl: def each (arg,*more_args) ( [] != more_args ) ? arg.each {|l| each(*more_args) {|r| yield [l]+ r }} : arg.each { |r| yield [r] } end each( 1..2, 'a'..'c', 'A'..'D') { |args| puts args.join " " } Then port this Python to Perl: def fib(): fn2 = 1 fn1 = 1 while True: (fn1, fn2, oldfn2) = (fn1+fn2, fn1, fn2) yield oldfn2 g = fib() for i in range(20): print i, g.next() See what I mean?
- jrockway 17y agoSome people refer to carbonated sugary beverages as "soda" and others say "pop", but both are still speaking the same language.
- btilly 17y ago$point->missed I know Perl far, far better than I know Ruby or Python. But I can't easily reach for the abstractions in those examples within Perl. That said, I'm in agreement with your basic point. On the whole the scripting languages (including JavaScript) are much more similar than different.
- deleted 17y ago[deleted]
- jrockway 17y agoI don't consider these as being particularly interesting differences. With the right modules, I can write code that looks like that in Perl. (It's not idiomatic, though, so it is worth exploring other languages to see which idioms you'd like to steal. I stole monads and applicative functors from Haskell for Perl in MooseX::Data, for example. Monadic control flow is not a common Perl idiom, but it is perfect for my asynchronous CPAN client.) I am talking major differences, things that are so fundamental that you can't really steal. Looking at Haskell, I see things like lazy evaluation, purity, static typing and type inference, etc. Very, very different from Perl. In Scheme, I see the "call stack" as a graph of frames, not as a linked-list as in C. This is quite radical. But in Ruby and Python all I see are different built-in functions, some with special syntax. (Generators, list comprehensions, etc., etc.) I know Perl far, far better than I know Ruby or Python. But I can't easily reach for the abstractions in those examples within Perl. I can. I hope you are considering CPAN as part of Perl, because "core perl" is a very, very outdated and broken programming language. I think I would even prefer Java!
- colomon 17y agoThe second one is easily translated into Perl 6: sub fib() { my $fn2 = 1; my $fn1 = 1; gather loop { my $oldfn2; ($fn1, $fn2, $oldfn2) = ($fn1 + $fn2, $fn1, $fn2); take $oldfn2; } } my @g = fib; for ^20 -> $i { say $i, @g.shift; } That's untested because lazy evaluation isn't yet supported in Rakudo Perl 6, but my understanding is that feature should be up and running in the next few weeks. I don't know enough Ruby to make heads or tails of the first example, though...
- jerf 17y agoReally? People make it all the time. The only way to see significant differences between them is to be too close to them, and too far from anything else, to have perspective. There certainly are differences, yes, but they are next-door neighbors in the sprawling, diverse city of programming languages.
- DanielStraight 17y agoOr to have a different opinion of significant I guess. Python has docstrings and list comprehensions and keyword arguments and generator functions and readable syntax. To me, these are all significant differences from Perl. See also Eric Raymond's piece "Why Python?" at http://www.linuxjournal.com/article/3882 http://www.linuxjournal.com/article/3882
- jrockway 17y agoNot sure your list of differences is up to date. We have keyword arguments (with rich user-defined type constraints) and docstrings via Moose and MooseX::Declare. We have generator functions (actually, first-class continuations and coroutines) via the Coro module. I have never had trouble reading even very bad Perl code, so it seems to me like it is "readable". (There a few list comprehension modules on CPAN, but they are all implemented wrong. A correct implementation is not difficult, but I personally don't see the value and haven't bothered to implement it right.)
- DanielStraight 17y agoI'll add another feature that Python tends toward standardization and batteries included rather than modules. With the right modules, you can probably make Java look like Python, but that's not the point... to me at least. I'm explicitly talking about opinion here. I hope it's ok for me to have a different opinion.
- seiji 17y agoRuby is definitely strongly perl based (cross-bred most noticeably with smalltalk). From http://linuxdevcenter.com/pub/a/linux/2001/11/29/ruby.html http://linuxdevcenter.com/pub/a/linux/2001/11/29/ruby.html: Stewart: I gather you had worked with both Perl and Python before creating Ruby. What bits of Perl did you incorporate in Ruby? Matz: A lot. Ruby's class library is an object-oriented reorganization of Perl functionality--plus some Smalltalk and Lisp stuff. I used too much I guess. I shouldn't have inherited $_, $&, and the other, ugly style variables.