<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Oop on cassiobotaro</title><link>https://cassiobotaro.dev/en/tags/oop/</link><description>Recent content in Oop on cassiobotaro</description><generator>Hugo</generator><language>en</language><lastBuildDate>Sat, 25 Jul 2026 13:06:19 -0300</lastBuildDate><atom:link href="https://cassiobotaro.dev/en/tags/oop/index.xml" rel="self" type="application/rss+xml"/><item><title>POOP: Python infected by Smalltalk</title><link>https://cassiobotaro.dev/en/posts/poop-python-infected-by-smalltalk/</link><pubDate>Tue, 05 May 2026 00:00:00 +0000</pubDate><guid>https://cassiobotaro.dev/en/posts/poop-python-infected-by-smalltalk/</guid><description>&lt;p&gt;&lt;img src="https://cassiobotaro.dev/images/poop.png" alt="POOP" title="The POOP project logo"&gt;&lt;/p&gt;
&lt;h2 id="a-provocation-aimed-at-object-orientation"&gt;
 A provocation aimed at object orientation
 &lt;a class="heading-link" href="#a-provocation-aimed-at-object-orientation"&gt;
 &lt;i class="fa-solid fa-link" aria-hidden="true" title="Link to heading"&gt;&lt;/i&gt;
 &lt;span class="sr-only"&gt;Link to heading&lt;/span&gt;
 &lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;There is a quote from Alan Kay that has been following me for years:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;OOP is, essentially, about message passing.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The first time I heard about it, I pretended to understand and went on writing &lt;code&gt;if&lt;/code&gt; and &lt;code&gt;for&lt;/code&gt; like always. But the idea would not leave my head. The final push came from Sandi Metz&amp;rsquo;s talk &lt;a href="https://www.youtube.com/watch?v=OMPfEXIlTVE" class="external-link" target="_blank" rel="noopener"&gt;&lt;em&gt;Nothing is Something&lt;/em&gt;&lt;/a&gt;, where she shows how to replace &lt;code&gt;nil&lt;/code&gt;, conditionals and operators with objects that respond to messages, including a &lt;code&gt;Null Object&lt;/code&gt; that knows how to behave like any other. I left it with a huge urge to make a concrete provocation to Python: what if I removed everything that &lt;em&gt;looks&lt;/em&gt; procedural, even when it isn&amp;rsquo;t? I know that &lt;code&gt;print(x)&lt;/code&gt; ends up calling &lt;code&gt;__str__&lt;/code&gt; and that &lt;code&gt;len(x)&lt;/code&gt; delegates to &lt;code&gt;__len__&lt;/code&gt;; Python&amp;rsquo;s data model is remarkably coherent in that regard. But the &lt;em&gt;look&lt;/em&gt; of those calls is that of a free function, not of a message to an object. No &lt;code&gt;if&lt;/code&gt;, no &lt;code&gt;for&lt;/code&gt;, no &lt;code&gt;print(x)&lt;/code&gt;, no &lt;code&gt;len(x)&lt;/code&gt;. Everything has to &lt;em&gt;look like&lt;/em&gt; a message sent to an object.&lt;/p&gt;</description></item><item><title>When Python Meets RPG: Rolling Dice with Style</title><link>https://cassiobotaro.dev/en/posts/dice-rolling-dsl/</link><pubDate>Sun, 01 Feb 2026 00:00:00 +0000</pubDate><guid>https://cassiobotaro.dev/en/posts/dice-rolling-dsl/</guid><description>&lt;p&gt;&lt;img src="https://cassiobotaro.dev/images/rpg.png" alt="People playing RPG" title="People playing RPG"&gt;&lt;/p&gt;
&lt;h2 id="shall-we-roll-the-dice"&gt;
 Shall we roll the dice?
 &lt;a class="heading-link" href="#shall-we-roll-the-dice"&gt;
 &lt;i class="fa-solid fa-link" aria-hidden="true" title="Link to heading"&gt;&lt;/i&gt;
 &lt;span class="sr-only"&gt;Link to heading&lt;/span&gt;
 &lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Imagine being able to write RPG dice rolls as naturally as:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#ae81ff"&gt;3&lt;/span&gt; &lt;span style="color:#f92672"&gt;*&lt;/span&gt; D6 &lt;span style="color:#f92672"&gt;+&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;2&lt;/span&gt; &lt;span style="color:#f92672"&gt;*&lt;/span&gt; D10
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;And running a roll simply with:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;(&lt;span style="color:#ae81ff"&gt;3&lt;/span&gt; &lt;span style="color:#f92672"&gt;*&lt;/span&gt; D10 &lt;span style="color:#f92672"&gt;+&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt; &lt;span style="color:#f92672"&gt;*&lt;/span&gt; D4)&lt;span style="color:#f92672"&gt;.&lt;/span&gt;roll()
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;That is possible in Python through operator overloading! Let&amp;rsquo;s create a DSL (Domain Specific Language) to make dice rolling intuitive and expressive.&lt;/p&gt;
&lt;h2 id="a-bit-of-context"&gt;
 A Bit of Context
 &lt;a class="heading-link" href="#a-bit-of-context"&gt;
 &lt;i class="fa-solid fa-link" aria-hidden="true" title="Link to heading"&gt;&lt;/i&gt;
 &lt;span class="sr-only"&gt;Link to heading&lt;/span&gt;
 &lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;In my teenage years I was an RPG game master and had a lot of fun playing Vampire: The Masquerade and Tagmar. Recently, while taking an online Smalltalk course, I came across a similar example of a dice rolling DSL. I found the idea brilliant and decided to implement it in Python! It was a lot of fun exploring how operator overloading can create such a natural and expressive interface.&lt;/p&gt;</description></item></channel></rss>