(no title)
VerifiedReports | 11 days ago
But there's a lot of hokey, amateurish stuff in there... with more added all the time. Let's start with the arbitrary "structs are passed by value, classes by reference." And along with that: "Prefer structs over classes."
But then: "Have one source of truth." Um... you can't do that when every data structure is COPIED on every function call. So now what? I spent so much time dicking around trying to conform to Swift's contradictory "best practices" that developing became a joyless trudge with glacial progress. I finally realized that a lot of the sources I was reading didn't know WTF they were talking about and shitcanned their edicts.
A lot of the crap in Swift and SwiftUI remind me of object orientation, and how experienced programmers arrived at a distilled version of it that kept the useful parts and rejected dumb or utterly impractical ideas that were preached in the early days.
ChrisMarshallNY|10 days ago
You can do classic OOP, FP, Protocol-Oriented Programming, etc., or mix them all (like I do).
A lot of purists get salty that it doesn’t force implementation of their choice, but I’m actually fine with it. I tend to have a “chimeric” approach, so it suits me.
Been using it since 2014 (the day it was announced). I enjoy it.
alper|10 days ago
zffr|11 days ago
There are plenty of valid reasons to use classes in Swift. For example if you want to have shared state you will need to use a class so that each client has the same reference instead of a copy.
VerifiedReports|7 days ago
raw_anon_1111|11 days ago
This is the same way that C# works and C and C++ why is this a surprise?
AlexandrB|11 days ago
sumuyuda|10 days ago
Swift structs use copy on write, so they aren’t actually copied on every function call.
Epskampie|10 days ago
amomchilov|10 days ago
It’s a common misconception that comes from the standard library data structures, which almost all do implement CoW
fingerlocks|11 days ago
You can also look at the source code for the language if any it’s confusing. It’s very readable.
mvdtnz|10 days ago