[swift-evolution] Hidden initiallizations ...

Andrey Tarantsov andrey at tarantsov.com
Tue Mar 29 08:26:21 CDT 2016


> Actually I use a lot of Applescript style naming, though admittedly I can be a bit inconsistent about it. For example, I like using eachFoo as a name for a loop variable like so:
> 
> 	for eachIndex in 1 ..< 100 { … }
> 
> Which can read nicely as natural language, but since I don’t use eachFoo anywhere else, helps to avoid name collisions. If eachFoo is optional, then I might unwrap the value into theFoo instead like-so:
> 
> 	let theValues:[Int?] = []
> 	for eachValue in theValues {
> 		if let theValue = eachValue { /* Do some stuff */ }
> 		else { /* Do some other stuff */ }
> 	}

Interesting! :-) I should explore this, sounds fun in some cases.

I typically just use the bare word:

for value in values {
  if let value = value {
    foo(value)
  }
}

...but sometimes that clashes with an argument or field, and yours could be a good convention to resolve those cases.

A.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160329/10dffb39/attachment.html>


More information about the swift-evolution mailing list