mwc 2.0 ++

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download
Post Reply
User avatar
Hamburger
Posts: 2578
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: mwc 2.0 ++

Post by Hamburger »

On formatting:
seems my code snippet got garbled by the [ code ] formatting software.
So here are some snapshots from what Eclipse offers and how that looks like.
BSD
BSD
BSD

GNU
GNU
GNU

KuR
KuR
KuR

whitesmiths
whitesmiths
whitesmiths


I'd say no real benefit from GNU, but it uses the most vertical space - bad.
Personal favorite is KuR.

User avatar
howardhb
Posts: 189
Joined: Tue Oct 11, 2011 7:10 pm
Location: Port Elizabeth, South Africa

Re: mwc 2.0 ++

Post by howardhb »

+1 for KuR!

Alexinparis
Posts: 1630
Joined: Wed Jan 19, 2011 9:07 pm

Re: mwc 2.0 ++

Post by Alexinparis »

Hi,

Please don't break the current indent ;)
I tried to correct it in LCD.pde, but I gave up...

I use only Arduino IDE to code, nothing else.
I think It's something like K&R style + 2 space indent and no tab.
If you use a third party IDE like Eclipse, please adapt it to use the same style.

generally speaking:
something after a { should begin 2 spaces after on the next line.
something after a #if should begin 2 spaces after on the next line.

I don't know if keeping # statement at the same indent as the other code (and not at the beginning) is clean or not, but I find it more readable.
here is something which is difficult to read for me:

Code: Select all

    case 0:
#if MAG
       Mag_getADC();
#endif
       break;
    case 1:
#if BARO
       Baro_update();
#if defined(LOG_VALUES)
       if (BaroAlt > BaroAltMax) BaroAltMax = BaroAlt;
#endif
#endif
       break;
    case 2:
#if BARO
       getEstimatedAltitude();
#endif
       break;
    case 3:
#if GPS
       GPS_NewData();
#endif
       break;
    }


here is something more natural for me:

Code: Select all

    switch (taskOrder) {
      case 0:
        #if MAG
          Mag_getADC();
          break;
        #endif
      case 1:
        #if BARO
          Baro_update();     
          break;
        #endif


please try also to gather as possible the place where LOG_VALUES appears.



Hamburger wrote:coding style / indentation

seems we should decide on a coding style / indentation rules. Alex is always busy correcting indentation, this should not be neccessary. I would like to stick with something common. Eclipse offers some builtin variants.
K&R looks like this:

Code: Select all

/*
 * A sample source file for the code formatter preview
 */
#include <math.h>

class Point {
public:
   Point(double x, double y) :
         x(x), y(y) {
   }
   double distance(const Point& other) const;

   double x;
   double y;
};

double Point::distance(const Point& other) const {
   double dx = x - other.x;
   double dy = y - other.y;
   return sqrt(dx * dx + dy * dy);
}

Available alternatives are GNU, BSD, Whitesmiths.
What do you think?

User avatar
Hamburger
Posts: 2578
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: mwc 2.0 ++

Post by Hamburger »

K&R, 2 space indent is fine.
Indenting the cpp macros may be different. Eclipse does not do it automatically and autocorrects it always. Not sure if that can be changed easily. Also in the old days cpp did not guarantee to always work on #something directives with leading white space. Not sure if they changed that.

Could we also agree on the following:
- macros are all capital letters with optional underscores
- variables either all lower case, or start with lower letter and use Camel style (cycleTimeMax) or get an all capitals prefix for the realm like GPS_latitude ( I found BaroAlt difficult to identify, rather prefer BAROalt or BARO_alt)
- function names ? it seems to be good practice in MWii to start with (optional the realm in all capital letters followed by) lower letter+Camel for functionality (like LCDconfiguration() or SOMESENSOR_init() ) - so same rules as for variables?

Please do not get me wrong, we do not want the Format Polizei; merely readable code without too much hassle and take the burden from Alex to re-format the code all the time.
Thanks.

User avatar
kos
Posts: 286
Joined: Thu Feb 16, 2012 4:51 am
Location: Fr

Re: mwc 2.0 ++

Post by kos »

Hamburger wrote:use Camel style (cycleTimeMax) or get an all capitals prefix for the realm like GPS_latitude ( I found BaroAlt difficult to identify, rather prefer BAROalt or BARO_alt)



everything with underscore or all upercase is const or a define, it is ok to use upper case for acronym or short word [1]


int GPSMaxSpeed = ok
define GPS_ALT_MAX 33000 = ok
int BAROalt = ok

int BARO_alt = bad
void INIT() = bad
int GPSHOME_latitude = bad

1 : http://en.wikipedia.org/wiki/CamelCase# ... _computing

User avatar
Hamburger
Posts: 2578
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: mwc 2.0 ++

Post by Hamburger »

while we are at it:

I think it is about time to create a proper Credits.txt file and remove the various names that are sprinkled all over the code sections.
ok?

User avatar
Hamburger
Posts: 2578
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: mwc 2.0 ++

Post by Hamburger »

...and more importantly a Maintainers.list

User avatar
Hamburger
Posts: 2578
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: mwc 2.0 ++

Post by Hamburger »

Please have a look at _shared.
I created the credits file and reformatted LCD.pde.
Anyone know how to indent cpp in Eclipse?

Alexinparis
Posts: 1630
Joined: Wed Jan 19, 2011 9:07 pm

Re: mwc 2.0 ++

Post by Alexinparis »

Hi,
No problem to create a Credits file, but with exhaustive information. (I see some missing info about OpenLRS contribution).
It would be better if a small summary could be added for each contribution.
I know this is some more work for you, but it's your initiative ;)

I'm not in favor of a Maintainers.list

User avatar
Hamburger
Posts: 2578
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: mwc 2.0 ++

Post by Hamburger »

Alexinparis wrote:Hi,
No problem to create a Credits file, but with exhaustive information. (I see some missing info about OpenLRS contribution).
It would be better if a small summary could be added for each contribution.
I know this is some more work for you, but it's your initiative ;)

ok, will do (with low priority). Just copy more of the CREDITS format over from linux. What is good for them should be good enough for us.:)
I'm not in favor of a Maintainers.list

ok.

User avatar
jevermeister
Posts: 708
Joined: Wed Jul 20, 2011 8:56 am
Contact:

Re: mwc 2.0 ++

Post by jevermeister »

Can someone please upload a info.txt with coding rules into svn?

SAo we all know what to do to code correctly

Alexinparis
Posts: 1630
Joined: Wed Jan 19, 2011 9:07 pm

Re: mwc 2.0 ++

Post by Alexinparis »

Hi,
Look at the readme file in http://code.google.com/p/multiwii/sourc ... vn%2Ftrunk

note you already violated one rule ;)
"no more tabs"
but your idea to add a buzzer tab is ok.

User avatar
Hamburger
Posts: 2578
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: mwc 2.0 ++

Post by Hamburger »

So far, the best I could come up with is

Code: Select all

indent  -kr -l100  -i2 -ppi 2 -nut  -brf

This still manipulates the cpp macros in an unwanted style. (Besides, on macosx 10.5 the included indent is not capable of this options set).

Hamburger wrote:Anyone know how to indent cpp in Eclipse?

again - anyone?

Tommie
Posts: 438
Joined: Sun Apr 08, 2012 9:50 am

Re: mwc 2.0 ++

Post by Tommie »

May I ask why everyone hate tabs?

Tabs have one major advantage over indentation by spaces: You can adjust the visual represenation to your liking without changing the code. Want to see more? Just instruct your editor to show tabs with a width of 2 spaces. You cannot do that with spaces, you are bound to the width present in the source file. That makes tabs IMO superior. They distinguish the represenation of the application logic from its visual representation.

User avatar
Hamburger
Posts: 2578
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: mwc 2.0 ++

Post by Hamburger »

Tommie,
Your argument is true. But I do not care about tab vs zpaces. In eclipse refomating is only one keystroke away.
Now with indentation of cpp directives in sync with code indentation is a different matter.

Alexinparis
Posts: 1630
Joined: Wed Jan 19, 2011 9:07 pm

Re: mwc 2.0 ++

Post by Alexinparis »

Tommie wrote:May I ask why everyone hate tabs?

Tabs have one major advantage over indentation by spaces: You can adjust the visual represenation to your liking without changing the code. Want to see more? Just instruct your editor to show tabs with a width of 2 spaces. You cannot do that with spaces, you are bound to the width present in the source file. That makes tabs IMO superior. They distinguish the represenation of the application logic from its visual representation.

The only reason is to be compatible with what Arduino IDE provides

Post Reply