3

I'm trying really hard to like Swift but every time I open the hood on this bird, it takes a shit on my windshield.

For example:

struct ContentView: View {

var body: some View {
let kFontPointSize = 25.0
var theFont: Font = .system( size: kFontPointSize )

theFont = .custom("Helvetica", size: kFontPointSize )

Text("Hello, World!")
.padding(.horizontal, 20.0)
.font( theFont )
}

}

... in spite of how wonderfully self documenting (🐂💩) Swift is, that dirty bird converts the 'var' to a 'let' and "theFont" cannot be reassigned after declaration.

3 things:

1. invisibly converting the 'var' to a 'let' and not indicating 'var' can't be used... really?! Suppose to just "know" these obscure inconsistencies? (sloppy design)

2. then the error Xcode presents on "theFont = ..." line is : "Type '()' cannot conform to 'View'"!? How about "can't use a 'var' here"? God forbid it should make sense. (sloppy design)

3. "var" means variable and "let" means letstant? If you are going to use "var", better use "const", or be consistent and use "set" and "let" instead of "var" and "let" (sloppy inconsistency)

4. and ".horizontal", who owns that? Self documenting?. It is owned Edge Set aka Edge.Set.horizontal and effectively a "global".

5. And reading the Swift coder's mind... No, you should NEVER NEVER NEVER use "25" as a constant literal passed like .system( size: 25 ). (magic numbers not aloud)

Have all best engineering practices been simply tossed out the window? Rule #1 in software "engineering": Globals are BAD. Corollary: magic numbers earn you a one-legged A on your project.

I am so incredibly disappointed in the Swift community right now. Swift designers are honestly earning a "script kiddy" badge of dishonor.

Comments
  • 0
    You should learn the basics of SwiftUI.
    There is a lot of misunderstanding in your rant.

    It’s not converting var to let.

    SwiftUI Views are immutable value types, that’s why using var for later mutation is an antipattern.

    If you want mutation and state inside of Views, you should use @State or @Binding or make dedicated view models.
  • 0
    A static constant living in a type is not a global.

    It’s like an enum case.
Add Comment