Dean Wampler's Mind Ruminations and Ruinations on Software tag:blog.aspectprogramming.com,2005:Typo Typo 2008-04-26T16:22:59-05:00 Dean Wampler urn:uuid:4e652833-7bfc-4336-b0a3-514d83fd53dc 2008-04-26T16:13:04-05:00 2008-04-26T16:22:59-05:00 Raising a different exception in &quot;after&quot; or &quot;after_raising&quot; 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&#8217;t</i> using ActiveRecord ;) and you have an OracleDriver class that handles Oracle database transactions. <pre> <code> class OracleDriver class OracleDriverException &lt; StandardException; ...; end class ConnectionError &lt; 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&#8230;).</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 =&gt; OracleDriverException, :in_types =&gt; ... 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 Wampler urn:uuid:ff241292-ac4a-4a38-a82b-613e006c0374 2008-04-03T04:37:23-06:00 2008-04-03T04:39:16-06:00 Short 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&#8230;).</p> Dean Wampler urn:uuid:24c72686-dc4f-4346-8342-f8b8a2310752 2008-02-26T12:12:25-06:00 2008-02-26T12:12:27-06:00 ANN: 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 &ldquo;pure Ruby&rdquo; 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 Wampler urn:uuid:7d30889d-ea71-495e-9f6b-23c83dfd5375 2008-01-21T13:38:00-06:00 2008-01-21T13:42:06-06:00 ANN: 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 &#8220;English-like&#8221; feel. For example, previously, you might declare an aspect like this:</p> <blockquote> <code> around :methods =&gt; :all, :types =&gt; [Foo, Bar], :advice =&gt; advice_proc </code> </blockquote> <p> Now you can write the same aspect as follows:</p> <blockquote> <code> around :calls_to =&gt; :all_methods, :within_types =&gt; [Foo, Bar], :use_advice =&gt; advice_proc </code> </blockquote> <p> which reads more like English. </p> <p> Similarly, attribute matching is simpler.</p> <blockquote> <code> after :attribute =&gt; name, :attribute_options =&gt; [:readers], :objects =&gt; [foo, bar] ... </code> </blockquote> <p>becomes</p> <blockquote> <code> after :reading =&gt; name, :on_objects =&gt; [foo, bar] ... </code> </blockquote> <p> There are many internal improvements to improve <span class="caps">DRY</span>&#8217;ness, robustness, and performance. </p> <p>There should be no upgrade issues, so give it a try!</p> Dean Wampler urn:uuid:8cef9449-5110-4429-84c7-5615b6fcc3ba 2007-12-08T12:02:14-06:00 2007-12-08T12:02:15-06:00 CJUG Downtown 12/18/07: Aspect-Oriented Programming and Software Design <p>I&#8217;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&#8217;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 Wampler urn:uuid:6928f8d3-afad-47b6-a8e0-77de878057d9 2007-10-20T20:50:00-05:00 2007-10-20T20:50:00-05:00 Presentation 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&#8217;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&#8217;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&#8217;m a little concerned that everyone will get so excited about crafting &#8220;elegant&#8221; DSLs that we&#8217;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&#8217;ll see&#8230;</p> Dean Wampler urn:uuid:46764fb9-bcc2-41dd-9946-20010e605d6b 2007-10-02T14:06:00-05:00 2007-10-02T14:07:02-05:00 Presentation on Aquarium with Exercises <p>I&#8217;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 Wampler urn:uuid:5bc010d2-a2d7-462a-b851-ae7bf225a3d3 2007-09-29T08:30:28-05:00 2007-09-29T08:30:29-05:00 Speaking 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 Wampler urn:uuid:049342b2-318c-4eda-b2aa-77b8a479149a 2007-09-17T21:15:00-05:00 2007-09-29T08:26:42-05:00 ANN: Aquarium v0.1.5 released <p>This is primarily a bug-fix release. I labeled it &#8220;v0.1.5&#8221; instead of &#8220;v0.1.1&#8221;, 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 &#8220;DSL methods&#8221; will need to require a new file or include a new module.</p> <p>See the &#8220;CHANGES&#8221; file in the distribution of <a href="http://aquarium.rubyforge.org/changes.html">here</a> for more information.</p> Dean Wampler urn:uuid:791ffd7b-7755-4f19-8f3e-d456bb059ca0 2007-09-13T11:19:38-05:00 2007-09-13T11:19:38-05:00 ANN: 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 &#8220;1.0&#8221; 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>