Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
How to specify `frozen_string_literal: true`
Search
Kazuhiro NISHIYAMA
September 19, 2017
Technology
1
330
How to specify `frozen_string_literal: true`
RubyKaigi 2017 の LT での発表資料です。
Kazuhiro NISHIYAMA
September 19, 2017
Tweet
Share
More Decks by Kazuhiro NISHIYAMA
See All by Kazuhiro NISHIYAMA
lilo.linux.or.jpをbusterからbullseyeに上げた
znz
0
20
小規模個人アプリをRails 7.xにバージョンアップした話
znz
0
16
Ruby リファレンスマニュアル改善計画 2022 進捗報告
znz
0
76
Rubyist Magazine Reboot
znz
0
77
History of Japanese Ruby reference manual, and future
znz
0
1.4k
qemuのriscv64にDebianを入れてみた
znz
0
88
systemd 再入門
znz
0
270
Ruby 3.0.0 コネタ集
znz
0
250
livedoor天気API終了対応
znz
0
240
Other Decks in Technology
See All in Technology
LLM とプロンプトエンジニアリング/チューターをビルドする / LLM and Prompt Engineering and Building Tutors
ks91
PRO
0
220
"好き"との生活/Regularly update profile with GitHub Actions
judeeeee
0
150
自動生成を活用した、運用保守コストを抑える Error/Alert/Runbook の一元集約管理 / Centralized management of Error/Alert/Runbook to minimize operational costs using automated code generation
biwashi
9
2.1k
複雑な構成要素を持つUIとの向き合い方 〜新・支出グラフでの実例〜 / B43 TECH TALK
nakamuuu
0
110
Databricks におけるデータエンジニアリング
databricksjapan
0
380
オブザーバビリティの Primary Signals
onk
PRO
0
550
Garoon 開発チーム / Garoon development team
cybozuinsideout
PRO
2
2.9k
Databricks における 『MLOps』
databricksjapan
2
140
0→1開発における技術選定において一番大切なこと
bicstone
1
330
[PlatformCon 24] Platform Orchestrators: The Missing Middle of Internal Developer Platforms?
danielbryantuk
1
180
プロデザ! BY リクルート vol.18_リクルートのリサーチ実践組織「リサーチブーストコミュニティ」
recruitengineers
PRO
3
240
コードを書く隙間を見つけて生きていく技術/Findy 思考の現在地
fujiwara3
24
5.2k
Featured
See All Featured
YesSQL, Process and Tooling at Scale
rocio
163
13k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
5
1.5k
RailsConf 2023
tenderlove
2
530
Building Effective Engineering Teams - LeadDev
addyosmani
27
1.8k
Product Roadmaps are Hard
iamctodd
43
9.7k
What’s in a name? Adding method to the madness
productmarketing
PRO
15
2.6k
GraphQLの誤解/rethinking-graphql
sonatard
50
9.2k
How STYLIGHT went responsive
nonsquared
92
4.8k
In The Pink: A Labor of Love
frogandcode
138
21k
Why Our Code Smells
bkeepers
PRO
331
56k
The Cost Of JavaScript in 2023
addyosmani
14
3.8k
How to Ace a Technical Interview
jacobian
272
22k
Transcript
How to specify frozen_string_literal: true Kazuhiro NISHIYAMA RubyKaigi 2017 LT
2017/09/19 Powered by Rabbit 2.2.1
self.introduce One of Ruby committers Twitter, GitHub: @znz 1/12
What’s frozen_string_literal magic comment Specify string literals are frozen or
not per fle Frozen string literals are faster Generate less objects Reduce GC 2/12
Example After coding if exist example: # -*- coding: utf-8
-*- # frozen_string_literal: true p ''.frozen? #=> true 3/12
Past release Add frozen_string_literal: false for almost *.rb fles when
Ruby 2.3.0 For compatibility with --enable=frozen-string- literal command line option of ruby 4/12
Changes in this year Recent Ruby programs tend to specify
true, but ruby standard libraries are false. So I changed to frozen_string_literal: true in some fles which assigned to no maintainer in doc/ maintainers.rdoc. 5/12
Review points before change Almost RuntimeError: can't modify frozen String
points are: String#<< bang methods (e.g. String#sub!) 6/12
Overlooked modifcation IO#read(length, out_buffer) this buffer is overlooked 7/12
Find modifed string literal --debug=frozen-string-literal command line option is very
useful examples: ruby --debug=frozen-string-literal test.rb make test-all TESTS='-v base64' RUBYOPT=--debug=frozen-string-literal 8/12
Tests --debug=frozen-string-literal needs to run codes. So tests are very
important. 9/12
No change if can’t If no tests, there is no
need to forcibly change it. I think working codes are useful than broken faster codes. 10/12
mkmf.rb mkmf.rb has many tests But mkmf.rb is too complex
to me in a short time So I remain false 11/12
Conclusion No tests may overlook modifcations Use frozen_string_literal: true if
you can You can use frozen_string_literal: false in some cases for compatibility for --enable=frozen- string-literal 12/12 Powered by Rabbit 2.2.1