Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98634 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 75973 invoked from network); 25 Mar 2017 12:19:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Mar 2017 12:19:04 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.52 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 74.125.82.52 mail-wm0-f52.google.com Received: from [74.125.82.52] ([74.125.82.52:35793] helo=mail-wm0-f52.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 89/EE-40046-63066D85 for ; Sat, 25 Mar 2017 07:19:03 -0500 Received: by mail-wm0-f52.google.com with SMTP id u132so30316786wmg.0 for ; Sat, 25 Mar 2017 05:19:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=Hgrs25hZA8ptynnQUr51H3l2XzcaoXiOYkyMx4zTVKk=; b=K+W9piEQXuLPzwk9JntOeaaXpUYk8SZh9Rr9+nGRS9to3GW0GEu+vSE3vG5F41Mrgb KOQCMcT2VJeBSC5i6IaPz/f8mWc/5juqg+cIE0hFW4bqOp2yn0vRZEcfm3mQKCvEGXjg 74Ojpkwmv9hPpSs7RMn6m4qL4Wfgr1lDjZFcJonGPqyVT9ZoaUhUkH7JJYx5J/x+TrCM 32ewEBJwIqJDXbtFKzcxaVkLgwGt+/dJs/eiqo4YCszBUVNc35NpoFkIOYBm8yNieeBB wzNtf4/5aI/hq90+MNllpPdWlEDKt5R1FyyQrh5gE7zGUWOQJDwmCix3bg7nt82LjXtY Bo8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=Hgrs25hZA8ptynnQUr51H3l2XzcaoXiOYkyMx4zTVKk=; b=Sn/rCwUlDbC/9a7IMEjF4wCtNOW8q/wGq7uGwv40nekigAupCN0tUqLGv8mVtcdXBH FXfWy2k5iCQ+UEMvEo/Vk6x64xAEJmVC8UnI0WDILLqpBHSr5IuizT4RPto5o/S5K+tM rmKcPm47NN+l2DtXSG/e9eSVGugBsc9Vk10WRHDZcSkmUTCmwauRUCS1B2AcjWe+erD3 lSYKHsIunzEH0YElIoNFx4RUjIK/gcG2W75o3MRhYa4g/lZe4JLSQM5GSs6HlKWTu1V5 2pRgqbPG03a+XVO9iBqyIaHKkUZLssKSgRMI3G3nMZKPjLaUmYl+nOh+G5IbmvB+RreX o9Ig== X-Gm-Message-State: AFeK/H2nD5BR4Uh5tgVaSukNgXusu5LWjpTHNAo5IYtYD7ymJQaBUnPxfUxME5aJHDbFpv25H1fLceFfFUS+Bw== X-Received: by 10.28.44.66 with SMTP id s63mr1940527wms.46.1490444339505; Sat, 25 Mar 2017 05:18:59 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.170.216 with HTTP; Sat, 25 Mar 2017 05:18:59 -0700 (PDT) In-Reply-To: References: <16.06.40046.20A35D85@pb1.pair.com> Date: Sat, 25 Mar 2017 13:18:59 +0100 Message-ID: To: PHP internals , Levi Morrison Content-Type: multipart/alternative; boundary=001a1143604869ef9d054b8d1d87 Subject: Re: [PHP-DEV] Re: TOKEN_AS_OBJECT for token_get_all() From: nikita.ppv@gmail.com (Nikita Popov) --001a1143604869ef9d054b8d1d87 Content-Type: text/plain; charset=UTF-8 On Sat, Mar 25, 2017 at 4:40 AM, Levi Morrison wrote: > On Fri, Mar 24, 2017 at 1:04 PM, Nikita Popov > wrote: > > On Fri, Mar 24, 2017 at 5:26 PM, Levi Morrison wrote: > >> I prefer a distinct function/method from `token_get_all`. I don't see > >> the value in having a return value that differs so much based on a > >> passed flag. I don't care so much about a function vs static method; I > >> just oppose the additional parameter to `token_get_all`. > >> > >> I like the idea very much overall aside from that detail. > > > > > > token_get_all() already has a $flags parameter controlling its output. > > Currently only the TOKEN_PARSE flag is supported, which changes the > > interpretation of certain tokens. In a previous thread on this topic Sara > > suggested another flag (something like TOKEN_ALWAYS_ARRAY) which makes > the > > output of token_get_all() consistently use arrays. I think handling this > as > > a flag is entirely reasonable, and by analogy, handling the object mode > as a > > flag is also reasonable. In the end, these are just minor variations on > the > > output format (minor relative to the very complex primary functionality > of > > the function: lexing). Another precedent is the json_decode() option to > use > > arrays or objects in the return value. > > > > Regards, > > Nikita > > Whether TOKEN_PARSE is passed or not the return type is Array Array>. You are proposing an entirely different return structure of > Array. What are the benefits of reusing the same function > have? To me adjusting a parameter and getting a totally different > structure is not a benefit, so there must be some other unspecified > advantage you haven't articulated yet. If there is a benefit to it > great; please say so. Otherwise I don't see why you want to make an > existing function more complicated when you can just make a different > function. > (cc'ing back internals) The benefit that I was alluding to in my previous reply, though failed to state explicitly, is essentially forward compatibility, in the sense of robustness to extension. We already have an existing flag controlling behavior, I am proposing to add another (whether or not it be implemented as an actual flag -- it is a flag in the sense of a combinatorial boolean option), and it is not unreasonable to expect that more such options may appear in the future. It is inconsistent if some of these options are implemented as flags, while others are separate functions. Implementing everything as separate functions results in combinatorial explosion. Having the variants token_get_all(), token_get_all_as_object(), token_get_all_with_positions(), token_get_all_as_object_with_positions() is certainly not an enviable circumstance to be in. Of course, you may argue that "as object" and "with positions" are different because one changes the return type while the other doesn't (in the particularly limited typesystem you happen to be using -- a more accurate description would be array> vs array>), so let's pick another example that can not be implemented as flag: The token_get_all_from_file() variant that Fleshgrinder has suggested (under a different name). While I do not personally believe this to be useful, there are some technical arguments that can be made in favor of having such a function (our lexer is capable of lexing directly from a file more efficiently). Now again, if we implement the AS_OBJECT mode using a separate function, this would require having all of token_get_all(), token_get_all_as_object(), token_get_all_from_file() and token_get_all_from_file_as_object(). Whether or not any of these specific examples are going to happen, I hope this serves to illustrate the general hazard of implementing flags (in the sense of combinatorial boolean options) as separate functions. As a more meta-level commentary: While I can appreciate the philosophy of preferring new functions over extended arguments, this is certainly not the first time this discussion has been had on this list. The end result tends to be the same: Whatever your personal philosophy might be, the existing corpus of PHP functions has a very strong preference towards extending existing functions rather than introducing new ones. Overall, I must say that this thread has left me rather disappointed. I was harboring the misguided hope that it might be possible to introduce a simple, self-contained improvement, that resolves a major ergonomics pain point in ext/tokenizer, while also improving performance and memory usage. Essentially, a win on all fronts. What I get instead is a continued escalation of this simple change, first into the addition of a new function (which I disagree with, but which is still a feasible suggestion), then into the addition of a complex object-oriented system involving three classes, at least six methods, iterators and even managing to involve the question of namespaced core functionality, a well known and extensively discussed unresolved question! What am I supposed to do with such suggestions? I will obviously not waste my time discussing the design of such a system, let alone implementing it in its glorious complexity. This is the point where I abandon this particular idea, as clearly my expectations of the scope of this change do not line up with those of others. I really wish people could get their priorities straight. Nikita --001a1143604869ef9d054b8d1d87--