对于一个简单的命令行TODO管理器(将在C中实现),这就是我对设计的看法:
-
该实用程序将支持多个用户,方法是将todo存储在每个用户的不同文件中。
-
运行程序时,所有数据都将保存在内存中。这将避免不必要的IO,并且当您不希望用户有超过20个TODO时也非常适合(我假设这是真的)。因此,如果用户已经存在,那么将读取用户todo文件,并将所有数据捕获到内存中(以行(结构)数组的形式),然后在用户注销时更新该文件。
这个项目的目的是展示如何做到这一点,同时保持事情非常简单。
这个伪伪代码概述了结构
// define data structure memory limits
// and other constants
bootup() {
// initialize data structures
}
readfile() {
use rot13();
}
writefile() {
use rot13();
}
login() {
ask_for_username
search for file or create one
if file present
readfile();
... and populate data structures
}
//1.
enter_new_task() {
read
record_time
is_starred
optional_due_date
}
//2.
...
fetch_commands() {
show_command_menu();
// 1. enter a new task
// 2. see the list of tasks
// 3. delete a task
// 4. edit a task
// 5. sort tasks by
}
while_not_logout() {
display_ui();
fetch_command();
while(command != logout) {
execute_command();
update_ui();
fetch_command();
}
writefile();
}
cleanup() {
// free memory
}
int main() {
bootup();
login();
while_not_logout();
cleanup();
}
如何改进程序结构/执行流程?
在我开始插入实际代码之前,我想知道在哪里可以改进程序结构。欢迎提出任何建议/意见。