Could we have a discussion about this? I think typically this is bad behavior and it's much better design to do the work when methods are called. This pattern can lead to all sorts of performance problems latter (doing too much work). It's also a pretty serious violation of SRP.
Thoughts?
Originally filed against the matrix actual exercise: exercism/website-copy#1051
[Edit maud] The current solution in the mentor notes is:
class Matrix
attr_reader :rows, :columns
def initialize(matrix_as_string)
@rows = extract_rows(matrix_as_string)
@columns = rows.transpose
end
private
def extract_rows(string)
string.each_line.map { |line| line.split.map(&:to_i) }
end
end
Could we have a discussion about this? I think typically this is bad behavior and it's much better design to do the work when methods are called. This pattern can lead to all sorts of performance problems latter (doing too much work). It's also a pretty serious violation of SRP.
Thoughts?
Originally filed against the matrix actual exercise: exercism/website-copy#1051
[Edit maud] The current solution in the mentor notes is: