News for hackers. Stuff that matters.
Re:Adding Syntax to the CPython Interpreter by 333c on Saturday October 19, 2024 @02:45PM (#41889718)
In Ruby, the `if [condition]` modifier at the end of a line is used for more cases than just assignment. For example, `return if s.blank?` and `raise "invalid" if input.length > 100`. In Ruby, this pattern makes it clear that the statement is only executed if the condition is met.

I'm not advocating for this feature to be added to Python, just explaining why it's not confusing in Ruby.

Re:Adding Syntax to the CPython Interpreter by mypalmike on Saturday October 19, 2024 @03:14PM (#41889944)
Though I used it for 2 years of it as my primary language at work, I never quite got used to Ruby's quirky idioms like this. It just reads badly to me, in terms of quickly understanding code flow, to have statements that start with "raise" or "return" which might not raise or return. Similar to the up-thread comment about assignment.