Just to add onto this topic: you'll find that many ways that you're thinking about doing things have been codified already into design patterns that might be more effective or efficient at getting the job done while maximizing reusable code that isn't brittle or hard to recycle/monolithic.
It might be worth checking out the book: Head First: Design Patterns. It's not written in Python but the ideas are very easily abstracted...I'm not sure about a Python specific one that I've read first hand, however I'm sure someone else can give a good suggestion. This might get you out of the habit of possibly making too monolithic code and help you start abstracting. I'm just assuming you might find that certain patterns pop up throughout your code and could hopefully lead to refactoring that can minimize the code. However if you're talking UI code...I haven't personally figured out many ways to minimize that code in a few scenarios. Sometimes it's not a great use of your time as I see many people prototyping/finalizing UI's in qt designer and leaving the files as is instead of trying to find a way to minimize the lines within (which if you've seen are seriously monolithic), but who knows...I'm assuming that's a pretty debatable one. On Thursday, April 27, 2017 at 6:47:40 PM UTC-4, Rudi Hammad wrote: > Hi Zeth, > I am trying to look for a long function I wrote to post it, but I am > realizing that I only get this long functions when it comes to UI > programming. And I can´t find an example to post that is not work > confidential. > It is like the example you said.So I guess that with more experience you > start to see better how to organize your code in a logical way. > And yes, I guess that when Marco is improvising the tutorials, he doesn´t > have time to organize it perfectly. > > El jueves, 27 de abril de 2017, 22:09:17 (UTC+1), zeth willie escribió: >> >> I actually made a video about refactoring python for maya basics a little >> while ago where I talk about some of that exact stuff! Never got around to >> uploading it, I'll do that soon, maybe there will be something helpful in >> it (depending on your coding prowess). >> >> To echo Marcus, it's hard to be really specific, but once you have a >> little bit of an eye for it, it can become more clear what the threshold is >> for extracting stuff. The example I think I used was: say you're codifying >> your day and you have a function called "waking up". It may seem totally >> reasonable to put all the steps for making and drinking coffee in that >> "waking up" function. Related process and you do it almost every morning. >> But what happens if you want to make a cup of coffee after dinner? It's not >> "wrong" to include coffee-making in the wake-up function, but it can be >> objectively better to extract it into its own function so that you can use >> it later in a different way or in a different script. Turns out it's easier >> to inspect, test and revise later also. >> >> I LOVE Marco's work, his tutorials and all that are awesome. So I don't >> want to sound like I'm contradicting what he did. But it's also often the >> case that when writing something, one can't be bothered to break everything >> up into the most perfectly efficient chunks. That's why there's a word for >> refactoring:) Sometimes you have to see how things work in the wild and how >> other might use it. Overthinking this stuff can lead to wasting time by >> designing for use-cases that never happen. . . again, that's why we >> refactor. >> >> In the case you mention, it might be worth looking into ways to dissect >> the comparison and filtering process, maybe the traversal process too. >> Loads of levels of indents, etc can indicate that maybe you're trying to do >> too much in one method or function and some of that sorting can be broken >> out. >> Hope that helps! >> > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/422f347f-90a5-4a4b-9264-16ece3c0f31c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
