|
|
|
|
|
by Swizec
502 days ago
|
|
Where I've found `?` super helpful in JS/TS and now miss it the most in Python is dealing with nested data structures. ```
if (foo.bar?.baz?.[5]?.bazinga?.value)
``` Is so much nicer than ```
if foo.bar and foo.bar.baz and foo.bar.baz[5] and foo.bar.baz[5].bazinga and foo.bar.baz[5].bazinga.value
``` I honestly don't care which one of those is falsy, my logic is the same either way. This enables you to ergonomically pass around meaningful domain-oriented objects, which is nice. Edit: looks like optional chaining is a separate proposal – https://github.com/golang/go/issues/42847 |
|
Its funny because when I was a beginner in both I strongly preferred python syntax. I thought it was much simpler.