DevWithTheHair / Conference-Talks

Conference talks and other presentations I have given
7 stars 0 forks source link

Use "standard" for loops? #7

Closed gregheo closed 7 years ago

gregheo commented 7 years ago

Why the forEach closures instead of for/in loops? For loops are a bit more "standard" and idiomatic, so just curious here.

https://github.com/DevWithTheHair/Conference-Talks/blob/3e5acb4ea6b1e10e0528f68a8c1d23a4b8651f83/Elementary-Celebrity-Recognition-My-Dear-Watson/SwiftCloudWorkshop2.swift#L74

DevWithTheHair commented 7 years ago

Hmm, I had a version with for/in loops:

for imageWithFaces in imagesWithFaces.images {
    for face in imageWithFaces.faces {
        if let identity = face.identity {
            // Is a celebrity
            let celebrity: [String: Any] = [
                "isCelebrity": true,
                "name": identity.name
                ]
            imageResults.append(celebrity)
        } else {
            // Is not a celebrity
            let anonymous: [String: Any] = [
                "isCelebrity": false,
                "name": "Unknown"
            ]
        }
    }
}

I thought maybe it might take more explaining than reading it in a style that is somewhat like prose as in forEach image in and forEach face in...

I'm not 100% certain which would be "easier" for non-technical folks to grok.

gregheo commented 7 years ago

for/in is definitely more iOS-friendly (Swift or Obj-C) but say Ruby folks would like the forEach. Not sure what your audience will be (more server?) so maybe this is more appropriate.

Up to your good judgement, of course ;)

DevWithTheHair commented 7 years ago

You've convinced me. 😅

Addressed in https://github.com/DevWithTheHair/Conference-Talks/pull/11.