[swift-users] Coding style for internal/private variables
adrian.zubarev at devandartist.com
Wed Jun 1 12:11:48 CDT 2016
@Austin: do you use self._name or just _name in your code?
I’ve seen self._name usage in swifts standard libraries and didn’t liked it at first glance, but it feels alright now.
My personal habit is to write self. everywhere it’s possible, because as soon as some private variable is nested inside a closure I’ll be forced to write self._name which does look odd if every other _name usage doesn’t contain self.. Again that’s my personal view.
Sent with Airmail
Am 1. Juni 2016 um 18:52:27, Erica Sadun (erica at ericasadun.com) schrieb:
From what I've observed, preceding (rather than trailing) single underscores indicate private use. The standard library includes a fair number of "Apple Internal" (I guess now "Swift Team Internal") variables, methods, functions, etc that follow this practice. This practice is, as far as I can tell, uncoupled with access levels. A function named _foo(), while global and public, is still "hands off please".
All in all, other "Hungarian Style" conventions, that is modifying the name to indicate types and uses, are not used in Swift or among most Swift developers.
On Jun 1, 2016, at 10:02 AM, Adrian Zubarev via swift-users <swift-users at swift.org> wrote:
I’d like to talk about your personal coding styles in swift for its access control.
Remember these variable names like __magic or _spell or even garbage_?
Sure swift solves the synthesize problem but there might be old habits that let us write such code.
Here are some examples:
// not sure where `garbage_` would fit
I’d love to see your responses and opinions what and why the style you choose suits you.
Sent with Airmail
swift-users mailing list
swift-users at swift.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-users