Over-documentation
-
This is from another forum I visit once in a while, somebody posting a code snippet:
void loop(){
byte rxbyte; //this tells the 'compiler' to allocate some memory for a variable called rxbyte
byte temp; //this tells the 'compiler' to allocate some memory for a variable called temp
rxbyte = serial_getch(); //this calls the 'function' serial_getch(), stores result in rxbyteif (rxbyte == 254) //Matrix uses 254 for commands, if rxbyte = 254 the the code below runs
{
switch (serial_getch()) //calls serial_getch() to get the next byte from the PC
// 'switches' based on that byte
{And it continues on like that. At least we know what the 'compiler' is doing when you declare a variable :)
Ron Beyer wrote:
At least we know what the 'compiler' is doing when you declare a variable
Actually, it's not even accurate, technically. The compiler doesn't allocate "some memory", it reserves space on the stack when the function is called. Yes, the stack is of course memory, but it's not the same kind of memory one uses when allocating / deallocating. Marc
-
This is from another forum I visit once in a while, somebody posting a code snippet:
void loop(){
byte rxbyte; //this tells the 'compiler' to allocate some memory for a variable called rxbyte
byte temp; //this tells the 'compiler' to allocate some memory for a variable called temp
rxbyte = serial_getch(); //this calls the 'function' serial_getch(), stores result in rxbyteif (rxbyte == 254) //Matrix uses 254 for commands, if rxbyte = 254 the the code below runs
{
switch (serial_getch()) //calls serial_getch() to get the next byte from the PC
// 'switches' based on that byte
{And it continues on like that. At least we know what the 'compiler' is doing when you declare a variable :)
Lovely Not only way over the top, but where comments would be useful, those comments aren't. I would only put 1 comment in there - //254 means we are about to process a command, so read one & process it. Plus a comment to add a description of each entry in the switch statement to translate the number into something sensible. This removes clutter, and also the need to look up op-codes in the event of brain-fade. Regards, Stewart
-
Lovely Not only way over the top, but where comments would be useful, those comments aren't. I would only put 1 comment in there - //254 means we are about to process a command, so read one & process it. Plus a comment to add a description of each entry in the switch statement to translate the number into something sensible. This removes clutter, and also the need to look up op-codes in the event of brain-fade. Regards, Stewart
-
This is from another forum I visit once in a while, somebody posting a code snippet:
void loop(){
byte rxbyte; //this tells the 'compiler' to allocate some memory for a variable called rxbyte
byte temp; //this tells the 'compiler' to allocate some memory for a variable called temp
rxbyte = serial_getch(); //this calls the 'function' serial_getch(), stores result in rxbyteif (rxbyte == 254) //Matrix uses 254 for commands, if rxbyte = 254 the the code below runs
{
switch (serial_getch()) //calls serial_getch() to get the next byte from the PC
// 'switches' based on that byte
{And it continues on like that. At least we know what the 'compiler' is doing when you declare a variable :)
-
"the the code"
-
The first time I saw something like that said "Paris in the / the spring". I saw this[^] sign a couple of weeks ago at http://en.wikipedia.org/wiki/Painted_Rocks_(Arizona)[^]
-
This is from another forum I visit once in a while, somebody posting a code snippet:
void loop(){
byte rxbyte; //this tells the 'compiler' to allocate some memory for a variable called rxbyte
byte temp; //this tells the 'compiler' to allocate some memory for a variable called temp
rxbyte = serial_getch(); //this calls the 'function' serial_getch(), stores result in rxbyteif (rxbyte == 254) //Matrix uses 254 for commands, if rxbyte = 254 the the code below runs
{
switch (serial_getch()) //calls serial_getch() to get the next byte from the PC
// 'switches' based on that byte
{And it continues on like that. At least we know what the 'compiler' is doing when you declare a variable :)
Amusingly, that doesn't really tell us much - the compiler doesn't "allocate" memory, the stack is allocated when the program starts - this simply updates stack pointers.
"If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.
-
This is from another forum I visit once in a while, somebody posting a code snippet:
void loop(){
byte rxbyte; //this tells the 'compiler' to allocate some memory for a variable called rxbyte
byte temp; //this tells the 'compiler' to allocate some memory for a variable called temp
rxbyte = serial_getch(); //this calls the 'function' serial_getch(), stores result in rxbyteif (rxbyte == 254) //Matrix uses 254 for commands, if rxbyte = 254 the the code below runs
{
switch (serial_getch()) //calls serial_getch() to get the next byte from the PC
// 'switches' based on that byte
{And it continues on like that. At least we know what the 'compiler' is doing when you declare a variable :)
Over-zealous on the documentation part but missed out some basic coding standards like below: 1) Magic Strings/Numbers in code. 2) It would be better to have the value of serial_getch() assigned in a variable and then used in switch instead of calling it directly as a function in the switch construct.
Vasudevan Deepak Kumar Personal Homepage You can not step into the same river twice.
-
This is from another forum I visit once in a while, somebody posting a code snippet:
void loop(){
byte rxbyte; //this tells the 'compiler' to allocate some memory for a variable called rxbyte
byte temp; //this tells the 'compiler' to allocate some memory for a variable called temp
rxbyte = serial_getch(); //this calls the 'function' serial_getch(), stores result in rxbyteif (rxbyte == 254) //Matrix uses 254 for commands, if rxbyte = 254 the the code below runs
{
switch (serial_getch()) //calls serial_getch() to get the next byte from the PC
// 'switches' based on that byte
{And it continues on like that. At least we know what the 'compiler' is doing when you declare a variable :)
Probably he had a boss who complained about insufficient comments - like my boss often does when reviewing my code complains about missing annotations (just review annotations, the code was already commented properly). So I did more or less the same like our guy here - and my boss was happy. He didn't get that it was supposed to be ironic...
-
This is from another forum I visit once in a while, somebody posting a code snippet:
void loop(){
byte rxbyte; //this tells the 'compiler' to allocate some memory for a variable called rxbyte
byte temp; //this tells the 'compiler' to allocate some memory for a variable called temp
rxbyte = serial_getch(); //this calls the 'function' serial_getch(), stores result in rxbyteif (rxbyte == 254) //Matrix uses 254 for commands, if rxbyte = 254 the the code below runs
{
switch (serial_getch()) //calls serial_getch() to get the next byte from the PC
// 'switches' based on that byte
{And it continues on like that. At least we know what the 'compiler' is doing when you declare a variable :)
No horror here if it was posted to someone who's not into programming. E.g. "==" operator is not obvious and may provoke questions what does it mean. Also, telling about "allocating" memory is more understandable that introducing to how stack and pointers work.
Greetings - Jacek