This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void core1_task(void *ptr) | |
{ | |
int i = ((thread_args *) ptr)->input; | |
((thread_args *) ptr)->output = fib(i); | |
xSemaphoreGive(xSemaphore); | |
vTaskDelete(NULL); | |
} | |
int test_dual_core(int num) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int fib(int n) | |
{ | |
if (n < 2) return n; | |
else { | |
int x = fib(n - 1); | |
int y = fib(n - 2); | |
return x + y; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* GOOD */ | |
// The state is derived by what is passed into the function | |
function int addOne(int number) | |
{ | |
return number + 1; | |
} | |
/* BAD */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* BAD */ | |
if ((food.status == 'available' | |
&& user.status == 'active' | |
&& user.money > food.price | |
&& shipper.status == 'free') | |
|| (user.sos && user.call911 | |
&& food.status == 'available' | |
&& shipper.status == 'free') | |
) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* BAD */ | |
for (int i = 0; i < 5; i++) | |
{ | |
s += (t[i] * 4) / 5; | |
} | |
/* GOOD */ | |
int realDaysPerIdealDay = 4; | |
const int WORK_DAYS_PER_WEEK = 5; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef struct { | |
date_time_t playhhmmdd; /* BAD */ | |
} mp3_audio_data_t; | |
typedef struct { | |
date_time_t play_time; /* GOOD */ | |
} mp3_audio_data_t; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Bad: We have a bunch of get_data, and after a few months, | |
we don't know which get_data is for what | |
*/ | |
data_t *get_data(); | |
/* | |
Good | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define AWAIT(a) if (a != OK) continue; | |
status_t _connect(state_t *state) | |
{ | |
if (state >= CONNECTED) { | |
return OK; | |
} | |
// do connect, return FAIL if failed | |
state = CONNECTED; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//for understanding weekday2 there are more details to think about | |
const char *weekday2(int dayOfWeek) | |
{ | |
if ((dayOfWeek < 1) || (dayOfWeek > 7)) { | |
ESP_LOGE(TAG, "dayOfWeek must be in range 1..7"); | |
return NULL; | |
} | |
const char *weekdays = { | |
"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//DON'T | |
public void DoSomething() | |
{ | |
for (var i = 0; i < 1000; i++) | |
{ | |
var productCode = $"PRC000{i}"; | |
//...implementation | |
} | |
} |
NewerOlder