[PLUG] Is PHP a good intro programming language?

Phil Tomson ptkwt at aracnet.com
Thu Jan 30 22:15:02 UTC 2003


On 30 Jan 2003, Wil Cooley wrote:

> On Thu, 2003-01-30 at 11:42, Phil Tomson wrote:
>
> Right away I spot of couple of errors in your understanding of Python
> (and I'm just barely a novice):
>
> > 1) Ruby is _very_ consistently object oriented (on par with SmallTalk).
> > Examples:
> >   #even numeric literals can accept messages:
> >   3.times { print " Hey " } #->  Hey Hey Hey
> >
> >   string = "This is my string"
> >   string.length #-> 17
> >   (NOTE: In python to get a string length you have to do:
> >    length(string)
> >    which doesn't seem very OO to me.)
>
> $ python2
> Python 2.2 (#1, Apr 12 2002, 15:29:57)
> [GCC 2.96 20000731 (Red Hat Linux 7.2 2.96-109)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> "123".__len__()
> 3
>
> IIRC, 'length()' is an operator in Python, not a function--the
> obj.__len__() is the way Python implements operator overloading.  So it
> really is OO, even if it doesn't look like it.
>

OK.  Not to get too much into language wars ;-) but Ruby has _real_
operator overloading:

class Foo

  def +(other)
    #do whatever you need to do to add foo's together
  end

  def [](index)
    #do whatever you need to do to index into your foo
  end

  def []=(index,value)
    #assign some foo index a value
  end

end

....not a complete example, of course...
I find Python's __operatorname__ way of doing operator overloading
annoying.

> > 2) Ruby has builtin regex facilities on par with Perl.
> > 3) Ruby has sigils, but they are used for indicating scope, not type as in
> > Perl, so they tend to show up less in Ruby code than they do in Perl code
> > (readability).
> > 4) Indentation is not a syntactical element as it is in some other P
> > language.  This can be important because a new programmer probably hasn't
> > used programming editors before and therefore may not be able to
> > differentiate between tabs and spaces which can lead to all manner of
> > frustration when it certainly looks as though their code is indented
> > correctly, but one line uses a tab and another uses spaces.
>
> Before I learned Python, I thought that was a problem too--but have only
> rarely had it be an issue.  I think the only time funny things happened
> was when I got my hands one a source file with DOS linebreaks (or maybe
> it was an X cut & paste gone awry).
>

Yes, lots of Pythonisas say this.  For me I found it caused trouble from
the first Python program I tried to type in.  I played with Python for
about three hours and then decided it wasn't for me mostly based on
this indentation as syntax thing (but also, it seemed odd to have to
pass in self everywhere to your instance methods, at least in their
definitions, and all those __xyz__ method names)...  I think the
Python/Ruby choice is one of taste - they
both have a lot of similar features.  I also tend to  find that if you're
coming from Perl you'll probably prefer Ruby.

Phil





More information about the PLUG mailing list