4 ms·
I hope they actually stick with this. Swift embedded, for example, is a sort of proof of concept more than viable platform, and you end up battling that more th
by mosura 1y ago
I hope they actually stick with this. Swift embedded, for example, is a sort of proof of concept more than viable platform, and you end up battling that more than the problem you are trying to solve.
It is a shame because aesthetically Swift is easily the nicest of the modern safe languages, but there have been really odd noises in the community about project leadership that sour things.
- deleted 1y ago[deleted]
- ranie93 1y agoguard let self = self else { return }
- timsneath 1y agoHa! But that's not semantically meaningful Swift code in any normal context, nor is it idiomatic. `self` is equivalent to `this` in C++, and is never normally null. You use this construct for unwrapping nullable fields, for example something like this: guard let httpResult else { return } Note that you don't need to assign the value to itself in modern Swift. This line takes an optional (httpResult?) and returns early if null. If not, you can use it with strong guarantees that it's not nullable, so no need for ? or ! to unwrap it later in the scope.
- CBMPET2001 1y agoI've seen that exact pattern used to safely unwrap a weakly captured 'self' within a closure (to avoid retain cycles)
- saagarjha 1y agoIt’s nil in Swift, and what the other comment said ;)
- viktorcode 1y ago> But that's not semantically meaningful Swift code in any normal context, nor is it idiomatic. `self` is equivalent to `this` in C++, and is never normally null. It is, when `self` is captured weakly in a closure, and that closure is outliving the instance.
- akmarinov 1y agoThis can now be guard let self else { return }
- mojuba 1y agoThere's a shorter form of it: guard let self else { return } which annoyingly the AI's don't know about.
- serial_dev 1y agoNot much better, to be honest.
- saagarjha 1y agoMost use of this is misguided unfortunately :(
- jitl 1y ago`guard let` is great what’s there to hate? The big problem with swift is “expression has ambiguous type” and “expression took too long to type check”. Those don’t trade in code aesthetics but are problems I’ve never had in another language.
- nicce 1y ago> Swift embedded, for example, is a sort of proof of concept more than viable platform, and you end up battling that more than the problem you are trying to solve. Yet Apple has managed to create WatchOS. I don’t know what is the portion of Swift, however.
- pta2002 1y agoWatchOS is hardly embedded though. An Apple Watch is basically a small iPhone tied to your wrist in terms of architecture. That’s got a whole lot more in common with a full desktop computer than it does with a microcontrollers, where they often have rather weird architectures by desktop standards, and it’s quite rare to have MMUs and things like that. Also, there is no underlying OS, and no heap allocator (unless you provide one). That’s the kind of challenge that an embedded language runtime has to provide.
- steve1977 1y agoWhich might be one of the reasons why battery lifetime on Apple Watch is so bad.