Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
How to specify `frozen_string_literal: true`
Kazuhiro NISHIYAMA
September 19, 2017
Technology
1
190
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
qemuのriscv64にDebianを入れてみた
znz
0
26
systemd 再入門
znz
0
120
Ruby 3.0.0 コネタ集
znz
0
100
livedoor天気API終了対応
znz
0
120
Wireguard 実践入門
znz
0
140
あまり知られていないRubyの便利機能
znz
0
140
workflow,job,step の使い分けの基準を考える
znz
0
100
Dockerのオフィシャルrubyイメージとは?
znz
0
36
チャットボットのススメ
znz
0
130
Other Decks in Technology
See All in Technology
What's Data Lake ? Azure Data Lake best practice
ryomaru0825
2
740
2024卒_freee_エンジニア職(ポテンシャル採用)_説明資料
freee
0
180
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
3
9k
さいきんのRaspberry Pi。 / osc22do-rpi
akkiesoft
5
4.9k
How to start with DDD when you have a Monolith
javujavichi
0
250
Camp Digital 2022: tailored advice
kyliehavelock
0
140
マネージャーからみたスクラムと自己管理化
shibe23
0
1k
ROS再入門-はじめてのSLAM-
miura55
0
390
MoT TechTalk #12 タクシーアプリ『GO』大規模トラフィックを捌く分析データ基盤の全容に迫る!
mot_techtalk
0
360
ソフトウェアライセンス 2022 / Software License 2022
cybozuinsideout
PRO
1
1k
The application of formal methods in Kafka reliability engineering
line_developers
PRO
0
150
Internet Explorer は Microsoft Edge へ - IE の歩みとこれから -
yuhara0928
1
3.5k
Featured
See All Featured
How GitHub Uses GitHub to Build GitHub
holman
465
280k
Atom: Resistance is Futile
akmur
255
20k
Making the Leap to Tech Lead
cromwellryan
113
7.4k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
29
4.3k
A better future with KSS
kneath
225
15k
A designer walks into a library…
pauljervisheath
196
16k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_i
23
15k
The Web Native Designer (August 2011)
paulrobertlloyd
74
1.9k
Building Flexible Design Systems
yeseniaperezcruz
310
34k
No one is an island. Learnings from fostering a developers community.
thoeni
9
1.3k
Mobile First: as difficult as doing things right
swwweet
213
7.5k
Rails Girls Zürich Keynote
gr2m
86
12k
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