Closed PhillipSenn closed 9 years ago
This uses method chaining like jQuery which is fairly commonplace. I acknowledge it's a bit clever but that's the intent of the headline to capture people's attention on "charge a card in 6 lines of code". I appreciate the feedback - I think a more involved sample in the readme that shows more usage and did not have any shortcuts would be a valuable addition?
Right. One of my pet-peeves is in the introduction to a book about a certain new technology, the writer says something along the lines of "This is an example of how complicated/powerful it can be". But for a proof-of-concept, I am looking for an explanation for everything. Method chaining is a shortcut. I don't mind taking a little longer on the first trip. So when would you assign account if you were not using method chaining? Would say
obj = svc.createCreditCard()
obj.setAccount()
obj.setMonth()
obj.setYear()
obj.setFirstName()
account = obj.setLastName()
It would be:
account = svc.createCreditCard()
account.setAccount()
account.setMonth()
account.setYear()
account.setFirstName()
account.setLastName()
Can
be rewritten so that one line of code does 1 thing? If I were to break this down into 6 lines, I wouldn't know which one to make an assignment statement to assign account to.