Thank you for pointing me towards references. The search engine for Julia manual is helpless with "[]" or [] search queries. I get zero or 152 unrelated results.
I wouldn’t encourage using a[] for arrays, a[begin] is more explicit and clear, albeit a bit verbose (and I think requires Julia v1.something, with something != 0). But for single-element arrays maybe it’s fine anyway
Edit: the problem of [] is that it breaks with containers with more than one element:
julia> x = [1, 2]
2-element Array{Int64,1}:
1
2
julia> x[]
ERROR: BoundsError: attempt to access 2-element Array{Int64,1} at index []
So you must be sure that the container has a single element in order to use it. For Ref-like containers this is usually the case (they have by design only one element, just make sure the object is always a Ref), but for arrays that can grow this assumption may be wrong.
That’s a feature! It’s wholly consistent with how omitting indexing dimensions work in general. In other words, it’s a nice shorthand for grabbing the only element — and ensuring that there’s only one.
When omitting all indices with A[], this semantic provides a simple idiom to retrieve the only element in an array and simultaneously ensure that there was only one element.
Nice to learn about only as well, though I think that [] may be nicer in some contexts like many observables lifted in a Makie.jl visualization for example. Placing only everywhere can pollute the code.
Observables are guaranteed to only have one item and using [] is perfectly natural for them. only is to be used on e.g. a Vector where you expect it to only have one item after e.g. some filtering step.
I would only use [] on “zero-dimensional” containers (e.g. Ref, zero-dimensional arrays, Observable, and similar objects), where passing an index doesn’t make sense and they are guaranteed to contain exactly one element.