3 ms·
It's so weird when you've been using a feature for years in a language (swift) and you see another language try to come up to solutions to a problem you never h
by bsaul 7y ago
It's so weird when you've been using a feature for years in a language (swift) and you see another language try to come up to solutions to a problem you never had..
Chaining ?[] sucks no matter what you do, and as for parser ambiguity, my guess is that if the parser doesn't know how to understand an expression, then the best thing is to have it fail and ask the programmer to add parenthesis. Because chances are it won't make any sense to a human as well.
- nnq 7y ago> you see another language try to come up to solutions to a problem you never had ...didn't Swift have the same problem to witch it came with the same solution? (I mean `?.`)
- bsaul 7y agolet a:[Int]? = nil let ai = a?[0] and let b: [Int:[Int]]? = nil let bi = b?[0]?[0] are valid in swift. ?. is used when you want to access a property, but i've never thought of it as an operator. Rather, i see it as "a?" (aka : unwrap a) followed by "." dot operator to access a property. I basically just replace a with a? every time a becomes nullable, and that's it.
- jerf 7y ago"Chaining ?[] sucks no matter what you do" I find myself wondering if making chaining easy just ends up affording bad design, and if that "suckage" is your program trying to tell you about your bad design. I don't chain very much at all, because I generally consider chaining to be a sign that I need to add a better method somewhere. The big exception being reaching into a "dead" data structure where there's no particular invariants being maintained and no real reason not to just reach in deeply, and, for most programs, you really shouldn't have very many of those. I'd say you almost certainly have a major design problem if you've got this chaining happening all the time.