Timeline for Working through the single responsibility principle (SRP) in Python when calls are expensive
Current License: CC BY-SA 4.0
25 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Apr 18, 2019 at 6:00 | history | tweeted | twitter.com/StackSoftEng/status/1118756170041311232 | ||
Apr 13, 2019 at 20:51 | answer | added | Steven Jackson | timeline score: 2 | |
Apr 13, 2019 at 17:35 | comment | added | Alexander | I love Python, but frankly, if regular method calls are becoming a significant source of performance degradation, then Python simply isn't the appropriate tool for the job. | |
Apr 13, 2019 at 14:00 | comment | added | Sklivvz | If a principle makes you write bad or inefficient code, ditch the principle. We are paid for working, performant code, not to make Uncle Bob happy. | |
Apr 13, 2019 at 13:59 | comment | added | lucasgcb | @jpmc26 It is hard to explain, but we are implementing analytical solutions which aren't implemented yet, can be parallelized for a purpose, and does yield results. As for the code itself it is just a structure example (and a poor one on top of that, we do use numpy/scipy whenever we can). Overall, maybe the question should be reworded to OOP paradigm instead of SRP. | |
Apr 12, 2019 at 22:29 | comment | added | jpmc26 | Furthermore, OOP is not encouraged in Python. It is generally unnecessary. The primary use of classes in OOP is to enable late binding, but Python supports late binding for everything, including methods not bound to an object. Also, why are you writing your own vector logic? You should probably be using a well known, C-implemented math package like numpy or scipy or whatever provides the functionality you need. You'll get a much better performance boost using those than you will fiddling with whether methods are bound to an object or not. | |
Apr 12, 2019 at 22:26 | comment | added | jpmc26 | It doesn't make sense to me that you're putting anything in parallel here. The GIL in Python prevents you from running multiple threads concurrently, and the overhead of multiprocessing seems like it would drastically outweigh the cost of a few method calls. | |
Apr 12, 2019 at 21:48 | comment | added | Voo | @Eevee There's a whole lot more book keeping going on in Python than in C when you're calling a method. That said, if someone's worrying about the performance of method calls Python is clearly the wrong language. Most business code is limited by IO and not CPU. | |
S Apr 12, 2019 at 21:21 | history | suggested | Peter Mortensen | CC BY-SA 4.0 |
Copy edited (e.g. ref. <https://en.wikipedia.org/wiki/Single_responsibility_principle>). Changed to sentence casing for the title.
|
Apr 12, 2019 at 21:11 | comment | added | Bakuriu | Use a JITted implementation of python such as PyPy. Should mostly fix this problem. | |
Apr 12, 2019 at 21:06 | comment | added | Eric Towers | Does your object really have four responsibilities: move, revert, get_coordinates, and move_and_revert_and_return? or does it really only have the one responsibility, move_and_revert_and_return? | |
Apr 12, 2019 at 20:47 | review | Suggested edits | |||
S Apr 12, 2019 at 21:21 | |||||
Apr 12, 2019 at 20:30 | comment | added | Eevee | note that function calls are expensive in any language, though AOT compilers have the luxury of inlining | |
Apr 12, 2019 at 18:07 | history | became hot network question | |||
Apr 12, 2019 at 17:18 | comment | added | lucasgcb | @RobertHarvey You're right, sorry for the poor example and I'll edit a better one when I have the time. In either case, readability and maintanability suffers and eventually the SRP breaks down within the codebase as we cut down on classes and their methods. | |
Apr 12, 2019 at 16:58 | history | edited | Robert Harvey | CC BY-SA 4.0 |
edited title
|
Apr 12, 2019 at 16:57 | comment | added | Robert Harvey | For what it's worth, your two code examples do not differ in number of responsibilities. The SRP is not a method counting exercise. | |
Apr 12, 2019 at 16:53 | history | edited | Robert Harvey | CC BY-SA 4.0 |
deleted 437 characters in body
|
Apr 12, 2019 at 16:50 | history | edited | lucasgcb | CC BY-SA 4.0 |
added 435 characters in body
|
Apr 12, 2019 at 16:43 | vote | accept | lucasgcb | ||
Apr 12, 2019 at 15:26 | answer | added | Ewan | timeline score: 16 | |
Apr 12, 2019 at 15:10 | review | Close votes | |||
Apr 18, 2019 at 3:05 | |||||
Apr 12, 2019 at 14:57 | answer | added | Robert Harvey | timeline score: 50 | |
Apr 12, 2019 at 14:53 | comment | added | gnat | Possible duplicate of Is micro-optimisation important when coding? | |
Apr 12, 2019 at 14:19 | history | asked | lucasgcb | CC BY-SA 4.0 |