On Sun, Feb 18, 2018 at 1:47 AM, Ian Kelly <ian.g.ke...@gmail.com> wrote: > On Fri, Feb 16, 2018 at 9:32 PM, Chris Angelico <ros...@gmail.com> wrote: >> You'd be surprised how rarely that kind of performance even matters. >> The author of that article cites C# as a superior language, but in the >> rewrite from C# to Python (the same one I mentioned in the other >> post), I sped the program up incredibly. Part of that is because C# >> requires the startup of its framework (in my case that's Mono) just as >> Python does, and partly it's because the simplicity of Python let me >> eliminate a number of unnecessary HTTP requests. Trust me, your choice >> of language doesn't help you if it means you do three (sequential) >> HTTP requests when one would have done. Clean code has its own >> advantages. > > Okay, I'm curious. How did C# force you to make extra HTTP requests > that were no longer necessary when you rewrote in Python?
It didn't *force* those requests to be made, but the code was so large and convoluted that I doubt its original author realized that the requests were being repeated. Pseudo-coded: def do_stuff(): if need_to_prepare(): prepare() really_do_stuff() def need_to_prepare(): requests.get("...") return True or False based on the response def really_do_stuff(): requests.get("same as need_to_prepare") if response says we need to prepare: prepare(), but only the bits we need requests.post("...") This whole structure was split across a number of separate files, making it highly unobvious that the request inside really_do_stuff is actually redundant in this context. (Plus, I could actually skip the check altogether and just do the work. If we need to do the preparation, that can be overlaid with a second request, done in response to a failure. Max of two HTTP requests, and usually just one.) By making the code MASSIVELY simpler, Python allowed me (as the programmer) to see where improvements could be made. When you have thousands upon thousands of lines of code, it's far harder to recognize where one function's job overlaps another's, and harder still to figure out a clean way to reduce the duplication without breaking everything. ChrisA -- https://mail.python.org/mailman/listinfo/python-list