Re: CGContext always creating a black rect.

Ben Kennedy

On 24 Jul 2021, at 12:56 pm, Alex Zavatone via <zav@...> wrote:

I know I don’t need the self, but I want the context. A variable just sitting around tells me nothing about the context in which it exists. I want to see the context and want to see the self.
I initially felt that way too, several years ago, when first coming from Obj-C. However, I learned to embrace the tools (which make it easy to find the declaration) and also be mindful of writing clear and well-organized code to keep the mental burden of symbol bookkeeping to a minimum.

Moreover, following conventional style (which, in Swift, eschews the redundant `self.`) makes it easier to work with other developers.

- That same function seems like it ought to be pure; i.e., have no side effects -- just draw a rect based on its argument. However, it does math and sets instance variables. If it needs to affect and act on persistent state, it ought to be refactored.
Refactored how? [...]

Here’s how I currently call it. [...]

self.roundedRect.configure(rectWidth: rectWidth, rectHeight: rectHeight, rectBgColor: rectBgColor , rectBorderColor: rectBorderColor, rectBorderWidth: rectBorderWidth, rectCornerRadius: rectCornerRadius)

Seems like your `configure(…)` method is the ideal place for those calculations.

In Swift, I HATE how they have done method parameters, so I’m opting for redundant redundancy over terseness or brevity.
I'm not sure what you're referring to about "how they have done method parameters".


Join { to automatically receive all group messages.