DataArrays.jl icon indicating copy to clipboard operation
DataArrays.jl copied to clipboard

Minimal constructors

Open johnmyleswhite opened this issue 11 years ago • 6 comments

Why discussing the recent changes to DA constructors, @simonster made a suggestion that I really like that would have us remove a constructor that isn't strictly.

I'd like to propose the following design principle:

  • We only offer two constructors for DA's and PDA's:
    • Construction using the implementation details
    • Construction using an empty DA/PDA of a specific type and size.
  • For creating objects, one either uses:
    • Literals written using @data or @pdata
    • Explicit conversions.

Does this sound right to you, @simonster?

johnmyleswhite avatar Jan 17 '14 03:01 johnmyleswhite

Not sure how I feel about this. Being able to create a DataArray from an array using the short DataArray(a) rather than the cumbersome convert(DataArray, a) is nice, just like there is sparse(a).

Anyway I don't care about other fancy constructors.

nalimilan avatar Jan 17 '14 20:01 nalimilan

Let's just add data and pdata functions for that use case.

johnmyleswhite avatar Jan 17 '14 21:01 johnmyleswhite

Sounds good to me. It would also be good if @data([a]) did conversion to a DataArray, as it does conversion to an Array in Base (but see JuliaLang/julia#3737). I'll see if I can make that happen.

simonster avatar Jan 17 '14 22:01 simonster

Shouldn't be too hard, just special case the macros to rewrite calls to the new data and pdata functions instead of calling the constructors.

johnmyleswhite avatar Jan 17 '14 23:01 johnmyleswhite

I added data and pdata in ae7d8203a1089b2cf05494c6cc209a6043f51b86

johnmyleswhite avatar Jan 18 '14 02:01 johnmyleswhite

Good!

nalimilan avatar Jan 18 '14 14:01 nalimilan