Earlier quoted context omitted.
> Isn't TCA a dependency framework? It is but it's quite straightforward to build your own simpler version using only Combine - that's what we're doing at the moment and it tends to work very well, interacting with Core Data has been kind of clunky though. > I am looking forward to SwiftUI. I really hope that the documentation improves, though. I've been on a project using it for the last 8 months both for macOS and…
If you are using TCA only for dependency management, I’d suggest to reconsider and put all business logic in it. In my experience, most serious efforts of wrangling SwiftUI into a complex app wind up with a solution that’s similar to TCA.
Hang your code out to DRY
71–80 of 82 posts
Re: Hang your code out to DRY
#72I once read a comment I wish I'd saved. It goes along the lines of: W beats X, X beats Y, Y beats Z; in terms of what principle you'd like to apply to your code. One of these letters was essentially representing DRY. I summed things up pretty nicely. Does someone happens to remember?
>I try to optimize my code around reducing state, coupling, complexity and code, in that order. I'm willing to add increased coupling if it makes my code more stateless. I'm willing to make it more complex if it reduces coupling. And I'm willing to duplicate code if it makes the code less complex. Only if it doesn't increase state, coupling or complexity do I dedup code.
https://news.ycombinator.com/item?id=11042400
edit: and of course it's from a long and worthwhile HN thread on Sandi Metz's original article which was the start of the back-and-forth resulting in the article for this thread
Re: Hang your code out to DRY
#73Earlier quoted context omitted.
If you are using TCA only for dependency management, I’d suggest to reconsider and put all business logic in it. In my experience, most serious efforts of wrangling SwiftUI into a complex app wind up with a solution that’s similar to TCA.
Ah! We're putting all our business logic in it, I guess I misunderstood what OP was asking and assumed they meant something else, that's why I mentioned we built our own version of it internally.
That's a nonstarter, for me. I'm pretty picky about dependencies. If I use external ones, I like them to be something that can be encapsulated/injected, as opposed to being totally interwoven.
But I'm not trying to make money, I just want to write really good apps.
Re: Hang your code out to DRY
#74Earlier quoted context omitted.
There's something to be said for preferring composition over inheritance, but in that case overly DRY code consists almost entirely of glue. As with almost anything it's a matter of choosing the right tool for the job. The only code style advices that I've found to hold nigh universally are the following: - The best code is no code - Don't end classes in 'er' or 'or' Coding paradigms are good when they let you do tho…
Almost every one of my classes (in my UIKit app) is a ViewController. I don't really need to write anything more. So they pretty much all are "er" classes. ¯\_(ツ)_/¯
I'm not ruling out that this is an illustration of the problem with classes ending in -er.
Re: Hang your code out to DRY
#75Earlier quoted context omitted.
Almost every one of my classes (in my UIKit app) is a ViewController. I don't really need to write anything more. So they pretty much all are "er" classes. ¯\_(ツ)_/¯
So what you're saying is you've got a bunch of views and most of your programming code is spent on classes that ensures they do the right thing? I'm not ruling out that this is an illustration of the problem with classes ending in -er.
It's just the way you write iOS apps (at least, the original design way).
It's classic MVC. Most of the action happens in the controllers.
BTW: I totally agree that the best code I write, is the code I don't write.
Re: Hang your code out to DRY
#76But DRYing your code can cause it to shrink...
Re: Hang your code out to DRY
#77Re: Hang your code out to DRY
#78Earlier quoted context omitted.
Why does the "does it actually work" go down over time? I would expect to be the other way round: more experience, more chances your software "actually works", even if it's not following strict rules anymore.
The axis is labelled "relative importance". If you place non-zero value on readability, you must place less than 100% importance on "does it work".
Re: Hang your code out to DRY
#79Earlier quoted context omitted.
Ah! We're putting all our business logic in it, I guess I misunderstood what OP was asking and assumed they meant something else, that's why I mentioned we built our own version of it internally.
Nah. I meant that it is a library, that needs to be included as a dependency. That's a nonstarter, for me. I'm pretty picky about dependencies. If I use external ones, I like them to be something that can be encapsulated/injected, as opposed to being totally interwoven. But I'm not trying to make money, I just want to write really good apps.
Re: Hang your code out to DRY
#80My first heuristic is: If I change the code in block A, is it assured that I will need to change the code in block B? My second heuristic is: Can I name the method I wish to de-duplicate in a way that is honest for all cases I wish to cover, yet explains its business purpose? The more it deviates from these heuristics, the more likely I am to duplicate the code in object oriented programming.
My slightly different heuristic: If fact X changes, how many places in the code do we have to change it? If the number is > 1, relying on humans to realize that will, on average, always fail. I know of two ways to fix that. [1]: DRY it up. [2]: Write a test asserting that all the places use the same value. Sadly, most people rely on this: [3]: We "just have to remember" to do these changes in all places, despite the…
[3b] is adding comments, which is better than relying purely on memory but can often be missed. I've locally improved on this a bit by including cross-references on the relevant lines, along with tooling such that the referents are automatically surfaced during code review.