Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:20107 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52702 invoked by uid 1010); 17 Nov 2005 23:06:53 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 52687 invoked from network); 17 Nov 2005 23:06:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Nov 2005 23:06:53 -0000 X-Host-Fingerprint: 80.137.10.70 p50890A46.dip0.t-ipconnect.de Received: from ([80.137.10.70:11711] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id E5/C8-07637-D0D0D734 for ; Thu, 17 Nov 2005 18:06:53 -0500 To: internals@lists.php.net,Rasmus Lerdorf Message-ID: <437D0D08.8060805@web.de> Date: Fri, 18 Nov 2005 00:06:48 +0100 User-Agent: Thunderbird 1.5 (Windows/20051025) MIME-Version: 1.0 CC: Ilia Alshanetsky References: <437B530A.5050105@prohost.org> <437CF6B4.5080207@web.de> <437CF943.7090800@lerdorf.com> In-Reply-To: <437CF943.7090800@lerdorf.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 80.137.10.70 Subject: Re: [PHP-DEV] dropping curly braces From: akorthaus@web.de (Andreas Korthaus) Hi Rasmus! Rasmus Lerdorf wrote: > > Very few people converted to using {} so the argument about reading old > code doesn't really hold. I can't belive that most of the code today is based on <=PHP3 code. I'm not talking about such "PHP3 based" code. I'm talking about code, you wrote 1 year ago and did not touch for 10 months. Or code you have to debug which someone else wrote. > If you go and grep through all the public > code out there, pretty much none of it uses {} for character offsets. That's the problem - also grep does not know if [] is used for arrays or stings. That's the same for programmers, it's often not easy to conclude from context - that's my point. > Having two syntaxes for the same thing makes no sense, and getting rid > of [] would break all sorts of stuff. Do you think it would break more stuff than getting rid of {}? How do you know? grep definitely can't help you here. > The original reason for the {} > was a technical one to simplify the parser, but the landscape has > changed and that reason no longer exists. But [] has been marked deprecated in favour of {} for 5 years now. Netcraft finds 10 times more php-domains today than 5 years ago. > As far a code readability and obviousness goes, I doubt anybody would > guess their way to the $str{5} syntax. But you know without understanding of any context, that it's the 6th character of the string "$str". When you see $var[5], it could be the 6th character of a string, or an element of an array... and what about the value? You can't be sure that it's a string with length 1, it also could be another array, an object, a string with length 4711... That increases complexity and decreases readability. > If you were new to PHP and you > were going to try to guess how you would get a character offset in a > string, what would your first guess be? Most non-PHP people I have > asked have answered []. Hm, most people I can think of would seach the manual for a string function, and not even think of syntax like {} or []. Some day I found {} syntax in the manual, saw that I could use [] too, but which is deprecated. {} was a very straightforward syntax in my eyes (at that time). If you want to use PHP, you have to know the manual anyway, so I don't think this is a big advantage. > Removing the obvious syntax just doesn't make > any sense. The other place {} is used outside of control blocks is in > quoted strings where "{$foo{1}}" is much uglier than "{$foo[1]}". Yes that's a disadvantage. But one of my most important goals when writing scripts (in a major project) is to reduce complexity and make scripts as easy to understand as possible. And PHP makes a good job here. But I think the {} -> [] change will reduce readability of scripts, because both programmers and "grep" can't differ arrays from strings using the [] syntax anymore. However, thanks a lot for your time/explanation! best regards Andreas