14 ms·
Trailing closures turn out to be magic when creating APIs and mini-DSLs. That slight reduction of friction that unifies regular language syntax with user-define
by jayvanguard 12y ago
Trailing closures turn out to be magic when creating APIs and mini-DSLs. That slight reduction of friction that unifies regular language syntax with user-defined functions is often the difference between a high usable extension and a kludge.
- mikeash 12y agoDo you happen to have any good examples? They look like a great feature but I'm less familiar with how they've already been used in other languages.
- chc 12y agoI think Ruby is the major banner-carrier for this feature. It is actually more awkward in Ruby to have non-trailing closures.
- bronxbomber92 12y agoScala is full of many libraries that take advantage of trailing closures. I think their standard library Future/Promise API is good example: http://docs.scala-lang.org/overviews/core/futures.html http://docs.scala-lang.org/overviews/core/futures.html Edit: Another popular one is the ScalaTest unit testing framework: http://www.scalatest.org http://www.scalatest.org
- jayvanguard 12y agoTake a look at one of the tutorials on writing a Ruby DSL. E.g. http://rubylearning.com/blog/2010/11/30/how-do-i-build-dsls-with-yield-and-instance_eval/ http://rubylearning.com/blog/2010/11/30/how-do-i-build-dsls-...