I've used a lot of different languages over the years and I've never seen such a fundamental language feature cause so many problems. Just search this forum for optionals to see the convoluted discussions people have about handling complex data structures with optionals and consider people working on projects having to deal with this.
I understand the motivation to try and make it harder to for people to accidentally put in nil values but the priority of a good development language is to make easily readable, easily maintainable and easily portable code. Putting question marks and exclamation marks (which are typically used for other purposes) all over a codebase with conditional assignments is a complete mess.
I just tried to upgrade a basic project in Swift after using some forced optional unwraps to avoid having to deal with as many cascading optional handlers and now get errors like the following:
asyncProgressHandler:((HTTPProgress!) -> Void)? = nil
Using '!' is not allowed here; perhaps '?' was intended?
It's torture having a compiler constantly barking at you about these things that aren't important for most projects. I deal with nil types all the time in other languages. Here's how it's done:
let obj = JSON.decode(json);
if (obj.value != nil) {
doSomethingWith(obj.value);
}
Clear for everyone, no confusing syntax, no having to look up what ?? or !? means. Maybe enterprise development benefits from all the clutter but I'm not seeing the value in it at all. Quite frankly, at this point, I'd rather develop an entire app in Typescript and have it transpiled to Swift if needed.
Are other developers actually seeing the benefit from optionals or are you also having to read through endless blog articles or forums on how to solve basic problems with them that are no issue at all in pretty much every other language?
It's such a waste of time trying to deal with this.
If people do see the benefit, that's great but can we at least get something like a strict or non-strict mode so the rest of us don't have to deal with it? I don't want to have to deal with it at all, I want to write code quickly without this distraction.
A non-strict mode would allow writing code the 'old-fashioned' way as in, not forcing people to use optional declarations or checks. Yes this means this software will potentially be unstable and have to be fixed by running it and checking it (the horror) but it also means you can copy/paste code between languages much more quickly and develop projects more quickly.
If people feel like optionals have been beneficial can you provide some stats? Has it reduced production bugs for you and at what rate? Has it come at the expense of production speed vs other languages? Has it noticeably increased code bloat or not? Do you feel like you'd be worse or better off developing the typical way without them?