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
17
riscv64.rubyci.org internal
znz
0
14
Rubyの日本語リファレンスマニュアルの現在と未来
znz
0
63
devise-two-factorを4.xから5.xに上げた話
znz
0
270
docs.ruby-lang.org/ja/ の生成方法を変えた
znz
0
77
Ubuntuのriscv64版をqemuで動かした
znz
0
96
lilo.linux.or.jpをbusterからbullseyeに上げた
znz
0
100
小規模個人アプリをRails 7.xにバージョンアップした話
znz
0
89
Ruby リファレンスマニュアル改善計画 2022 進捗報告
znz
0
150
Other Decks in Technology
See All in Technology
意志の力が9割。アニメから学ぶAI時代のこれから。
endohizumi
1
110
AWSの最新サービスでAIエージェント構築に楽しく入門しよう
minorun365
PRO
9
530
形式手法特論:位相空間としての並行プログラミング #kernelvm / Kernel VM Study Tokyo 18th
ytaka23
3
1.5k
生成AI活用のROI、どう測る? DMM.com 開発責任者から学ぶ「AI効果検証のノウハウ」 / ROI of AI
i35_267
4
140
RAID6 を楔形文字で組んで現代人を怖がらせましょう(実装編)
mimifuwa
0
170
Autonomous Database Serverless 技術詳細 / adb-s_technical_detail_jp
oracle4engineer
PRO
18
52k
あとはAIに任せて人間は自由に生きる
kentaro
3
920
第64回コンピュータビジョン勉強会@関東(後編)
tsukamotokenji
0
190
Backlog AI アシスタントが切り開く未来
vvatanabe
1
170
新卒(ほぼ)専業Kagglerという選択肢
nocchi1
0
1.6k
AIと描く、未来のBacklog 〜プロジェクト管理の次の10年を想像し、創造するセッション〜
hrm_o25
0
110
AIドリブンのソフトウェア開発 - うまいやり方とまずいやり方
okdt
PRO
8
360
Featured
See All Featured
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
126
53k
Balancing Empowerment & Direction
lara
2
570
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
110
20k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.4k
Testing 201, or: Great Expectations
jmmastey
45
7.6k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
131
19k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
8
470
Git: the NoSQL Database
bkeepers
PRO
431
65k
Designing for humans not robots
tammielis
253
25k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3k
A Modern Web Designer's Workflow
chriscoyier
695
190k
Rebuilding a faster, lazier Slack
samanthasiow
83
9.1k
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