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
12
riscv64.rubyci.org internal
znz
0
11
Rubyの日本語リファレンスマニュアルの現在と未来
znz
0
55
devise-two-factorを4.xから5.xに上げた話
znz
0
250
docs.ruby-lang.org/ja/ の生成方法を変えた
znz
0
74
Ubuntuのriscv64版をqemuで動かした
znz
0
93
lilo.linux.or.jpをbusterからbullseyeに上げた
znz
0
95
小規模個人アプリをRails 7.xにバージョンアップした話
znz
0
84
Ruby リファレンスマニュアル改善計画 2022 進捗報告
znz
0
140
Other Decks in Technology
See All in Technology
データエンジニアリング 4年前と変わったこと、 4年前と変わらないこと
tanakarian
2
330
TROCCO今昔
gtnao
0
200
Railsの限界を超えろ!「家族アルバム みてね」の画像・動画の大規模アップロードを支えるアーキテクチャの変遷
ojima_h
3
280
All About Sansan – for New Global Engineers
sansan33
PRO
1
1.2k
QAを早期に巻き込む”って どうやるの? モヤモヤから抜け出す実践知
moritamasami
2
170
20150719_Amazon Nova Canvas Virtual try-onアプリ 作成裏話
riz3f7
0
130
Shadow DOM & Security - Exploring the boundary between light and shadow
masatokinugawa
0
640
PdM業務における使い分け
shinshiro
0
540
20250718_ITSurf_“Bet AI”を支える文化とコストマネジメント
helosshi
1
200
分散トレーシングによる コネクティッドカーのデータ処理見える化の試み
thatsdone
0
150
Digitization部 紹介資料
sansan33
PRO
1
4.6k
Step Functions First - サーバーレスアーキテクチャの新しいパラダイム
taikis
1
260
Featured
See All Featured
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
331
22k
Into the Great Unknown - MozCon
thekraken
40
1.9k
A better future with KSS
kneath
238
17k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
138
34k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
33
2.4k
The Cost Of JavaScript in 2023
addyosmani
51
8.6k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
357
30k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
4 Signs Your Business is Dying
shpigford
184
22k
Typedesign – Prime Four
hannesfritz
42
2.7k
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