WWDC

Nycturne

Elite Member
Posts
1,137
Reaction score
1,484
I'm excited to see the news on the Metal & SwiftUI fronts too. SwiftUI is still very new, so great changed year after year are still expected, but it's hard to know what they'll try to cover first, there's still so much to do.

Same. I'd like to not have to drop into UIKit for my UISplitView to not behave like it's drunk and having a hard time remembering what it's supposed to do.

I’ve slowly started being unable to keep up - SwiftUI seems to be better documented for things like Combine than for presenting locally stored, generated or calculated information.

The crux with SwiftUI is that they seem to be unwilling to commit to a development model. MVC, MVVM or the like. So there's all this stuff to help wire things up, but not a lot of guidance on what good, maintainable, code actually looks like when solving real problems.

I've been focused on following MVVM which involves using a lot of @ObservedObject and generic views. Works pretty well, but it does mean you wind up ignoring a good chunk of what SwiftUI offers in a lot of your code. Stuff like @AppStorage and @FetchedResults are honestly maintainability traps, IMHO. It's also really easy to over-observe with @ObservedObject, and I've seen folks trying to use Redux-like state management get caught by that.
 

DT

I am so Smart! S-M-R-T!
Posts
6,405
Reaction score
10,455
Location
Moe's
Main Camera
iPhone
I'm always hopeful, especially at a WWDC, that we finally see "user accounts" at least on iPadOS.

And to be clear, I get it, there's certainly __a__ business model to limiting unique user account/setting/config to a single device (at outside of the education and enterprise markets). You want two unique user devices? Buy two. I think, however, that's being a touch short sighted. A lot of folks I talk to, myself included, who just grumble over the lack of accounts, don't buy a device-per-person and most importantly, don't upgrade as often as the lack of user accounts dilutes the value of the device.

The little G started using the iPad Pro more*, I setup an existing Magic KB+TP for it, and a stand, but since I was logged in, as she started configuring it, hahaha, my devices started getting her new focus defs, plus she'd like to use her Messages, but I kind of need mine too, it's a PITA.








* regular readers will know this is due to a MBP mishap
 

Andropov

Site Champ
Posts
617
Reaction score
776
Location
Spain
and the newer versions of swift give me headaches. I am beginning to think like a swift programmer instead of a c programmer, but it is evolving very fast and it’s hard for me to keep up.
I taught myself C. Then later on, C++. Then really later on, C#. I never really got the hang of Obj-C. But I had nothing on the line. I wasn't trying to write an app, I was just curious. Then it wasn't long before Swift came around, and I taught myself that. Had I had a goal beyond "learn Objective-C", I might have picked up and retained it better. I must say I'm a fan of Swift and especially SwiftUI.
I learned programming with a online course on Python. Soon after, C, as it was all that my college courses used. I went a couple years using some combination of C and Python or compiled Python (using Cython or Numba), so even when I was using Python I was thinking of what the C code underneath was doing. High performance was a must back then. I love Swift, and I'm a fan of how it does some things too, but I don't like not knowing what some things (like some of Swift's newest features or how SwiftUI's refreshing works) are doing underneath.

And I despise optionals. There's just too many ways to unwrap them and I have a hard time reading the code still. When I see an oddly placed ? or !, half the time I need to go look up what it means. But that's just from not doing it enough. I'd not heard about anything coming with Swift optionals, but now I'm really curious. If they could fix that, I think it would be a fantastic language.
I *really* like the optionals. Having to specify at compile time how nil values are handled avoids a lot of weird bugs and crashes happening. You can still write crappy code with them, for sure, like having almost everything be optional and then having half your code being guard or if let lines. But a lot of things that could have been crashes get to be just empty UIs, and you have a good idea of how they'd look.

That said, there are a lot of ways to unwrap them, that's true. Maybe I feel like that's less of a problem because I only ever use guard, if let or optional chaining. I never force unwrap or implicitly unwrap variables.

I've sadly not dug into Combine much at all. I find it confusing and uninteresting (it's that second one that kills me). I might try to dig a little deeper into that this year.
I worked in a project that used Combine heavily. At some points the codebase had types that were a paragraph long. Things like variables with type:

PasstroughSubject<(PassthroughSubject<String, Never>, PassthroughSubject<Int, Never>), Never>

I was not amused. I like how SwiftUI has most of the functionality we were using from Combine hidden behind useful property wrappers.

Same. I'd like to not have to drop into UIKit for my UISplitView to not behave like it's drunk and having a hard time remembering what it's supposed to do.
Heh. My problem is with horizontal scrolling lists. There's LazyHStacks, but I need the cells to be recycled.

The crux with SwiftUI is that they seem to be unwilling to commit to a development model. MVC, MVVM or the like. So there's all this stuff to help wire things up, but not a lot of guidance on what good, maintainable, code actually looks like when solving real problems.

I've been focused on following MVVM which involves using a lot of @ObservedObject and generic views. Works pretty well, but it does mean you wind up ignoring a good chunk of what SwiftUI offers in a lot of your code. Stuff like @AppStorage and @FetchedResults are honestly maintainability traps, IMHO. It's also really easy to over-observe with @ObservedObject, and I've seen folks trying to use Redux-like state management get caught by that.
I think SwiftUI strongly encourages a MVVM architecture. That's what Apple uses for its tutorials, and it makes the most sense given the features of the framework, although it's true that it can cause issues like over-observing objects or having massive ViewModels.

In fact, I think the transition to SwiftUI is going to be a giant pain for a lot of codebases (or downright impossible). Changing language (like on the Objective-C to Swift transition) is a pain, but it's mostly interoperable and can be made in small chunks, progressively. But embracing SwiftUI requires (IMHO) embracing MVVM, and changing architectures is not something easy to do progressively.
 

MEJHarrison

Site Champ
Posts
927
Reaction score
1,828
Location
Beaverton, OR
Soon after, C, as it was all that my college courses used.

WHAT??!?!? While I was in college, I learned Pascal, C (which I already knew), some light assembly stuff, Modula-2, Prolog, LISP, ADA, Fortran, and several more I'm forgetting at the moment. I want to say I learned 10-12 different languages (some deeply and some we just scratched the surface) while I was in college.

I *really* like the optionals. Having to specify at compile time how nil values are handled avoids a lot of weird bugs and crashes happening. You can still write crappy code with them, for sure, like having almost everything be optional and then having half your code being guard or if let lines. But a lot of things that could have been crashes get to be just empty UIs, and you have a good idea of how they'd look.

I like the idea of optionals. That's brilliant. It's their implementation I struggle with. And to be fair, I honestly don't have any better ideas for how to implement them. I just know that without more exposure, I find them hard to decipher.

To put it simply, I can read code but I need to decipher optionals. It's like reading a book, then coming across a paragraph where you need to stop reading and translate from a foreign language.

Also, to be completely fair, if I worked with Swift on a normal basis, I'd learn to read them. But I play with Swift for 1-3 months just after WWDC, then get bored and move on. This is entirely a ME problem. I'm not saying Swift is a bad language because of optionals. If I put more effort into it, they would cease to bother me.

That said, there are a lot of ways to unwrap them, that's true. Maybe I feel like that's less of a problem because I only ever use guard, if let or optional chaining. I never force unwrap or implicitly unwrap variables.

That's another thing about optionals. Looking back at some old notes, I see 6 ways to deal with optionals. I've got Force Unwrapping, Check for nil value, Optional Binding, Nil Coalescing Operator, Optional Chaining and Guard. That's a lot of options for a language that removes options when possible (no semi-colon, always use curly braces, etc).

When it's all said and done, I think there's far more to like in Swift than stuff not to like. I'd still say out of 20+ languages I've picked up over the years, it's my all-time favorite. I'd love to work with it on a more regular basis.
 

Cmaier

Site Master
Staff Member
Site Donor
Posts
5,326
Reaction score
8,512
WHAT??!?!? While I was in college, I learned Pascal, C (which I already knew), some light assembly stuff, Modula-2, Prolog, LISP, ADA, Fortran, and several more I'm forgetting at the moment. I want to say I learned 10-12 different languages (some deeply and some we just scratched the surface) while I was in college.



I like the idea of optionals. That's brilliant. It's their implementation I struggle with. And to be fair, I honestly don't have any better ideas for how to implement them. I just know that without more exposure, I find them hard to decipher.

To put it simply, I can read code but I need to decipher optionals. It's like reading a book, then coming across a paragraph where you need to stop reading and translate from a foreign language.

Also, to be completely fair, if I worked with Swift on a normal basis, I'd learn to read them. But I play with Swift for 1-3 months just after WWDC, then get bored and move on. This is entirely a ME problem. I'm not saying Swift is a bad language because of optionals. If I put more effort into it, they would cease to bother me.



That's another thing about optionals. Looking back at some old notes, I see 6 ways to deal with optionals. I've got Force Unwrapping, Check for nil value, Optional Binding, Nil Coalescing Operator, Optional Chaining and Guard. That's a lot of options for a language that removes options when possible (no semi-colon, always use curly braces, etc).

When it's all said and done, I think there's far more to like in Swift than stuff not to like. I'd still say out of 20+ languages I've picked up over the years, it's still my all-time favorite. I'd love to work with it on a more regular basis.

I tend to check for nil more than I should, just so i can read my code months later. I mean, how can stuff like ”if let foo = foo …” be any good?
 

Nycturne

Elite Member
Posts
1,137
Reaction score
1,484
To put it simply, I can read code but I need to decipher optionals. It's like reading a book, then coming across a paragraph where you need to stop reading and translate from a foreign language.

Also, to be completely fair, if I worked with Swift on a normal basis, I'd learn to read them. But I play with Swift for 1-3 months just after WWDC, then get bored and move on. This is entirely a ME problem. I'm not saying Swift is a bad language because of optionals. If I put more effort into it, they would cease to bother me.

For me, the other aspect is that optionals are something that crop up a lot when working with certain Objective-C libraries. It’s gotten better over the years, but initially, you were inundated with optionals from UIKit and the like. These days, it’s more constrained to specific libraries like CoreData.

But yes, if you are used to dealing with pointers, it’s definitely a trip getting used to.

That's another thing about optionals. Looking back at some old notes, I see 6 ways to deal with optionals. I've got Force Unwrapping, Check for nil value, Optional Binding, Nil Coalescing Operator, Optional Chaining and Guard. That's a lot of options for a language that removes options when possible (no semi-colon, always use curly braces, etc).

When it's all said and done, I think there's far more to like in Swift than stuff not to like. I'd still say out of 20+ languages I've picked up over the years, it's my all-time favorite. I'd love to work with it on a more regular basis.

The difference is that for the most part they aim for different uses, versus “++” and “+= 1” which have identical behaviors. Forced/implicit unwrap is more code smell, but has some uses with Obj-C interop and things like IBOutlet and other limited cases where you can guarantee that a value is valid by the time it can be used. Guard was mostly introduced because using Optional Binding for preconditions was leading to the pyramid of doom.

But yes, nil coalescing and optional chaining are really there as syntactic sugar. But without coalescing you get the mess of something like:

let string = {
if let value = maybeValue {
return value
} else {
return “Unknown Value”
}
}()

or more accurately, making it a function call or computed property instead of:

let string = maybeValue ?? “Unknown Value”

I tend to check for nil more than I should, just so i can read my code months later. I mean, how can stuff like ”if let foo = foo …” be any good?

It’s one reason I’ve adopted the patterns of: “if let realFoo = foo” or “if let foo = maybeFoo”, to avoid the variable shadowing behaviors. But “if let foo = self.foo” has been a bit too common in my code.

I worked in a project that used Combine heavily. At some points the codebase had types that were a paragraph long. Things like variables with type:

PasstroughSubject<(PassthroughSubject<String, Never>, PassthroughSubject<Int, Never>), Never>

I was not amused. I like how SwiftUI has most of the functionality we were using from Combine hidden behind useful property wrappers.

It also seems like the Swift team is currently more interested in the benefits of structured concurrency than Combine at the moment. Chunks of what you might use Combine for are being written into a library that operates on AsyncSequences instead. But it does look like it requires changes that are in Swift 5.6. So I think this general trend of ignoring Combine as a tool for app developers will continue.

Heh. My problem is with horizontal scrolling lists. There's LazyHStacks, but I need the cells to be recycled.

Hmm, I’m not too familiar with the issue there, but I am curious. What’s the problem being faced?

I think SwiftUI strongly encourages a MVVM architecture. That's what Apple uses for its tutorials, and it makes the most sense given the features of the framework, although it's true that it can cause issues like over-observing objects or having massive ViewModels.

In fact, I think the transition to SwiftUI is going to be a giant pain for a lot of codebases (or downright impossible). Changing language (like on the Objective-C to Swift transition) is a pain, but it's mostly interoperable and can be made in small chunks, progressively. But embracing SwiftUI requires (IMHO) embracing MVVM, and changing architectures is not something easy to do progressively.

Fair enough, looking over the tutorials again, I do see that they are pretty MVVM. I’d still argue that Apple doesn’t do a good enough job getting folks onto the golden path, and some of their choices of what to include are great for prototyping, but are traps that make it harder to consolidate similar views that should be consolidated. I learned more looking at how they implemented the SwiftUI API itself than from the tutorials.

To a point I agree that existing codebases aren’t going to be able to transition easily. That said, with how you can mix and match AppKit/UIKit and SwiftUI means that you can use SwiftUI in more limited ways which are much less costly to implement. I can see legacy apps using SwiftUI as a means to start building out specific components in the view hierarchy. With this bottom up approach, you can start with components that are built around bindings and simple state rather than full view model objects. And it’s not like you can’t back a view model with a data source or some other data available to a delegate/controller object as part of a transitional state. If you want an MVVM-compliant @FetchedResults, you need to do something similar anyways by wrapping NSFetchedResultsController yourself.
 

Yoused

up
Posts
5,620
Reaction score
8,937
Location
knee deep in the road apples of the 4 horsemen
they aim for different uses, versus “++” and “+= 1” which have identical behaviors

That is not quite correct, though. Getting rid of "++" is a net positive because it lacks the coherence of "+=". Consider a C statement like
Code:
if ( a < x++ ) a = a + x-- ;
What is the value of x at the end of such a statement? Without the "++" operator, the programmer has to compose expressions in a more verbose, comprehensible way. Or there might be something like
Code:
a = x++ * ( b - x );
I am not sure how compilers work, but I would expect the "( b - x )" to happen before the "x++" in object program flow (because that makes the most operational sense), which would yield a different result than a strict left-to-right interpretation. If there is variation in different compiler output due to weird features like this (or, say, bitfields in a struct), your portability/consistency will suffer.
 

MEJHarrison

Site Champ
Posts
927
Reaction score
1,828
Location
Beaverton, OR
I tend to check for nil more than I should, just so i can read my code months later. I mean, how can stuff like ”if let foo = foo …” be any good?

I would never in a million years write "if let foo = foo ..." o_O

I've been writing code for a long time. In all that time, the best compliment I've ever received was "Hey, I was in that old project of yours making changes and it was really easy to read and modify". That was on code that was 10 years old at that point. My worst experience was the first thing I did out of college. It used binary trees and all kinds of complicated algorithms. It's was super efficient, but 6 months later, I couldn't understand it. It's easy to write code computers understand, the skill/art is in writing code people understand.
 

Cmaier

Site Master
Staff Member
Site Donor
Posts
5,326
Reaction score
8,512
Hmm

Prior WWDC Announcement Dates

2010: Wed. Apr. 28
2011: Mon. Mar. 28
2012: Wed. Apr. 25
2013: Wed. Apr. 24
2014: Thurs. Apr. 03
2015: Tue. Apr. 14
2016: Mon. Apr. 18
2017: Thurs. Feb. 16
2018: Tue. Mar. 13
2019: Thurs. Mar. 14
2020: Fri. Mar. 13 / Jun. 5
2021: Tue. Mar. 30
 

Nycturne

Elite Member
Posts
1,137
Reaction score
1,484
That is not quite correct, though. Getting rid of "++" is a net positive because it lacks the coherence of "+=".

Fair. For a bit I did blank out on the side-effect nature of the thing. I really have spent too much time away from C/C++, and far too much time in the RN/Swift/Java world. :|

While I phrased it poorly, I think my point was more to show that the different modes of optional handling came out of different patterns (or anti-patterns), with the goal of addressing those directly. It's the cost of requiring developers to be explicit with an optional.

Or there might be something like
Code:
a = x++ * ( b - x );
I am not sure how compilers work, but I would expect the "( b - x )" to happen before the "x++" in object program flow (because that makes the most operational sense), which would yield a different result than a strict left-to-right interpretation. If there is variation in different compiler output due to weird features like this (or, say, bitfields in a struct), your portability/consistency will suffer.

I agree and would just add that even if the language and compiler is consistent enough to make this particular snippet portable, it’s not legible.

I would never in a million years write "if let foo = foo ..." o_O

And yet, Xcode will happily auto-complete it for you. Go figure. I think Apple is expecting folks to lean on auto-complete to know when variables are in-scope or not, but I still don't like it.
 

Cmaier

Site Master
Staff Member
Site Donor
Posts
5,326
Reaction score
8,512
To be honest, I do

If let _foo = foo

Usually. A habit from my c days when dealing with local variables.
 

Yoused

up
Posts
5,620
Reaction score
8,937
Location
knee deep in the road apples of the 4 horsemen
I agree and would just add that even if the language and compiler is consistent enough to make this particular snippet portable, it’s not legible.
If I were designing a language, the specification would include a "framing rule" stating that within the frame of an expression, all variables would yield the value they had prior to the beginning of the expression and no secondary assignments would commit until the expression had been completed. I think a language has to be defined in more strict terms than classical C, so that programmers are not using synthetic stunts (like that evil thing I was doing in Objective C, using "self = …" to build and navigate internally linked structures within a method).
 

Andropov

Site Champ
Posts
617
Reaction score
776
Location
Spain
WHAT??!?!? While I was in college, I learned Pascal, C (which I already knew), some light assembly stuff, Modula-2, Prolog, LISP, ADA, Fortran, and several more I'm forgetting at the moment. I want to say I learned 10-12 different languages (some deeply and some we just scratched the surface) while I was in college.
I was in for a Physics BSc, so there was a limited amount of programming-related courses. In fact, the only programming-related mandatory subjects were an introductory course to informatics on the first year (C and C++) and a course on Computational Physics on the second year (also in C) which was less about programming and more about useful algorithms in simulations. Other courses had programming assignments, and it was possible to fit a decent amount of experience on numerical simulations with that, but there wasn't a lot of push for learning new languages. We didn't even *really* need to learn Python, but since we had freedom to chose whatever language we wanted and Python has NumPy/SciPy and the like... it was the best tool for some of the assignments, so some of us used it.
I had some contact with Fortran too, since I was given a bunch of Fortran code written by my proffessor to compute some things for a section my final graduate dissertation. And, for the rest of the project, since I had chosen to make it run on the GPU, I used Metal. And then I wrote the UI in Swift, which I had learned for a different reason outside college. But a lot of people graduated knowing only C.

Hmm, I’m not too familiar with the issue there, but I am curious. What’s the problem being faced?
You can set up SwiftUI lists to recycle cells, as long as you initialize them with:
Swift:
List(items) { item in
    ExampleCellView(item)
}
If you are scrolling down, ExampleCellViews that go offscreen at the top simply get reused and start appearing at the bottom (with new parameters). So, at any given time, no matter how much you've scrolled, there's only a handful of ExampleCellViews in memory. So you can create a infinite scrolling List trivially. LazyHStacks, on the other hand, don't deallocate or recycle instances of its views in memory. So if you do:
Swift:
LazyHStack {
    ForEach(items, id: \.self) { item in
        ExampleCellView(item)
    }
}
At first you have just a couple cells in memory, since they're lazily loaded. But if you scroll through a long array of items, new ExampleCellViews keep being added to memory, without the first ones being deallocated/recycled. So if you try to create an infinite scrolling LazyHStack, it'll eventually run out of memory.

Fair enough, looking over the tutorials again, I do see that they are pretty MVVM. I’d still argue that Apple doesn’t do a good enough job getting folks onto the golden path, and some of their choices of what to include are great for prototyping, but are traps that make it harder to consolidate similar views that should be consolidated. I learned more looking at how they implemented the SwiftUI API itself than from the tutorials.
Agreed.

To a point I agree that existing codebases aren’t going to be able to transition easily. That said, with how you can mix and match AppKit/UIKit and SwiftUI means that you can use SwiftUI in more limited ways which are much less costly to implement. I can see legacy apps using SwiftUI as a means to start building out specific components in the view hierarchy. With this bottom up approach, you can start with components that are built around bindings and simple state rather than full view model objects. And it’s not like you can’t back a view model with a data source or some other data available to a delegate/controller object as part of a transitional state. If you want an MVVM-compliant @FetchedResults, you need to do something similar anyways by wrapping NSFetchedResultsController yourself.
Oh, putting little SwiftUI views inside existing UIKit screens (which is how most codebases are going to start the transition) is for sure going to be the easy part. And with just that it's going to make a *great* design system for apps. But when you're using entirely SwiftUI screens and not just components, you're going to want to switch to MVVM, and for a while the architecture is going to be a mess.

And yet, Xcode will happily auto-complete it for you. Go figure. I think Apple is expecting folks to lean on auto-complete to know when variables are in-scope or not, but I still don't like it.
I think most people do if let foo = foo { ... } now. I haven't seen any codebase where unwrapping optionals doesn't use variable shadowing by default. You get used to it, and it becomes perfectly natural... but it's still a terrible choice of syntax for any newcomer IMHO. Zero readability. I used to hate it.
 

Nycturne

Elite Member
Posts
1,137
Reaction score
1,484
At first you have just a couple cells in memory, since they're lazily loaded. But if you scroll through a long array of items, new ExampleCellViews keep being added to memory, without the first ones being deallocated/recycled. So if you try to create an infinite scrolling LazyHStack, it'll eventually run out of memory.

Good to know. So far I’ve limited my LazyHStacks to avoid too much horizontal scrolling on iPhone form factors. Haven’t yet tried it on tvOS in an unbounded way, but I am about to. Explains why I haven’t seen this yet.

Oh, putting little SwiftUI views inside existing UIKit screens (which is how most codebases are going to start the transition) is for sure going to be the easy part. And with just that it's going to make a *great* design system for apps. But when you're using entirely SwiftUI screens and not just components, you're going to want to switch to MVVM, and for a while the architecture is going to be a mess.
I think my point is more that by going bottom-up, you can build out the view model layer incrementally, focusing on what components and screens need, and that those early view models can be backed by something akin to a view controller initially if absolutely have to.

But having worked a lot on large legacy codebases, these sort of incremental efforts are not new to me. It’s costly, but everything in a legacy codebase tends to be costly.
 

Yoused

up
Posts
5,620
Reaction score
8,937
Location
knee deep in the road apples of the 4 horsemen
I have to wonder what a Mac Pro would look like. 20-some years ago, I had a Mac 7500. My mom bought me my first digital camera, I had to have a way to get images onto the computer, so I put a USB+FW card into a PCI slot. Obviously, the serial stuff is now all standard, and Apple is laser-focused on iGPU, so what would anyone really need slots for anymore? There is really no other functionality to be gained that one could not obtain through a TB peripheral. I just find it difficult to imagine a Pro Mac that would look significantly different from a Studio (sexier color, maybe), certainly not a cheese grater or garbage can.
 

B01L

SlackMaster
Posts
175
Reaction score
131
Location
Diagonally parked in a parallel universe...
Top Bottom
1 2