String concatination without +

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

String concatination without +

Cedric neuland
Hi,



I hope this is the right place for this..

I was wondering why this: 1+'b' +    "c"
cant be written like this: 1'b'     "c"

Perhapse this can be a new feature of ES?

greetz Cedric



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: String concatination without +

kdex
No one says you have to use the "+" operator. Why don't you use template literals?

On Dienstag, 17. Mai 2016 16:35:28 CEST Cedric neuland wrote:

> Hi,
>
>
>
> I hope this is the right place for this..
> I was wondering why this: 1+'b' +    "c"cant be written like this: 1'b'     "c"
> Perhapse this can be a new feature of ES?
> greetz Cedric
>
>  
>
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: String concatination without +

Isiah Meadows-2

They don't trim the leading indent, but that's easy enough to implement in a template tag.


On Tue, May 17, 2016, 12:39 kdex <[hidden email]> wrote:
No one says you have to use the "+" operator. Why don't you use template literals?

On Dienstag, 17. Mai 2016 16:35:28 CEST Cedric neuland wrote:
> Hi,
>
>
>
> I hope this is the right place for this..
> I was wondering why this: 1+'b' +    "c"cant be written like this: 1'b'     "c"
> Perhapse this can be a new feature of ES?
> greetz Cedric
>
>
>
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Re: String concatination without +

Cedric neuland
In reply to this post by Cedric neuland
It would be less to write like example below.
a='a'
console.log(`b${a}`); //7 chars
console.log('b'+a); //5 chars
console.log('b'a); //4 chars -> SyntaxError

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: String concatination without +

kdex
@Cedric: Your proposed change would break template literals. Consider this example:

```js
const tag = () => 1;
console.log(tag`test`); // Valid syntax, but no way to keep apart tagged template literals from your syntax syntactically
```
Further, with your approach, I don't see a way to take care of proper spacing between the injected variables.
How would you concatenate just two variables, `a` and `b`, without a space in between, without accidentally referencing `ab`?

Lastly, is there any considerable benefit from your proposal, apart from maybe saving a space character in certain cases?
In most real-world use cases, template literals are usually shorter than their `+` equivalent, even if you uglify your whitespace:
```js
const message1 = `Good job, ${user.name}! You've earned ${user.points} with your comment.`;
const message2 = "Good job, " + user.name + "! You've earned " + user.points + " with your comment.";
const message3 = "Good job, "+user.name+"! You've earned "+user.points+" with your comment.";
```

On Dienstag, 17. Mai 2016 19:19:59 CEST Cedric neuland wrote:
> It would be less to write like example below.
> a='a'
> console.log(`b${a}`); //7 chars
> console.log('b'+a); //5 chars
> console.log('b'a); //4 chars -> SyntaxError
>
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: String concatination without +

Bob Myers
In reply to this post by Cedric neuland
According to Brian Kernighan in "Masterminds of Programming":

"A more dubious design decision in AWK is that concatenation was expressed by adjacency, without an explicit operator; a sequence of adjacent values is just concatenated....I think that's an example of stupid design."
Bob

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: String concatination without +

Andrea Giammarchi-2
concatenation was expressed by adjacency

I've seen worst in few PL, using adjacency to justify function invocation ( you know ... bash, ES.next @decorators ... )

Although I agree with all the thing we could discuss here, this about strings is honestly, IMO, the least.

String templates + tags solved them all.

Best Regards

On Tue, May 17, 2016 at 9:19 PM, Bob Myers <[hidden email]> wrote:
According to Brian Kernighan in "Masterminds of Programming":

"A more dubious design decision in AWK is that concatenation was expressed by adjacency, without an explicit operator; a sequence of adjacent values is just concatenated....I think that's an example of stupid design."
Bob

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss