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
430
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の日本語リファレンスマニュアルの現在と未来
znz
0
42
devise-two-factorを4.xから5.xに上げた話
znz
0
170
docs.ruby-lang.org/ja/ の生成方法を変えた
znz
0
63
Ubuntuのriscv64版をqemuで動かした
znz
0
79
lilo.linux.or.jpをbusterからbullseyeに上げた
znz
0
79
小規模個人アプリをRails 7.xにバージョンアップした話
znz
0
68
Ruby リファレンスマニュアル改善計画 2022 進捗報告
znz
0
130
Rubyist Magazine Reboot
znz
0
180
History of Japanese Ruby reference manual, and future
znz
0
1.6k
Other Decks in Technology
See All in Technology
Webアプリを Lambdaで動かすまでに考えること / How to implement monolithic Lambda Web Application
_kensh
7
1.3k
新卒エンジニアがCICDをモダナイズしてみた話
akashi_sn
2
230
Road to Go Gem #rubykaigi
sue445
0
450
AWSの新機能検証をやる時こそ、Amazon Qでプロンプトエンジニアリングを駆使しよう
duelist2020jp
1
170
AIコーディングの最前線 〜活用のコツと課題〜
pharma_x_tech
3
1.3k
ブラウザのレガシー・独自機能を愛でる-Firefoxの脆弱性4選- / Browser Crash Club #1
masatokinugawa
1
470
Amazon CloudWatch を使って NW 監視を行うには
o11yfes2023
0
160
OSSコントリビュートをphp-srcメンテナの立場から語る / OSS Contribute
sakitakamachi
0
1.4k
Creating Awesome Change in SmartNews
martin_lover
1
280
ElixirがHW化され、最新CPU/GPU/NWを過去のものとする数万倍、高速+超省電力化されたWeb/動画配信/AIが動く日
piacerex
0
140
Terraform Cloudで始めるおひとりさまOrganizationsのすゝめ
handy
2
180
ソフトウェア開発現代史: "LeanとDevOpsの科学"の「科学」とは何か? - DORA Report 10年の変遷を追って - #DevOpsDaysTokyo
takabow
0
380
Featured
See All Featured
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
19
1.1k
Mobile First: as difficult as doing things right
swwweet
223
9.6k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Typedesign – Prime Four
hannesfritz
41
2.6k
KATA
mclloyd
29
14k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.1k
GraphQLとの向き合い方2022年版
quramy
46
14k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
227
22k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
Measuring & Analyzing Core Web Vitals
bluesmoon
7
390
RailsConf 2023
tenderlove
30
1.1k
BBQ
matthewcrist
88
9.6k
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