returnvalue namespace #659
Labels
No Label
API Change
Breaking API Change
bug
build
cosmetics
Documentation
duplicate
feature
help wanted
hotfix
invalid
question
Refactor
Tests
wontfix
No Milestone
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Blocks
Reference: fsfw/fsfw#659
Loading…
Reference in New Issue
No description provided.
Delete Branch "mueller/expand-retval-if"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
result
namespace which containsOK
andFAILED
returnvaluemakeCode
constexpr functionHasReturnvaluesIF::makeReturnCode
deprecatedThis prevents from having to implement an interface just to able to use a shorter
version of the general returnvalues.
mueller/expand-retval-ifto Expand returnvalue moduleA class is already a namespace, so I do not see any improvement by creating an additional namespace.
The style of the fsfw is to prefer explicit names which give their intention clearly instead of short ones which might be typed faster (we assume programmers to use an IDE/Editor capable of suggesting names anyway). So, I also see no reason to rename
HasReturnvaluesIF
toretval
andmakeReturnCode
tomakeCode
orRETURN_OK/FAILED
toOK/FAILED
.The latter two could be argued to not need the return as part of their name as they are scoped within
HasReturnvaluesIF
, but especially withRETURN_OK/FAILED
it is intentional, as they are often used within classes inheriting fromHasReturnvaluesIF
without namespace specifier andOK
as well asFAILED
are too generic to be good names.As it is used at the moment, one could argue
ReturnvaluesIF
fits better thanHasReturnvaluesIF
, but I think the difference is so minimal that I would keep it as is.As a sidenote, I think
using retval = HasReturnvaluesIF;
is not adding to readability and more or less reducing clarity for the inattentive reader who might miss theusing
and will not link it to the better known (it is one of the core interfaces of the fsfw after all)HasReturnvaluesIF
.My goal is not to replace the old way but to provide a shorter alternative when writing out a value which is very commonly used across the whole framework, including when writing unittests.
I think
HasReturnvalueIF::RETURN_OK
is just cumbersome to write, even with IDE support.retval::OK
is a lot more convenient and more brief. I prefer to simply write outretval::OK
. It is still explicit enough, and there is no environment pollution. Both ways still work.About the topic with having a shorter way to write this value out, here are how some other libraries do it with general returnvalues :
FreeRTOS:
pdPASS
andpdFAIL
LwIP:
ERR_OK
or plain check against 0 andERR_OK
!= 0ESP-IDF:
ESP_OK
andESP_FAIL
Rust
Most of the style in the FSFW ressembles Java code with the long names, but I don't have issues with smaller names when it is for values which are commonly used when they are still clear enough. For example,the function
System.out.println
is explicit enough, but is also kind of annyoing to write, and I prefer theprint
/println
syntax more common to other languages. Kotlin as a Java extension even introducedprint
again: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.io/print.htmlAbout the usage of the
retval
namespace: That was something really old, not even directly related to this PR, but was then an issue because of namespace clashes. Apparently I was annoyed by this some time ago and used this namespace to have some more convenience. I also remember providing a shorter way, but I think this was in some breaking way which was why this feature was rejected. The solution above does not break anything now.I can remove the deprecation warning.
Another suggestion: Use
result
instead ofretval
as the namespace nameUPDATE:
Agreement reached: Conversion of
HasReturnvaluesIF
to namespacereturnvalue
HasReturnvaluesIF::RETURN_OK
->returnvalue::OK
HasReturnvaluesIF::RETURN_FAILED
->returnvalue::FAILED
For an even shorter version, users can use
using returnvalue
at the top of the source file.Expand returnvalue moduleto WIP: Expand returnvalue moduleWIP: Expand returnvalue moduleto returnvalue namespaceLGTM