From: Chad Perrin Date: 2007-03-10T17:36:31+09:00 Subject: Re: A couple of questions from a Ruby neophyte On Sat, Mar 10, 2007 at 12:23:04PM +0900, 7stud 7stud wrote: > Chad Perrin wrote: > > In the quartet of commonly cited web > > scripting languages (Perl, PHP, Python, and Ruby), PHP's regular > > expression handling is by far the worst. It's kludgy, inconsistent, and > > unwieldy. I try to avoid it. I don't like Python's much either, but > > it's a darn sight better than PHP's. > > It seems like regular expressions are slightly different from language > to language, but not so much so that it is much of a problem. Although, > if you are used to using advanced features like negative look behinds, > and they aren't available in the language you are coding in, I guess > that would be frustrating. What deficiencies are there in Python's > regex support? If you've ever noticed the way OOP characteristics look bolted-on in Perl, you might understand how regex support looks bolted-on in Python. For one thing, regex support is provided only through a library, rather than as part of the core language -- in other words, it really *is* bolted on. It's better than Java's regex support. In fact, it may be in the top half-dozen languages for regex support, but after extensive use of Perl's it feels half-baked. So far (which isn't too far yet), Ruby's regex support is a very close second to Perl's, in my opinion. In fact, there are a couple things I think Ruby does better. > > > > That's a pretty good take on it. > > > > The languages I'd suggest, off the top of my head, for the tasks > > mentioned here include: > > > > Perl > > Python > > Ruby > > > > Each has its benefits and detriments, of course. I personally am not a > > fan of Python, but it's still a great language in (most of) the ways > > that matter. Ruby's my favorite, by a long shot, for OOP. Perl may > > provide the most comfortable syntax for people who like a unixlike > > environment (including me). All three of them handle the needs outlined > > in the original post of this thread admirably. > > I've been looking at Ruby and Python this week, and I am drawn more to > Python. I went through the "Ruby in 20 minutes tutorial" at the Ruby > website here: > > http://www.ruby-lang.org/en/ > > and the syntax is not that appealing to me. I also started reading the > book "Dive into Python", which targets experienced programmers moving to > Python, and which is also available for free download at the author's > web site: > > http://www.diveintopython.org/ You might want to judge Ruby syntax on something other than a demonstration of irb. One of the problems I have with Python's syntax is that it always looks unfinished, somehow, to me. I realize that the footnote-like construction of Python source code might be more appealing to some people, but not to me. The way things look in irb examples isn't really representative of Ruby code in general, though. > > It's given a 5 star rating in the python book reviews here(click on the > book names for the full reviews): > > http://www.awaretek.com/book.html > > How great is that?! A free 5 star rated programming book? It has a > unique format: the author starts each section with a few lines of some > indecipherable code, and then spends the rest of the section introducing > the concepts and language features that make the code crystal clear by > the end. The first two chapters are definitely worth reading, and they > introduce Python's data structures: arrays(called "lists"), > dictionaries("associative arrays, i.e. arrays with non numeric index > values), and tuples(immutable arrays). There's a quality Ruby book for just about every writing style out there. Between Programming Ruby, Learning to Program, Everyday Scripting, The Ruby Way, Why's (poignant) Guide, and half a dozen other notable works, each written in a different style so that they don't tend to be redundant, there isn't much ground left uncovered. Shop around a little, and you can probably find what you need -- if what you need involves Ruby. Just stay away from Mr. Neighborly's Humble Little Ruby Book. In my opinion, it's organized exceedingly well to get a beginner started, but written just as poorly as the organization of it was done well. Of those, early versions of Programming Ruby and Learning to Program, as well as the only edition of Why's (poignant) Guide (and the Humble Little Ruby Book for that matter), are available for free online. > > The poster might be interested in a quick look at a "python in 10 > minutes tutorial": > > http://www.poromenos.org/tutorials/python > > Anyway, I was wondering if you could give some further insights into why > you prefer Ruby and don't like Python? I've done a little of that. I could explain more if you like, but it'd be a short email -- I spent a fair bit of time giving it a good look, decided I didn't like what I found, and set it aside. I then proceeded to forget most of what I knew, so I'm not sure I'd even remember the specifics so well. I mostly just remember that I prefer other languages, I suspect. . . . though I'll probably come back to it and really learn Python at some point in the distant future. You know, when I'm done with Ruby, UCBLogo, Objective Caml, Objective C, Common Lisp, Scheme, Haskell, Perl 6, and refamiliarizing myself with C. I'm pretty sure refamiliarizing myself with Java comes after Python, though. Unfortunately, the realities of the work world will probably result in learning even more PHP before I get to Python, too. Ew. On the other hand, as I learn about Rails, I find that if at all possible I'm far better off if I can convince any clients that Rails is the way to go than to go with PHP, all else being equal. (Brief anecdote, re my happiness with Rails: I followed along with the text in Agile Web Development with Rails, and found myself thinking "Woah, this is talking like I already have a database set up, but I don't remember anything about that." I went back, read between the lines a bit, and realized that creating database tables is so absurdly easy in Rails that I'd already done so and didn't even realize it. I mean, really. So easy, it's scary.) -- CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ] "It's just incredible that a trillion-synapse computer could actually spend Saturday afternoon watching a football game." - Marvin Minsky