Skip to content

Instantly share code, notes, and snippets.

@bqmackay
bqmackay / gist:4c91ed8c6e18c445046e02099358705e
Created January 15, 2021 23:28
Example of good and bad comments
//Bad Comment (https://improvingsoftware.com/2011/06/27/5-best-practices-for-commenting-your-code/)
// Loop through all bananas in the bunch
foreach(banana b in bunch) {
monkey.eat(b); //make the monkey eat one banana
}
//Good Comment (https://www.freecodecamp.org/news/code-comments-the-good-the-bad-and-the-ugly-be9cc65fbf83/)
function addSetEntry(set, value) {
//Bad White Space
func request(_ demand: Subscribers.Demand) {
assert(demand > 0)
guard let downstream = downstream else { return }
self.downstream = nil
streamHandler { stream in
_ = downstream.receive(stream)
if case .complete = stream.event { downstream.receive(completion: .finished) }
}.resume()
}
@bqmackay
bqmackay / gist:9098e52f6aabebcc1f74bb4e8770e3d5
Created January 15, 2021 23:00
Clear Variable Name Example
//clear variables
username = "bob.smith"
is_authenticated = true
//not-so-clear variables
u = "kevin.james"
auth = true