You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Swift, parentheses in loops / control structures are optional. They often times make readability easier, but in some cases can also overly complicate the code. It is up to you whether you want to use them or not, but there are a couple of places in this project in which I feel they could be removed. Here is an example:
In Source/Factories/LinkedList.swift:
//the number of itemsvarcount:Int{
if (head.key ==nil){return0}else{varcurrent:LLNode= head
varx:Int=1//cycle through the list of items
while ((current.next)!=nil){
current = current.next!
x++}return x
}}
I think that we could change the code, for example in the if statement, to be:
var count:Int{
if head.key ==nil{return0}
and in the while loop:
//cycle through the list of items
while current.next !=nil{
current = current.next!
x++}
Again, up to you, the author, but I think it could help Swift learners looking at this code to recognize some of the readability features of Swift versus Objective-C.
The text was updated successfully, but these errors were encountered:
Thanks for bringing up this great point. I was planning on mentioning the optional use of parentheses with my next essay on closures, but it would be worth noting this with the existing code base. If there are other areas you feel should / could be updated, feel free to send along the filename and line numbers and I can take a look.
In Swift, parentheses in loops / control structures are optional. They often times make readability easier, but in some cases can also overly complicate the code. It is up to you whether you want to use them or not, but there are a couple of places in this project in which I feel they could be removed. Here is an example:
In
Source/Factories/LinkedList.swift
:I think that we could change the code, for example in the if statement, to be:
and in the while loop:
Again, up to you, the author, but I think it could help Swift learners looking at this code to recognize some of the readability features of Swift versus Objective-C.
The text was updated successfully, but these errors were encountered: