Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The basic idea is adding methods to single instances. It _does_ work. What you're talking about is sugar. You could easily create a factory which manipulates instances as they are created.


Yes but you still need to inject the Factory. My point is not that Java is better than Ruby but that this style, which is commonly associated with Java, is better in any language.


Parameterizing behavior is usually a good thing in any language, yes...

The part that Python/Ruby got right is that their culture says don't parameterize until you have to. While Java culture tends to build in generality for the sake of generality, whether or not the actual system needs it. Many systems don't, but if you use typical Java libraries, you need to pay the costs for it regardless.

There was a red-flag in one of your comments above: "since you don't control the code, this technique doesn't work". If you don't control the code enough to make necessary modifications, you have a cultural problem, not a technical problem. Fix the culture, not the code. You should be building the simplest system that possibly works, not hacking around code ownership restrictions.

Parameterization is useful when you have one piece of code that you know needs to work in multiple contexts, not when you're trying to make sure a piece of code will work in all possible contexts a priori.




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

Search: