开发者

How can I improve this program design for a simple todo list manager?

For a simple command-line todo manager (that is to be implemented in C), this is what I have thought of the design:

  • The utility would support multiple users by storing the todo's in different files for each

  • While running the program would hold all the data in memory itself. This would avoid unnecessary IO and is also quite suitable when开发者_C百科 you do not expect the user to have more than 20 todos (I am assuming this is true). So, if the user already exists, the user todo file would be read and all the data captured to memory (in arrays of rows(structures)) and then when user logs out the file would be updated.

The aim of the project is to show how it can be done while keeping things very simple.

This pseudo pseudocode outlines the structure

// 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();
}

How can I improve the program structure/execution flow?

I want to know where all can I improve the program structure before I start plugging in the actual code. Any suggestions/comments are welcome.


If you want to keep everything in memory, then only call writefile from cleanup, or from main after while_not_logout. Why not support multiple users by keeping their todo list in their own homedir?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜