What factors determine which approach is more appropriate?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think both have their places.
You shouldn’t simply use
DoSomethingToThing(Thing n)just because you think ‘Functional programming is good’. Likewise you shouldn’t simply useThing.DoSomething()because ‘Object Oriented programming is good’.I think it comes down to what you are trying to convey. Stop thinking about your code as a series of instructions, and start thinking about it like a paragraph or sentence of a story. Think about which parts are the most important from the point of view of the task at hand.
For example, if the part of the ‘sentence’ you would like to stress is the object, you should use the OO style.
Example:
Most of the time when you’re passing around file handles, the main thing you are thinking about is keeping track of the file it represents.
CounterExample:
In this case submitting the HTTP request is far more important than the string which is the body, so
submitHttpRequst(x)is preferable tox.submitViaHttp()Needless to say, these are not mutually exclusive. You’ll probably actually have
in which you mix them both. The important thing is that you think about what parts are emphasized, and what you will be conveying to the future reader of the code.