Skip to content
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

proper c++-Style with many changes #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

orgua
Copy link

@orgua orgua commented Apr 28, 2015

I implemented some compiler-optimizations and made a first attempt to get closer to recommended c++-style:

  • used constness wherever possible
  • cleaner constructor with proper initialized variables
  • replaced defines (preprocessor) by const type to get better compiler-errors
  • inlined the display-functions --> typically found in the header
  • made the class uncopyable to get no strange undefined behavior if someone tries it
  • controllerDirection and Mode have been int-type, but char will suffice

The changes are tested. My own code behaves the same and the examples still compile. Footprint of code & ram-usage is reduced.

- used constness wherever possible
- cleaner constructor with proper initialized variables
- replaced defines (preprocessor) by const type to get better
compiler-errors
- inlined the display-functions --> typically found in the header
- made the class uncopyable to get no strange undefined behavior if
someone tries it
- controllerDirection and Mode have been int-type, but char will suffice
@orgua
Copy link
Author

orgua commented May 13, 2015

Well, enums are fine, but the given implementation in PR#21 breaks old code (tradeoff for better capsulation). You would get the same result by moving my "constants" into the class-public-area. Scott Meyers has done a good job explaining all the differences between defines and const/enums in "Effective C++ third edition" - Item 2. The essence is: defines are simple string-replacments in global namespace handled by the preprocessor. The later coming compiler has no clues of these replacements. By using consts you can operate in local namespaces, have to think about the type of your constant (less errors) and in case of an error you get a reference to the name of the constant involved.
I have not searched for any ardu-libs using that style. Should that be an important point? Good Practice allows current and coming compilers to optimize code as needed, regarding size, speed, ramusage.
2:
I have tested the new code in a heating-control of an espresso-machine and in quadcopter-code. so far i noticed no differences in the behavior.

@arielbernal
Copy link

2015!! What happened to this? the library clearly needs to be refactored. @orgua there should be no difference other than probably more efficient code generation. Specially using floats instead of doubles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants