4 ms·
I apologize for being nitpicky, but you shouldn't abuse the tuple assignment syntax. I had to expand out msum2 to be able to read it reasonably.
by snprbob86 18y ago
I apologize for being nitpicky, but you shouldn't abuse the tuple assignment syntax. I had to expand out msum2 to be able to read it reasonably.
- ralph 18y agoAgreed. The pseudo-code had it in a more readable style. If it must be compressed onto one line then a = 0; b = (0, 0); c = float('infinity') is preferable if a, b, and c are logically unrelated compared to a, b, c = 0, (0, 0), float('infinity') especially as the list gets longer. Why should the reader first count to find where variable `foo' is on the left-hand side before then counting the same number of places on the right?
- brent 18y agoAre you referring to this line where he initializes 4 variables? bounds, s, t, j = (0,0), -float('infinity'), 0, 0
- snprbob86 18y agoYes, and the `bounds, s = (j, i+1), t` especially when forced onto the same line as the if statement. See the Python Style Guide: http://www.python.org/dev/peps/pep-0008/ http://www.python.org/dev/peps/pep-0008/ "Compound statements (multiple statements on the same line) are generally discouraged."
- brent 18y agoI agree about compound statements, but I think most people will use the tuple assignment style, especially when its simply initializing variables. There is no reason to expand it beyond one line.
- snprbob86 18y agoThere is a reason: it reduces the reading distance from variable to initial value. It also reduces the amount of effort you need to exert to map them to each other. This is especially true when you are using () which impact the meaning of ','. There's also no reason to keep it on one line :-) Newlines and equal signs are cheap; go wild!