> This is actually a statement that strong typing should not exist.
Nope. It is a statement that objects shouldn't be different depending on how you look at them.
The example is a class, so a reference type. That means that greeter and greeter1 are just two references to the exact same underlying object.
Your example are two distinct value type instances that you happened to initialize from the same literal.
So not even close to comparable situations. Speaking of comparable:
> Both a and b are "the same" value, insofar as they are `==`
Also nope.
let a: Int = 3
let b: Float = 3
let r=a==b
print(r)
Let's compile this:
swiftc numbers.swift
numbers.swift:4:8: error: binary operator '==' cannot be applied to operands of type 'Int' and 'Float'
let r=a==b
~^ ~
numbers.swift:4:8: note: expected an argument list of type '(Int, Int)'
let r=a==b
^
You may not be familiar with swift but a protocol isn’t necessarily a class. Structs ( so, value type) can also implements a protocol, and so in effect you can not tell a lot about what you’re manipulating, beyond what’s declared at the protocol level.
> That means that greeter and greeter1 are just two references to the exact same underlying object
They are two references that differ in type. It is a feature in Swift (and any strongly-typed language) that references are typed and when types differ, behaviors can differ. I understand you disagree with this design principle but it is an inherent property of strong type systems that have reference semantics.
> two distinct value type instances
“Nope.” There isn’t any such thing as a “value type instance” since instances are a semantic of reference types.
> objects shouldn’t be different depending on how you look at them
The “difference” here is only in the types, so this statement is equivalent to “references shouldn’t be different depending on their type.” This statement implies that types should be useless
> There isn’t any such thing as a “value type instance”
Hmm..
"An instance of a class is traditionally known as an object. However, Swift structures and classes are much closer in functionality than in other languages, and much of this chapter describes functionality that applies to instances of either a class or a structure type. Because of this, the more general term instance is used."
and
"Structure and Class Instances"
..
"Structures and Enumerations Are Value Types
A value type is a type whose value is copied when it’s assigned to a variable or constant, or when it’s passed to a function.
You’ve actually been using value types extensively throughout the previous chapters. In fact, all of the basic types in Swift—integers, floating-point numbers, Booleans, strings, arrays and dictionaries—are value types, and are implemented as structures behind the scenes."
> “references shouldn’t be different depending on their type.”
You are confusing the type of the variable with the type of the object/value contained in the variable. A static type system is there to ensure that the type of the variable matches the type its contents.
> You are confusing the type of the variable with the type of the object/value contained in the variable.
I’m not “confusing” them; I’m prioritizing the former over the latter, whereas you are prioritizing the latter over the former. This is the classic strong/weak typing debate.
If you want a language in which the dynamic type overrides the static type, there are several (including Swift if you are explicit about the override, and sometimes even if you are not explicit).
> A static type system is there to ensure that the type of the variable matches the type in its contents
A strong type system is there to apply strict type rules. one of Swift’s type rules is that Greeter.greet() calls that function or an override, not an unrelated function that could only be inferred at runtime.
Nope. It is a statement that objects shouldn't be different depending on how you look at them.
The example is a class, so a reference type. That means that greeter and greeter1 are just two references to the exact same underlying object.
Your example are two distinct value type instances that you happened to initialize from the same literal.
So not even close to comparable situations. Speaking of comparable:
> Both a and b are "the same" value, insofar as they are `==`
Also nope.
Let's compile this: