Skip to main content
Post Closed as "Duplicate" by gnat, Ben Cottrell, CommunityBot
deleted 62 characters in body
Source Link

I have a few years of background in software engineering, but soSo 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?

I have a few years of background in software engineering, but 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?

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?

Source Link

How do I properly write these functions?

I have a few years of background in software engineering, but 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?