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
基于AST的代码优化
Search
flyerhzm
October 10, 2015
Programming
10
770
基于AST的代码优化
flyerhzm
October 10, 2015
Tweet
Share
More Decks by flyerhzm
See All by flyerhzm
玩转 AST
flyerhzm
0
150
Find and Replace Code based on AST
flyerhzm
0
210
Rails Performance Tips
flyerhzm
0
1.2k
Refactor ruby code based on AST
flyerhzm
4
3.5k
Write ruby code to change ruby code
flyerhzm
5
3.5k
Building Asynchronous APIs
flyerhzm
25
8.9k
构建异步API服务
flyerhzm
19
7.1k
JRuby @ OpenFeint
flyerhzm
23
3.1k
Other Decks in Programming
See All in Programming
PagerDuty を軸にした On-Call 構築と運用課題の解決 / PagerDuty Japan Community Meetup 4
horimislime
1
110
讓數據說話:用 Python、Prometheus 和 Grafana 講故事
eddie
0
350
Jakarta Concurrencyによる並行処理プログラミングの始め方 (JJUG CCC 2024 Fall)
tnagao7
1
230
Modern Angular: Renovation for Your Applications
manfredsteyer
PRO
0
200
生成 AI を活用した toitta 切片分類機能の裏側 / Inside toitta's AI-Based Factoid Clustering
pokutuna
0
570
JaSST 24 九州:ワークショップ(は除く)実践!マインドマップを活用したソフトウェアテスト+活用事例
satohiroyuki
0
260
Kubernetes for Data Engineers: Building Scalable, Reliable Data Pipelines
sucitw
1
200
飲食業界向けマルチプロダクトを実現させる開発体制とリアルな現状
hiroya0601
1
390
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
7
430
Synchronizationを支える技術
s_shimotori
1
150
外部システム連携先が10を超えるシステムでのアーキテクチャ設計・実装事例
kiwasaki
1
220
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
210
Featured
See All Featured
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.2k
What's in a price? How to price your products and services
michaelherold
243
12k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
790
Happy Clients
brianwarren
97
6.7k
Designing Experiences People Love
moore
138
23k
Navigating Team Friction
lara
183
14k
Intergalactic Javascript Robots from Outer Space
tanoku
268
27k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
Transcript
基于 AST 的代码优化 ⻩黄志敏
⾃自我介绍 • Xinmin Labs 创始⼈人 • 前 OpenFeint 资深⼯工程师 •
开源社区贡献者 • 半⻢马完赛者 • @flyerhzm
遇到的问题
代码审查
None
None
重复重复重复
None
None
解决⽅方案
CodeClimate
None
None
PullReview
None
如何做到的
开源⼯工具!
flay 分析代码结构相似度
None
flog 分析代码复杂度
None
reek 检查代码类、模块和⽅方法,报告Code Smell
None
roodi 分析并报告代码设计问题
None
rails_best_practices 针对 rails 项⺫⽬目代码检查 code smell
None
如何实现的呢
ruby 代码解析库 => AST
ParseTree • 最早的 ruby 代码解析库 • 不⽀支持 ruby 1.9 和后续版本
ruby_parser • 最流⾏行的 ruby 代码解析库 • 输出结果和 ParseTree ⼀一致
None
None
ActiveRecord::Base belongs_to :user touch :archived_at def archive
ripper • ruby 内置的解析库 • ⽀支持 ruby 的新语法
None
ActiveRecord::Base belongs_to :user def archive touch :archived_at
parser • 新的 ruby 代码解析库 • ⽀支持代码重写
None
ActiveRecord::Base belongs_to :user def archive touch :archived_at
满⾜足需求?
⾃自动修改!
transpec ⾃自动将 rspec 2 的语法转换成 rspec 3 的语法
None
None
None
rubocop 基于社区版的 ruby style guide 的代码分析和重写⼯工具
None
None
None
None
Synvert ruby 语法转换⼯工具
None
None
None
演⽰示
内部项⺫⽬目
None
None
奖励 • seeing_is_believing • method_log
参考资料 CodeClimate - https://codeclimate.com/ PullReview - https://www.pullreview.com/ flay - https://github.com/seattlerb/flay
flog - https://github.com/seattlerb/flog reek - https://github.com/troessner/reek roodi - https://github.com/roodi/roodi rails_best_practices - https://github.com/railsbp/rails_best_practices
参考资料 parsetree - https://github.com/seattlerb/parsetree ruby_parser - https://github.com/seattlerb/ruby_parser parser - https://github.com/whitequark/parser
rubocop - https://github.com/bbatsov/rubocop transpec - https://github.com/yujinakayama/transpec synvert - https://github.com/xinminlabs/synvert
招聘 fl
[email protected]
谢谢 提问