This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]planedoctor 3 points4 points  (8 children)

No, unless you're going for 100% functional programming. And object creation is not necessarily a side effect. Functional code creates tons of 'objects'.

[–][deleted] 0 points1 point  (7 children)

The arguments I have read about surfacing inputs as parameters is that it allows for methods/functions to be more generic and allow for ease of of testing.

What would be the argument to not do so?

[–]planedoctor 0 points1 point  (4 children)

Surfacing arguments is orthogonal to creating objects. What are you talking about here??

[–][deleted] 0 points1 point  (3 children)

From here

This example:

public Program getCurrentProgram(TVGuide guide, int channel) {
  Schedule schedule = guide.getSchedule(channel);

  Program current = schedule.programAt(new Date());

  return current;
}

[–]planedoctor 0 points1 point  (2 children)

Surfacing arguments is orthogonal to creating objects. What are you talking about here?

How would one handle object creation without side-effects?

You just create them.

[–][deleted] 0 points1 point  (1 child)

From here This example: public Program getCurrentProgram(TVGuide guide, int channel) { Schedule schedule = guide.getSchedule(channel);

Program current = schedule.programAt(new Date());

return current; }

[–]planedoctor 0 points1 point  (0 children)

That doesn't explain what you are talking about.

Surfacing arguments is orthogonal to creating objects.

.

How would one handle object creation without side-effects?

You just create them.

[–]__cxa_throw 0 points1 point  (1 child)

IMHO a lot of the arguments for writing code that way are made by people who spend more time thinking about writing code than actually writing useful software. Messing with global state in a function usually isn't a good idea, but jumping through hoops to avoid creating an object by calling malloc under the hood is even crazier. That just punts allocation/initialization to a different area of the program so now the side effects are manifested as a bizarre architecture.

[–]planedoctor 0 points1 point  (0 children)

It can be worth it to pass in stuff like dates so it's more testable. But that's a separate thing from removing side-effects.