On Wednesday, 29 January 2014 at 16:26:05 UTC, Cooler wrote:
On Wednesday, 29 January 2014 at 16:15:36 UTC, Tobias Pankrath wrote:
On Wednesday, 29 January 2014 at 16:01:08 UTC, Cooler wrote:

Do you read my post? I am answering... why do I need fun3() if I already have fun1() and fun2().

fun3 guarantees that the argument has the same length for example.

Where argument has the same length? After function call, or inside function? I don't understand what my intention should be to push me to use fun3()?

If you want to modify the slice and make changes visible in caller, you should use ref. If you don't care whether changes are visible in caller, you can omit any attributes and use plain array. This belongs to the case you are asking about. If you don't want to change array in callee, pass it as const qualified.

Now, after rethinking the issue I am inclining that "don't care whether changes are visible for caller" is not very wrong, but not very good design. Ideally it should be specified to avoid unexpected problems to pop up. So yes, it is better to qualify array.

Another point. This casino games of whether changes would be visible or not is direct consequence of how slices are implemented (and how runtime service them). Remember, that many features in D work in a strange way not because of wise design but as a consequence of not fully thought design (like array). As a result, some features work in not best way they should. Although many folks in newsgroups would eagerly say that you don't understand the lang, it wouldn't make a bad design a good one.

Reply via email to