# Strategy help

**URL:** <https://discourse.julialang.org/t/strategy-help/109370>\
**Category:** General Usage\
**Created:** [January 28, 2024, 10:35pm UTC](https://discourse.julialang.org/t/strategy-help/109370 "2024-01-28T22:35:18Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![mpeters2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mpeters2/32/202247_2.png) [@mpeters2](https://discourse.julialang.org/u/mpeters2)\
**Post date:** [January 30, 2024, 2:42am UTC](https://discourse.julialang.org/t/strategy-help/109370/21 "2024-01-30T02:42:30Z")

</div>

DNF: `Using `Vector`for *any* of these seems like a suboptimal approach. I would use a data structure that enforces the correct format, such as`Tuple`s and a Color type. There is nothing in the type of`Vector`that 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.

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [January 30, 2024, 3:23am UTC](https://discourse.julialang.org/t/strategy-help/109370/22 "2024-01-30T03:23:23Z")

</div>

> [@mpeters2](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [January 30, 2024, 4:10am UTC](https://discourse.julialang.org/t/strategy-help/109370/23 "2024-01-30T04:10:17Z")

</div>

> [@mpeters2](#):
>
> I’m not trying for an optimal approach (i.e. speed),

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

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

---

<div class="post-metadata">

**Author:** ![GHTaarn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ghtaarn/32/216007_2.png) [@GHTaarn](https://discourse.julialang.org/u/GHTaarn)\
**Post date:** [January 30, 2024, 6:42am UTC](https://discourse.julialang.org/t/strategy-help/109370/24 "2024-01-30T06:42:26Z")

</div>

> [@mpeters2](#):
>
> On the otherhand, for color, what if I typed `lineColor` as Any, and called an external function to translate it (string or float colors) to an internal variable \_lineColor for drawing?
> 
> ```julia
> lineColor::Any # what the usesr passes: string, or vectors of ints or floats
> _lineColor::Vector{Int64} # internal SDL-style RGBA255 color
> 
> ```
> 
> or does it make more sense to use a Union\*
> 
> ```julia
> lineColor::Union{String, MVector{4, Int64}, MVector{4, Float64}} # what the usesr passes: string, or vectors of ints or floats
> _lineColor::Vector{Int64} # internal SDL-style RGBA255 color
> 
> ```

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.

[Previous page](https://discourse.julialang.org/t/strategy-help/109370.md?page=1)
