Comments (10)
The section Split method instead of Boolean parameter partially covers this. A little unsure whether linking there will do, or whether we should add a new small sub-section on the choice of data type.
from styleguides.
I´d definitely prefer banning booleans in the first place - as a most likely inadequate data type. If then you end up with an enumeration Do.This or Do.That, then you know how to proceed..
from styleguides.
Added a section Use Booleans wisely that I think closes this issue.
from styleguides.
good start, but...
- the link to "Split methods..." is broken (mind the s)
- references 2 & 3 would better fit to "Split methods.." rather than "Use Booleans wisely"
- I am missing the point that readability of booleans is often worse than enumerations even if the domain is binary
from styleguides.
There are several reasons why I didn't comment on the readability so far.
For once, this affects other languages far more than ABAP, because ABAP usually requires you to repeat the parameter names:
// Java
updateDocument(true, true, false);
while
" ABAP
update_document( synchronous = abap_true
with_commit = abap_true
write_logs = abap_false ).
ABAP becomes ambiguous only when you're down to one parameter and you can ommit the parameter name:
update( abap_true ).
Although this issue frequently occurs with Booleans, it's not caused by them. The issue is in fact caused by the unavailability of the parameter names in the method call, and can happen with all data types. In most cases, enumerations are not even an option:
// Java
someString.substring(0, 3); // what's 3? length? end index?
sendEmail("", "", "", ""); // title, body, recipient, sender - or the other way round?
assertEquals(a, b); // which one is the expected value? a or b?
In return, it's not necessary to use a different data type to provide a meaningful enumeration:
" ABAP
CONSTANTS:
BEGIN OF save_mode,
with_commit TYPE abap_bool VALUE abap_true,
without_commit TYPE abap_bool VALUE abap_false,
END OF save_mode.
update( save_mode-with_commit ).
Over the years, most IDEs added the feature to show parameter names inline without them actually being present in the code. This greatly reduces this issue's impact. As far as I know, the ABAP Development Tools do not (yet) support this feature.
In summary, yes, I agree that it's a good idea to challenge whether a Boolean is the right choice, but this ambiguous-call argument is a rather weak one.
from styleguides.
Over the years, most IDEs added the feature to show parameter names inline without them actually being present in the code. This greatly reduces this issue's impact. As far as I know, the ABAP Development Tools do not (yet) support this feature.
If I understood correctly, you can do this with <alt>-F2 from anywhere inside a method.
from styleguides.
That is Eclipse's "Element Info", a quick preview of the method signature in a separate window.
What I mean are "Parameter Hints", as found for example in IntelliJ:
from styleguides.
Ah, nice!
But I guess since parameter names are required if more than one, then it is less of a priority for ABAP.
from styleguides.
agreed - ABAP is better by naming arguments.
sendEmail("", "", "", ""); // title, body, recipient, sender - or the other way round?
actually signatures like these could use more specific types rather then generic types. E.g. recipient and sender could be a class that also provides validation in addition to having a string representation. Is your body html, rtf, or text? Lazy coders..
// Java someString.substring(0, 3); // what's 3? length? end index? assertEquals(a, b); // which one is the expected value? a or b?
no idea.
from styleguides.
After the fixes in #25, is there still something we should change?
from styleguides.
Related Issues (20)
- 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
- "New rule" Tables > Prefer a Table Expression to READ TABLE
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.