Re: Ternary operator enhancement for fluent code

From: Date: Tue, 04 Jul 2000 22:39:14 +0000
Subject: Re: Ternary operator enhancement for fluent code
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-23510@lists.php.net to get a copy of this message
> RL>> I really don't like magical operators like this. It may seem like a nice > RL>> thing when you are sitting there working on thousands of lines of code, > RL>> but when the next poor soul comes along and sees: > RL>> > RL>> if(!!$a) { $b = $c ?&? $d; } > > Yeah, looks like Perl: print "%$&&@^&$!" if(!%$&&@^&$!); > > Perl-ers invented English module just because of this. I have to agree that that sort of syntax is too confusing. I've been known to refer to PHP as Perl-lite and quite a few people have commented to me that one of the things that drew to them to PHP is that Perl is just too cryptic. Things like function($foo, $bar, $baz) are just easier to learn than sub foo { my ($foo,$bar,$baz) = @_}, even if they have the same effect and they allow the compiler to help you find improper usage. I do like some of the proposed functionality but would prefer something that doesn't look like line noise. For example, instead of $foo = $a ? $b; which would set $foo to $a if $a wasn't false and $b if $a was false, even resusing or again to produce something like $foo = $a or $b; seems cleaner. Even better might be a function which would return the first parameter which isn't false: $foo = first_valid($a, $b, $c, $d ...). This would be handy for more than simple binary work, too: $text_color = first_valid(@$MemberSetting["PageColor"], @$InstallationSetting["PageColor"], "WHITE"); The other advantage, of course, is that this wouldn't require any changes to the core language, which is why I wrote http://gateway.digitaria.com/~chris/php/first_valid/ back when I needed it.

« previous php.dev (#23510) next »