-1

According to Is it OK to split long functions and methods into smaller ones even though they won't be called by anything else?, I should split long functions into smaller functions even if they are used once only, but my question is , how should I name extracted functions? For example, I have code like that:

var changeProfilePic=function(){
  //upload image to server, get response "response1"
  //submit upload result to another server
}

how should I name the extracted functions? Should I name it as number:

var changeProfilePic=function(){
  changeProfilePic1();
  changeProfilePic2();
}

changeProfilePic1(){
  //upload image to server, get response
}

changeProfilePic2(){
  //submit upload result to another server
}

or name it relate to the task:

var changeProfilePic=function(){
  uploadImage();
  submitUploadResult();
}

uploadImage(){
  //upload image to server, get response "response1"
}

submitUploadResult(){
  //submit upload result to another server
}

?

ocomfd
  • 5,652
  • 8
  • 29
  • 37
  • 2
    If you answer yourself why splitting functions in small ones will be better for you - you will get answer your question. – Fabio May 09 '18 at 05:24

1 Answers1

6

By considering future use of your code,

you should always give the function name according to the action you are doing in to it. For. ex. If you are uploading image then the name should be uploadImage(), if you are retrieving data, then it should be retrieveData() or to submit result function name should be submitUploadedResult().

So in future, if new developer sees name of your function, without seeing code inside the function, he/she will get to know for which purpose your code is written.