Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84490 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 43151 invoked from network); 10 Mar 2015 01:04:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Mar 2015 01:04:56 -0000 Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.170 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.214.170 mail-ob0-f170.google.com Received: from [209.85.214.170] ([209.85.214.170:42082] helo=mail-ob0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 01/80-36114-6334EF45 for ; Mon, 09 Mar 2015 20:04:55 -0500 Received: by obbnt9 with SMTP id nt9so12930379obb.9 for ; Mon, 09 Mar 2015 18:04:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=ZrnXUI61Vsjnujnt7m8PM9dNAnddDG2iK6T4edmeqWg=; b=DjTnoHQ37MTFVYJrg/FWhUVUvEOn6DuG6cLfeUCDeX+4d1pLUmb0HfNVNn33mE+vmH DwZKUfjoHJaGSdYPdVnMRDOsVgMo/bwfifoJKuiS9iqtti5782QuxgoPlP5XtyzUsmZH Fgcqv6GckfAUtFd4fx/WCerD6hDdAjR2mnsQpTdnTZ/SLYT5C7RLdHgMIJNK804E1V8r 89CWrozyWhcAJA/rZLd6112bmDH4EgzfYQswJHA4RU00ZBdqNn4WK1c5/hLwt+W3K+WM O+fnwiG3EIn8dVUUC7kHR4+BuJBA2OJ6DWqreuApe1wLkbHuO2VhyRIlSXaihUQ95YCE UGzA== X-Received: by 10.60.48.98 with SMTP id k2mr23919086oen.49.1425949490729; Mon, 09 Mar 2015 18:04:50 -0700 (PDT) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.202.58.2 with HTTP; Mon, 9 Mar 2015 18:04:09 -0700 (PDT) In-Reply-To: <54FC1E67.3070504@luni.fr> References: <5D8591E2-5AE6-4B4C-AAE0-3D15523410AC@gmail.com> <54F83C4D.1020206@gmail.com> <54FB3175.3000308@luni.fr> <54FC1E67.3070504@luni.fr> Date: Tue, 10 Mar 2015 10:04:09 +0900 X-Google-Sender-Auth: ULuGFQ7g9OurtOxnsPnoQa8dm_w Message-ID: To: =?UTF-8?Q?Gr=C3=A9gory_Planchat?= Cc: "internals@lists.php.net" , Pierre Joye , Arvids Godjuks , Rowan Collins , Larry Garfield Content-Type: multipart/alternative; boundary=001a1134cd26dcdb270510e4bcf1 Subject: Re: [PHP-DEV] Consistent function names From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a1134cd26dcdb270510e4bcf1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Gregory, On Sun, Mar 8, 2015 at 7:03 PM, Gr=C3=A9gory Planchat wro= te: > Le 08/03/2015 00:44, Yasuo Ohgaki a =C3=A9crit : > > Hi Gregory, >> >> On Sun, Mar 8, 2015 at 2:12 AM, Gr=C3=A9gory Planchat = wrote: >> >> Le 07/03/2015 02:39, Yasuo Ohgaki a =C3=A9crit : >>> >>> We may provide new names and new parameter order in new namespace. >>>> The difference is "alias" or "namespace" basically. I don't object to >>>> use >>>> namespace for it at all. In fact, I would love to have it even if ther= e >>>> is >>>> issue >>>> like writing extremely difficult to read code is possible. >>>> >>>> >>> Hello all, >>> >>> I join the thread as a seasoned PHP developer (in user-space), not as a >>> PHP core developer. I work since 6 years now for large companies websit= es >>> and I write PHP scripts and programs since 15 years now. I would like t= o >>> bring my brick to this wall. >>> >>> I follow the thread since a few days now and I have some suggestion whi= ch >>> can resolve both the functions naming issue for some of you, some other= s >>> suggested to have an object-oriented API and some are fearing massive B= C >>> breaks. >>> >>> I read Larry Garfield and Pierre Joye suggesting the idea of an >>> object-oriented API, maybe others suggested it already as long as this >>> idea >>> is running here since a few years. >>> >>> I wrote these days the start of a spec of an API, it is far from being >>> finished for the scalar types but the array part is almost finished and >>> integrates every method documented in the current array API. >>> >>> https://github.com/gplanchat/php-oop-api >>> >>> Suggestions are welcome, you can fork and comment. I don't have the >>> ambition to rewrite all the PHP core, but just using the existing >>> underlying code and applying it a new interface in the userspace. >>> Additionally to the current API. >>> >>> I use the ideas from the [PECL SPL types extension](http://php.net/ >>> manual/en/book.spl-types.php) and Nikita Popov's [scalar objects >>> extension](https://github.com/nikic/scalar_objects). >>> >>> Those enhancements could be part of one RFC or several, as the amout of >>> work can be massive. The essential point is that this refactoring *MUST= * >>> be >>> using only existing code in the core. It *SHOULD* make it appear >>> differently to the user. The risk is then lower than a full refactoring= . >>> It >>> is, IMHO, the best compromise for the entire PHP community. >>> >>> There are several goals and possibilities behind this : >>> * Create a consistent and complete API that can satisfy OOP programmers >>> and give them a more powerful API >>> * Do not create BC breaks on these core types, the ZVAL struct is >>> unchanged and the IS_STRING, IS-DOUBLE, ect... are still used as usual >>> * Make it possible in a future release (let's say PHP 8, 9 or 10+) to >>> deprecate and even remove the old API >>> * Build easily encoding-aware strings (binary, ASCII, UTF-8, UTF-16BE, >>> UTF-16BE, UTF-32, JIS, Big5, ect...) >>> >>> Thanks for reading. >>> >>> >> Nice post indeed! I'll insist to keep procedural API, though :) >> > > The point wasn't about deleting the procedural API now. I just mentioned > it was a possibility, I meant at the (very) long term that this API could > be deprecated or deleted, but it is not a mandatory rule. > > If this appears to happen someday, it will be done after 5 or even 10 > years following PHP 7.0 release and when a very large majority of project= s > has migrated to PHP 7 *AND* this possible new API. There will posibly be > some who prefer OO and others procedural and both could cohabit > indefinitely. > Procedural API should exist forever. IMO. > We are better to have unified encoding for simplicity. Multibyte string >> comparison is >> complex, so it's better to have NFC/NFG normalized UTF-8 strings as the >> default. >> Other encodings can be supported as conversions. >> > > I have no personal preference for a specific default encoding as long as > it is portable and widely used (UTF-8 seems to be the standard nowadays b= y > the way). > > I have though a preference for an unified API for all strings values, > either they are managed by the standard API or mbstring or which ever > specific extension you plan to use. This is - I think - the most importan= t > point, changing the default encoding could then become a detail (or be > defined in php.ini). > > Then using multiple encodings in a same script or using a same script for > multiple encodings becomes straightforward and standard. Most PHP > developers doesn't even know what is Unicode or a character encoding, the= y > just see "odd characters that are removed with a header() call or > utf8_decode()", no teasing intended, they just don't want to have to hand= le > this. PHP should not let this sort of consideration to the sole awareness > of user-space developers. > I've already made UTF-8 as default PHP encoding by https://wiki.php.net/rfc/default_encoding Mixing encoding is nice and flexible, but it would make implementation more complex. It many cases needlessly. UTF-8 is standard now a days, so it would be the most reasonable choice for the default. Problem is Unicode has many forms for "a character", has many ways to "compare" them. For example, MySQL has utf8_general_ci and utf8_unicode_ci. utf8_unicode_ci is just unusable with Japanese because it treats "=E3=83=91=E3=83=91"(father) and "=E3=83=8F=E3=83=8F"(mother) as the same s= tring. We may have many ways to compare strings, but the default should be the most reasonable one and string should be encoded so that simple byte by byte could be done to check equality if it's possible. There are enough complex things in Unicode only, adding multiple default encoding support may not worth it. > We are better to have consistency between procedural functions and OO >> methods >> where it is possible. I see a few inconsistencies like "hasKey", "has", >> "recursiveWalk". >> These names could be adjusted by function and/or method. >> > > Yes, that's the point of my message, if some method names or parameter > orders seems inconsistent to you, let's talk about it and make it more > concistent. I also may have made mistakes or oversight witing it. > > But one thing seems important to say, the docs I wrote do not map to > existing procedural API names and parameter order, as this API is not > concistent with itself. > > To be remembered that this OO API does not use classic objects, it is > syntaxic sugar over existing scalar, array and string types. > I agree that these basic OO feature should be consistent with procedural APIs. I don't object to have $str->indexOf(5)/$str->length()/etc, but almost all of basic OO API should reflect procedural API. This RFC could be made so that it leaves space for consistency. i.e. Do no= t >> touch >> variable related functions to have consistent names for both procedural >> functions and >> OO methods in the future. >> > > I don't understand what you mean with "variable related functions", are > you talking about functions like list() and compact()? > I meant "array", "scalar" related functions. > > > Or we may discuss/adjust consistency fully. The change may be introduced >> PHP 7.x or even PHP 8. We may take time as long as it takes and have vot= es >> for multiple RFCs that have consistent names/parameters at once. >> >> The latter is better choice. IMO. >> > > As some mentioned in the thread, adding aliases to the current API will > have 2 main consequences > * create confusion for newcomers, that will not understand why there are = 2 > names for one function > * it will be difficult to impose to seasoned developers, as they shall > prefer to not change and keep a relatively backward-compatible code base > instead of having to maintain 2 code bases. > Newcomers will not be confused if they lookup new manual. There will be only main function listed and aliases are mentioned as "valid" function names unless we decide deprecate it. There is nothing wrong to use old names because they are valid and good names for them. > Also, making all existing projects use this new API will take time, I > remember the release of PHP 5.0 and PHP 5.1 that was at this time bothly > not availiable on most shared hostings and not supported by most projects > (or as a rough PHP 4 port). > > Additionally, as Rasmus mentioned, lots of methods names are mappings to > the extension's underlying C API or responding to an IEEE standard. Some = of > us are used to C development and their underlying APIs and found it easie= r > to have a simple mapping between languages. > > Changing evrything now would just create a Python 3 effect IMHO, even if = I > agree that it looks like confusing nowadays for newcomers, 20 years after > the first releases of PHP. Adding an OO API is a compromise, every > developer/team would use one or the other for his own reasons. I think th= at > in a long term > IEEE/C lib names exist as standard violating names currently. My RFC will make them "valid" and part of "standard". I don't think deprecating IEEE/C lib name functions is not good idea at all. Making them standard, or at least exceptions, seems only reasonable resolution for this. IMO. > My objective with this RFC is to make sure to have consistent procedural >> function names "someday" so that PHP will have nice and consistent >> procedural >> functions forever. >> > > I understand and, as I wrote above, this will have a big impact on the > userbase, with consequences that are not measurable now. Maybe this could > be done with a new language, but as PHP is now old of a couple decades an= d > has multiple engines (HHVM, Phalanger, Quercus, Parrot, ect...), making > this move is very hazardous. > > I think that's the point Rasmus, Larry Garfield, Pierre Joye and others > did have in mind, out of the pure beauty of code. > Why hazardous? Old names are kept as valid function names, only new consistent names are introduced. I've renamed pg_loopen() (and like) to pg_lo_open() about 10 years ago. http://php.net/pg_lo_open I didn't get even single compliant for this from users. (I'm one of a director of Japanese PostgreSQL Users Group and know many PostgreSQL and PHP users) Programmers are used to refactoring and renaming today and old names will never removed unless there are good reasons to remove. I don't see any reasons to be hazardous. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a1134cd26dcdb270510e4bcf1--