News for hackers. Stuff that matters.
Re:Apple is patenting Swift features by kbsletten on Friday January 25, 2019 @09:46AM (#18998277)
Well, given that Rust and C# also have these features I think the likelihood that the patent is upheld is unlikely. I guess they could threaten you with it since lawyers are expensive, but it seems silly to me.
Re:Apple is patenting Swift features by _Codemonkeyism on Friday January 25, 2019 @10:13AM (#18998599)
Re:Apple is patenting Swift features by tasubotadas on Friday January 25, 2019 @11:16AM (#18999299)
Re:Apple is patenting Swift features by vorg on Friday January 25, 2019 @05:37PM (#19003273)
In Apache Groovy you need to write `a?.b?.c` for nullsafe chaining on both `b` and `c`. In the past, its project managers have discussed propagating nullsafety down the chain so you'd only need to write `a?.b.c` to make both `b` and `c` nullsafe, but they've never implemented it.

Not sure if that's in Rust, Kotlin, C#, or Ruby, or in Groovy's Antlr 4 parser.

Re:Apple is patenting Swift features by masklinn on Friday January 25, 2019 @10:02AM (#18998474)
FWIW Rust does not have optionals chaining, except in the monadic sense (in which case ML and Haskell have optionals chaining).

That is, in Rust you'd use Option::map or Option::and_then, there is no equivalent to the `?.` and `?[]` operators, the `?` operator (or `try!` macro) is a shortcut for an "unwrapping guard".

Re:Apple is patenting Swift features by lalaithion on Friday January 25, 2019 @10:49AM (#18998936)
Right, but isn't `?.` just syntactic sugar on `Option::and_then`? Is this a patent on a piece of syntactic sugar, or is it a patent on the idea of chaining optional values?
Re:Apple is patenting Swift features by saghm on Friday January 25, 2019 @01:43PM (#19000983)
Ruby does seem to have the exact thing: http://mitrev.net/ruby/2015/11/13/the-operator-in-ruby/
Re:Apple is patenting Swift features by dep_b on Friday January 25, 2019 @10:42AM (#18998868)
I'm also pretty sure I had it in C# before Swift was introduced.
Re:Apple is patenting Swift features by dotuser on Friday January 25, 2019 @12:00PM (#18999857)
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.
Re:Apple is patenting Swift features by zmmmmm on Friday January 25, 2019 @06:17PM (#19003551)
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
Re:Apple is patenting Swift features by dotuser on Friday January 25, 2019 @11:13PM (#19004731)
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.
Re:Apple is patenting Swift features by rhodysurf on Friday January 25, 2019 @12:15PM (#19000016)
Yeah and using optionals in rust vs swift makes rust super annoying to use because of that.
Re:Apple is patenting Swift features by pnw_hazor on Friday January 25, 2019 @01:00PM (#19000490)
Do Rust and C# implement these features the same exact way as Apple claims in this patent?

Patents protect how you something, not what you do.

Re:Apple is patenting Swift features by dotuser on Friday January 25, 2019 @01:56PM (#19001136)
Technically speaking, C# does not have optionals so I don't think it can be argued that C# violates the patent unless it's generalized to include null propagation which operates on reference types.
Re:Apple is patenting Swift features by int_19h on Friday January 25, 2019 @04:41PM (#19002787)
C# Nullable<T> is optional for all purposes (a struct with .Value and .HasValue), it's just restricted to value types.
Re:Apple is patenting Swift features by dotuser on Friday January 25, 2019 @11:20PM (#19004752)
right, c#'s nullable types are the ultimate in syntactic sugar in that you can just use them like regular value types in most places without realizing they are monads underneath.
Re:Apple is patenting Swift features by int_19h on Saturday January 26, 2019 @12:05AM (#19004861)
I wouldn't say they have substantially more syntactic sugar than other languages with the same. If you need to use them in the context that is not optional, you need to use HasValue/Value, or casts, or (since recent versions) pattern matching to extract the value.

The only special sauce I can think of is that C# also implements null-lifting for most operators in the language, which is not necessarily a good thing because it treats null as "unknown" rather than "missing" - e.g. a + b works on int?, and will produce null if either a or b is null. With Boolean operators, it's even clearer - false & null is false, true | null is true, but true & null is null, and false | null is null. But quite often this is not what I actually want! If null really means that the value is missing, then a + b shouldn't even compile for optionals. But in practice, I'd say that vast majority of all uses of Nullable are to denote missing rather than indeterminate values.