Actually, I looked at the code to make some changes to
my private language
file and didn't understand it. I know somehow what the code does but not
how, because I didn't want to spend that much time decoding all those
regexps that make the code pretty cryptic and hard to maintain - with the
added bonus of not having /any/ documentation.
In case anyone's wondering, yes the code is in CVS now. But it's not
finished: there's still at least one more update to Language.php to come.
Sorry about that Jens but you'd probably be better off commenting the whole
section out for now. As for not having any documentation, I can fix that in
my next commit.
Why not rearrange the code into two segments: Segment
one would parse the
linked date like present in the article into three numerical values: day,
month, year. The second segment then would only have to concat those values
(maybe with a converted month name) into the final form. This form could be
given in the usual "$1 $2 $3 $4" syntax (with e.g. $4 being the month
name). That also would take some load off the server that now has to
interpret lots of regexp patterns, which isn't too cheap because these
patterns normally first get converted into some form of a finite automaton
that is eventually given the input string for processing. (At least the
code by Tatu Ylonen proceeds in this way.)
No, I think your way would be slower, not faster. There's a "pre-analysis"
flag you're meant to use if you run the same regular expression many times,
but according to the PHP manual it only provides a speedup if the regular
expression starts with something other than a fixed character. So it sounds
like there's no compilation. Besides, if regular expressions were slow,
well, the rest of the parser would be in trouble.
By splitting the replacing from the parsing, you're just turning one job
into two. The same tasks are still required, there's just some extra
administrative overhead. Plus since PHP is an interpretive language, I'd
really rather have the O(N) code written in C.
As for your way being simpler, well, I would contest that too. You code it
your way, and we'll put them side by side. My way really is pretty simple if
you understand Perl regular expressions.
-- Tim Starling.
_________________________________________________________________
Hotmail is now available on Australian mobile phones. Go to
http://ninemsn.com.au/mobilecentral/signup.asp