What should I call this method?

I am developing an API for a service that deals with Job objects. I need to get assignments based on status. So, I ended up calling my methods the following:

 List<Job> getJobsByStatus(JobStatus status); 

And later I realized that I also need to be able to receive tasks that do not belong to a certain status. Say I want to get everything but closed tasks.

I could not come up with a suitable and intuitive name for this method.

I thought about the bottom, but did not find them correctly.

 List<Job> getJobsAllButStatus(JobStatus status); List<Job> getJobsNotStatus(JobStatus status); 

I canโ€™t use a specific status, such as private and baptize my getAllButClosedJobs method, because my method will be general, able to handle any status.

PS: I hope this question relates to SO, although this is not technically programming. Otherwise, please feel free to transfer it to a suitable site.

+7
source share
4 answers
 List<Job> getJobsExcludingStatus(JobStatus status); 

or even

 List<Job> getJobsExcluding(JobStatus status); 

.......

And for good measure, here is why you shouldn't use a boolean parameter. Say you had an interface like this:

 List<Job> getJobs(JobStatus status, boolean exclude); 

then imagine code that reads like this:

 List<Job> jobLIst = getJobs(status, false); 

How should anyone know how this works? They will need to dig inside the method to find out that a lie is a switch for inclusion or exclusion or something else. The if , which will be inside the method implementation, hides two methods in your API - the one that makes the true case and the other the false. Typing is not a bottleneck in software development โ€” it's thinking.

+11
source
 List<Job> Jobs.allWith(JobStatus... status); List<Job> Jobs.allBut(JobStatus... status); 

The combination of poor api and varargs

+6
source
 List<Job> getJobsWithoutStatus(JobStatus status) 
+4
source

Try to make it simple -

 List<Job> getJobsBelongTo(JobStatus status) 

to return all tasks belonging to the status.

 List<Job> getJobsNotBelongTo(JobStatus status) 

to return all non-status assignments.

+1
source

All Articles