Git Product home page Git Product logo

Comments (7)

bjoern-jueliger-sap avatar bjoern-jueliger-sap commented on July 17, 2024 5

I think in general it is better to avoid mutating data in this manner altogether. In your example, is there is really a benefit to using change_by_ref instead of a method

methods add_to_parameter_name
  importing parameter_name type string
  returning value(result) type string.

and replacing

change_by_ref( ref #( variable ) ).

by

variable = add_to_parameter_name( variable ).

? Personally I find the latter much more readable - it is immediately clear to me that this line changes the content of variable based on its previous content.

from styleguides.

bjoern-jueliger-sap avatar bjoern-jueliger-sap commented on July 17, 2024 2

@bjoern-jueliger-sap really nice way of doing that! I forgot about such variant. I completely agree that it's much cleaner in case of data types.

Would you do the same for object instances, when for example variable is instance of an object? Or just importing can be enough? I guess in the case of objects the argument about mutation is not so strong, they are expected to mutate at any time, isn't it?

For objects, the better solution is often to turn this into a method on the object. A function that takes an object instance as input and returns an object instance as output is isomorphic to a method on the object instance itself. (On the level of abstract type signatures, a method of an object type obj is just a function obj -> obj)

Concretely, if variable is an object, then that object type should define a method:

  methods add_to_parameter_name.

and we'd call it as

variable->add_to_parameter_name( ).

instead.

from styleguides.

nununo avatar nununo commented on July 17, 2024 1

Fully agree with @bjoern-jueliger-sap. With the added bonus that method add_to_parameter_name can now be a pure function, making it much more straightforward to cover with unit tests.

from styleguides.

ruthiel avatar ruthiel commented on July 17, 2024

"I'd prefer to use REF# as it offers a cleaner and simpler approach. However, I understand the argument that by using CHANGING, everyone will know that the variable will be modified within the method.

from styleguides.

Yrfo avatar Yrfo commented on July 17, 2024

@bjoern-jueliger-sap really nice way of doing that! I forgot about such variant. I completely agree that it's much cleaner in case of data types.

Would you do the same for object instances, when for example variable is instance of an object? Or just importing can be enough? I guess in the case of objects the argument about mutation is not so strong, they are expected to mutate at any time, isn't it?

from styleguides.

bjoern-jueliger-sap avatar bjoern-jueliger-sap commented on July 17, 2024

Closing this since there seems to be agreement that the guide's recommendation against CHANGING in most situations is appropriate as is.

from styleguides.

Yrfo avatar Yrfo commented on July 17, 2024

@bjoern-jueliger-sap really nice way of doing that! I forgot about such variant. I completely agree that it's much cleaner in case of data types.
Would you do the same for object instances, when for example variable is instance of an object? Or just importing can be enough? I guess in the case of objects the argument about mutation is not so strong, they are expected to mutate at any time, isn't it?

For objects, the better solution is often to turn this into a method on the object. A function that takes an object instance as input and returns an object instance as output is isomorphic to a method on the object instance itself. (On the level of abstract type signatures, a method of an object type obj is just a function obj -> obj)

Concretely, if variable is an object, then that object type should define a method:

  methods add_to_parameter_name.

and we'd call it as

variable->add_to_parameter_name( ).

instead.

Ah, yes, it is true. Thank you guys for help! I'll try to remember that way of thinking 🙂

from styleguides.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.