<story><title>The use of ‘class’ for things that should be simple free functions (2020)</title><url>https://quuxplusone.github.io/blog/2020/05/28/oo-antipattern/</url></story><parent_chain><item><author>mojuba</author><text>I once, a long time ago, had a similar argument (somewhere online) with a bunch of Java coders. I asked them to create a library for solving quadratic equations. Asking to create a library itself was a trap of course.&lt;p&gt;Everybody came up with some solver classes in Java, some stateful, some stateless. One guy presented the most monstrous solution with 100+ lines of code where you could individually assign the coefficients, individually modify them, trigger recalculation, get the number of roots, get the roots. That guy was very proud of what he did.&lt;p&gt;Oh, I found bugs in his code. But that was considered normal. People make mistakes, right?&lt;p&gt;I showed them a two-line solution with a single function (where you&amp;#x27;d try hard to make a mistake) and nobody liked it. I was ridiculed right there, for not solving the problem &amp;quot;properly&amp;quot;.&lt;p&gt;It struck me how someone can overengineer a solution to the simplest problem &lt;i&gt;and be proud of it&lt;/i&gt;. I thought at the time this industry is screwed if this is the norm.&lt;p&gt;In fact probably some 90% of so called library code on GitHub is overenginnered crap. 90% is arbitrary but from my experience every time I look for some solution let&amp;#x27;s say for some GUI effect on iOS, find a library or a framework, take the source, analyze it, start simplifying it and I end up with a version that is orders of magnitude shorter and can be just copied into my project it&amp;#x27;s so trivial.&lt;p&gt;You realize that it was so trivial that there was no need for a library in the first place.&lt;p&gt;I liked the post about minimaism the other day here on HN [1]. It still amazes me how minimalism is not the norm, is not taught as &lt;i&gt;the only way&lt;/i&gt; you should solve problems in software engineering. There&amp;#x27;s no &amp;quot;proper&amp;quot; way other than the most minimalist one, period.&lt;p&gt;However, minimalism requires some extra effort to achieve, and that&amp;#x27;s the whole point of engineering.&lt;p&gt;[1] The post was about minimalism in programming languages, but the author had another, more general post: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;pointersgonewild.com&amp;#x2F;2018&amp;#x2F;02&amp;#x2F;18&amp;#x2F;minimalism-in-programming&amp;#x2F;&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;pointersgonewild.com&amp;#x2F;2018&amp;#x2F;02&amp;#x2F;18&amp;#x2F;minimalism-in-progra...&lt;/a&gt;&lt;p&gt;Edit: mandatory favorite essay: &lt;a href=&quot;http:&amp;#x2F;&amp;#x2F;www.paulgraham.com&amp;#x2F;power.html&quot; rel=&quot;nofollow&quot;&gt;http:&amp;#x2F;&amp;#x2F;www.paulgraham.com&amp;#x2F;power.html&lt;/a&gt;</text></item></parent_chain><comment><author>kgeist</author><text>&amp;gt;You realize that it was so trivial that there was no need for a library in the first place&lt;p&gt;Minimalism can bite you, too. We have around 30 microservices written in Go, each one one of them living in their own repository (separate codebases owned by different teams). Initially we followed Go&amp;#x27;s idiom &amp;quot;a little copying is better than a little dependency&amp;quot;. So every team simply was borrowing code snippets from other microservices&amp;#x27; codebases without creating a common shared library, because those snippets were &amp;quot;trivial&amp;quot;. Then it hit production and we found that under load&amp;#x2F;diverse user input many of those trivial functions were quite buggy or inefficient with edge cases. Since those functions&amp;#x2F;classes were copypasted over multiple codebases, now you had to contact owners of 30 repositories and coordinate bugfixing in all of them, which is slow and painful. Now we&amp;#x27;re back to having a shared library of common functions, because it&amp;#x27;s well tested  and it&amp;#x27;s easy to fix bugs by just upgrading. Often what seems trivial is not trivial at all.</text></comment>
<story><title>The use of ‘class’ for things that should be simple free functions (2020)</title><url>https://quuxplusone.github.io/blog/2020/05/28/oo-antipattern/</url></story><parent_chain><item><author>mojuba</author><text>I once, a long time ago, had a similar argument (somewhere online) with a bunch of Java coders. I asked them to create a library for solving quadratic equations. Asking to create a library itself was a trap of course.&lt;p&gt;Everybody came up with some solver classes in Java, some stateful, some stateless. One guy presented the most monstrous solution with 100+ lines of code where you could individually assign the coefficients, individually modify them, trigger recalculation, get the number of roots, get the roots. That guy was very proud of what he did.&lt;p&gt;Oh, I found bugs in his code. But that was considered normal. People make mistakes, right?&lt;p&gt;I showed them a two-line solution with a single function (where you&amp;#x27;d try hard to make a mistake) and nobody liked it. I was ridiculed right there, for not solving the problem &amp;quot;properly&amp;quot;.&lt;p&gt;It struck me how someone can overengineer a solution to the simplest problem &lt;i&gt;and be proud of it&lt;/i&gt;. I thought at the time this industry is screwed if this is the norm.&lt;p&gt;In fact probably some 90% of so called library code on GitHub is overenginnered crap. 90% is arbitrary but from my experience every time I look for some solution let&amp;#x27;s say for some GUI effect on iOS, find a library or a framework, take the source, analyze it, start simplifying it and I end up with a version that is orders of magnitude shorter and can be just copied into my project it&amp;#x27;s so trivial.&lt;p&gt;You realize that it was so trivial that there was no need for a library in the first place.&lt;p&gt;I liked the post about minimaism the other day here on HN [1]. It still amazes me how minimalism is not the norm, is not taught as &lt;i&gt;the only way&lt;/i&gt; you should solve problems in software engineering. There&amp;#x27;s no &amp;quot;proper&amp;quot; way other than the most minimalist one, period.&lt;p&gt;However, minimalism requires some extra effort to achieve, and that&amp;#x27;s the whole point of engineering.&lt;p&gt;[1] The post was about minimalism in programming languages, but the author had another, more general post: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;pointersgonewild.com&amp;#x2F;2018&amp;#x2F;02&amp;#x2F;18&amp;#x2F;minimalism-in-programming&amp;#x2F;&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;pointersgonewild.com&amp;#x2F;2018&amp;#x2F;02&amp;#x2F;18&amp;#x2F;minimalism-in-progra...&lt;/a&gt;&lt;p&gt;Edit: mandatory favorite essay: &lt;a href=&quot;http:&amp;#x2F;&amp;#x2F;www.paulgraham.com&amp;#x2F;power.html&quot; rel=&quot;nofollow&quot;&gt;http:&amp;#x2F;&amp;#x2F;www.paulgraham.com&amp;#x2F;power.html&lt;/a&gt;</text></item></parent_chain><comment><author>arinlen</author><text>&amp;gt; &lt;i&gt;I asked them to create a library (...) I showed them a two-line solution with a single function (...) and nobody liked it. I was ridiculed right there, for not solving the problem &amp;quot;properly&amp;quot;&lt;/i&gt;.&lt;p&gt;And did you solved the problem &amp;quot;properly&amp;quot;?&lt;p&gt;Odds are you did not.&lt;p&gt;I mean, it&amp;#x27;s terribly easy to come up with all sorts of two-liners if you just ignore all requirements and constraints, and don&amp;#x27;t pay attention to usecases.&lt;p&gt;This is a major problem plaguing software development. Plenty of people act like they have to carry the burden of being the only competent and smart individual in a sea of fools, and proceed to criticize everything that everyone around them does, for the sin of not doing something that exactly matches your personal opinions and tastes.</text></comment>