When should I choose a struct, mutable struct, Dict, named tuple or DataFrame?

Although this is hard, I can only emphasize

I’ve been there and I’ve messed up my first non-small project sufficiently. It’s definitely an experience to learn from. And it’s incredibly hard to forsee what will work out eventually, what’s a good and what’s a bad optimization until you’re knee-deep in the stuff, so delay most of that though until when you’re there.

A lot of those details can often be circumvented by less considering what you use in favor of how you use it. Expressing your high-level operations in terms of low-level operations that you can specialize on a particular datastructure may go a long way. Many things can also be written generically, so that they just work for most inputs, irrespective of the concrete type. Just be sure to not put unnecessary type restrictions everywhere (again, I did that mistake myself). Example: if you need to iterator over something, you usually don’t need to know the particular structure if you just keep to the usual iteration functions. Use eachindex instead of 1:... and so on. I guarantee that you’ll get a feeling for this eventually ^^

On your case: Struct for position looks fine. You could use a StaticArray, that’s basically what those are for, but that doesn’t come with the named dimensions.

So does NamedTuple for returning many things in a way that is “self-explanatory” at the other side. But returning a whole lot of things from a huge function may be a sign to split that into smaller pieces.

Good luck with your application.

3 Likes