| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|---|
| 2 | <html xmlns="http://www.w3.org/1999/xhtml"> |
|---|
| 3 | <head> |
|---|
| 4 | <title></title> |
|---|
| 5 | |
|---|
| 6 | <link rel="stylesheet" type="text/css" href="lt.css" media="screen,tv"/> |
|---|
| 7 | <meta name="robots" content="noindex,nofollow"/> |
|---|
| 8 | |
|---|
| 9 | <script type="text/javascript" src="lib/jquery-1.2.6.min.js"></script> |
|---|
| 10 | <script type="text/javascript" src="lib/jquery.blockUI.js"></script> |
|---|
| 11 | <script type="text/javascript" src="lib/keystring.js"></script> |
|---|
| 12 | <script type="text/javascript" src="lib/lt.js"></script> |
|---|
| 13 | </head> |
|---|
| 14 | <body> |
|---|
| 15 | <div id="whole"> |
|---|
| 16 | <h1 id="top"><a href="/"></a></h1> |
|---|
| 17 | |
|---|
| 18 | <div id="content"> |
|---|
| 19 | |
|---|
| 20 | <div class="section"> |
|---|
| 21 | <h2>net-irc</h2> |
|---|
| 22 | <ul><li>cho45</li><li><a href="http://www.lowreal.net/">http://www.lowreal.net/</a></li><li>google 「ちんこ演算子の人」</li><ul><li>Chemr (きめぇwww)</li><li>JSDeferred</li><li>$X</li></ul></ul> |
|---|
| 23 | <p><br /></p> |
|---|
| 24 | </div> |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | <div class="section"> |
|---|
| 28 | <h2>Agenda</h2> |
|---|
| 29 | <ol><li>Introducing to net-irc</li><li>Applications using net-irc</li><li>Citrus IRC BOT framework</li><li>About the DSL (or something DSL-ish)</li><li>DSL in the language</li></ol> |
|---|
| 30 | |
|---|
| 31 | <p><br /></p> |
|---|
| 32 | </div> |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | <div class="section"> |
|---|
| 36 | <h2></h2> |
|---|
| 37 | <div class="title-leaf"> |
|---|
| 38 | <p>Introducing to net-irc</p> |
|---|
| 39 | </div> |
|---|
| 40 | </div> |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | <div class="section"> |
|---|
| 44 | <h2>My IRC status</h2> |
|---|
| 45 | <ul><li>irssi user</li><li>window number -> 54 (not channel num)</li><li>IRC addict</li></ul> |
|---|
| 46 | </div> |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | <div class="section"> |
|---|
| 50 | <h2>...</h2> |
|---|
| 51 | <p>I want to watch all information by IRC.</p> |
|---|
| 52 | <ul><li>twitter...</li><li>lingr...</li><li>server log...</li></ul> |
|---|
| 53 | </div> |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | <div class="section"> |
|---|
| 57 | <h2>...</h2> |
|---|
| 58 | <ul><li>Posting to mixi...</li><li>Recent hatena stars...</li><li>Posting to Hatena Haiku...</li><li>etc.. etc..</li></ul> |
|---|
| 59 | </div> |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | <div class="section"> |
|---|
| 63 | <h2>...</h2> |
|---|
| 64 | <p>But there were no library to write IRC server easily...</p> |
|---|
| 65 | <p>And I made it.</p> |
|---|
| 66 | <p><br /></p> |
|---|
| 67 | </div> |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | <div class="section"> |
|---|
| 71 | <h2>What is net-irc?</h2> |
|---|
| 72 | <ul><li><a href="http://lowreal.rubyforge.org/net-irc/">http://lowreal.rubyforge.org/net-irc/</a></li></ul> |
|---|
| 73 | <ul><li>Is IRC library</li><li>Parser from RICE by akira yamada</li><li>Has both Client and Server</li></ul> |
|---|
| 74 | <p><br /></p> |
|---|
| 75 | </div> |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | <div class="section"> |
|---|
| 79 | <h2>Changes from RICE</h2> |
|---|
| 80 | <ul><li>Violate RFC for practical issue</li><li>Don't use observer design pattern</li><li>Wrote prettily</li></ul> |
|---|
| 81 | <p><br /></p> |
|---|
| 82 | </div> |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | <div class="section"> |
|---|
| 86 | <h2>Violate RFC</h2> |
|---|
| 87 | <ul><li>no restriction on nick length</li><ul><li>RFC restrict nick length to 9 chars</li></ul><li>allow utf-8 nick</li><ul><li>allow multibyte string</li></ul><li>(extendable MODE parser)</li><ul><li>(working)</li></ul></ul> |
|---|
| 88 | </div> |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | <div class="section"> |
|---|
| 92 | <h2>Don't use observer</h2> |
|---|
| 93 | <ul><li>Observer pattern</li><ul><li>in the end, must write event dispatcher</li></ul><li>on_<var>event</var> is popular</li><li>no more charms</li></ul> |
|---|
| 94 | </div> |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | <div class="section"> |
|---|
| 98 | <h2>Wrote prettily</h2> |
|---|
| 99 | <p>Write to server socket:</p> |
|---|
| 100 | <pre>post PRIVMSG, '#foo', 'msg' |
|---|
| 101 | post NOTICE, '#foo', 'msg'</pre> |
|---|
| 102 | <p>All commands are defined as constant.</p> |
|---|
| 103 | <p>Use RFC as reference instead of net-irc reference.</p> |
|---|
| 104 | <p><br /></p> |
|---|
| 105 | </div> |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | <div class="section"> |
|---|
| 109 | <h2>Sample Client</h2> |
|---|
| 110 | <pre>class SimpleClient < Net::IRC::Client |
|---|
| 111 | def on_privmsg(m) |
|---|
| 112 | super |
|---|
| 113 | post NOTICE, m[0], m[1] # echo |
|---|
| 114 | end |
|---|
| 115 | end |
|---|
| 116 | |
|---|
| 117 | SimpleClient.new("host", 6667, { |
|---|
| 118 | :nick => "foobartest", |
|---|
| 119 | :user => "foobartest", |
|---|
| 120 | :real => "foobartest", |
|---|
| 121 | }).start</pre> |
|---|
| 122 | <p><br /></p> |
|---|
| 123 | </div> |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | <div class="section"> |
|---|
| 127 | <h2>Sample Server</h2> |
|---|
| 128 | <pre>class Sample < Net::IRC::Server::Session |
|---|
| 129 | def on_privmsg(m) |
|---|
| 130 | super |
|---|
| 131 | post "foo!foo@host", NOTICE, m[0], m[1] # echo |
|---|
| 132 | end |
|---|
| 133 | end |
|---|
| 134 | |
|---|
| 135 | Net::IRC::Server.new(opts[:host], opts[:port], Sample, opts).start</pre> |
|---|
| 136 | </div> |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | <div class="section"> |
|---|
| 140 | <h2></h2> |
|---|
| 141 | <div class="title-leaf"> |
|---|
| 142 | <p>Applications using net-irc</p> |
|---|
| 143 | </div> |
|---|
| 144 | <p><br /></p> |
|---|
| 145 | </div> |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | <div class="section"> |
|---|
| 149 | <h2>mini-blog IRC gateways</h2> |
|---|
| 150 | <ul><li>Twitter (tig.rb) like TIG</li><li>Wassr (wig.rb)</li><li>Nowa (nig.rb) すいませんまだ使ってません</li></ul> |
|---|
| 151 | <p>Suitable for practical use!</p> |
|---|
| 152 | <p>Distributed with net-irc. (examples/)</p> |
|---|
| 153 | </div> |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | <div class="section"> |
|---|
| 157 | <h2>Lingr IRC gateway</h2> |
|---|
| 158 | <ul><li>Using Linger API</li></ul> |
|---|
| 159 | <p>Suitable for practical use!</p> |
|---|
| 160 | <p>Distributed with net-irc. (examples/)</p> |
|---|
| 161 | <p>でもたまに切れる。</p> |
|---|
| 162 | </div> |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | <div class="section"> |
|---|
| 166 | <h2>...</h2> |
|---|
| 167 | <p>examples なのはテスト書くのがめんどうだから……</p> |
|---|
| 168 | </div> |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | <div class="section"> |
|---|
| 172 | <h2>昨日書いたもの</h2> |
|---|
| 173 | <p>demo</p> |
|---|
| 174 | </div> |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | <div class="section"> |
|---|
| 178 | <h2>Citrus IRC BOT framework</h2> |
|---|
| 179 | <pre>http://coderepos.org/share/wiki/Citrus</pre> |
|---|
| 180 | <ul><li>Has testing framework (using rspec)</li><li>Supports gettext</li><li>Has dynamic re-loading plugins</li></ul> |
|---|
| 181 | <p>coderepos++</p> |
|---|
| 182 | </div> |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | <div class="section"> |
|---|
| 186 | <h2>Citrus</h2> |
|---|
| 187 | <ul><li>Sample: chokan @freenode (registered)</li></ul> |
|---|
| 188 | <p><br /></p> |
|---|
| 189 | </div> |
|---|
| 190 | |
|---|
| 191 | |
|---|
| 192 | <div class="section"> |
|---|
| 193 | <h2>Citrus plugin</h2> |
|---|
| 194 | <ul><li>Plugin tests are in same file!</li><li>Use RSpec</li><li>DummyCore class for test</li></ul> |
|---|
| 195 | <ul><li><a href="http://lab.lowreal.net/test/citrus/">http://lab.lowreal.net/test/citrus/</a></li></ul> |
|---|
| 196 | <p><br /></p> |
|---|
| 197 | </div> |
|---|
| 198 | |
|---|
| 199 | |
|---|
| 200 | <div class="section"> |
|---|
| 201 | <h2>Citrus plugin</h2> |
|---|
| 202 | <pre>class SimpleReply < Citrus::Plugin |
|---|
| 203 | def on_privmsg(prefix, channel, message) |
|---|
| 204 | # do... |
|---|
| 205 | end |
|---|
| 206 | end |
|---|
| 207 | |
|---|
| 208 | test do |
|---|
| 209 | # run when test |
|---|
| 210 | describe SimpleReply do |
|---|
| 211 | before :all do |
|---|
| 212 | @core = DummyCore.new({}) |
|---|
| 213 | @socket = @core.socket |
|---|
| 214 | |
|---|
| 215 | @plugin = SimpleReply.new(@core, { |
|---|
| 216 | "SimpleReply" => { config } |
|---|
| 217 | }) |
|---|
| 218 | end |
|---|
| 219 | |
|---|
| 220 | it "should ..." do |
|---|
| 221 | end |
|---|
| 222 | end |
|---|
| 223 | end</pre> |
|---|
| 224 | <p><br /></p> |
|---|
| 225 | </div> |
|---|
| 226 | |
|---|
| 227 | |
|---|
| 228 | <div class="section"> |
|---|
| 229 | <h2></h2> |
|---|
| 230 | <div class="title-leaf"> |
|---|
| 231 | <p>About the DSL</p> |
|---|
| 232 | </div> |
|---|
| 233 | </div> |
|---|
| 234 | |
|---|
| 235 | |
|---|
| 236 | <div class="section"> |
|---|
| 237 | <h2>It's DSL</h2> |
|---|
| 238 | <pre># client |
|---|
| 239 | post PRIVMSG, "#foo", "bar" |
|---|
| 240 | |
|---|
| 241 | # server |
|---|
| 242 | post prefix, PRIVMSG, "#foo", "bar</pre> |
|---|
| 243 | <p><br /></p> |
|---|
| 244 | </div> |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | <div class="section"> |
|---|
| 248 | <h2>Effective utilzation of Constant</h2> |
|---|
| 249 | <pre>PRIVMSG = 'PRIVMSG' |
|---|
| 250 | NOTICE = 'NOTICE' |
|---|
| 251 | ... |
|---|
| 252 | RPL_WELCOME = '001'</pre> |
|---|
| 253 | <p>I don't want to use String.</p> |
|---|
| 254 | <ul><li>It mades typo.</li><li>It is not pretty.</li></ul> |
|---|
| 255 | </div> |
|---|
| 256 | |
|---|
| 257 | |
|---|
| 258 | <div class="section"> |
|---|
| 259 | <h2></h2> |
|---|
| 260 | <div class="title-leaf"> |
|---|
| 261 | <p>DSL in the language</p> |
|---|
| 262 | </div> |
|---|
| 263 | <p><br /></p> |
|---|
| 264 | </div> |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | <div class="section"> |
|---|
| 268 | <h2>...</h2> |
|---|
| 269 | <pre>post PRIVMSG, "#foo", "bar"</pre> |
|---|
| 270 | <p>DSL...?</p> |
|---|
| 271 | <p>Maybe not.</p> |
|---|
| 272 | </div> |
|---|
| 273 | |
|---|
| 274 | |
|---|
| 275 | <div class="section"> |
|---|
| 276 | <h2></h2> |
|---|
| 277 | <p>Often, I try to make DSL.</p> |
|---|
| 278 | <p>But I assessed that DSL is irrelevance for this library..</p> |
|---|
| 279 | <p><br /></p> |
|---|
| 280 | </div> |
|---|
| 281 | |
|---|
| 282 | |
|---|
| 283 | <div class="section"> |
|---|
| 284 | <h2>DSL bad example</h2> |
|---|
| 285 | <ul><li>scrAPI</li></ul> |
|---|
| 286 | <pre>ebay_auction = Scraper.define do |
|---|
| 287 | process "h3.ens>a", :description=>:text, :url=>"@href" |
|---|
| 288 | process "td.ebcPr>span", :price=>:text |
|---|
| 289 | process "div.ebPicture>a>img", :image=>"@src" |
|---|
| 290 | result :description, :url, :price, :image |
|---|
| 291 | end</pre> |
|---|
| 292 | <p>Can't understand the purpose at first view.</p> |
|---|
| 293 | <p>某所で scrAPI なコードをメンテしたとき発狂しそうだった</p> |
|---|
| 294 | </div> |
|---|
| 295 | |
|---|
| 296 | |
|---|
| 297 | <div class="section"> |
|---|
| 298 | <h2>DSL bad example - scrAPI</h2> |
|---|
| 299 | <ul><li>what is second argument of process</li><li>need to look the reference</li><li>lerning cost > convenience</li><li>mechanize and hpricot is better</li></ul> |
|---|
| 300 | <p><br /></p> |
|---|
| 301 | </div> |
|---|
| 302 | |
|---|
| 303 | |
|---|
| 304 | <div class="section"> |
|---|
| 305 | <h2>DSL good examples</h2> |
|---|
| 306 | <ul><li>Rake</li><li>RSpec</li></ul> |
|---|
| 307 | <p><br /></p> |
|---|
| 308 | </div> |
|---|
| 309 | |
|---|
| 310 | |
|---|
| 311 | <div class="section"> |
|---|
| 312 | <h2>DSL good examples - Rake</h2> |
|---|
| 313 | <pre>desc "Publish to RubyForge" |
|---|
| 314 | task :rubyforge => [:rdoc, :package] do |
|---|
| 315 | require 'rubyforge' |
|---|
| 316 | Rake::RubyForgePublisher.new(RUBYFORGE_PROJECT, 'fobar').upload |
|---|
| 317 | end</pre> |
|---|
| 318 | <p>Good example of hash arrow to represent dependency.</p> |
|---|
| 319 | <p><br /></p> |
|---|
| 320 | </div> |
|---|
| 321 | |
|---|
| 322 | |
|---|
| 323 | <div class="section"> |
|---|
| 324 | <h2>DSL good examples - RSpec</h2> |
|---|
| 325 | <pre>obj.should == "foo" |
|---|
| 326 | foo.should be_true</pre> |
|---|
| 327 | <p>Easy to read, easy to write.</p> |
|---|
| 328 | <p><br /></p> |
|---|
| 329 | </div> |
|---|
| 330 | |
|---|
| 331 | |
|---|
| 332 | <div class="section"> |
|---|
| 333 | <h2>DSL good examples</h2> |
|---|
| 334 | <ul><li>Rake</li><li>RSpec</li></ul> |
|---|
| 335 | <p>Can understand the purpose at first view!</p> |
|---|
| 336 | <p><br /></p> |
|---|
| 337 | </div> |
|---|
| 338 | |
|---|
| 339 | |
|---|
| 340 | <div class="section"> |
|---|
| 341 | <h2>So, DSL requires...</h2> |
|---|
| 342 | <ul><li>Readable!</li><ul><li>not requires precedent</li></ul><li>Writable!</li><ul><li>not relying on reference</li></ul></ul> |
|---|
| 343 | </div> |
|---|
| 344 | |
|---|
| 345 | |
|---|
| 346 | <div class="section"> |
|---|
| 347 | <h2>DSL's problems</h2> |
|---|
| 348 | <ul><li>hard to trace process</li><li>hard to know Class defining the method</li><li>IT IS A LANGUAGE.</li><ul><li>It is difficult to design a language.</li></ul></ul> |
|---|
| 349 | <p><br /></p> |
|---|
| 350 | </div> |
|---|
| 351 | |
|---|
| 352 | |
|---|
| 353 | <div class="section"> |
|---|
| 354 | <h2></h2> |
|---|
| 355 | <p>Any sufficiently designed DSL is indistinguishable from NEW language.</p> |
|---|
| 356 | <p>高度に発達した DSL は新言語と見分けがつかない</p> |
|---|
| 357 | <p><br /></p> |
|---|
| 358 | </div> |
|---|
| 359 | |
|---|
| 360 | |
|---|
| 361 | <div class="section"> |
|---|
| 362 | <h2></h2> |
|---|
| 363 | <p>Think before using DSL!</p> |
|---|
| 364 | <p><br /></p> |
|---|
| 365 | </div> |
|---|
| 366 | |
|---|
| 367 | |
|---|
| 368 | <div class="section"> |
|---|
| 369 | <h2>End</h2> |
|---|
| 370 | <p>Thank you</p> |
|---|
| 371 | </div> |
|---|
| 372 | |
|---|
| 373 | |
|---|
| 374 | </div> |
|---|
| 375 | |
|---|
| 376 | <div id="footer"> |
|---|
| 377 | <address>© 2008 cho45@lowreal.net</address> |
|---|
| 378 | </div> |
|---|
| 379 | </div> |
|---|
| 380 | </body> |
|---|
| 381 | </html> |
|---|