3 ms·
When it comes to monkeypatching, this is one thing that JS and Ruby got wrong. C# got it right. It'd be great if you could monkeypatch in JS/Ruby in a module le
by jonpaul 14y ago
When it comes to monkeypatching, this is one thing that JS and Ruby got wrong. C# got it right. It'd be great if you could monkeypatch in JS/Ruby in a module level scope vs a global scope. Good to see that Ruby is taking steps to remedy this. Too bad my favorite language, JS, hasn't yet.
- hnriot 14y agoJust write your own JS interpreter inside of JS and make sure you execute your functions inside your own interpreter and not the one provided by the browser... problem solved.
- munificent 14y agoC# had an easier time here, though, because it's statically typed. Extension methods rely entirely on static types and static binding. Getting normal method call syntax while still being lexically scoped like extension methods without opening the monkey-patching can of worms is still an open research area as far as I know. I know of classboxes, a proposal for something similar to ES Harmony (that they ended up passing on) and Ruby refinements, and that's pretty much it.
- cageface 14y agoI had a good ten year run with Ruby and I still enjoy using it for quick utility scripts but I will never again voluntarily build any large systems in a dynamically typed language. The benefits of static typing for performance, correctness, and tooling are just too valuable.
- ssmoot 14y agoI agree with the intent, but unless you're referring to something else (could well be), Extension Methods in c# aren't monkey patches. They're just semantic sugar. They didn't require new runtime support, just compiler support. Which is a neat way to go about it.