{"action":"opened","issue":{"url":"https://api.github.com/repos/Spartan-Racing-Electric-SJSU/sre-3b/issues/24","repository_url":"https://api.github.com/repos/Spartan-Racing-Electric-SJSU/sre-3b","labels_url":"https://api.github.com/repos/Spartan-Racing-Electric-SJSU/sre-3b/issues/24/labels{/name}","comments_url":"https://api.github.com/repos/Spartan-Racing-Electric-SJSU/sre-3b/issues/24/comments","events_url":"https://api.github.com/repos/Spartan-Racing-Electric-SJSU/sre-3b/issues/24/events","html_url":"https://github.com/Spartan-Racing-Electric-SJSU/sre-3b/issues/24","id":379376635,"node_id":"MDU6SXNzdWUzNzkzNzY2MzU=","number":24,"title":"Refactoring Code Base","user":{"login":"TimothyLe","id":15038959,"node_id":"MDQ6VXNlcjE1MDM4OTU5","avatar_url":"https://avatars0.githubusercontent.com/u/15038959?v=4","gravatar_id":"","url":"https://api.github.com/users/TimothyLe","html_url":"https://github.com/TimothyLe","followers_url":"https://api.github.com/users/TimothyLe/followers","following_url":"https://api.github.com/users/TimothyLe/following{/other_user}","gists_url":"https://api.github.com/users/TimothyLe/gists{/gist_id}","starred_url":"https://api.github.com/users/TimothyLe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TimothyLe/subscriptions","organizations_url":"https://api.github.com/users/TimothyLe/orgs","repos_url":"https://api.github.com/users/TimothyLe/repos","events_url":"https://api.github.com/users/TimothyLe/events{/privacy}","received_events_url":"https://api.github.com/users/TimothyLe/received_events","type":"User","site_admin":false},"labels":[{"id":1118609888,"node_id":"MDU6TGFiZWwxMTE4NjA5ODg4","url":"https://api.github.com/repos/Spartan-Racing-Electric-SJSU/sre-3b/labels/Task%20Low%20Priority","name":"Task Low Priority","color":"72db83","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-11-10T01:41:50Z","updated_at":"2018-11-10T01:41:50Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Change coding format to respond to the following guidelines, feel free to critique in comments below:\r\n```c++\r\n// 1a: If applicable, put units in the variable names\r\nubyte8 mWheelSpeedTimeoutUsecs;\r\n\r\n// 1b: Typedef structs should be cohesive and loosely coupled (this is a maybe for OOD)\r\ntypedef struct _FakeSensorData {\r\n    ubyte4  tireData;\r\n    float4  tempData;\r\n} FakeSensorData;\r\n\r\ntypedef struct _FakeSensorTime {\r\n    ubyte1  tireTimestamp;\r\n    ubyte1  tempTimestamp;\r\n} FakeSensorTime;\r\n\r\ntypedef struct _FakeSensor {\r\n    FakeSensorData  *fsd;\r\n    FakeSensorTime  *fst;\r\n} FakeSensor;\r\n\r\n// 1c: Prepend pointer variable with a p \r\nubyte4 *pObject = ( FakeSensor* ) malloc(sizeof(struct _FakeSensor));\r\n\r\n// 1d: Avoid upper casing the entire name \r\nstruct IAmAbcObject     // NOT IAmABCObject \r\nstruct theWssData       // NOT theWSSData\r\n\r\n// 1e: Clarify objects that are mutable and immutable with 'r'\r\nDataSensorInfo&         rInfo();\r\nconst DataSensorInfo&   Info() const;\r\n\r\n// 2a: Variables on the stack are spaced, lowercased, and snake cased\r\nbool checkSensor(FakeSensor *fs) {\r\n    ubyte1          error_timeout = TtcError();\r\n    float4          data_calcs;\r\n    IO_Error_Type   sensor_status;\r\n}\r\n\r\n// 2b: Clarify global variables with a 'g'\r\nDataLogger  gLog;\r\nDataLogger* gpLog;\r\n\r\nMyScope thisIsGoingToBeMyStack() {\r\n    ...\r\n}\r\n\r\n// 2c: Global constants should be snake cased and upper cased\r\nconst ubyte4 MY_GLOBAL_CONST = 20;\r\n\r\n// 2d: Static variables should have an 's' \r\nstatic bool sStatusChecker; \r\n\r\n// 2e: Avoid redefining data types\r\n#define static LOCAL    // Confusing for maintainers\r\n#define ubyte2 halfword // No, just no  \r\n\r\n// 3a: Type Names should be used for native types with Type appended \r\nstruct _FakeSensor              // We'll call it FakeSensor \r\ntypedef struct FakeSensor {     // We'll call it FakeSensorType\r\n    ...\r\n} _FakeSensor;\r\n\r\n// 3b: Enums should have snake case upper case labels and prepended names \r\nenum DashButtonStates {\r\n    DASH_ECO_ON,\r\n    DASH_ECO_OFF\r\n};\r\n\r\n//< labels for Error states is a must, based on thread lifespan from OS \r\nenum { BMS_ERR, MCM_ERR, STATE_WAIT, STATE_RUNNING, STATE_TERMINATE };\r\n\r\n// 3c: Linking names from different files \r\nextern FakeSensor FakeSensor_Must_Use // dumb linkers outsmarted with encoding type info in link symbols for link time type safety AKA name mangling\r\n\r\n// 3d: AVOID MACROS PLEASE! For efficiency, try inline operators if needed \r\n#define MIN(a,b)    ((x < y) ? x : y)   // NO! Who can understand this? Potential for side effects\r\ninline ubyte1 \r\nmin(ubyte1 a, ubyte b) \r\n{\r\n    return ((x < y) ? x : y);\r\n}\r\n\r\n// 3e: STOP USING WEIRD MAGIC NUMBERS! Use defines with meaningful names instead\r\nif (safety_error == 0x69) { do_the_thing(); }   // What in the world is 0x69?\r\n\r\n#define         THROTTLE_CALIBRATION_MISSING (0x69)     // option 1\r\nconst ubyte1    THROTTLE_CALIBRATION_MISSING = 0x69;    // option 2\r\nenum {                                                  // option 3\r\n    THROTTLE_CALIBRATION_MISSING = 0x69\r\n};\r\nif (safety_error == THROTTLE_CALIBRATION_MISSING) { do_the_thing(); }\r\n\r\n// 4a: Commenting out large code blocks for testing, try binary directives\r\nvoid example() {\r\n    this_is_some_code;\r\n\r\n    #if 0\r\n    this_is_a_lot_of_code;\r\n    #endif\r\n\r\n    some_other_code;\r\n}\r\nUsing /**/ doesn't allow comments and #ifdef will be accidentally triggered from compiler command line \r\nFor example, cc -c lurker.cc -DDEBUG=0 will turn off debug info \r\n\r\n// 4b: Also avoid just using #if 0, have a better name with a comment explaining why \r\n#if WE_TEST_MCM\r\n#if NOT_USED\r\n\r\n// 5a: Manage code complexity with delegation\r\n#include \"parentSensor.h\"\r\nvoid childSensorData(Parent *par) {\r\n    par->get_data(); // delegate task to someone else\r\n}\r\n\r\n// 5b: Manage code with Law of Demeter\r\nDo:     fs->IncreaseBrightness(1);\r\nDon't:  fs->Light->Increase(1);\r\n\r\n// 5c: Function pointers coming soon!\r\n```\r\n\r\nReferences:\r\n1. [C++ Coding Standard - CMU ECE](https://users.ece.cmu.edu/~eno/coding/CppCodingStandard.html)\r\n2. [Global Constants in C++](https://softwareengineering.stackexchange.com/questions/290744/is-it-bad-practice-to-use-constant-variables-with-global-scope-in-c)\r\n3. [Function Pointers](https://www.geeksforgeeks.org/function-pointer-in-c/)"}}
{"actor":{"display_login":"TimothyLe"}}