Should functions be used as means to organize code, even if the function is only executed once?

Viewed 220

I often find myself chunking code into functions just as a means to make it more readable.

Example:

// Returns 4 random menus
function getRandomMenus(menus_in){
  //Return random menus
}

// Assign random decision times for players 1 and 2
function getTimes(){
  // Return random times
}

But then these functions are only executed once (when initiating the program):

menus = getRandomMenus(all_menus);
all_times = getTimes();

This seems inefficient, but the alternative seems harder to follow (even for me, who wrote the code), and this is even more so true when the functions become more complicated than in the above examples.

Even if this is inefficient (which I feel like it is) is it ok to sacrifice efficiency for the sake of readability?

0 Answers
Related