or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing
xxxxxxxxxx
你這段 Ruby Code 超速摟,已經沒有人看得懂了! - 蒼時弦也
tags:
COSCUP2020
中階
TR411
歡迎來到 https://hackmd.io/@coscup/2020 共筆
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →點擊本頁上方的 開始用 Markdown 一起寫筆記!
手機版請點選上方 按鈕展開議程列表。
簡報:https://speakerdeck.com/elct9620/2020-coscup-ni-zhe-duan-ruby-code-chao-su-lou-yi-jing-mei-you-ren-kan-de-dong-liao
接下來會讓大家知道,什麼叫做步驟拆開來都會,合起來完全不會。
DSL,針對特定情境所設計的語言。
以前常聽到的笑話,有人說他會Rails語言。咦Rails不是個framework嗎什麼時候變成一個語言。就像是這個樣子。
DSL算是實現meta programming的一種方法。
那麼第一件事情,我們要知道要怎麼做一個DSL。
既然我們可以在new裡面設定一些屬性,那我們也可以讀一個YAML做這件事情。
@topic[4]
the eval way@topic[5]
Unlight - Code Generator前面我們看到的叫分解動作。我們現在看看合起來的樣子。
裡面有一堆找不到的method。
為什麼需要動態產生method。
不像我們現在用json。這個遊戲是十幾年前的時代,網路還不快,要盡可能縮減傳輸的資料。
它用ruby生成了一段ruby code然後用ruby執行。
@topic[6]
接下來,你以為Unlight這麼簡單嗎。
感覺這個人是個資工學霸。
什麼招式都會使出來。
class CheckAdditionalDrawPassiveEvent < EventRule
確認一個角色的被動技會不會發動。
它把所有角色的技能都寫在同一個檔案。
所以你code寫不到10行為什麼裡面會有兩萬多行。
你以為它只有兩萬行嗎,其實它又生成了更多ruby code給你。
DuelController
這個controller很high。
c.add_finsish_listener_on_feat_event
在十幾年前的時候試圖在ruby裡面使用跟javascript一樣的東西。
要怎麼改進
class ImprovedCodeGenerator
在module_eval的時候告訴他這是哪一個檔案的第幾行生出來的。
但是很遺憾的這是 Ruby 1.9 或 1.8 的時候,所以沒有這個功能。
instance_eval + here doc
其實一部分問題是變數命名。你看它的f、c、q這些變數。你看到前面的c然後就要一直記住c是什麼。或是看很久才發現q這個變數的意思是query。
測試
要測試這些生成出來的東西是可行的,前提是你要記得你有生成這個method才能對它寫測試。