Dean Wampler's MindRuminations and Ruinations on Softwaretag:blog.aspectprogramming.com,2005:TypoTypo2008-04-26T16:22:59-05:00Dean Wamplerurn:uuid:4e652833-7bfc-4336-b0a3-514d83fd53dc2008-04-26T16:13:04-05:002008-04-26T16:22:59-05:00Raising a different exception in "after" or "after_raising" advice<p>An <a href="http://aquarium.rubyforge.org">Aquarium</a> user asked recently if you can use <tt>after_raising</tt> advice to raise a different exception, <i>e.g.,</i> to wrap the original exception. Now you can, with the commits I did today. (This change will appear in the forthcoming V0.4.2 release.) Actually, this feature was partially implemented already, but never finished (OOPS!)</p>
<p>The following made-up example illustrates what you can do. Imagine you are one of the handful of Ruby programmers who <i>aren’t</i> using ActiveRecord ;) and you have an OracleDriver class that handles Oracle database transactions.
<pre>
<code>
class OracleDriver
class OracleDriverException < StandardException; ...; end
class ConnectionError < OracleDriverException; ...; end
def connect
if try_to_connect == false
raise ConnectionError
end
...
end
def find query_parameters
...
end
end
</code>
</pre>
<p>In the application code that uses the <tt>OracleDriver</tt> you ignore any exceptions raised (because we will implement an exception handling strategy elsewhere…).</p>
<pre>
<code>
...
def load_object oracle_driver, query_parameters
oracle_driver.connect
oracle_driver.find query_parameters
end
...
</code>
</pre>
<p>Finally, you implement an application-wide exception handling strategy for any exceptions raised by the driver.</p>
<pre>
<code>
Aspect.new :after_raising => OracleDriverException,
:in_types => ... do |jp, object, *args|
# Ruby needs a standard way to wrap one exception in another.
original = jp.context.raised_exception
app_exception = ApplicationException.new(original.message)
app_exception.set_backtrace(original.backtrace)
jp.context.raised_exception = app_exception
end
</code>
</pre>
<p>In other words, any exceptions raised by calls to OracleDriver are wrapped in an <tt>ApplicationException</tt>, which will be thrown by Aquarium when the advice block finishes.</p>
<p>This technique can also be used when handling exceptions in <tt>after</tt> advice.</p>
<p>By the way, in a similar way, you can also change the return value in <tt>after</tt> and <tt>after_returning</tt> advice. In this case, you assign a new value to <tt>jp.context.returned_value</tt>.</p>Dean Wamplerurn:uuid:ff241292-ac4a-4a38-a82b-613e006c03742008-04-03T04:37:23-06:002008-04-03T04:39:16-06:00Short presentation Aquarium<p>I just posted the <a href="http://aspectprogramming.com/papers/Aquarium_AOP_for_Ruby_presentation.pdf"><span class="caps">PDF</span></a> for a short (30 minute) presentation on <a href="http://aquarium.rubyforge.org">Aquarium</a> that I presented to the aspect-oriented programming research community at the <a href="http://aosd.net/2008/">Aspect-Oriented Software Development 2008 Conference</a>. It assumes some familiarity with aspects, but not much experience with Ruby. The talk was based on my <a href="http://www.aosd.net/2008/program/industry.php">Industry Track</a> paper.</p>
<p>There is a <a href="http://aspectprogramming.com/papers/Aquarium_RubyAOP.pdf">longer presentation on Aquarium</a> on my <a href="http://aspectprogramming.com/papers">papers</a> page, which is better if you are new to <span class="caps">AOP</span> (although the syntax shown in the Aquarium examples is a bit dated…).</p>Dean Wamplerurn:uuid:24c72686-dc4f-4346-8342-f8b8a23107522008-02-26T12:12:25-06:002008-02-26T12:12:27-06:00ANN: Aquarium V0.4.0 Released with Initial Support for Java Aspects in Aquarium<p>The new V0.4.0 release of Aquarium adds support for JRuby. Not only do the regular “pure Ruby” Aquarium specs run reliably under JRuby (V1.1RC2), but you can now write aspects for Java types with Aquarium!</p>
<p>There are some limitations and issues. For details, see my <a href="http://blog.objectmentor.com/articles/2008/02/25/writing-java-aspects-with-jruby-and-aquarium">blog</a> at <a href="http://blog.objectmentor.com">Object Mentor</a> and the <a href="http://aquarium.rubyforge.org/jruby.html">JRuby</a> page at the Aquarium website.</p>Dean Wamplerurn:uuid:7d30889d-ea71-495e-9f6b-23c83dfd53752008-01-21T13:38:00-06:002008-01-21T13:42:06-06:00ANN: Aquarium V0.3.0 released<p>I released V0.3.0 of Aquarium today. The most visible change is a new set of synonyms for many of the parameters passed to <span class="caps">API</span> methods, providing a more “English-like” feel. For example, previously, you might declare an aspect like this:</p>
<blockquote>
<code>
around :methods => :all, :types => [Foo, Bar], :advice => advice_proc
</code>
</blockquote>
<p>
Now you can write the same aspect as follows:</p>
<blockquote>
<code>
around :calls_to => :all_methods, :within_types => [Foo, Bar], :use_advice => advice_proc
</code>
</blockquote>
<p>
which reads more like English. </p>
<p>
Similarly, attribute matching is simpler.</p>
<blockquote>
<code>
after :attribute => name, :attribute_options => [:readers], :objects => [foo, bar] ...
</code>
</blockquote>
<p>becomes</p>
<blockquote>
<code>
after :reading => name, :on_objects => [foo, bar] ...
</code>
</blockquote>
<p>
There are many internal improvements to improve <span class="caps">DRY</span>’ness, robustness, and performance.
</p>
<p>There should be no upgrade issues, so give it a try!</p>Dean Wamplerurn:uuid:8cef9449-5110-4429-84c7-5615b6fcc3ba2007-12-08T12:02:14-06:002007-12-08T12:02:15-06:00CJUG Downtown 12/18/07: Aspect-Oriented Programming and Software Design<p>I’m reprising my <a href="http://www.cjug.org/Wiki.jsp?page=2007.09.06.west"><span class="caps">CJUG</span> West talk</a> on <a href="http://www.cjug.org/Wiki.jsp?page=2007.12.18.downtown">Aspect-Oriented Programming and Software Design in Java and AspectJ</a> for the downtown Chicago group on December 18th.</p>
<p>I will briefly describe the problems that <span class="caps">AOP</span> addresses and how the principles of object-oriented design influence <span class="caps">AOP</span> and vice versa. If you’re in the area, I hope to see you <a href="http://www.cjug.org/Wiki.jsp?page=2007.12.18.downtown">there</a>.</p>Dean Wamplerurn:uuid:6928f8d3-afad-47b6-a8e0-77de878057d92007-10-20T20:50:00-05:002007-10-20T20:50:00-05:00Presentation on AOP in Academia and Industry<p>Yesterday evening, I gave a talk on <span class="caps">AOP</span> at <a href="http://www.depaul.edu/">DePaul University</a> called <em>Aspect-Oriented Programming in Academia and Industry</em>. Here’s the <a href="http://aspectprogramming.com/papers/AOP_Academia_and_Industry.pdf"><span class="caps">PDF</span></a>.</p>
<p>This talk was a little different than the usual talks I give. Since this audience was mostly students and faculty, I wanted to show how groups in both industry and academia were looking at similar problems that led to the emergence of <span class="caps">AOP</span>, how they each contributed to <span class="caps">AOP</span> in different ways, and how they can continue complementing each other’s work on emerging trends, like <a href="http://en.wikipedia.org/wiki/Language-oriented_programming">Language-Oriented Programming</a>.</p>
<p><a href="http://en.wikipedia.org/wiki/Language-oriented_programming">Language-Oriented Programming</a> is not a new idea, but it is getting renewed attention recently. I see it as a way of formalizing our understanding of how <a href="http://martinfowler.com/bliki/DomainSpecificLanguage.html">Domain-Specific Languages</a> should be designed.</p>
<p>I’m a little concerned that everyone will get so excited about crafting “elegant” DSLs that we’ll end up with a <a href="http://en.wikipedia.org/wiki/Tower_of_Babel">Tower of Babel</a> situation; lots of gratuitously-different ways of describing the same thing and no one getting much work done.</p>
<p>Anyway, we’ll see…</p>Dean Wamplerurn:uuid:46764fb9-bcc2-41dd-9946-20010e605d6b2007-10-02T14:06:00-05:002007-10-02T14:07:02-05:00Presentation on Aquarium with Exercises<p>I’ve posted a <a href="http://aspectprogramming.com/papers/Aquarium_RubyAOP.pdf"><span class="caps">PDF</span></a> for the presentation I did last night on <a href="http://aquarium.rubyforge.org/">Aquarium</a> at the Chicago Ruby Users Group (Chirb).</p>
<p>I also posted a <a href="http://aspectprogramming.com/papers/Aquarium_RubyAOP_exercises.zip">zip</a> file with three exercises that are adapted from the examples on the aquarium web site.</p>Dean Wamplerurn:uuid:5bc010d2-a2d7-462a-b851-ae7bf225a3d32007-09-29T08:30:28-05:002007-09-29T08:30:29-05:00Speaking at the Chicago Ruby Users Group (Chirb)<p>I will give a presentation on Aquarium at Chirb this Monday evening, Oct. 1st. David Chelimsky will also be speaking on new developements in RBehave and RSpec. Details are <a href="http://chirb.org/">here</a>.</p>
<p>David and I will be doing a joint presentation at the December meeting. It will be a tutorial on Ruby metaprogramming.</p>Dean Wamplerurn:uuid:049342b2-318c-4eda-b2aa-77b8a479149a2007-09-17T21:15:00-05:002007-09-29T08:26:42-05:00ANN: Aquarium v0.1.5 released<p>This is primarily a bug-fix release. I labeled it “v0.1.5” instead of “v0.1.1”, because a non-trivial <span class="caps">API</span> change was required; Aquarium no longer automatically adds methods to <code>Object</code>, due to collisions with Rails. This means that users of the “DSL methods” will need to require a new file or include a new module.</p>
<p>See the “CHANGES” file in the distribution of <a href="http://aquarium.rubyforge.org/changes.html">here</a> for more information.</p>Dean Wamplerurn:uuid:791ffd7b-7755-4f19-8f3e-d456bb059ca02007-09-13T11:19:38-05:002007-09-13T11:19:38-05:00ANN: Contract4J5 V0.8.0 Released<p>I just released V0.8.0 of <a href="http://contract4j.org/contract4j">Contract4J5</a>. This release deprecates support for JRuby (for reasons discussed in the <a href="http://www.contract4j.org/contract4j/c4j5#v0800"><span class="caps">README</span></a>) and provides general robustness improvements, especially in the area of test expression evaluation.</p>
<p>My plan is to complete all the remaining “1.0” features by the 0.9 release towards the end of the year. I hope to (finally) release 1.0 early next year.</p>
<p>Please visit the <a href="http://contract4j.org/contract4j">Contract4J</a> web site for more information.</p>