Re: Woah

From: Date: Sat, 08 Sep 2001 06:36:33 +0000
Subject: Re: Woah
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-65443@lists.php.net to get a copy of this message
> Using obscure single character operators is simply something that we don't > do in PHP, it's totally inconsistent with the language. You know I hate magic more than most. I have lobbied against it forever. However, sometimes you need to conform with the underlying 3rd-party mechanism you are connecting to. Regular expressions are butt-ugly and full of magic. I'd love to deprecate regular expressions and tell everyone to use a better mechanism for string matching and manipulation. The LDAP reverse-polish query format is also butt-ugly and non-intuitive, but people who have been doing LDAP for years are quite fluent in it. At the function level, strlen(), strchr(), strcmp(), strtok(), etc... are all inconsistent with the PHP function naming standard. They should logically be str_len(), str_chr(), str_tok()... or perhaps string_length()... We don't do this because it would drive people very familiar with the underlying API we copied crazy. Having no efficient way to use _() would drive people very familiar with gettext crazy because everywhere else they have used gettext they could use this syntax. There are even gettext pre-processors that are keyed on _("...") and go in and do static replacements of this text. This doesn't mean I agree with the magic _() function, but until we have some sort of efficient run-time function aliasing mechanism like they do in Python, removing _() and telling people to create a user-space function that calls gettext() is not going to make the gettext using people very happy with us. The way this was solved in Python is that they have a gettext.install method which creates the _() function in the builtin namespace. The function is only present once this install method is called on the gettext object. See http://www.python.org/doc/2.1/lib/node187.html Python has a second gettext API which is not as powerful and thus not used as often and the typical usage of that is: import gettext _ = gettext.gettext print _('blah blah') ie. they use user-space function aliasing to create the _() function. The thing to realize here is that _() is everywhere. Everything you read about gettext will refer to _(), so people who want to use the PHP gettext extension are going to want to use _(). There is no way around that. How many hoops we force people to jump through to get there is the only real question. We can't go back in time and change this convention. It's there and we need to deal with it. Now, ff this worked in PHP it would be an option: define("_","gettext"); _("blah"); Or if there was a way to call a function like gettext_init() or maybe just make it part of textdomain() or bindtextdomain() and have it dynamically add the _ alias it would also be a good option. This doesn't seem impossible actually. I don't like the idea of forcing people to do: function _($str) { return gettext($str); } Since this is a function that will be called for every single string that is output from an application, it is a function that will be called dozens of times on every request. Adding the overhead of a user-space wrapper call is irritating. -Rasmus

« previous php.dev (#65443) next »