4 ms·
It is the language plus the community. And not just the language. As an example, there is nothing about Ruby that makes it more or less prone to monkey-patchi
by btilly 7y ago
It is the language plus the community. And not just the language.
As an example, there is nothing about Ruby that makes it more or less prone to monkey-patching than many other dynamic languages. But once a certain number of popular frameworks did that, there was no getting away from that. (Rails even has a convention around where you put your monkey patches.)
- deleted 7y ago[deleted]
- joelbluminator 7y agoYou're talking about ActiveSupport probably, and I really love it. It augments Ruby in a very beautiful way. I really like 2.days.ago There were zero times were I wished it wouldn't do that. But to each his own.
- pas 7y agoSupporting postfix operators, extension methods, etc. is different from monkey patching. Scala has "2 days ago" conversion to Duration type via implicits, but it doesn't monkey patches Integer for that. C# has extension methods and it can do the same without monkey patching. And monkey patching is not necessarily the end of the world, it's just error prone if multiple libs try to do it (on the same targets) without being careful.
- joelbluminator 7y agoNever said you can't reach the same outcome with other languages. I guess C# can do DateTime.Today.AddDays(-3). It's all turing complete, so yes, you can do it in assembly as well. I just really love Ruby's (Rails actually) 2.days.ago and never saw the harm in that. It's readable, easy and nice.
- sethammons 7y agoReadable yes. I don't feel it is writable. Discovery only happens when you read what someone else did or you guess unless you read over the entire docs related to $thing. It is a major reason I dislike Ruby as these things are encouraged. In testing, it is even worse. Made up DSL: Expect(myFunc).WithParams(4).To().BeCalled(1).Returns(8).InUnder(2). Milliseconds().WithEspilon(30).Microseconds(). You have to be fully familiar with a custom DSL to write this kind of test. I prefer Go's principal of "tests are just code." It is more verbose to write, but no custom DSL to learn. The more verbose code is often not harder to read either as it is the same code style as the application too.
- joelbluminator 7y agoRuby's default test suite is minitest, not RSpec. I agree that RSpec can be overkill sometimes. And well, libraries and frameworks expect you to go over their docs if u wanna use them, that's kinda universal. Can u write a Spring MVC app without going over he docs?
- jspash 7y agoYou'd be lucky if it was all just a chain of methods. In reality one of those links would be replaced by space. Which is an implicit method call. (Invisible parenthesis) I find this infuriating because the DSL isn't discoverable. You have to know what each method returns. Is it self, or is it a value. Spot the difference: Expect(myFunc).WithParams(4).To BeCalled(1).Returns(8).InUnder(2). Milliseconds().WithEspilon(30).Microseconds().
- pas 7y agoWhy isn't it discoverable? You know what type is returned by "To()" and if that has a BeCalled() method you can call it :) Now, the problem that requires an IDE, that many curse Scala for comes in when you have implicit things. So even if "To()" returns a WhateverTestDslElement that might not tell you anything because there might be a hundred implicit functions that convert WhateverTestDslElement to OtherFancyDslThingWithTheMethodYouAreLookingFor. Of course, at this point you are basically back to reading the documentation, which is kind of what C programming looks like. That said efficient and useful and really "domain specific" layers are great, and many systems would benefit from one. (Which is sort of what the whole clean code "entities" is about - https://blog.cleancoder.com/uncle-bob/images/2012-08-13-the-clean-architecture/CleanArchitecture.jpg https://blog.cleancoder.com/uncle-bob/images/2012-08-13-the-... )
- btilly 7y agoEver encountered code where you have to load 2 modules in a particular order or else they don’t work? Or maybe you didn’t figure out why a module that works fine for others doesn’t for you. Monkey patching is one of the top causes of that. And is part of why Ruby projects tend not to scale in complexity as well as Python.
- joelbluminator 7y agoIt's quite rare to be honest, so no. And I've been doing Ruby for a long time. It's not like every Ruby developer out there tries to monkey patch esoteric things just to confuse the enemy. And again, monkey patching is possible in every dynamic language.
- joelbluminator 7y agoI"ve seen a developer break 20000 websites at once because he monkey patched a jquery method in a widget our company built, so lets not make this out to be a Ruby thing.
- btilly 7y agoIf it is rare, then I must be unlucky. Because I'm not a Ruby developer, but I have had to help people diagnose exactly that problem more than once.
- chipperyman573 7y agoFor anyone (like me) who doesn't know what monkey patching is, wikipedia says it is "dynamic modifications of a class or module at runtime, motivated by the intent to patch existing third-party code as a workaround to a bug or feature which does not act as desired" https://en.wikipedia.org/wiki/Monkey_patch https://en.wikipedia.org/wiki/Monkey_patch
- Izkata 7y agoFor anyone further curious, this is how python's `mock` module works - structured application and removal of monkeypatches.
- pansa2 7y ago> there is nothing about Ruby that makes it more or less prone to monkey-patching than many other dynamic languages. Python disallows making changes to fundamental types like `int` and `list`. It’s not possible for a Python framework to support something like Rails’ `2.days.ago`. Interestingly, I don’t think this was an explicit decision made when designing Python - it’s just a side effect of the built-in types being written in C rather than in Python itself.
- switch007 7y ago> Python disallows making changes to fundamental types like `int` and `list`. Not directly via Python but you can achieve if it you really want https://github.com/clarete/forbiddenfruit https://github.com/clarete/forbiddenfruit :D
- btilly 7y agoTrue, more things are objects in Ruby than Python. But you can still monkeypatch classes in Python.