I put Swift into the category of "almost memory managed" languages and it's never fully clicked in my brain. Thinking about strong/weak/unowned references is more difficult in my opinion than when to malloc/free something. Following the examples in the article just reinforced that maybe Swift's approach is a little too complex.
The examples are complex to follow because Swift model works just fine for all the normal cases. It only becomes problematic in some edge cases that regular programmer rarely meet.
And with all the help that the compiler now provides (even before swift 5), it's becoming really really hard to shoot yourself in the foot.
Right. This is one of the things I don't like about automatic reference counting, that it's almost a complete solution, but cycles require more thought (but less cases) to deal with than manual memory management itself.
Looking from a distance, what Swift does is actually taking best practices from modern C++ (14+) and incorporating them on the language level instead of introducing new library tools.
If you regularly code C++, the "fuck, yes!" moment is there when you learn Swift.
I'm not totally versed in Swift. In the example provided is it ambiguous because the closure captures `count` and count itself is being modified by the method calling the block?
I don't understand why this is an example of an unsafe operation. Wouldn't clearly defined behavior of closures clarify the "3 or 4" question?
> I don't understand why this is an example of an unsafe operation. Wouldn't clearly defined behavior of closures clarify the "3 or 4" question?
I believe that it's possible to specify this, and that's basically the behavior we had before SE-0176 was implemented. The issue with this is that it was slower for a dubious benefit (the semantics are obscure and non-obvious), so it was decided that it's just better to disallow this and get the benefit of clear behavior and better optimization opportunities, at the cost of removing this somewhat uncommon and not-all-that-hard to-rewrite-for-clarity pattern.
kris-s|7 years ago
bsaul|7 years ago
And with all the help that the compiler now provides (even before swift 5), it's becoming really really hard to shoot yourself in the foot.
saagarjha|7 years ago
giornogiovanna|7 years ago
diegoperini|7 years ago
If you regularly code C++, the "fuck, yes!" moment is there when you learn Swift.
Teknoman117|7 years ago
jake_the_third|7 years ago
zaksoup|7 years ago
I don't understand why this is an example of an unsafe operation. Wouldn't clearly defined behavior of closures clarify the "3 or 4" question?
saagarjha|7 years ago
I believe that it's possible to specify this, and that's basically the behavior we had before SE-0176 was implemented. The issue with this is that it was slower for a dubious benefit (the semantics are obscure and non-obvious), so it was decided that it's just better to disallow this and get the benefit of clear behavior and better optimization opportunities, at the cost of removing this somewhat uncommon and not-all-that-hard to-rewrite-for-clarity pattern.
unknown|7 years ago
[deleted]
saagarjha|7 years ago
atrick6|7 years ago
hnbroseph|7 years ago
Temasik|7 years ago
saagarjha|7 years ago