-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[cpp] Getting rid of string constants in public API #67
Comments
On the other hand, having the constants around makes it possible to change the code in one place in case a constant value changes. So I am open to discussion. |
I'd support removing them. I think the constants are more work to maintain than they're worth: The variable name contains the contents of the string in most cases, so there isn't any abstraction included. If the user wants this type of constant, they can declare their own that is specific to their application and provides abstraction. |
The hardcoded string constants are findable via IDE completion As for the python interface, I'm sure its easy to use but I've never even I think the last problem (type safety) needs to be solved by using an enum, On Tue, May 5, 2015 at 2:51 PM Wasabi Fan notifications@github.com wrote:
|
That's a good point that I didn't consider. Maybe we should just shift this constant system that's currently in there over to a full enum? |
I agree with @dsharlet's point about IDEs (I overlooked this since my IDE of choice is vim :) ). The problem with enums is that the system then becomes too strong and does not allow any deviations. For example, #57 was solved by supplying custom port name ("in3:sv1") to a servo motor constructor. It would be impossible if we restricted ports to the current four values of So I am thinking of leaving the constants as strings for documentation purposes, and updating them for the current kernel. By the way, this could be easily done if we had possible values stored in |
If you are looking to create a template file for whole lines of code like we already do with our getters/setters (meaning it doesn't require any extra functionality in the script) and are just looking to include this info in the spec, go for it -- I'm not quite sure what specific strings you want, but if you are willing to find a structure to support holding these strings in the JSON I'm fine with it. |
I am thinking of adding a nested lists of possible values to each of the properties. E.g.
Each value should translate to a string constant in the code: static const std::string command_run_timed = "run-timed";
... The question is, would it be possible to loop over the |
I think this is definitely possible. I'll try to propose a PR in the coming days. |
Resolved by #69 |
…e-python. Changed the autogen template location to be in the python folder
I'd like to get rid of hard coded string constants like these.
to this:
irsens.set_mode("IR-PROX");
In case of python possible string values are easily checked in interactive python shell:
taho-motor
class.So I'd like to get rid of most of the strings constants at least in public API. What do you think?
CC @fdetro.
The text was updated successfully, but these errors were encountered: