4 ms·
I love how everything is available at runtime. Python's "we are all consenting adults here" philosophy has been super useful in a pinch. I was monkey patching
by Waterluvian 9y ago
I love how everything is available at runtime. Python's "we are all consenting adults here" philosophy has been super useful in a pinch.
I was monkey patching an external library in JavaScript today, rather than having to fork the thing for one slight modification, and thought about this philosophy again.
- Demiurge 9y agoOh yeah, the first time I monkey patched a method, it was an "aha" moment. I really understood the 'self' variable, and class as variable, and python just clicked all of a sudden for me.
- yen223 9y agoAs a person who has to maintain such systems, I really hate this aspect of Python.
- Waterluvian 9y agoI empathize. But I'm not convinced sloppy python is any worse than any other language used sloppily. Your beef is likely with the reality of doing business and shipping a real product.
- yen223 9y agoThe effort required to unwind these technical debts is actively inhibiting our ability to deliver real value. That's the reality we've got. Sloppy Python is particularly bad, because Python gives you a massive footgun to play with. Like you could write functions that radically alter its behaviour depending on where it's getting called - that's similar to the hack that the parent post was talking about. It's easy to build systems that are coupled in really weird and unexpected ways, and that makes reasoning about code much harder than it needs to be.
- ageofwant 9y agoThe reality is that Python provided you with a paying job, because it carried you to where you are. The effort and sheer dumb luck involved in keeping a business alive to the point that some dev can complain about technical debt is a very underappreciated luxury. Not that you are wrong, just saying...
- scaryclam 9y agoThat's not really the languages fault though. I've seen some amazingly bad Java, Python, JavaScript, PHP and bash. Be cross that technical debt was introduced and not paid back rather than at the tools used to do it.
- ghusbands 9y agoMost languages don't facilitate directly accessing the variables of other stack frames. Of the languages you listed, only Python does that (though bash has equivalent terrible bits), so that in particular _is_ Python's fault.
- SerLava 9y agoIn other words, not everyone involved is consenting to the things they're doing at runtime.
- progval 9y agoit's also a pain for compilers
- stochastic_monk 9y agoIf Python is interpreted, what’s the pain? Do you mean static compilers like Cython/pybind11/Boost.Python, or JIT compilers?
- gt_ 9y agoWhat does this mean?
- progval 9y agoIt's hard to make optimizations, because you cannot make a lot of assumptions ahead of time on how the code is going to run. For instance, one can override most of the builtin functions like len().
- gt_ 9y agoI am curious how this effects the compiler in particular?Does the compiler measure this in some way and respond with different behavior? Or is it already designed less efficient to account for these types of operations? Or a mixture of both and/or more nuanced hurdles? Thanks for any info you can provide.
- progval 9y agoPython 3.6 added a version field to dictionnaries. As all variables are looked up in dictionnaries (aka namespaces), a compiler can replace a call to a builtin by a test of the version of the builtins dict (aka a guarde), which chooses between an optimized version and the "naive" code. Further reading: https://www.python.org/dev/peps/pep-0509/ https://www.python.org/dev/peps/pep-0509/
- btilly 9y agoMonkey patching is something that you should know how to do. And then learn not to do. Monkey patching is how you get into situations where the order in which libraries get loaded causes software to unpredictably work or break. Or, worse yet, to work reliably on the developer's machine and break in the wild. (Because the external library on someone else's server loads slower for the developer than their local library, and faster for some users.)
- Waterluvian 9y agoNever say never. I saved hours on proof of concept code that dies in weeks. I think you learn when not to do it, which is most of the time.
- RcouF1uZ4gsC 9y ago> dies in weeks. Code can end up living a lot longer than people think it will (see Y2K bug).
- dingo_bat 9y agoAlso I've seen managers pushing people to use prototype code directly for the production app, because "why fix what's not broken" and "we need this last week". So I write my prototypes as if they are going to be shipped.
- rrcaptain 9y ago>see Y2K bug One of my biggest pet-peeves is how since popular media hyped Y2K up as a potential world ending disaster when nothing happened people thought the whole thing was a myth. When it was not a myth (though it was overblown), it was just avoided because people engineered around it. I can't wait to see how people handle the Year 2038 Problem.
- dagw 9y agoI'm embarrassed to think about how many of my quick hack proof of concepts are still running years later.
- pbalau 9y agoAnd then you start hating everything about everything else when you are a teen debugging code written by kids in a consenting adults environment.
- beagle3 9y agoIt is also the main reason python is so hard to speed up and optimize ; JavaScript is not quite as dynamic, so it can be speeded up more (though super dynamic constructs like “with” do kill all optimization’s and hinder JITting)