Code style query: multiple assignments in if/elif tree
Rustom Mody
rustompmody at gmail.com
Mon Mar 31 12:20:27 EDT 2014
On Monday, March 31, 2014 9:33:54 PM UTC+5:30, Chris Angelico wrote:
> On Tue, Apr 1, 2014 at 2:40 AM, Marko Rauhamaa wrote:
> > As a simple layout question, I'd do it like this:
> > ========================================================================
> > if mode == "Brake2":
> > # Already got the brakes fully on
> > distance_to_full_braking_power = 0.0
> > speed_full_brake = curspeed
> > elif mode == "Brake1":
> > # The brakes went on one second ago, they're nearly full
> > distance_to_full_braking_power = curspeed - 0.2125
> > speed_full_brake = curspeed - 0.425
> > else:
> > # Brakes aren't on.
> > distance_to_full_braking_power = (curspeed - 0.1) + (curspeed - 0.4125)
> > speed_full_brake = curspeed - 0.625
> > # If we hit the brakes now (or already have hit them), we'll go another
> > # d meters and be going at s m/s before reaching full braking power.
> > ========================================================================
> No particular advantage over the current version - it doesn't simplify
> it any, all you've done is break it across more lines.
Not answering your original question but the above comment
Your version was sufficiently garbled indentation-wise (it may give you sweet
pleasure to know my 'client' is GG) that I gave up on reading it.
Marko's version was clear enough that it seems to match your spec
[Ive not really verified it word for word... Just sayin']
On the whole I prefer multiple assignments.
Maybe in this case use small variable names with
separate(d) explanatory comments??
More information about the Python-list
mailing list