New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Adjacent string literal concatenation #55

Closed
kentor opened this Issue Jul 31, 2015 · 8 comments

Comments

Projects
None yet
7 participants
@kentor

kentor commented Jul 31, 2015

This would be great when breaking up strings into multiple lines in the source code. It would save us from writing a + for every line break. This is a feature present in C, Python, and Ruby. It's most useful when your style guide enforces max characters per line and you want to keep a level of indentation.

Example:

// gettext is used for translations
gettext('This is a string literal '
        'written in multiple lines');

should be transpiled to a single string.

// gettext is used for translations
gettext('This is a string literal written in multiple lines');

Other thoughts:

  • An indented template string introduces multiple spaces in between words and line feed characters.
  • Stripping line feeds and multiple spaces is not entirely the point. Yes we can create a function that does that, but having the interpreter/compiler handle the concatenation should be more performant and the strings can be statically analyzed by tools (linting, makemessages)
@getify

This comment has been minimized.

Show comment
Hide comment
@getify

getify Jul 31, 2015

Contributor

We already have that:

gettext(`This is a string literal 
        written in multiple lines`);

See: [https://github.com/lukehoban/es6features#template-strings](Template Strings)

Contributor

getify commented Jul 31, 2015

We already have that:

gettext(`This is a string literal 
        written in multiple lines`);

See: [https://github.com/lukehoban/es6features#template-strings](Template Strings)

@michaelficarra

This comment has been minimized.

Show comment
Hide comment
@michaelficarra

michaelficarra Jul 31, 2015

Member

Those are not the same thing, @getify. @kentor's proposal would be the same as

// gettext is used for translations
gettext('This is a string literal ' +
        'written in multiple lines');
Member

michaelficarra commented Jul 31, 2015

Those are not the same thing, @getify. @kentor's proposal would be the same as

// gettext is used for translations
gettext('This is a string literal ' +
        'written in multiple lines');
@shovon

This comment has been minimized.

Show comment
Hide comment

shovon commented Jul 31, 2015

@kentor

This comment has been minimized.

Show comment
Hide comment
@kentor

kentor Aug 1, 2015

@getify @michaelficarra Right, if I were to indent the block containing the template string, I would add spaces in between literal and written. Also the \n character may not be desired.

I'm running my javascript through django's makemessages for translations, and it looks for strings in between gettext (static analysis I think). If the spaces are introduced it will think the source string has changed. I'm concatenating using + for now to avoid the problem, but it would just be a nice feature not to have to do that.

Also this could perhaps be a performance boost depending on the environment/VM. I definitely see it being transpiled to a single string without using +.

kentor commented Aug 1, 2015

@getify @michaelficarra Right, if I were to indent the block containing the template string, I would add spaces in between literal and written. Also the \n character may not be desired.

I'm running my javascript through django's makemessages for translations, and it looks for strings in between gettext (static analysis I think). If the spaces are introduced it will think the source string has changed. I'm concatenating using + for now to avoid the problem, but it would just be a nice feature not to have to do that.

Also this could perhaps be a performance boost depending on the environment/VM. I definitely see it being transpiled to a single string without using +.

@allenwb

This comment has been minimized.

Show comment
Hide comment
@shovon

This comment has been minimized.

Show comment
Hide comment
@shovon

shovon Aug 1, 2015

Also this could perhaps be a performance boost depending on the environment/VM. I definitely see it being transpiled to a single string without using +.

Yeah, that's definitely a big win.

shovon commented Aug 1, 2015

Also this could perhaps be a performance boost depending on the environment/VM. I definitely see it being transpiled to a single string without using +.

Yeah, that's definitely a big win.

@pluma

This comment has been minimized.

Show comment
Hide comment
@bterlson

This comment has been minimized.

Show comment
Hide comment
@bterlson

bterlson Sep 22, 2015

Member

Closing this now. Proposals should have an identified champion and repository set up where work happens. This is not the place to brainstorm about proposals.

Member

bterlson commented Sep 22, 2015

Closing this now. Proposals should have an identified champion and repository set up where work happens. This is not the place to brainstorm about proposals.

@bterlson bterlson closed this Sep 22, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment