3 ms·
This is why: it's hard to get things right. When I started programming for Apple almost 20 years ago (mainly using Objective C), too many hours of my time were
by herodotus 4y ago
This is why: it's hard to get things right. When I started programming for Apple almost 20 years ago (mainly using Objective C), too many hours of my time were spent making sure that I was dealing with memory correctly. Easier in Objective C than C's primitive malloc/free, but still hard, even with the tools to help. During my time there, new things were tried: firstly garbage collection, and then automatic reference counting. This last got rolled into Swift, and hours spent looking for memory leaks or dangling pointers become a thing of the past. It is still possible to have memory problems in Swift, but mostly they can be avoided.
In the case of UI, use of a library is essential. And of course boring technology has libraries. But the real problem is layout: not just where your elements sit on the page, but where they go after the user resizes a window. In the early years, this was not too difficult because screens were mostly fixed size and in landscape mode. But now there are many aspect ratios, four possible orientations and so on. Apples earlier solution was a system called Layout Constraints. Frankly I found them really difficult to use, even when I stuck with the ones provided within Xcode. SwiftUI seems to me the exactly correct way to deal with layout complexity. Admittedly lots of it needs to be improved (as the article points out), but I would much rather use a declarative approach to layout than any alternatives I know of.
- nodemaker 4y agoFor an expert with some mathematical intuition layout constraints can do a custom layout that lays out perfectly on all screen sizes much better than declarative. However there is a learning curve I admit.
- Pulcinella 4y agoI love AutoLayout constraints…unfortunately Apple has never improved debugging tools. So when the system breaks and spews a bunch of autolayout constraint complaints to the debug console, it can be difficult to determine what went wrong (especially because the system will sometimes generate its own constraints, like if you are using stack views, and you have no insight into why they were generated or why the system is ignoring and discarding the constraints you made). Apple’s documentation has also gotten way, way worse. Apple expects you to watch the WWDC videos, but it’s not like they make refresher videos on old topics all the frequently and they often remove or hide old videos.
- nodemaker 4y agoYeah there is a learning curve I admit. Usually you try to change the size of your view and see how things resize. And yes StackView is your biggest friend. Usually when the system ignores your constraint it says that on the log. It can be a bit tricky to find out which constraint its breaking but the View Debugger and also the constraint constant value can help find it.
- allenu 4y agoWhen they introduced auto-layout, I started using it all the time. The debug spew from the console was definitely frustrating to debug though. Eventually I tried going back to manual layout because a coworker still used it all the time and I noticed that it was pretty easy to follow the layout rules in imperative code (so long as it's well-structured). Since then I just do manual layout for everything. It's just easier for my brain to describe the layout I want that way. I feel like it takes me longer to come up with constraints that match what I want, but I'll admit if I went back to auto-layout, I'd probably be better at it.