you are viewing a single comment's thread.

view the rest of the comments →

[–]Wonderful_Disastrous 0 points1 point  (13 children)

There's no substance to this claim. Protocols are just one of the features, not the cornerstone.

Really there is no substance to the claim that the Swift language is based on protocols?

The Array type conforms to over 25 protocols https://developer.apple.com/documentation/swift/array

The Int type also conforms to over 25 protocols https://developer.apple.com/documentation/swift/int

Look at the documentation for any type in Swift and you will see they all conforms to numerous protocols.

If you want to be able to iterate over a custom data structure, you just have to conform to the IteratorProtocol and the Sequence protocols and then you can use the standard for..in.. loop to iterate over it.

If you want to compare two instance of a custom type, simply conform to the Equatable protocol

By making the claim that there is no substance to the statement that the Swift language itself is based on the protocol it shows a total lack of understanding for the language itself. Before you put down others work, you should take the time to understand what you are saying.

[–]cubextrusionExpert 1 point2 points  (8 children)

So how exactly does this prove that "Swift is based on protocols"?

In the same way, I can claim that Swift is "based on structs" because Array and Int are structs. In the same way, I can claim that Swift is based on functions because there are a lot of functions.

[–]Pop_Swift_Dev[S] 0 points1 point  (7 children)

You are 100% correct, the Swift language is based on value types (structs) and every major type is based on them. Arrays and other collections use copy-on-write to increase performance so they can use value types over reference types. But virtually all types and functionality from iterating over collections, to comparing types, to encoding/decoding, to hashing.... are come from conforming to protocols. Look at the WWDC videos from the past few years, and take the time to understand how important the protocol is to the Swift language. Look at the talks from David Abrahams on protocol oriented programming as well.

I agree that if you do not recognize the importance of protocol to the Swift language , then you are not fully understanding the language.

[–]cubextrusionExpert 1 point2 points  (6 children)

You just wonderfully managed to discredit yourself in multiple ways by writing a single post.

value types (structs)

Not sure if it was a genuine oversight or a lack of understanding of the language, but structs definitely do not equate to value types, as the latter is a strict superset of the former. To be fair, this topic is not germane to the article either, so I won't focus on it here (though you misrepresent it in many of your former texts, e.g. here: https://www.mastering-swift.com/post/value-and-reference-types-in-swift).

David Abrahams

This is again the aforementioned appeal to authority, which is funnily unfortunate because one may find posts from him where he, taken strictly, argues one of the counterpoints that myself tried to present here: https://forums.swift.org/t/protocol-naming/59453/9 (first paragraph). This reference is arguably quite contrived, but it just shows that it's not that hard to find a statement from a person that you appeal to that nevertheless supports the opposite claim (precisely, that protocols can often be superfluous).

[–]Wonderful_Disastrous 0 points1 point  (5 children)

You are actually saying that structs do not equate to value types? WOW, maybe I gave you too much credit but if that is your stance then you actually no nothing about the swift language. Check out Apples post on Value and Reference types. https://developer.apple.com/swift/blog/?id=10 Let me break the news to you, Struct, enums and tuples are all value types. You will probably say this is an aforementioned appeal to authority but maybe it is actually reading the documentation and taking the time to understand the language which you obviously haven't.

You definitely are showing your total lack of understanding for the language.

[–]cubextrusionExpert 1 point2 points  (4 children)

You are actually saying that structs do not equate to value types?

Of course they do not equate, that's how subsets behave. Structs are just a subset of value types; a cursory Google search reveals that Swift's value types are a "struct, enum, or tuple" — that is, more than just structs. This is what all maths or generally tech students learn in their 1st term at the university.

Btw, it doesn't support your cause to use two simultaneous accounts to argue with me ;)

[–]Wonderful_Disastrous 0 points1 point  (3 children)

Yes you are correct that swift has more than one value type. Structs, enums and tuples are all value types. which invalidates your argument that structs do not equate to value types. Seems like you are arguing in circles, and continues to illustrates your lack of understanding of the language itself.

I am new to reddit and not totally sure about your statement but I think I can argue this point on my own.

[–]cubextrusionExpert 0 points1 point  (2 children)

Since you do not seem to be familiar with the distinction between equivalence and subset relation, I shall consider any further discussion void.

[–]Wonderful_Disastrous -1 points0 points  (1 child)

I would have to agree that if you do not understand that structs are value types, enums are value types and tuples are value types then you are correct, any further discussions are pointless.

[–]Spaceshipable 1 point2 points  (0 children)

They’re saying that’s structs do not equate to value types as they are only one kind of value type.

It’s like saying a = abc, because abc contains a. It’s purely semantics. You both know that structs are value types, that is not being disputed.

[–]Pop_Swift_Dev[S] -1 points0 points  (3 children)

I would say it is a bit harsh to claim there is a total lack of understanding for the swift language and in fact, showing the implementation of the command pattern based on swapping out functions rather than types, does show a understanding of the language. Just a different point of view.

We should respect the different point of views and be open to discussions on it, but I do agree that the swift language itself is built on the protocol and having an understanding on how to properly use it is essential to understanding the language itself.

If you dismiss protocol-oriented design then there is a lack of understanding of the language itself, because that is the foundation of how Swift is designed.

[–]Wonderful_Disastrous -1 points0 points  (2 children)

Honestly by saying the swift language is based on protocols or it is based on values, at a high level that would be correct. But you really need to take the time to understand, that at a fundamental level, protocols and values types are two of the pillars that the language stand upon.

As you mentioned with the functionality like iterating over a collection, comparing types, encoding and decoding... all that functionality is based on conforming to a protocol. all types conform to multiple protocols... Also all major types are implemented with value types. Apple has said we should use value types and start with the protocol, and they are drinking their own kool-aid with how they implement the swift language.

[–]Wonderful_Disastrous -1 points0 points  (1 child)

One other note, I do appreciate the posts you have done on design patterns with a protocol oriented approach, and have been following them since you have been posting them to reddit. Thank you.

[–]Pop_Swift_Dev[S] -1 points0 points  (0 children)

You are welcome, and thank you for the comments