Skip to main content
2 of 2
deleted 62 characters in body

How do I properly write these functions?

So far my weakest side has been proper code structuring and organization. I wanted to know how I can properly apply separation of concerns to the following code to make it more organized.

I have a function deleteCurrentList().

It does two things: deletes the currently selected list and navigates back to the previous page.

function deleteCurrentList() {
     deleteList(current_list_id);
     navigate("..");
}

From my understanding, this is bad code because

  • A: It does more than one thing.
  • B: Its name doesn't describe fully what it does.

So one idea that I had in mind is to rename this function to deleteCurrentListAndNavBack(), but that is a long name, and it still doesn't solve the issue of the function doing more than one thing.

So I wanted to know, what should I do in this situation?

How do I split these two actions while still being able to delete the list and navigate back in the same sequence?