[swift-evolution] SE-0105: Removing Where Clauses from For-In Loops

Haravikk swift-evolution at haravikk.me
Fri Jun 24 17:00:38 CDT 2016


> On 24 Jun 2016, at 22:33, Erica Sadun via swift-evolution <swift-evolution at swift.org> wrote:
> 
> most of these read as if there is too much logic stuffed into a single line:
> 
>> for otherWall: Wall in self where otherWall != wall && !removedWalls.contains(otherWall) {
>> 
>>         for otherPieceOfFurnitureNode in localFurnitureModelUUIDsToInterfaceElements!.values where otherPieceOfFurnitureNode !== pieceOfFurnitureNode {
>> 
>>         for lineSegmentObject in wallRelatedLineSegments where remainingLineSegments.contains(lineSegmentObject) {
>> 
>>         for colinearLineSegmentObject in remainingLineSegments where colinearLineSegmentObject.angle.isEssentially(infiniteLineAngle: lineSegmentObject.angle) {
>>
Personally the logic seems pretty simple to me (especially the second and third one, plus the fourth isn't actually complex), I'd say the biggest problem to readability here is that the names seem too verbose, though without seeing the rest of the code that's hard to judge. For example the last example doesn't look so bad if you shorten the names like so:

	 for colinearSegment in remainingSegments where colinearSegment.angle.isEssentially(angle: segment.angle) { // Is parameter name even necessary?

Basically on the basis that it's probably obvious from context that this is to do with lines that this is to do with lines, not sure if .isEssentially()'s parameter name can be changed, but I'm not sure why there needs to be a distinction that the angle is for an infinite line (an angle is an angle).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160624/51737ae2/attachment.html>


More information about the swift-evolution mailing list