Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » PHP
  • » [PHP-DEV] dropping curly braces [RSS Feed]

#1 Nov. 17, 2005 21:43:03

Rasmus L.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] dropping curly braces


Andreas Korthaus wrote:Can someone tell me the reason for this decision?Very few people converted to using {} so the argument about reading oldcode doesn't really hold. If you go and grep through all the publiccode out there, pretty much none of it uses {} for character offsets.And internally there is absolutely no difference between {} and .Having two syntaxes for the same thing makes no sense, and getting ridof would break all sorts of stuff. The original reason for the {}was a technical one to simplify the parser, but the landscape haschanged and that reason no longer exists.As far a code readability and obviousness goes, I doubt anybody wouldguess their way to the $str{5} syntax. If you were new to PHP and youwere going to try to guess how you would get a character offset in astring, what would your first guess be? Most non-PHP people I haveasked have answered . Removing the obvious syntax just doesn't makeany sense. The other place {} is used outside of control blocks is inquoted strings where "{$foo{1}}" is much uglier than "{$foo}".-Rasmus

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#2 Nov. 17, 2005 22:27:57

Christian S.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] dropping curly braces


Rasmus Lerdorf wrote:Very few people converted to using {} so the argument about reading oldcode doesn't really hold. If you go and grep through all the publiccode out there, pretty much none of it uses {} for character offsets.I'd like to cite Andi here:
"Regarding BC breakage. I'm not saying we shouldn't break BC in some
cases, but in many cases, there's no big advantage (except for some
people's warm and fuzzy feelings), and it can cause a lot of heart
aches and disruption in PHP use. Migration is very important. "

See <http://news.php.net/php.internals/19415> for the full post.

Please think twice before breaking BC light-heartedly.

Thanks,
- Chris

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#3 Nov. 17, 2005 23:05:02

Robert C.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] dropping curly braces


On Thu, 2005-11-17 at 16:42, Rasmus Lerdorf wrote:
> Andreas Korthaus wrote:
>
> > Can someone tell me the reason for this decision?
>
> Very few people converted to using {} so the argument about reading old

Ugh, so those of us that did are going to have to comb back through our
code and revert after following the original suggestion. UGH!

Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework -http://www.interjinn.com|
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#4 Nov. 17, 2005 23:07:22

Andreas K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] dropping curly braces


Hi Rasmus!

Rasmus Lerdorf wrote:Very few people converted to using {} so the argument about reading oldcode doesn't really hold.I can't belive that most of the code today is based on <=PHP3 code. I'mnot talking about such "PHP3 based" code. I'm talking about code, youwrote 1 year ago and did not touch for 10 months. Or code you have todebug which someone else wrote.If you go and grep through all the publiccode 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 orstings. That's the same for programmers, it's often not easy to concludefrom context - that's my point.Having two syntaxes for the same thing makes no sense, and getting ridof would break all sorts of stuff.Do you think it would break more stuff than getting rid of {}? How doyou know? grep definitely can't help you here.The original reason for the {}was a technical one to simplify the parser, but the landscape haschanged 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 wouldguess their way to the $str{5} syntax.But you know without understanding of any context, that it's the 6thcharacter of the string "$str". When you see $var, it could be the6th character of a string, or an element of an array... and what aboutthe value? You can't be sure that it's a string with length 1, it alsocould be another array, an object, a string with length 4711...That increases complexity and decreases readability.If you were new to PHP and youwere going to try to guess how you would get a character offset in astring, what would your first guess be? Most non-PHP people I haveasked have answered .Hm, most people I can think of would seach the manual for a stringfunction, and not even think of syntax like {} or . Some day I found{} syntax in the manual, saw that I could use too, but which isdeprecated. {} was a very straightforward syntax in my eyes (at thattime). If you want to use PHP, you have to know the manual anyway, so Idon't think this is a big advantage.Removing the obvious syntax just doesn't makeany sense. The other place {} is used outside of control blocks is inquoted strings where "{$foo{1}}" is much uglier than "{$foo}".Yes that's a disadvantage. But one of my most important goals whenwriting scripts (in a major project) is to reduce complexity and makescripts as easy to understand as possible. And PHP makes a good jobhere. But I think the {} -> change will reduce readability ofscripts, because both programmers and "grep" can't differ arrays fromstrings using the syntax anymore.However, thanks a lot for your time/explanation!


best regards
Andreas

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#5 Nov. 17, 2005 23:12:03

Rasmus L.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] dropping curly braces


Andreas Korthaus wrote:As far a code readability and obviousness goes, I doubt anybody wouldguess their way to the $str{5} syntax.But you know without understanding of any context, that it's the 6thcharacter of the string "$str". When you see $var, it could be the6th character of a string, or an element of an array... and what aboutthe value? You can't be sure that it's a string with length 1, it alsocould be another array, an object, a string with length 4711...That increases complexity and decreases readability.Your argument falls apart there. Try it:

$a = array("ab","cd","ef");
echo $a{2};Guess what that prints? {} has nothing to do with strings. They are100% equivalent to and as such add nothing to clarity.-Rasmus

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#6 Nov. 17, 2005 23:20:32

Jevon W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] dropping curly braces


Is there anything wrong with having a convention for character access of
strings? Most PHP programmers see {} as string access and as array access -
sure, they might be functionally identical, but its the convention which is
important.

Jevon


> -------Original Message-------
> From: Rasmus Lerdorf <>
> Subject: Re: dropping curly braces
> Sent: 17 Nov '05 12:11
>
> Andreas Korthaus wrote:
> >> 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, 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.
>
> Your argument falls apart there. Try it:
>
> $a = array("ab","cd","ef");
> echo $a{2};
>
> Guess what that prints? {} has nothing to do with strings. They are
> 100% equivalent to and as such add nothing to clarity.
>
> -Rasmus
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit:http://www.php.net/unsub.php>
>

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#7 Nov. 17, 2005 23:27:23

Andreas K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] dropping curly braces


Rasmus Lerdorf wrote:Andreas Korthaus wrote:But you know without understanding of any context, that it's the 6thcharacter of the string "$str". When you see $var, it could be the6th character of a string, or an element of an array... and whatabout 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.Your argument falls apart there. Try it:

$a = array("ab","cd","ef");
echo $a{2};Guess what that prints? {} has nothing to do with strings. They are100% equivalent to and as such add nothing to clarity.OK, but by dropping {} for strings you also remove the possibility tohave a convention like " for arrays and {} for strings".If I could decide I would drop {} for arrays and for strings, but Ifear I will not be asked to decide... ;-)Best regards
Andreas

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#8 Nov. 17, 2005 23:32:37

Rasmus L.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] dropping curly braces


Andreas Korthaus wrote:OK, but by dropping {} for strings you also remove the possibility tohave a convention like " for arrays and {} for strings".If I could decide I would drop {} for arrays and for strings, but Ifear I will not be asked to decide... ;-)And you are willing to break just about every application out there forthis? There are millions of lines of code that uses for stringoffsets.-Rasmus

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#9 Nov. 17, 2005 23:36:26

Ilia A.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] dropping curly braces


Andreas Korthaus wrote:
> OK, but by dropping {} for strings you also remove the possibility to
> have a convention like " for arrays and {} for strings".
> If I could decide I would drop {} for arrays and for strings, but I
> fear I will not be asked to decide... ;-)

You may think that {} and are different, but in reality same code
deals with both. Having two constructs for the same behavior is silly
and leads to confusing, hard to read code. Especially so when you
consider the fact {} has another meaning that is completely different.

Ilia

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#10 Nov. 17, 2005 23:51:56

Robert C.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] dropping curly braces


On Thu, 2005-11-17 at 18:33, Ilia Alshanetsky wrote:
> Andreas Korthaus wrote:
> > OK, but by dropping {} for strings you also remove the possibility to
> > have a convention like " for arrays and {} for strings".
> > If I could decide I would drop {} for arrays and for strings, but I
> > fear I will not be asked to decide... ;-)
>
> You may think that {} and are different, but in reality same code
> deals with both. Having two constructs for the same behavior is silly
> and leads to confusing, hard to read code. Especially so when you
> consider the fact {} has another meaning that is completely different.

That should have been considered before everyone was told that was
deprecated for strings in favour of {}. Dropping support for string
access via {} is akin to slapping those who followed the lead. Once
bitten, twice shy. I don't see support for <? being dropped anytime, yet
it falls under the exact same argument. But maybe there's a trend
emerging here, and in fact <?php will be deprecated in the near future.
It's a tough call since credibility is rapidly swirling down the toilet.

Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework -http://www.interjinn.com|
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

  • Root
  • » PHP
  • » [PHP-DEV] dropping curly braces [RSS Feed]

Board footer

Moderator control

Enjoy the 24th of April
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support