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
440
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 on Rails と私
znz
0
20
riscv64.rubyci.org internal
znz
0
15
Rubyの日本語リファレンスマニュアルの現在と未来
znz
0
65
devise-two-factorを4.xから5.xに上げた話
znz
0
320
docs.ruby-lang.org/ja/ の生成方法を変えた
znz
0
79
Ubuntuのriscv64版をqemuで動かした
znz
0
97
lilo.linux.or.jpをbusterからbullseyeに上げた
znz
0
100
小規模個人アプリをRails 7.xにバージョンアップした話
znz
0
91
Ruby リファレンスマニュアル改善計画 2022 進捗報告
znz
0
150
Other Decks in Technology
See All in Technology
オブザーバビリティが広げる AIOps の世界 / The World of AIOps Expanded by Observability
aoto
PRO
0
370
allow_retry と Arel.sql / allow_retry and Arel.sql
euglena1215
1
170
人工衛星のファームウェアをRustで書く理由
koba789
15
7.9k
品質視点から考える組織デザイン/Organizational Design from Quality
mii3king
0
200
開発者を支える Internal Developer Portal のイマとコレカラ / To-day and To-morrow of Internal Developer Portals: Supporting Developers
aoto
PRO
1
460
5年目から始める Vue3 サイト改善 #frontendo
tacck
PRO
3
220
Rustから学ぶ 非同期処理の仕組み
skanehira
1
140
Generative AI Japan 第一回生成AI実践研究会「AI駆動開発の現在地──ブレイクスルーの鍵を握るのはデータ領域」
shisyu_gaku
0
170
エラーとアクセシビリティ
schktjm
1
1.3k
2025年になってもまだMySQLが好き
yoku0825
8
4.7k
Autonomous Database - Dedicated 技術詳細 / adb-d_technical_detail_jp
oracle4engineer
PRO
4
10k
なぜテストマネージャの視点が 必要なのか? 〜 一歩先へ進むために 〜
moritamasami
0
220
Featured
See All Featured
BBQ
matthewcrist
89
9.8k
Java REST API Framework Comparison - PWX 2021
mraible
33
8.8k
Embracing the Ebb and Flow
colly
87
4.8k
The Power of CSS Pseudo Elements
geoffreycrofte
77
6k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
VelocityConf: Rendering Performance Case Studies
addyosmani
332
24k
Bash Introduction
62gerente
615
210k
Making the Leap to Tech Lead
cromwellryan
135
9.5k
Practical Orchestrator
shlominoach
190
11k
Context Engineering - Making Every Token Count
addyosmani
2
41
Navigating Team Friction
lara
189
15k
Building Better People: How to give real-time feedback that sticks.
wjessup
368
19k
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