Hacker News new | ask | show | jobs
by dotuser 2700 days ago
one thing though, in swift you can actually mutate fields using optional chaining, e.g. person?.name = "Bob". you can't do that in c#. not sure about rust but in scala you would unwrap the optional with a foreach or something.
2 comments

In Groovy you can mutate through optional (null-safe) chaining, eg:

    x = [ foo: [ bar: 1] ]
    x.foo.bar // 1
    x.boo?.bar // null because x.boo is null
    x.boo?.bar = 1 // succeeds even though x.boo is null
    x.boo // still null
I knew I had seen this somewhere else. I don't understand why C# doesn't support this since most C# code is mutable anyway. I can see why it doesn't fit well with functional languages but C# usually espouses pragmatism over purity and having this would clean up a lot boilerplate null checking.
Yeah and using optionals in rust vs swift makes rust super annoying to use because of that.