ghidinelli / cfpayment

ColdFusion payment processing library makes plumbing e-commerce apps easy. Charging credit cards has never been easier. Inspired by Ruby's ActiveMerchant.
Other
90 stars 54 forks source link

Method chaining is a bit confusing for a proof-of-concept #11

Closed PhillipSenn closed 9 years ago

PhillipSenn commented 9 years ago

Can

account = svc.createCreditCard().setAccount(4242424242424242).setMonth(10).setYear(year(now())+1))
             .setFirstName("John").setLastName("Doe");

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.

ghidinelli commented 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?

PhillipSenn commented 9 years ago

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()
ghidinelli commented 9 years ago

It would be:

account = svc.createCreditCard()
account.setAccount()
account.setMonth()
account.setYear()
account.setFirstName()
account.setLastName()