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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Kazuhiro NISHIYAMA
September 19, 2017
Technology
500
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
How to specify `frozen_string_literal: true`
RubyKaigi 2017 の LT での発表資料です。
Kazuhiro NISHIYAMA
September 19, 2017
More Decks by Kazuhiro NISHIYAMA
See All by Kazuhiro NISHIYAMA
Reforming the Japanese Ruby reference manual
znz
0
16
Rubyの配布パッケージの変遷
znz
0
51
Headscale + Tailscale に移行中
znz
0
90
Ruby on Rails と私
znz
0
88
riscv64.rubyci.org internal
znz
0
67
Rubyの日本語リファレンスマニュアルの現在と未来
znz
0
120
devise-two-factorを4.xから5.xに上げた話
znz
0
450
docs.ruby-lang.org/ja/ の生成方法を変えた
znz
0
130
Ubuntuのriscv64版をqemuで動かした
znz
0
150
Other Decks in Technology
See All in Technology
プロダクトエンジニアに必要な「いい感じ」に作る能力 〜たくさん作れる時代に、どこまで作るかの決め方〜
jnishime_dresscode
2
1.4k
ペアプロの価値はコードを書くことだけじゃない
codmoninc
PRO
0
140
V8コントリビュート超入門
riyaamemiya
0
150
コスト最適化の「めんどくさい」を AWS FinOps Agent でチョット楽にする
classmethod_kaz
0
280
AI時代に、プロダクトの数だけ積み上がる所有コストをどうエンジニアリングするか / Engineering the Cost of Ownership
kzkmaeda
1
1.1k
アリアドネの糸と、20年ごとの建て替え ── 長尾真『電子図書館』を、伊勢で読み直す / Rereading Makoto Nagao’s "Electronic Library" in Ise
ykiyota
0
100
リージョンの壁を越える、 ちょっと変わったAWSサービスの話
falken
PRO
0
270
振り返りこそエンジニアの本領
negima
0
340
[DroidKaigi 2026] Making UI specifications visible: Android UI development in the AI agent era supported by Compose Screenshot Testing and galleries
syarihu
0
610
目の前の楽しいが人生を変える - コミュニティの螺旋の歩き方と楽しむコツ / change your life
soudai
PRO
2
130
SQL文一行も書けない人事がCortexもろもろを使って人事業務を楽にしてみる
ponponmikankan
1
150
Redmine 7.0で私が開発した新機能の狙いと背景
vividtone
1
120
Featured
See All Featured
HDC tutorial
michielstock
2
850
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
450
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
Leo the Paperboy
mayatellez
8
2.2k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
320
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
190
Discover your Explorer Soul
emna__ayadi
2
1.3k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.4k
Skip the Path - Find Your Career Trail
mkilby
1
220
A better future with KSS
kneath
240
18k
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