I also prefer the second one. Declaring all of your variables at the top of the function body is a very C language thing to do.
On Fri, May 12, 2017, 11:56 PM Alok Gandhi <[email protected]> wrote: > I prefer and use the second one. > > On Fri, May 12, 2017 at 7:36 PM, Rudi Hammad <[email protected]> wrote: > >> Hello, >> quick question. Do you declare the variables on top of the function like >> this: >> >> def myFunc(): >> """The description""" >> listA = [] >> listB = [] >> >> ''' >> some code in the middle >> bla bla >> ''' >> for i in range(10): >> listA.append(i) >> >> ''' >> more code in the middle >> bla bla >> ''' >> for j in range(5): >> listB.append(j) >> >> or would you do it like this? >> >> def myFunc(): >> >> ''' >> some code in the middle >> bla bla >> ''' >> listA = [] >> for i in range(10): >> listA.append(i) >> >> ''' >> more code in the middle >> bla bla >> ''' >> listB = [] >> for j in range(5): >> listB.append(j) >> >> >> >> In the second case, for me, it does make sense declaring the variable >> right before the loop, because then you read it like a paragraph. >> in the fist case, declaring everything at the beginning looks cleaner, >> but makes you having to track where the variable comes from. >> Is this a personal preference?If so, I am not sure which makes more sence. >> >> thanks >> >> -- >> 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/477cb809-6a81-4e21-8168-b8f9c95fda81%40googlegroups.com >> <https://groups.google.com/d/msgid/python_inside_maya/477cb809-6a81-4e21-8168-b8f9c95fda81%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > > -- > 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/CAPaTLMR1f6JrVrAwr4nOm8x9W5tX%2B3B4SK6R8930wJ%3DxggwS%3DA%40mail.gmail.com > <https://groups.google.com/d/msgid/python_inside_maya/CAPaTLMR1f6JrVrAwr4nOm8x9W5tX%2B3B4SK6R8930wJ%3DxggwS%3DA%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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/CAPGFgA2LFABj%2B_c2tfYARm1QR_E_HczxbJ-hz7ptDz0UMHh%3Dqg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
