Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
inaba46256y$c = ($a < $b) ? 'W' :
($a > $b) ? 'E' :
' ';
This will produce 'E' unless a and b are equal. How broken is that!
http://sandbox.onlinephpfunctions.com/... -
@inaba Well you can write ugly code in every language if you try hard enough..
Not like anyone with their right mind would write production code like that. -
TheOct039316yIsn't it:
<?php
$c = ' WE'[$b<=>$a];
?>
? <== (Don't know where to put my question mark)
Also PHP is ugly in my opinion, but I like using it :) -
TheOct039316y@TheOct0 I messed my shit up as well. Mismatched the order for $a and $b, and probably some other shit. I've never been good at optimizing code ^^'
-
c = (a>b?'E':a<b?'W':'') in any moderately competent language tho
And in a good one
let c = match a<b with | 1->'W' | 0->'' | -1->''E';; -
Skayo88596y<@TheOct0>
Whoopsie yeah I mixed that up with the actual code I wrote for the Code Golf I did...
As you said, it should be:
$c = ' WE'[$b<=>$a]; -
It'll make whoever ends up maintaining your code hunt you down.. shit like this is unreadable and fucking annoying.
-
I am going to stick to
$c = $a < $b ? 'W' : 'E';
Unless the spaceship method allows for the else c = ' '
Related Rants
In PHP, this:
<?php
if($a < $b) {
$c = 'W';
} elseif($a > $b) {
$c = 'E';
} else {
$c = ' ';
}
?>
Does the same as this:
<?php
$c = ' WE'[$c<=>$a];
?>
How cool is that?!? xD
random
php