Swift programming language inconsistency

  • Release Candidate 6
    Guest:
    We are at a “proposed final” true release candidate with nothing known remaining to be changed or fixed. For the full story, please see this page in the "Pre-Release Announcements & Feedback" forum.
    /Steve.
  • Be sure to checkout “Tips & Tricks”
    Dear Guest Visitor → Once you register and log-in:

    This forum does not automatically send notices of new content. So if, for example, you would like to be notified by mail when Steve posts an update to his blog (or of any other specific activity anywhere else), you need to tell the system what to “Watch” for you. Please checkout the “Tips & Tricks” page for details about that... and other tips!

    /Steve.

Any Swift programming language developers here? I notice that there is some grammatical inconsistency with the language.

Example 1​

Take for example optional binding:

if let constantName = someOptional { ... }

Within the 'if' statement, you don't need to force unwrap 'contantName' to access the value in 'someOptional'. In other words, the right side of the assignment is an optional, while the left side is a non-optional.

But in other context, both sides of the assignment have to be optionals:

anotherOptional = someOptional

You need to force unwrap 'anotherOptional' to access the value in 'someOptional'.

Example 2​

To assign a value to an optional, you do this:
optionalInteger = 42

To access the value of the same option, you do this:
optionalInteger! // 42

In the first statement, the left side of the assignment is an optional while the right side is a literal. They are not the same data types. To be grammatically consistent, it should be:

optionalInteger!=42

My rant​

These types of grammatical inconsistencies increases the cognitive load on programmers!! 🙄

I yearn for the good old days of the C programming language, where the grammar of the language is highly consistent.