Skip to main content
Post Closed as "Duplicate" by Doc Brown, CommunityBot
edited tags
Link
Shaolin
  • 43
  • 1
  • 7
added 35 characters in body
Source Link
Shaolin
  • 43
  • 1
  • 7

I have some incoming request - it's an instance of class generated from api specification - POJO with public getters/setters. I would like to normalize some values. For example dimensions (to use metric system).

I have a service class which has method processing incoming requests. First I would like to normalize the request.

So I define the method like:

private void normalizeDimensions(Request request);

and inside I normalize request's fields related to dimensions.

But from the readability perspective I think it's better to return the modified object so it's more explicit that something was changed and ideally the caller should use the returned object:

private Request normalizeDimensions(Request request);

What do you think is better from readability perspective or generally?

I have some incoming request - it's an instance of class generated from api specification. I would like to normalize some values. For example dimensions (to use metric system).

I have a service class which has method processing incoming requests. First I would like to normalize the request.

So I define the method like:

private void normalizeDimensions(Request request);

and inside I normalize request's fields related to dimensions.

But from the readability perspective I think it's better to return the modified object so it's more explicit that something was changed and ideally the caller should use the returned object:

private Request normalizeDimensions(Request request);

What do you think is better from readability perspective or generally?

I have some incoming request - it's an instance of class generated from api specification - POJO with public getters/setters. I would like to normalize some values. For example dimensions (to use metric system).

I have a service class which has method processing incoming requests. First I would like to normalize the request.

So I define the method like:

private void normalizeDimensions(Request request);

and inside I normalize request's fields related to dimensions.

But from the readability perspective I think it's better to return the modified object so it's more explicit that something was changed and ideally the caller should use the returned object:

private Request normalizeDimensions(Request request);

What do you think is better from readability perspective or generally?

Source Link
Shaolin
  • 43
  • 1
  • 7

Should a method modifying object passed as a parameter return the modified object?

I have some incoming request - it's an instance of class generated from api specification. I would like to normalize some values. For example dimensions (to use metric system).

I have a service class which has method processing incoming requests. First I would like to normalize the request.

So I define the method like:

private void normalizeDimensions(Request request);

and inside I normalize request's fields related to dimensions.

But from the readability perspective I think it's better to return the modified object so it's more explicit that something was changed and ideally the caller should use the returned object:

private Request normalizeDimensions(Request request);

What do you think is better from readability perspective or generally?