Skip to content
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

Add frozen_string_literal to every file and enforce Rubocop rule #649

Merged
merged 1 commit into from
May 10, 2018

Conversation

brandur
Copy link
Contributor

@brandur brandur commented May 10, 2018

Adds the magic frozen_string_literal: true comment to every file and
enables a Rubocop rule to make sure that it's always going to be there
going forward as well.

See here for more background [1], but the basic idea is that unlike many
other languages, static strings in code are mutable by default. This has
since been acknowledged as not a particularly good idea, and the
intention is to rectify the mistake when Ruby 3 comes out, where all
string literals will be frozen. The frozen_string_literal magic
comment was introduced in Ruby 2.3 as a way of easing the transition,
and allows libraries and projects to freeze their literals in advance.

I don't think this is breaking in any way: it's possible that users
might've been pulling out one of are literals somehow and mutating it,
but that would probably not have been useful for anything and would
certainly not be recommended, so I'm quite comfortable pushing this
change through as a minor version.

As discussed in #641.

[1] https://stackoverflow.com/a/37799399

@remi Would you mind quickly commenting as to whether you have any FUD about
this? This is a really uninteresting PR (the only change is adding a new line
to the top of every file) and the team is pretty busy this week, so I think I'm
going to just self-approve if not. Thanks!

cc @stripe/api-libraries

Adds the magic `frozen_string_literal: true` comment to every file and
enables a Rubocop rule to make sure that it's always going to be there
going forward as well.

See here for more background [1], but the basic idea is that unlike many
other languages, static strings in code are mutable by default. This has
since been acknowledged as not a particularly good idea, and the
intention is to rectify the mistake when Ruby 3 comes out, where all
string literals will be frozen. The `frozen_string_literal` magic
comment was introduced in Ruby 2.3 as a way of easing the transition,
and allows libraries and projects to freeze their literals in advance.

I don't think this is breaking in any way: it's possible that users
might've been pulling out one of are literals somehow and mutating it,
but that would probably not have been useful for anything and would
certainly not be recommended, so I'm quite comfortable pushing this
change through as a minor version.

As discussed in #641.

[1] https://stackoverflow.com/a/37799399
Copy link
Contributor

@remi-stripe remi-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure someone must be doing something somewhere that breaks our assumptions but at the same time I feel they are likely not doing it on purpose and it would help them to find that?

I'm in favor of this change and I don't think it's a breaking change either.

@brandur-stripe
Copy link
Contributor

Thanks Remi!

@brandur-stripe brandur-stripe merged commit ec66c3f into master May 10, 2018
@brandur-stripe brandur-stripe deleted the brandur-frozen-strings branch May 10, 2018 22:41
@brandur-stripe
Copy link
Contributor

Released as 3.15.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants