Open SoniEx2 opened 8 years ago
What's the use of the has()
function?
Instead of returning a proper List
, we'd return a wrapped List
that returns an empty Arg
for args out of bounds.
That appears to be a really bad idea to me.
Could always use Map<Integer, Arg>
instead.
Could always expect programmers to be able to use List#size
...
Returning a valid value on out of bounds without changing List.size()
should be safe. Not sure if it's allowed by the List.get
contract but w/e, it doesn't matter, your code shouldn't rely on OutOfBoundsException
s anyway.
No, this clearly breaks the contract of List<T>
. Nobody expects List
to do that. If you want to create an interface like this, then we should create an Args
class instead of List<Arg>
.
With Args.asList()
?
Maybe, but not as the main API, it should have size()
and get(int)
(like List<T>
), but return EmptyArg
classes instead of index error.
Should Args.asList()
return a List<Arg>
view of the args? Or should it return a List<Arg>
copy of the args?
@SoniEx2 semantics, return a Collections.immutableList view of it.
@RX14 why?
Why not?
@RX14 Well idk but why should Args
be immutable?
Because they are in reality immutable, you run the command with arguments, and you can't retroactively change what the user meant.
@RX14 Technically, you're given an Args
. The Args
is never used anywhere else so you're free to do with it as you like.
Technically, you're wrong.
@RX14 Why limit the user?
because it's the true state of the world that you cannot retroactively change the arguments the user passed into a command. That's time travel and pretending otherwise has no benefits and doesn't show the true state of the user interaction.
@RX14 Everything is mutable if you put enough hacks into it. And you might want to pass the Args
forward after some tweaking.
@SoniEx2 I have explaied why multiple times, and I'm pretty sure the other developers will agree with me that having Args be mutable "feels wrong". You can construct your own Args objects with your own list.
I agree with having Args be immutable.
Should there be a CommandFactory
or should it just be a Command
instance?
I'm not sure the purpose of a CommandFactory other than to waste my RAM?
Current idea:
Questions:
asString
?as
take anyClass
, and if there's no converter for it then cause a runtime error? (This seems like bad API design, but it'd let you pass inString.class
)Args.asList()
return the backing list, or should it return a copy of the backing list? Should we wrap the backing list such that it doesn't acceptnull
?Collection
?