digitalmars.D - Suggestion: arrays.
- DLearner (29/30) Aug 11 2015 Static array properties are:
- John Colvin (11/41) Aug 11 2015 2 choices:
- jmh530 (6/16) Aug 11 2015 The OP could also make it a property to make it even more
From dlang:Static array properties are: ... .dup Create a dynamic array of the same size and copy the contents of the array into it. .idup Create a dynamic array of the same size and copy the contents of the array into it. The copy is typed as being immutable. ... Dynamic array properties are: ... .dup Create a dynamic array of the same size and copy the contents of the array into it. .idup Create a dynamic array of the same size and copy the contents of the array into it. The copy is typed as being immutable. D 2.0 only ... <<< The problem: 'dup' is an abbreviation of 'duplicate'. However, for static arrays, result is not a true duplicate of the source. But, for dynamic arrays, result is a true duplicate. So the same abbreviation produces two different effects. Bugsource? Suggested solution: For static arrays, replace '.dup' with '.dyn' (and similarly for 'idup'). Use of 'dyn' would also add clarity.
Aug 11 2015
On Tuesday, 11 August 2015 at 08:59:50 UTC, DLearner wrote:From dlang:2 choices: 1) break people's code and documentation by renaming .dup on static arrays 2) have 2 equivalent names for the same thing Neither is likely to happen. If you want it for your own code: T[] dyn(T, size_t n)(T[n] a) { return a.dup; }Static array properties are: ... .dup Create a dynamic array of the same size and copy the contents of the array into it. .idup Create a dynamic array of the same size and copy the contents of the array into it. The copy is typed as being immutable. ... Dynamic array properties are: ... .dup Create a dynamic array of the same size and copy the contents of the array into it. .idup Create a dynamic array of the same size and copy the contents of the array into it. The copy is typed as being immutable. D 2.0 only ... <<< The problem: 'dup' is an abbreviation of 'duplicate'. However, for static arrays, result is not a true duplicate of the source. But, for dynamic arrays, result is a true duplicate. So the same abbreviation produces two different effects. Bugsource? Suggested solution: For static arrays, replace '.dup' with '.dyn' (and similarly for 'idup'). Use of 'dyn' would also add clarity.
Aug 11 2015
On Tuesday, 11 August 2015 at 09:08:57 UTC, John Colvin wrote:2 choices: 1) break people's code and documentation by renaming .dup on static arrays 2) have 2 equivalent names for the same thing Neither is likely to happen. If you want it for your own code: T[] dyn(T, size_t n)(T[n] a) { return a.dup; }The OP could also make it a property to make it even more similar. Perhaps the least amount of work would be if alias worked on functions (I don't see anything in the docs about that). The broader issue that it is very easy to mix up static and dynamic arrays remains.
Aug 11 2015