What are these bad practices ?



  • Hello,

    I tried to compile the MySensors v2.11 library with a code which was compiling and running perfectly with Mysensors v1.42 and Arduino 1.6.5 IDE.
    I saw in this new library a lot of bad practices like including "cpp" files by the following ways (#include should only include header files) :

    #include "core/MyHwESP8266.cpp"
    

    or including directly relatives path in #include (pathes should be managed by make file) :

    #include "drivers/AVR/DigitalWriteFast/digitalWriteFast.h"
    

    I saw this too (wh'y don't declare directly the relevant type like: "const uint8_t NODE_SENSOR_ID=255" because 'C' casts are from the previous century, no ?)

    #define NODE_SENSOR_ID			((uint8_t)255)
    

    I would like to point out that I am a professional C ++ developer since about 20 years.
    I post this because i've got a LOT of errors trying compiling my code in the new library. I'd already wrote a post to expose my problem but nobody is able to understand what happens and I already spent a lot of hours trying to solve the problem.

    As soon as I add a #include of custom header file, the compiler told me "multiple definition of" :

    [https://forum.mysensors.org/topic/5928/compilation-problem-under-arduino-1-8-1](link url)

    Maybe I'm wrong and sorry for the bad review but I'm so frustrated 😞
    If anyone could help...


  • Admin

    This bad practice (yes we are very well aware of it) is the only way we can allow users to control configuration and feature inclusion directly from the sketch.

    Earlier we had all configuration in a separate file distributed with the library. But it was much harder to handle for newbies (which is a target group for this library). You had to edit this file between sketch compilations to get different features (like SOFT-SPI) enabled.

    But the root cause is the Arduino IDEs crappy build system and this setup is (unfortunately) not uncommon.

    May I ask why you want to include core files yourself?



  • Hello,

    My previous post is only a review of the MySensors library, not what I do in my code.
    Anyway, thanks for the answer.
    I will continue searching for my compilation problem.
    May I ask you with which environment you compile your sketches (Linux, Arduino IDE, ... ) ?


  • Admin

    For linux we have setup automake... See here:
    https://www.mysensors.org/build/raspberry

    Our CI server runs Arduino IDE (headless) when verifying PRs and sketches.

    Personally I still load up the IDE when compiling. People here also use other builders like platformio


  • Mod

    Does using visual studio with visual micro plug in make any difference than arduino ide when compiling code?


  • Hardware Contributor

    No. it uses arduino. Better it's a lot more ergonomic/friendly to use 😉


  • Mod

    In fact I do use it, but I also use arduino ide for quick changes in code 😄



  • @lrtsenar
    "multiple definition of"
    I got too when experimenting with some libraries.
    For example I edit my version "mcp_can.cpp" and rename original version to "mcp_can_old.cpp"
    ( and leave it in original library directory )
    Then when compiling I got this "multiple definition of" error.
    When I rename original to "mcp_can.xxx" compilation works ok.
    "mcp_can_old.cpp" is not included in any place in the code.
    It seems that Arduino IDE uses at first ( for preprocessor ? ) all .h and .cpp files in the library directory.


  • Hardware Contributor

    @scalz
    I am not sure, if visualmicro really does the same as the arduino ide when compiling code. Ihave here code, that doesn't compile with visualmicro but it does with the arduino IDE....



  • I have found my problem. Please have a look at the link in mine (1st) post 😉


  • Hardware Contributor

    @FotoFieber maybe. i've not got this case yet. if i remember visualmicro use arduino core and boards. and both use the gcc toolchain; then i've not checked how it's compiled sure.. visualmicro still works nice for me. but i also use arduino ide 😉


Log in to reply
 

Suggested Topics

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts