Write code which is readable and then put in effort to speed things
up, if need be.

The "Code 1" is definitely confusing.  Why don't you create a class
and fill up the member variables. Much more readable.

There is a dis module which allows you to dump assembly code. You can
check how many instructions are being generated.
Thanks
Shankha Banerjee


On Fri, May 23, 2014 at 12:21 PM, Mandar Vaze / मंदार वझे
<mandarv...@gmail.com> wrote:
> Currently I came across the code that returned 9 values (return statement
> spanned 5 lines due to pep8 limitation of 79 characters per line)
>
> The function returns various values that are used by the template to render
> HTML
>
> To give you an idea - consider following two code snippets :
> (This is just a sample - it might lead you to believe these are various
> columns of a "user" table. Actual code isn't a row from DB table.
> All 9 values are computed, and aren't related to each other)
>
> Code 1:
> ...
> return dict(fname=fname, lname=lname, saluation=salutation,
>          gender=gender, addr1=addr1, addr2=addr2,
>          city=city, state=state, country=country)
>
> Code 2:
>
> user = {}
> user['fname'] = fname
> user['lname'] = lname
> ...
> ...
> ...
> user['country'] = country
>
> return dict(user=user)
>
>
> I was told first style is more "readable" since it tells you what is being
> passed to the template (I disagree, but it is subjective/personal opinion)
>
> Queries :
>
> 1. Is there a *limit* on "How many values can be returned from a function" ?
> 2. What is *performance impact* of returning so many values - (push and pop
> from the stack)
> 3. Based on #1 and #2 is there a *recommendation* on "where to draw the
> line"
>
> Thanks,
> -Mandar
> _______________________________________________
> BangPypers mailing list
> BangPypers@python.org
> https://mail.python.org/mailman/listinfo/bangpypers
_______________________________________________
BangPypers mailing list
BangPypers@python.org
https://mail.python.org/mailman/listinfo/bangpypers

Reply via email to