[julia-users] Recommended way of implementing getters and setters

2015-07-30 Thread Tomas Lycken
For getters, I would opt for the latter approach with methods which you call on 
the time signal. However, I would also encourage you to extend already existing 
functions rather than creating new ones. For example, you could get the number 
of samples as Base.length(ts::TimeSignal). Sometimes it may make sense to 
provide more than one argument to these functions. 

For setters, I'd do the same thing where it makes sense, but make sure to 
follow the convention that the function name ends with a bang (!) and that the 
time signal is the first argument, eg det stuff!(ts::TimeSignal, stuff...) 

Good luck! 

[julia-users] Recommended way of implementing getters and setters

2015-07-29 Thread Adriano Vilela Barbosa
Hi,

This question is about programming style. I would like to know what's the 
recommended way of writing getters and setters in Julia.

I have a TimeSignal class written in Matlab that I'm trying to port over to 
Julia. In the Matlab implementation, I have some getter methods for 
computing the values of the dependent properties (e.g., the number of 
samples n_samples, the associated time vector time_vector, etc.). My 
question is: what's the recommended way of implementing these getter 
functions in Julia? Maybe implementing a getindex() function so that I can 
do, for example, time_signal[:n_samples]? Or is it better to explicitly 
write getter functions like get_n_samples(time_signal), 
get_time_vector(time_signal), etc?

I read the thread about dot overloading at

https://github.com/JuliaLang/julia/issues/1974

but this still seems to be an open issue at the moment.

Thanks a lot,

Adriano