<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Generics on Roads Less Taken</title><link>https://goran.krampe.se/categories/generics/</link><description>Recent content in Generics on Roads Less Taken</description><generator>Hugo</generator><language>en</language><lastBuildDate>Fri, 31 Oct 2014 00:00:00 +0000</lastBuildDate><atom:link href="https://goran.krampe.se/categories/generics/index.xml" rel="self" type="application/rss+xml"/><item><title>Nim and OO, Part II</title><link>https://goran.krampe.se/2014/10/31/nim-and-oo-part-ii/</link><pubDate>Fri, 31 Oct 2014 00:00:00 +0000</pubDate><guid>https://goran.krampe.se/2014/10/31/nim-and-oo-part-ii/</guid><description>&lt;p>In the &lt;a href="https://goran.krampe.se/2014/10/29/nim-and-oo" >previous article&lt;/a>
 when I explored OO mechanisms in &lt;a href="http://nim-lang.org" target="_blank" rel="noopener noreferrer">Nim&lt;/a>
 I felt I dropped the ball a bit in my Fruit example. This is a followup.&lt;/p>
&lt;p>In that article we first implemented some Fruit &amp;ldquo;classes&amp;rdquo; mixing methods and procs. Then I presented a cleaned up version using methods only, and a teeny template in order to reuse a base method. This template was needed since Nim currently doesn&amp;rsquo;t have a &amp;ldquo;call-next-method-matching&amp;rdquo; for multimethods like Dylan or CLOS have. This is being discussed and I think all agree that there needs to be &lt;strong>some&lt;/strong> mechanism so that you can call a &amp;ldquo;next lesser match&amp;rdquo; of all matching multimethods.&lt;/p>
&lt;p>But I also wrote that the example &lt;strong>can be written perfectly well using generics and procs only&lt;/strong>, thus ensuring static binding and maximum speed. But the &amp;ldquo;super call&amp;rdquo; problem also existed for procs, and the template hack was just a hack. After more experimentation I now &lt;strong>think I found the proper Nim way&lt;/strong> to do this so let&amp;rsquo;s take a look&amp;hellip;&lt;/p></description></item><item><title>Nim and OO, Part III</title><link>https://goran.krampe.se/2014/10/31/nim-and-oo-part-iii/</link><pubDate>Fri, 31 Oct 2014 00:00:00 +0000</pubDate><guid>https://goran.krampe.se/2014/10/31/nim-and-oo-part-iii/</guid><description>&lt;p>So previously in &lt;a href="https://goran.krampe.se/2014/10/31/nim-and-oo-part-ii" >Nim and OO Part II&lt;/a>
 we saw how we could solve the &amp;ldquo;super call&amp;rdquo; issue using only procs and generics in &lt;a href="http://nim-lang.org" target="_blank" rel="noopener noreferrer">Nim&lt;/a>
. This means that all code is statically bound.&lt;/p>
&lt;p>But if you have read all these article you know I also tried the more appropriate mechanism for OO - so called &lt;strong>methods&lt;/strong>. In Nim a proc is a regular statically bound function, simple and fast. A &lt;strong>method&lt;/strong> on the other hand uses dynamic multimethod dispatch on the &lt;strong>runtime types&lt;/strong> of all object parameters. The easy way to do objects in Nim (with inheritance of behavior) is using methods - but of course, this means dynamic lookup that has a runtime cost, but quite small as we will see.&lt;/p>
&lt;p>Time for benchmarking!&lt;/p></description></item></channel></rss>