Go Down

Topic: Do these people get paid by the LOC? (Read 1 time) previous topic - next topic

liudr


I don't see the point you're trying to make stimmer.
Automatic boxes are for people with more money than sense, or who can't be bothered to learn to drive properly.


Maybe I've been in a hole for too long but I just have not heard how to manually drive my continuously variable transmission to get good gas mileage yet.

codlink


I don't see the point you're trying to make stimmer.
Automatic boxes are for people with more money than sense, or who can't be bothered to learn to drive properly.


And I have found my new best friend!  90% of my cars have been manual.  Automatics are just, boring.. 

Of course, my other hobby is racing stock cars..
//LiNK

Nick Gammon


Is there any justification for this style (or lack of it)?


There are subtle differences to the two methods you presented. For example, give a class "myClass":

Code: [Select]

myClass B;
myClass A = B;   // make an instance of A based on B


The above calls the copy constructor for A.




Code: [Select]

myClass B;
myClass A;
A = B;   // copy B to A


The above calls operator= for A.




So they do different things. Admittedly for simple types there won't be much, if any, difference.

I think there is an argument for separating out the declaration from the initialization. Example:

Code: [Select]

int i = 10;
while (i--)
  {
  // do something
  }


Later on you need to do that again (in the same function) so you copy and paste:

Code: [Select]

int i = 10;
while (i--)
  {
  // do something
  }


Oops! Duplicate declaration of "i". Now if the declaration had been on its own line you just copy the initialization downwards and not the declaration. Or you fudge it like this for the second loop:

Code: [Select]

i = 10;
while (i--)
  {
  // do something
  }


Now one loop has the declaration and one doesn't which looks asymmetrical.

westfw

Quote
Why on Earth not simply
Code: [Select]
  unsigned long size = FB_SIZE;
  void* addr = alloc_aligned (size, 4096);

I've worked in groups where the prevailing "style guide" recommended against combining variable initialization with variable declarations.  I forget the exact justifications; there are people who like it better simply from a "compiler purity" point of view ("Declarations should not be mixed with code.")   Like many "elements of programming style", it's something not worth fighting for (in either direction), IMO.

It's not like the code produced is going to be different.


kf2qd

#14
Dec 07, 2012, 07:39 pm Last Edit: Dec 07, 2012, 07:41 pm by kf2qd Reason: 1
Depends on when and where you learned.

Some aspects of style are for ease of reading. Some are because they help reduce mistakes. Some are because someone in charge (and signs off on the paycheck) decides that's how it will be done.

Is one better than the other? Apparently you feel it shold be done one way and others feel it should be done another.

Defined and Initialized variables - how will they do when they aren't used because the code changed. Won't get the little message, declared but unused... So there is some memory that is plugged up for nothing. Compiling for a PC, Who Cares??? for an Arduino - might make a difference. What's the difference at execution time? That's what should really matter.

Personally, I like to keep the assignment of values away from the declaration unless its a CONSTANT... As well as the fact that C isn't my only programming language.

Go Up