I think it's important to note that Python is a scripting language. A lot 
of the time when you're "scripting", you're writing a function that does a 
series of different, one-off things. If you try to break it up into 
reusable components you might make everything far more complicated. 
Creating a UI is often a good example of this.

I don't want to discourage you from making short, reusable functions in 
general, but just point out that it's not always the right thing to do.

Making your code readable and easy to debug, on the other hand, is always 
important! If splitting your code up makes it more readable, testable or 
easily debugged, then go for it.


On Friday, 28 April 2017 08:47:40 UTC+10, 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/0d74f0cc-6043-42a4-88e5-d7c0ed7522a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to