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
330
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
lilo.linux.or.jpをbusterからbullseyeに上げた
znz
0
20
小規模個人アプリをRails 7.xにバージョンアップした話
znz
0
16
Ruby リファレンスマニュアル改善計画 2022 進捗報告
znz
0
76
Rubyist Magazine Reboot
znz
0
79
History of Japanese Ruby reference manual, and future
znz
0
1.4k
qemuのriscv64にDebianを入れてみた
znz
0
88
systemd 再入門
znz
0
270
Ruby 3.0.0 コネタ集
znz
0
250
livedoor天気API終了対応
znz
0
240
Other Decks in Technology
See All in Technology
アクセシビリティを考慮したUI/CSSフレームワーク・ライブラリ選定
yajihum
2
980
ここが嬉しいABAC ここが辛いよABAC #再解説+補足編
masahirokawahara
1
260
Next'24 事例セッションの紹介とクラウド資格を活用したキャリア形成について語りMuscle
yasumuusan
1
410
SIEMを用いて、セキュリティログ分析の可視化と分析を実現し、PDCAサイクルを回してみた
coconala_engineer
0
270
On Your Data を超えていく!
hirotomotaguchi
2
610
Vertex AI を中心に 生成AIのアップデートを共有します
kaz1437
0
270
Terraformあれやこれ/terraform-this-and-that
emiki
8
1.3k
WebアプリケーションにおけるPDOの使い方入門 / phpcon odawara 2024
meihei3
2
440
Delivering Millions of Messages within seconds @ Duolingo
pelelgrino
0
340
AWS を使う上で知っておきたいオンプレミス知識/aws-on-premise-essentials
emiki
1
4.3k
Hands-on / Kaname Frusawa / Cloud Compare Users Meetup 2024 at University of Tokyo on April 17
paraworld
2
480
VS CodeでAWSを操作しよう
smt7174
7
1.6k
Featured
See All Featured
Product Roadmaps are Hard
iamctodd
43
9.7k
Optimizing for Happiness
mojombo
370
69k
The Pragmatic Product Professional
lauravandoore
24
5.8k
The Art of Programming - Codeland 2020
erikaheidi
41
12k
From Idea to $5000 a Month in 5 Months
shpigford
377
45k
Clear Off the Table
cherdarchuk
83
310k
[RailsConf 2023] Rails as a piece of cake
palkan
22
3.9k
Debugging Ruby Performance
tmm1
70
11k
Building a Modern Day E-commerce SEO Strategy
aleyda
16
6.4k
Build your cross-platform service in a week with App Engine
jlugia
225
17k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
226
16k
Ruby is Unlike a Banana
tanoku
96
10k
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