I’m currently writing a CLI tool that handles a specific JSON data format. And I also want to give the user to get a slice of the item array of the file. It’s a slice in form of --slice START:END through commandline options. So in example --slice 1:2.

  1. Should I provide a 0 based index for the access or a 1 based index? In example --slice 1:2 with 0 based index would start with the second element and with 1 based index it would start with the first element.
  2. And would you think its better to have the END to be inclusive or exclusive? In example --slice 1:2 would get only one element if its exclusive or it gets two elements if its inclusive.

I know this is all personal taste, but I’m currently just torn between all options and cannot decide. And thought to ask you what you think. Maybe that helps me sorting my own thoughts a bit. Thanks in advance.

  • thingsiplay@beehaw.orgOP
    link
    fedilink
    arrow-up
    3
    ·
    2 days ago

    A dash is a bit problematic from practical point of view. In example I allow single numbers without a colon like just 6 which would be interpreted as 6:6. And each element is optional as well, which would make -6 either be a negative number, an commandline option or a range? Some languages also use dots .. instead. If I want ever support negative numbers, then the hypen, dash or minus character would be in the way.

    I mean I could just do a duck typing like stuff, where I accept “any” non digit character (maybe except the minus and plus characters) with regex. Hell even a space could be used… But I think in general a standardized character is the better option for something like this. Because from practical point of view, there is no real benefit for the end user using a different character in my opinion. Initially I even thought about what format to use and a colon is pretty much set in stone for me.