|
|
|
|
@d = default
in last example. I would drop it. If you don't provide value for optional argument, it should be set to default value by default - you shouldn't have to explicitly state it. You shouldn't have to mention the variable at all. There also should be way for you to use them just as they were mandatory, so you don't have to type @name = value for every argument, but you would have to preserve order then.
|
|
MatthewRock wrote: |
---|
Oh, I missed @d = default in last example. I would drop it. If you don't provide value for optional argument, it should be set to default value by default - you shouldn't have to explicitly state it. You shouldn't have to mention the variable at all. |
= default
and = delete
.MatthewRock wrote: |
---|
because: - You save keystrokes you'd have to use for default - You explicitly mention the value name, so less mistakes - If function had some large amount of optional arguments, it would be painful to write default for all of them. Also, - order doesn't matter - you wouldn't have to remember whether it's 3rd or 5th value you have to change. You mention its name with keyword. |
fun( a, b, c, d, , , g, , i);
MatthewRock wrote: |
---|
And when I said that you shouldn't have to mention the variable if you're not using it, I meant that you *shouldn't have to* mention variable - but you should also have a possibility to explicitly say that it should be default. Sometimes it may be easier to read. |
void foo(int bar, int y=1, int z)
|
|