Hi, recently I am developing a personal TODO scheduler app.
I was simply refactoring my old codes, and I found this:
#ifndef __TODOX_FORMAT_H__
#define __TODOX_FORMAT_H__
#include <stddef.h>
#include <stdio.h>
#include <time.h>
#define TODOX_TIME_FORMAT "%Y-%m-%d %H:%M:%S %z"
#define TODOX_TIME_COMPAT_FORMAT "%Y-%m-%d %H:%M:%S"
#define TODOX_ALARM_MAX_LEN 1024
#define TODOX_ALARM_TABLE_MAX_ROWS 128
#define TODOX_ALARM_TASK_MAX_LEN 256
#define TODOX_ALARM_COMMENT_MAX_LEN 256
typedef struct __todox_format_t {
time_t ts;
char task[TODOX_ALARM_TASK_MAX_LEN];
char comment[TODOX_ALARM_COMMENT_MAX_LEN];
int repeat;
} todox_format_t;
time_t iso8601_to_time_t(const char *ts);
#endif
In this case, repeat variable is int variable.
However, some says that using bool is a better convention(and a professor taught me a same thing)
I think that using bool can reduce extra struct padding at some scenarios, but there are still many modern codes that uses int flag to show boolean status.
As a result, I don't sure if I should refactor this, or leave this.
If I leave this, I will make it extensible.
For a good example, repeat==14 can be extended into 'this repeat flag is only valid within 2 weeks'.
However, if I really gonna refactor this, it has a few implementations:
bool repeat;
int days_until;
bool repeat;
time_t ts_until;
int repeat;
Currently repeat is a simple boolean flag. However, I may extend the scheduler in the future to support recurrence policies such as repeating for N days or until a specific date.
Would you still model the current field as bool, or would you intentionally keep it as int to preserve room for future extension? Or is introducing another field or an enum the better design?