Skip to main content
deleted 158 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Looking at my code, I feel like it is not instantly clear for someone whowho did not write it. II feel like readability will be important for me in the future, if I'm ever to write code on an enterprise, or open source project. DoDo you have any advice as to how I can make this and future C more readable?

#include "datatypes.h"
#include <stddef.h>

//Changes the node's child (if it doesn't exist) to newChild
//or appends newChild to the end of the node's child's sibling list
void addChild ( treeNode *root, treeNode *newChild ) {
  treeNode *temp;
  if ( root->child == NULL ) {
    root->child = newChild;
  } else {
    temp = root->child;
    while ( temp->sibling != NULL ) {
      temp = temp->sibling;
    }
    temp->sibling = newChild;
  }
}

//Returns a new treeNode with default data values or {0,NULL,NULL}
treeNode newNode () {
  treeNode node = {0, NULL, NULL};
  return node;
}

datatypes.h

typedef struct treeNode {
  int n;
  struct treeNode *child;
  struct treeNode *sibling;
} treeNode;

treeNode newNode (); //Returns a treenode with default {0,NULL,NULL}
void addChild ( treeNode *t, treeNode *c ); //Adds child to the given  treeNode

Crossposted from Stack Overflow (Improving the legibility of my C code) at commenter's suggestion.

Looking at my code, I feel like it is not instantly clear for someone who did not write it. I feel like readability will be important for me in the future, if I'm ever to write code on an enterprise, or open source project. Do you have any advice as to how I can make this and future C more readable?

#include "datatypes.h"
#include <stddef.h>

//Changes the node's child (if it doesn't exist) to newChild
//or appends newChild to the end of the node's child's sibling list
void addChild ( treeNode *root, treeNode *newChild ) {
  treeNode *temp;
  if ( root->child == NULL ) {
    root->child = newChild;
  } else {
    temp = root->child;
    while ( temp->sibling != NULL ) {
      temp = temp->sibling;
    }
    temp->sibling = newChild;
  }
}

//Returns a new treeNode with default data values or {0,NULL,NULL}
treeNode newNode () {
  treeNode node = {0, NULL, NULL};
  return node;
}

datatypes.h

typedef struct treeNode {
  int n;
  struct treeNode *child;
  struct treeNode *sibling;
} treeNode;

treeNode newNode (); //Returns a treenode with default {0,NULL,NULL}
void addChild ( treeNode *t, treeNode *c ); //Adds child to the given  treeNode

Crossposted from Stack Overflow (Improving the legibility of my C code) at commenter's suggestion.

Looking at my code, I feel like it is not instantly clear for someone who did not write it. I feel like readability will be important for me in the future, if I'm ever to write code on an enterprise, or open source project. Do you have any advice as to how I can make this and future C more readable?

#include "datatypes.h"
#include <stddef.h>

//Changes the node's child (if it doesn't exist) to newChild
//or appends newChild to the end of the node's child's sibling list
void addChild ( treeNode *root, treeNode *newChild ) {
  treeNode *temp;
  if ( root->child == NULL ) {
    root->child = newChild;
  } else {
    temp = root->child;
    while ( temp->sibling != NULL ) {
      temp = temp->sibling;
    }
    temp->sibling = newChild;
  }
}

//Returns a new treeNode with default data values or {0,NULL,NULL}
treeNode newNode () {
  treeNode node = {0, NULL, NULL};
  return node;
}

datatypes.h

typedef struct treeNode {
  int n;
  struct treeNode *child;
  struct treeNode *sibling;
} treeNode;

treeNode newNode (); //Returns a treenode with default {0,NULL,NULL}
void addChild ( treeNode *t, treeNode *c ); //Adds child to the given  treeNode
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Looking at my code, I feel like it is not instantly clear for someone who did not write it. I feel like readability will be important for me in the future, if I'm ever to write code on an enterprise, or open source project. Do you have any advice as to how I can make this and future C more readable?

#include "datatypes.h"
#include <stddef.h>

//Changes the node's child (if it doesn't exist) to newChild
//or appends newChild to the end of the node's child's sibling list
void addChild ( treeNode *root, treeNode *newChild ) {
  treeNode *temp;
  if ( root->child == NULL ) {
    root->child = newChild;
  } else {
    temp = root->child;
    while ( temp->sibling != NULL ) {
      temp = temp->sibling;
    }
    temp->sibling = newChild;
  }
}

//Returns a new treeNode with default data values or {0,NULL,NULL}
treeNode newNode () {
  treeNode node = {0, NULL, NULL};
  return node;
}

datatypes.h

typedef struct treeNode {
  int n;
  struct treeNode *child;
  struct treeNode *sibling;
} treeNode;

treeNode newNode (); //Returns a treenode with default {0,NULL,NULL}
void addChild ( treeNode *t, treeNode *c ); //Adds child to the given  treeNode

Crossposted from Stack Overflow (Improving the legibility of my C codeImproving the legibility of my C code) at commenter's suggestion.

Looking at my code, I feel like it is not instantly clear for someone who did not write it. I feel like readability will be important for me in the future, if I'm ever to write code on an enterprise, or open source project. Do you have any advice as to how I can make this and future C more readable?

#include "datatypes.h"
#include <stddef.h>

//Changes the node's child (if it doesn't exist) to newChild
//or appends newChild to the end of the node's child's sibling list
void addChild ( treeNode *root, treeNode *newChild ) {
  treeNode *temp;
  if ( root->child == NULL ) {
    root->child = newChild;
  } else {
    temp = root->child;
    while ( temp->sibling != NULL ) {
      temp = temp->sibling;
    }
    temp->sibling = newChild;
  }
}

//Returns a new treeNode with default data values or {0,NULL,NULL}
treeNode newNode () {
  treeNode node = {0, NULL, NULL};
  return node;
}

datatypes.h

typedef struct treeNode {
  int n;
  struct treeNode *child;
  struct treeNode *sibling;
} treeNode;

treeNode newNode (); //Returns a treenode with default {0,NULL,NULL}
void addChild ( treeNode *t, treeNode *c ); //Adds child to the given  treeNode

Crossposted from Stack Overflow (Improving the legibility of my C code) at commenter's suggestion.

Looking at my code, I feel like it is not instantly clear for someone who did not write it. I feel like readability will be important for me in the future, if I'm ever to write code on an enterprise, or open source project. Do you have any advice as to how I can make this and future C more readable?

#include "datatypes.h"
#include <stddef.h>

//Changes the node's child (if it doesn't exist) to newChild
//or appends newChild to the end of the node's child's sibling list
void addChild ( treeNode *root, treeNode *newChild ) {
  treeNode *temp;
  if ( root->child == NULL ) {
    root->child = newChild;
  } else {
    temp = root->child;
    while ( temp->sibling != NULL ) {
      temp = temp->sibling;
    }
    temp->sibling = newChild;
  }
}

//Returns a new treeNode with default data values or {0,NULL,NULL}
treeNode newNode () {
  treeNode node = {0, NULL, NULL};
  return node;
}

datatypes.h

typedef struct treeNode {
  int n;
  struct treeNode *child;
  struct treeNode *sibling;
} treeNode;

treeNode newNode (); //Returns a treenode with default {0,NULL,NULL}
void addChild ( treeNode *t, treeNode *c ); //Adds child to the given  treeNode

Crossposted from Stack Overflow (Improving the legibility of my C code) at commenter's suggestion.

Post Merged (destination) from codereview.stackexchange.com/questions/109261/…

Crossposted from stack overflow at commenter suggestion

Looking at my code, I feel like it is not instantly clear for someone who did not write it. I feel like readability will be important for me in the future, if I'm ever to write code on an enterprise, or open source project. Do you have any advice as to how I can make this and future C more readable?

#include "datatypes.h"
#include <stddef.h>

//Changes the node's child (if it doesn't exist) to newChild
//or appends newChild to the end of the node's child's sibling list
void addChild ( treeNode *root, treeNode *newChild ) {
  treeNode *temp;
  if ( root->child == NULL ) {
    root->child = newChild;
  } else {
    temp = root->child;
    while ( temp->sibling != NULL ) {
      temp = temp->sibling;
    }
    temp->sibling = newChild;
  }
}

//Returns a new treeNode with default data values or {0,NULL,NULL}
treeNode newNode () {
  treeNode node = {0, NULL, NULL};
  return node;
}

datatypes.h

typedef struct treeNode {
  int n;
  struct treeNode *child;
  struct treeNode *sibling;
} treeNode;

treeNode newNode (); //Returns a treenode with default {0,NULL,NULL}
void addChild ( treeNode *t, treeNode *c ); //Adds child to the given  treeNode

Crossposted from Stack Overflow (Improving the legibility of my C code) at commenter's suggestion.

Crossposted from stack overflow at commenter suggestion

Looking at my code, I feel like it is not instantly clear for someone who did not write it. I feel like readability will be important for me in the future, if I'm ever to write code on an enterprise, or open source project. Do you have any advice as to how I can make this and future C more readable?

#include "datatypes.h"
#include <stddef.h>

//Changes the node's child (if it doesn't exist) to newChild
//or appends newChild to the end of the node's child's sibling list
void addChild ( treeNode *root, treeNode *newChild ) {
  treeNode *temp;
  if ( root->child == NULL ) {
    root->child = newChild;
  } else {
    temp = root->child;
    while ( temp->sibling != NULL ) {
      temp = temp->sibling;
    }
    temp->sibling = newChild;
  }
}

//Returns a new treeNode with default data values or {0,NULL,NULL}
treeNode newNode () {
  treeNode node = {0, NULL, NULL};
  return node;
}

datatypes.h

typedef struct treeNode {
  int n;
  struct treeNode *child;
  struct treeNode *sibling;
} treeNode;

treeNode newNode (); //Returns a treenode with default {0,NULL,NULL}
void addChild ( treeNode *t, treeNode *c ); //Adds child to the given  treeNode

Looking at my code, I feel like it is not instantly clear for someone who did not write it. I feel like readability will be important for me in the future, if I'm ever to write code on an enterprise, or open source project. Do you have any advice as to how I can make this and future C more readable?

#include "datatypes.h"
#include <stddef.h>

//Changes the node's child (if it doesn't exist) to newChild
//or appends newChild to the end of the node's child's sibling list
void addChild ( treeNode *root, treeNode *newChild ) {
  treeNode *temp;
  if ( root->child == NULL ) {
    root->child = newChild;
  } else {
    temp = root->child;
    while ( temp->sibling != NULL ) {
      temp = temp->sibling;
    }
    temp->sibling = newChild;
  }
}

//Returns a new treeNode with default data values or {0,NULL,NULL}
treeNode newNode () {
  treeNode node = {0, NULL, NULL};
  return node;
}

datatypes.h

typedef struct treeNode {
  int n;
  struct treeNode *child;
  struct treeNode *sibling;
} treeNode;

treeNode newNode (); //Returns a treenode with default {0,NULL,NULL}
void addChild ( treeNode *t, treeNode *c ); //Adds child to the given  treeNode

Crossposted from Stack Overflow (Improving the legibility of my C code) at commenter's suggestion.

Post Unlocked by 200_success
Notice removed Content dispute by 200_success
Post Locked by 200_success
Notice added Content dispute by 200_success
Rollback to Revision 7
Source Link
200_success
  • 145.7k
  • 22
  • 191
  • 481
Loading
Rollback to Revision 5
Source Link
Loading
edited tags; edited title
Link
200_success
  • 145.7k
  • 22
  • 191
  • 481
Loading
Rollback to Revision 2
Source Link
200_success
  • 145.7k
  • 22
  • 191
  • 481
Loading
added 29 characters in body
Source Link
Loading
edited tags
Link
200_success
  • 145.7k
  • 22
  • 191
  • 481
Loading
deleted 48 characters in body
Source Link
Loading
deleted 762 characters in body
Source Link
Loading
Source Link
Loading