The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
Although in some strange realm that may be something one needs to do, if one were writing their own strlen(...), would it not be better to give it its own name, too? Or maybe create some weird-ass overload if the language permits it?
On the other hand, if it's scope is wide enough, think of the fun you could have with other members of some team when their code goes insane for no discernible reason.
You can add methods right to core classes! You don’t have to call Time.now.advance(days: -1), you can write 1.day.ago! It makes Ruby a joy to read and write. Until…
You hit weird bugs because a patch changed Hash.
You get confused about which code actually ran, so you can’t debug it when it breaks.
And you finally figure out that all your problems were caused six months ago, when you monkey-patched Enumerable to make one line of code five characters shorter.
That example perfectly encapsulates one of the issues of modern programming languages. History repeats itself, as programmers in the 90's mistook less lines of code, with obfuscated one-liners.
Now the line's not obfuscated, but you're still sacrificing so much... for a few lines of code.
If I remember right, PHP did not have anything like namespaces. I think this was their grand alternative to solving name collision. Just what I would expect from guys playing around with a badly thought through interpreter.
I have lived with several Zen masters - all of them were cats.
His last invention was an evil Lasagna. It didn't kill anyone, and it actually tasted pretty good.
Someone told me that in Forth, every token is a symbol of a defined value. So you may define 3.14159 to have the value 3.0. Or to have the symbol 3 have the value 17. I never programmed in Forth, so I never tested out if this is true. If it is ...
What do you achieve that is different from an "override" or something as primitive as providing a subclass implementation of a virtual function?
Once you let the cats loose, you loose control of them. You can't say "Define your own functions by providing implementation of virtual functions, but in no other way!" Once you have opened the cage, they run loose. There is not that much difference between providing an alternate virtual function definition from replacing one real function definition by another one.
Maybe not this specific example, but you could use it in testing (similar to monkey patching functions for unit tests in other languages).
I’d never recommend using monkey patching in production code. It is helpful in unit testing though to patch functions outside the unit or to patch database access functions during unit testing. This is, of course, provided you unpatch the function at the end of the test.
Not too sure if PHP has a defer mechanism for unpatching when the function is no longer in scope, but that is one way to test a single unit and have predictable interactions with external code (an external call to the unit fails, returns weird data, returns expected data, etc).
In answer to the original question, I have needed to do this in TCL, for example redefining exit to check whether the work has been saved and put up a dialog box if not, before calling out to the original function which gets renamed "tcl_exit". Of course, destructors are a better solution to this problem, but not many languages have those
One of Fluent’s nicer features is the Reveal tool that illuminates the borders around an object, showing quickly which screen elements allow interaction, lighting up as you mouse over or tab into an active field
That sentence seems completely out of place because it says "as you mouse over or tab" but those functions are completely gone when a person is using a pad/phone (touch device).
But, Fluent Design has been driven by the fact that Microsoft is running toward pad/phone (touch devices) even though Microsoft doesn't have a phone and barely has a pad device.
Microsoft Wants To Be The Cool Kid Too
It's honestly as if Microsoft is just trying to be like the cool kids even though everyone knows they're not.
Hey, Microsoft, just be Microsoft, ok?
And to further my rant, here's what microsoft says about their new design:
UWP helps by automatically adjusting UI elements so that they're legible and easy to interact with on all devices and screen sizes.
But that really isn't true. Things are too big on a desktop and take up too much space. Everything is targeted toward smaller touch devices.