Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.
This repository was archived by the owner on Jan 25, 2022. It is now read-only.

please consider different syntax for replacement targets #39

@getify

Description

@getify

I'm concerned about the readability hazard of the current proposed syntax for named string replacement targets:

let result = '2015-01-02'.replace(re, '$<day>/$<month>/$<year>');

First, the common usage of ' is so close to ` that it will be very easy to visually mistake that as an interpolated string (aka template string). That's made much worse if the suggested alternative of ${ .. } syntax is used, so please don't do that.

But as an anecdote of the readability hazard, before I read the surrounding text explaining, I glanced at the code snippet, and my brain thought the < was a typo for { and the ' was a `, and that the intent of the proposal was to use template strings (which I was immediately going to scoff at, until I read the text). I can't imagine I'll be the only one who may, on glancing at code, get confused.

I understand all the nice symmetry and reasons why. But I think this readability hazard leans in favor of a more-different syntax.

Would you consider any of these options (or something like them)?

let result = '2015-01-02'.replace(re, '@{day}/@{month}/@{year}');

let result = '2015-01-02'.replace(re, '#{day}/#{month}/#{year}');

let result = '2015-01-02'.replace(re, '$day$/$month$/$year$');

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions