Hacker News new | past | comments | ask | show | jobs | submit login
Monkey-Patching, Single Responsibility Principle, and Scala Implicits (jamesgolick.com)
26 points by danielharan on Feb 9, 2010 | hide | past | favorite | 5 comments



Implicit type conversion is often noted as a misfeature of C++ and PHP. I've never used them in Scala myself, but they are highlighted as a positive feature of Scala in this article, and I am inclined to believe the author when he says they are.

The insight here was just that implicit type conversion is very bad when you don't know it's happening. When you DO know it's happening -- because you imported the conversions -- and it's used to save brainstrokes ("codetree nodes"), then it can be very helpful.


"The technique is known as monkey-patching. "

There seem to be two views of this among Rubyists. People who think this sort of practice is inherently suspect, and those who see it as no more unusual than reassigning to a variable.

The first group use the term "monkey patching"; with all of its underlying tone of ad-hoc-ery and last-resort duct tape coding.

The other group just refers to it as re-opening classes.


In C# this is called extension methods: monkey-patching (for methods) without polluting the global scope.


Like all powerful things, when used properly implicits add rather than detract from the code. In Scala's case, you can limit the scope of the implications which is just so nice. I'm not a fan-boy but it sure beats the heck out of Java.


The advantage of implicit conversions over monkey patching seems solid, but I'm not an unqualified fan of implicit conversions either. As a Scala newcomer (i.e. never written a significant app in Scala myself), I find implicit conversions hinder reading code closely enough to be able to modify or extend it. Although the original author may know which import has added some implicit conversions, why, and what they do, this isn't easy to discover after the fact.

It seems that the Idea plugin will show the implicit conversions that are actually used, but it would also be nice to see all implicits in scope at any time.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: