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
410
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
Rubyの日本語リファレンスマニュアルの現在と未来
znz
0
28
devise-two-factorを4.xから5.xに上げた話
znz
0
110
docs.ruby-lang.org/ja/ の生成方法を変えた
znz
0
52
Ubuntuのriscv64版をqemuで動かした
znz
0
55
lilo.linux.or.jpをbusterからbullseyeに上げた
znz
0
65
小規模個人アプリをRails 7.xにバージョンアップした話
znz
0
50
Ruby リファレンスマニュアル改善計画 2022 進捗報告
znz
0
110
Rubyist Magazine Reboot
znz
0
150
History of Japanese Ruby reference manual, and future
znz
0
1.6k
Other Decks in Technology
See All in Technology
EMConf JP の楽しみ方 / How to enjoy EMConf JP
pauli
2
140
Amazon Q Developerで.NET Frameworkプロジェクトをモダナイズしてみた
kenichirokimura
1
190
Goで実践するBFP
hiroyaterui
1
120
Azureの開発で辛いところ
re3turn
0
240
Evolving Architecture
rainerhahnekamp
3
250
AWS re:Invent 2024 re:Cap Taipei (for Developer): New Launches that facilitate Developer Workflow and Continuous Innovation
dwchiang
0
150
.NET AspireでAzure Functionsやクラウドリソースを統合する
tsubakimoto_s
0
180
2025年の挑戦 コーポレートエンジニアの技術広報/techpr5
nishiuma
0
140
月間60万ユーザーを抱える 個人開発サービス「Walica」の 技術スタック変遷
miyachin
1
110
AWSサービスアップデート 2024/12 Part3
nrinetcom
PRO
0
140
あなたの人生も変わるかも?AWS認定2つで始まったウソみたいな話
iwamot
3
820
WantedlyでのKotlin Multiplatformの導入と課題 / Kotlin Multiplatform Implementation and Challenges at Wantedly
kubode
0
240
Featured
See All Featured
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
570
Fireside Chat
paigeccino
34
3.1k
Visualization
eitanlees
146
15k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.2k
It's Worth the Effort
3n
183
28k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
How GitHub (no longer) Works
holman
312
140k
The Language of Interfaces
destraynor
155
24k
Building Applications with DynamoDB
mza
93
6.2k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
33
2.7k
Raft: Consensus for Rubyists
vanstee
137
6.7k
How STYLIGHT went responsive
nonsquared
96
5.3k
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