Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

gnat (29)

gnat
  (email not shown publicly)

Journal of gnat (29)

Sunday December 16, 2001
03:29 PM

Regular expressions

[ #1678 ]
I've been documenting POSIX-style regular expressions for The PHP Book, and they're starting to grow on me. Perl has some nice stuff ($ matching before trailing newline) but the sheer readability (and extensibility) of the POSIX named character classes (e.g., [[:cntrl:]]) is very nice. I know Perl now supports POSIX classes, but I get the feeling they're thought-of as second-class citizens.

My current "oh my GOD" reaction to PHP is the great inconsistency in the function names. String functions start with str_, string_, and sometimes something else. This is important, of course, because PHP doesn't have namespaces. The POSIX regular expression function names are only somewhat similar to the Perl regular expression function names. And so on.

This really shows up the dangers of unplanned growth. I'm not suggesting design by committee, but simply articulating a few module design principles could have solved these messes.

Which principles? I'm thinking things like:

  1. Simple is better
  2. Look at other similar modules
  3. Be consistent
  4. Name similar functions similarly

I suppose 3 and 4 are really the same. That's the problem with trying to write down commonsense. The underlying principles that govern our behavior are sometimes completely invisible to us. That's why we need people like Damian, who can describe what we're supposed to do in such a way that we go "oh! well, duh. Why didn't I think of that myself?"

--Nat

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • My current "oh my GOD" reaction to PHP is the great inconsistency in the function names.

    You're not kidding. It's great that we can remember that Perl builtins never have underscores. With PHP, the use of underscores is totally random (sort of like CGI.pm used to be). is_array(), is_numeric(), etc., have underscores, but isset() doesn't. strlen(), strtr(), and a bunch of other str* function have no underscore, but str_pad(), str_repeat(), and str_replace() do. And you've got stuff like frenchtojd() t