-
Notifications
You must be signed in to change notification settings - Fork 20
Coding Templates
dehann edited this page May 2, 2020
·
15 revisions
Copyright NavAbility (2020) - All rights reserved.
When working with a field of a structure directly (in the Caesar ecosystem). I prefer the dot notation with get/setproperty[!]
overloaded if needed.
- It is easier to read and clearer that you are working with a reference:
val1 = mytype.a[1]
mytype.a[1] = val1 + 1
- compared to:
vals = getA(mytype)
val1 = vals[1]
-
vals[1] = val1 + 1
- DF, I don't mind that much on the user side, but is slightly easier to modify the package internal code if accessors are used, since old
verbNoun
can go through a deprecation cycle first. JT - See code below as an example for deprecation cycle.
- DF, I don't mind that much on the user side, but is slightly easier to modify the package internal code if accessors are used, since old
- Autocomplete. I'm lazy and can't remember method names.
We do not have to fore one method as deprecation can just as easily be done with get/setproperty[!]
.
struct MyType
new::Int
end
Base.propertynames(x::MyType, private::Bool=false) = private ? (:old, :new) : (:new,)
Base.getproperty(x::MyType,f::Symbol) = begin
if f == :old
@warn "old is deprecated, use new"
getfield(x, :new)
else
getfield(x,f)
end
end
julia> MyType(5).old
┌ Warning: old is deprecated, use new
└ @ Main untitled-69d23f940d4201fb549f03efe37c8103:11
5