• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Clean Code: A Handbook of Agile Software Craftsmanship - Granularity

 
Tomasz Prus
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see that functions are covered in the book. There is something about granularity? I have often problem what is good way for example in webservices:

login(Person person)

or

login(String userName, String password, String ip)

?
 
Petr Shilkin
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course, Person is much better.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Petr Shilkin:
Of course, Person is much better.


Why? I'm not sure it's that obvious - or even possible to decide without knowing more about the context.
 
Alaa Nassef
Ranch Hand
Posts: 471
Hibernate Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I assumed from Petr's comment is that he favors the second style since it uses less parameters, and all the data are contained in one object which might seem more OO. I totally agree with Ilja that the context must be known upfront to be able to make a better decision
 
Jeff Langr
author
Ranch Hand
Posts: 799
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kent Beck recently posted an article on the topic: http://www.threeriversinstitute.org/AbstractVsConcreteParameters.html
 
Robert Martin
Author
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tomasz Prus:
I see that functions are covered in the book. There is something about granularity? I have often problem what is good way for example in webservices:

login(Person person)

or

login(String userName, String password, String ip)

?


The fewer arguments you pass into a function the better. If there are more than three, you should turn them into an object. Even three is a lot, and probably should be turned into an object.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic