btwael / mammouth

Unfancy PHP
http://mammouth.boutglay.com
MIT License
214 stars 22 forks source link

Concatenation operator <-> shorter alternative #51

Closed sanotto closed 8 years ago

sanotto commented 9 years ago

The concatenation is very common in php code, I feel that the chosen operator <-> is too long. I looked into Mammouth in the search of the "write less do more" holy grail ...and it delivers...until I've found '<->'. It is too long. Furthermore, it is confusing, the eye sees <-> and the mind concludes "comparisson". Why not the '+' symbol? or '~' or '^' or even '@'... Please make it shorter and less confussing. Thank you for your atention

btwael commented 9 years ago

We will try to find a better and shorter notation for concatenation, thank you!

sanotto commented 9 years ago

I've found that the following code: {{ i=0 while i < 10 i++ echo "Esto vale $i" }}

compiles to ...

<?php $i = 0; while($i < 10) { $i++; echo "The value is: $i"; } ?>

So using string interpolation is feasible and you can avoid the <-> operator

dellermann commented 9 years ago

But using string interpolation is much more expensive than concatenating strings. Thus, a shorter concatenation operator would be appreciated. I recommend something like $ or |.

btwael commented 9 years ago

@sanotto @dellermann , you can just use +

{{
var1 = 'sdfsdfsd'
var2 = 12
var3 = var1 + var2 # automatic concatenation
}}

compiled to

<?php
function mammouth($func, $arg1, $arg2){if ( $func == '+' ){if((is_string($arg1) && is_numeric($arg2))||(is_string($arg2) && is_numeric($arg1))) {return $arg1.$arg2;} else {return $arg1+$arg2;}}}

$var1 = 'sdfsdfsd';
$var2 = 12;
$var3 = mammouth("+", $var1, $var2);
?>
dellermann commented 9 years ago

I know, but it's done via a separate function which is a performance issue.

catexa commented 9 years ago

Thumbs up for this change. I would suggest '--' for the operator. Easier to type, especially with one hand (the other is on the mouse)

btwael commented 9 years ago

@catexa we cant use -- because it's already used for --variable and variable--, and it will version cause many grammatical conflict, so in the next vetrsion check the branch v3.x: we are going to use this operators <->, ~~ and ~, in addition of+` if you're in the strict mode