Earlier quoted context omitted.
If you don't like awkward ugly clunky syntax, you probably shouldn't program in Python. And, for that matter, if you like correctness checking, you also shouldn't program in Python...
Serious question, what alternative(s) to Python would you recommend with nicer syntax?
New Ways to Be Told That Your Python Code Is Bad
221–230 of 262 posts
Re: New Ways to Be Told That Your Python Code Is Bad
#222Earlier quoted context omitted.
I prefer this Python syntax: x = condition() and 4 or 5
If you know the first value is truthy, sure. x = condition() and [] or True is not equivalent to x = [] if condition() else True Now, I have seen a genuine application of `X and A or B` before. That occurs when you're checking a condition before, say, popping from a list -- but if the list is empty, you still want a default value.
Re: New Ways to Be Told That Your Python Code Is Bad
#223Based on my 25+ years of experience I strongly believe that the "if/else" that this author complains about is actually BETTER than the ternary he recommends. This is yet another example of the endemic problem where software engineers think "harder to read is a virtue".
Re: New Ways to Be Told That Your Python Code Is Bad
#224Ah, leave people alone. I stopped using ternary expressions because someone told me not to. I could start using them again, whatever. I use while loops when the burden of describing the loop as an iteration is too high (too much of a stretch), or when I'm writing something that really isn't a composition of forEach/map/filter/reduce (gasp). For me, it's whatever I need to do to get through code review without arguing…
Consistent style is really nice.
Re: New Ways to Be Told That Your Python Code Is Bad
#225Ah, leave people alone. I stopped using ternary expressions because someone told me not to. I could start using them again, whatever. I use while loops when the burden of describing the loop as an iteration is too high (too much of a stretch), or when I'm writing something that really isn't a composition of forEach/map/filter/reduce (gasp). For me, it's whatever I need to do to get through code review without arguing…
> Don't add linter checks for these things, it's condescending. Well as he states, these checks are not turned on by default. I have trouble seeing why someone who liked these extensions enough to turn them on manually would feel condescended to by them.
Re: New Ways to Be Told That Your Python Code Is Bad
#226Earlier quoted context omitted.
If you don't like awkward ugly clunky syntax, you probably shouldn't program in Python. And, for that matter, if you like correctness checking, you also shouldn't program in Python...
Serious question, what alternative(s) to Python would you recommend with nicer syntax?
For data science stuff: Julia
Re: New Ways to Be Told That Your Python Code Is Bad
#227Earlier quoted context omitted.
What's so monstrous about it? It's practically English: cssClass = 'selected' if isCurrentTab else 'deselected'
You have a weird perception of English. "If the tab is selected, the CSS class is 'selected', else it's deselected. Or in pseudocode if isCurrentTab cssClass = 'selected' else cssClass = 'deselected' Even ternaries read weird. "css class is current tab HUH?? selected COLON! deselected"
Re: New Ways to Be Told That Your Python Code Is Bad
#228Earlier quoted context omitted.
God bless gofmt and tools like prettier.
Python has Black, which uses the same premise as gofmt. Guido doesn't like it, though, but the community seems to.
Re: New Ways to Be Told That Your Python Code Is Bad
#229Earlier quoted context omitted.
I've actually found that there are a number of situations where I really want: while True: ... if condition: break ... and kinda wish there was a nicer syntax for this.
Rust has `loop {}` which I thought was weird at first, but also ended up use more than I would have expected.
let foo = loop {
// ...
if condition {
break value;
}
// ...
}Re: New Ways to Be Told That Your Python Code Is Bad
#230Earlier quoted context omitted.
If you know the first value is truthy, sure. x = condition() and [] or True is not equivalent to x = [] if condition() else True Now, I have seen a genuine application of `X and A or B` before. That occurs when you're checking a condition before, say, popping from a list -- but if the list is empty, you still want a default value.
Can you give me an example where the two return different values?
Try it out. https://ideone.com/GciAs8