News for hackers. Stuff that matters.
Re:Clear is better than clever [pdf] by c22 on Monday May 06, 2019 @02:11PM (#19842125)
In Python you can write it like this:

  if      a < b: x = -1
  else if a > b: x =  1
  else:          x =  0
Which a lot of people seem to hate for some reason, but I always appreciated the compromise between terseness and clarity.
Re:Clear is better than clever [pdf] by o_pax on Tuesday May 07, 2019 @04:30AM (#19847527)
Python has its version of the ternary operator as well. It may look unusual due to the different order of the operands, but it works quite nicely, in my opinion:

  x = (-1 if a < b else
       1  if a > b else
       0)
This emphasizes the possible values that x may be assigned to.
Re:Clear is better than clever [pdf] by c22 on Tuesday May 07, 2019 @03:46PM (#19852801)
I agree, the ternary style is better for this sort of variable assignment situation. Usually if I am using the above pattern I am calling different functions as the result of the conditionals.
Re:Clear is better than clever [pdf] by Technetium_Hat on Wednesday May 08, 2019 @10:47AM (#19859290)
Python uses the `elif` keyword if you want to place an `else if` on one line. And column indentation isn't very "pythonic", apparently.