Strategy help

DNF: Using Vectorfor *any* of these seems like a suboptimal approach. I would use a data structure that enforces the correct format, such asTuples and a Color type. There is nothing in the type ofVectorthat guarantees length, for example.Vector s are also bad for memory and performance.

I’m not trying for an optimal approach (i.e. speed), I’m trying for an optimal approach in regard to user experience. I’m trying to translate/mimic a set of Python libraries, and introducing new data formats for the user would slow down productivity.

I’m trying to write something so that a person can give me X (a string), Y (a float Vector from 0-1), or Z (an integer vector from 0-255) and automagically deal with it.

Here you describe the interface of your library which has not much to do with how you store things internally. If the meaning of the strings, ints, floats is the same then make your life easy by (internally!) choosing one of the representations and convert the other forms to it. The user will never see it and you don’t have to handle all possible representations each time you want to use the datastructure.

4 Likes

I was using ‘suboptimal’ as a diplomatic euphemism for ‘bad’ :wink: It’s just not an appropriate representation.

For the rest, I was trying to make the same point as @abraemer did very succinctly.

3 Likes

Whether to use the Union or Any is just a matter of personal preference, I like Union because it throws an error if called with an unsupported type.

I don’t know MVector (it is not a standard Julia type), but it seems like what you are suggesting makes sense. Personally, I avoid using external libraries unless there is a big benefit, so I would probably prefer Tuple{Float64,Float64} rather than MVector{2,Float64}.

I hope that it is essential for you to have access to the original user input, because otherwise I would join the others in this thread that suggest only saving the internal representation of the line.