What should a GetSelectedIndex method return when no rows are selected
https://softwareengineering.stackexchange.com/questions/129014
-
03-11-2019 - |
Question
I'm creating a UI table component that returns an array of selected indices.
Some typical return values would be
var myRetVal1 = [0];//one value selected
var myRetVal2 = [0,1,2,3,8,11];//multiple value selected
as you can see I'm always returning an array.
I had an idea to return -1
when nothing is selected, but then I thought that might be confusing when in every other condition an array is returned.
So checking for an empty set of values would be either
//returns -1
var selectedItems = tbl.GetSelectedIndex();
if(selectedItems !== -1){
//we have data to process
}
OR
//returns []
var selectedItems = tbl.GetSelectedIndex();
if(selectedItems.length > 0){
//we have data to process
}
OR
//returns null
var selectedItems = tbl.GetSelectedIndex();
if(selectedItems){
//we have data to process
}
Maybe I'm making too big a deal over this, but is there a standard expectation for this type of control?
As I build other controls should they conform to a standard empty return value or should they always return a "empty" version of their expected return type?
No correct solution