Comments (5)
An observation: The argument runs both ways.
Suppose I have a method drive
and want to rename its parameter speed
to speed_in_mph
.
Consumers calling ->drive( 50 )
are fine. Consumers calling ->drive( speed = 50 )
have to adjust to ->drive( speed_in_mph = 50 )
. In this case, naming the parameter is worse than omitting the name.
from styleguides.
Another observation: Adding parameters that are OPTIONAL
or have a DEFAULT
is compatible.
Suppose I have a method drive
with a parameter speed
and want to add a parameter unit
.
Adding unit TYPE char3 OPTIONAL
or unit TYPE char3 DEFAULT 'MPH'
is okay. Neither breaks consumers that call ->drive( 50 )
.
from styleguides.
One more observation: This touches key questions of stable API design.
APIs, and that includes classes and functions that serve as APIs, should change only in compatible ways.
For a method, this means that the change must not break any existing calls, neither from a technical nor from a logical point of view. Renaming a parameter or adding a mandatory parameter are incompatible changes because it (likely) breaks existing calls. Adding an OPTIONAL or DEFAULT parameter is compatible if omitting the parameter produces the same behavior as before, when the parameter did not exist.
from styleguides.
Hello again,
I have tested your points and you are right.
a) If method has just one parameter and OPTIONAL of DEFAULT is added, the CALL without parameter name remains OK.
b) If a method has 1 normal parameter + 1 OPTIONAL parameter, it must be called with the parameter names (if uses both), so again no harm to add a third parameter, also OPTIONAL.
c) But there is a case, which can be wrong: If a method has only one parameter, which is OPTIONAL.
If such method is called without the parameter name... Then if we add a second OPTIONAL parameter, the method call will be wrong. I see just one advice to put PREFERRED PARAMETER on the first one.
from styleguides.
IMHO in the example given either the method name (drive) is not descriptive enough or it violates "the method should do one thing" concept. Either there should be 2 methods, e.g. set_speed( 50 ) and drive( ) or the method should be drive_with_speed or something more than just "drive".
I feel there is no issue here and the problem is that Clean ABAP was not followed in other parts of the program, which lead to it causing such ambiguity.
Side note. "Drive" example is not the best here as we don't really set speed and then drive IRL but in SAP world, similar business object methods frequently end up being "overloaded" with parameters. I fall into this trap myself frequently because especially for experienced ABAPers creating more smaller things goes counter to what we've been taught for years before. But the whole point of Clean ABAP is to get away from such mentality, not to indulge it.
from styleguides.
Related Issues (20)
- Strategy regarding translations HOT 2
- Strategy for handling dependencies to system releases HOT 4
- Text on logo not readable in dark mode (Code Review Guide) HOT 3
- [Exploit the test tools] Add CL_AUNIT_AUTHORITY_CHECK to the list? HOT 6
- [Consider decomposing complex conditions] bad use case example HOT 1
- German Translation: Typo HOT 1
- Use assert class instead of ASSERT HOT 12
- Are comments bad or not?
- [Use CHANGING sparingly, where suited] Is it ok to use IMPORTING REF instead of CHANGING? HOT 7
- New rule: prefer inferring types HOT 1
- Abap Exception categories HOT 3
- Use READ-ONLY sparingly - new abap command FINAL HOT 2
- How to add sample code to Clean ABAP? HOT 1
- Unclear explanation of [Use LOCAL FRIENDS to access the dependency-inverting constructor] HOT 5
- Follow rules when abbreviating HOT 1
- "Dead" link at section "split-method-instead-of-boolean-input-parameter" HOT 3
- Chapter "Avoid abbreviations" HOT 7
- [Prefer RAISE EXCEPTION NEW to RAISE EXCEPTION TYPE] In defense of RAISE EXCEPTION TYPE HOT 6
- Prefer ENUM to constants interfaces HOT 1
- [Use | to assemble text] Is a caveat needed in case of translatable texts? HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from styleguides.