Live data from Hacker News

Comparing PHP, Perl, Python and Ruby

hyperpolyglot.org

71–80 of 92 posts

Re: Comparing PHP, Perl, Python and Ruby

#72
post #55

This is a really great effort, but I noticed a handful of areas where the PHP example was off. I wonder if people with more experience with the other languages noticed the same thing for their language. Some examples: Null test: $var === null // omitted isset($var) // actually checks if $var exists and is not null (apparently-- I actually didn't know about the not null part) Undefined variable access: it's a notice.…

I noticed that block statements were missing from PHP, eg: using if(): ... endif; etc. instead of if(){ ... }

Re: Comparing PHP, Perl, Python and Ruby

#73
post #25

Earlier quoted context omitted.

It also means you have to stumble upon Moose to start using objects in a reasonably sane way. The average new Perl programmer is not going to go looking for a library that does object-oriented behavior until it's too late. They'll probably have some crazy idea that the language should be doing OO for them. If you were to navigate a largish Perl codebase today, you'd encounter the old-school bless, Moose trickiness, a…

I'm not a Perl programmer, but I'm aware of Moose. It's frequently mentioned in beginner tutorials on how to do OO.

You mean Moose being mentioned in Non-Perl beginner tutorials? That's interesting! Do you happen to have some links to those tutorials?

Re: Comparing PHP, Perl, Python and Ruby

#74

Earlier quoted context omitted.

ruby will get you a job at twitter. I heard that twitter are moving from ruby to scala.

that was more then a year or two ago, they changed their mind in the meantime. they do have some cool software developed in scala I think.

I too would like to get a reference for this. It sounds interesting, but it's the first I hear of it.

Re: Comparing PHP, Perl, Python and Ruby

#75
post #69
post #63

Earlier quoted context omitted.

my hosting is still on 5.2.17 and are in the "security testing" phase of 5.3.

I wonder what they mean by security testing? What exactly are they testing and how? BTW given that there's no security patches released for 5.2 anymore (while bugs are still being found and published of course) - their understanding of security is certainly unorthodox.

I retract my security testing statement. The are currently testing if 5.3 is stable on their servers and have no ETA for the upgrade :-(. This was in mid October.

Re: Comparing PHP, Perl, Python and Ruby

#76
post #68

"Passing by reference" section is wrong about Ruby (not sure about Python). Ruby passes everything by reference, it's only that integers are immutable so that the function can't alter them. Strings, though, are mutable: def foo s s.concat 'foo' end a = 'bar' foo a a # => "barfoo"

Niether Ruby or Python do "pass by reference".

They both do "pass reference by value". Which is a big difference.

Re: Comparing PHP, Perl, Python and Ruby

#77
post #68

"Passing by reference" section is wrong about Ruby (not sure about Python). Ruby passes everything by reference, it's only that integers are immutable so that the function can't alter them. Strings, though, are mutable: def foo s s.concat 'foo' end a = 'bar' foo a a # => "barfoo"

Not exactly. Let's tweak your example to create a new object in your method.

  def foo s
    s = 'foo'
  end
  a = 'bar'
  foo a
  puts a
  # => bar
The assignment in the method doesn't change the object you "passed" in. Rather than passing by reference, think of Ruby as passing the value of a reference.

For more examples and explanation, see http://khelll.com/blog/ruby/ruby-pass-by-value-or-by-referen...

Re: Comparing PHP, Perl, Python and Ruby

#78
Very good comparison between all the languages, and like other people said: a nice Rosetta stone. With that said, it would be very useful to add a comparison of the database layer syntax as that it is, at least for a me, a common task in all of the scripting languages. I also agree with the comments about adding the features that are unique to the languages, as that would be extremely helpful.

Re: Comparing PHP, Perl, Python and Ruby

#79
post #68

"Passing by reference" section is wrong about Ruby (not sure about Python). Ruby passes everything by reference, it's only that integers are immutable so that the function can't alter them. Strings, though, are mutable: def foo s s.concat 'foo' end a = 'bar' foo a a # => "barfoo"

Well, integers are immutable (and conceptually a singleton per value) unless you override stuff in FixNum and add instance variables. Here's an evil example that works at least in MRI 1.8.6:

    class Fixnum

      alias :realplus :+
    
      def + b
        @a ||= 0
        @a = @a.realplus(b)
        self.realplus(@a)
      end
    end
The integer value itself is immutable, though.

Of course all hell will break loose and adding instance variables in certain classes like Fixnum will be extra slow (as if there aren't enough other reasons not to), since MRI uses type-tagging for Fixnum, Symbol and a few others, and so since they're not "real" objects, if you do anything that requires one, it creates one that's stored in a hash table.

Re: Comparing PHP, Perl, Python and Ruby

#80

Earlier quoted context omitted.

Nothing I love more than watching someone try way too hard to act "grizzled" and in the process make an idiot out of themselves. http://hyperpolyglot.org/

Was that in response to his exhortation to learn different languages, or do you actually believe that Perl and its self-proclaimed successors have any profound differences?

I think the point is that while the article link is to the scripting category, the site does in fact cover a lot more languages.
Post reply on HN