to cast or not to cast?
-
bahuvrihi
It definitely is something to think about.
My first reaction was 'not to cast' mainly coming from a performance standpoint. Looking at a .dat file, many sections including queries have a lot of numbers that would have to be cast.
On further reflection though, I think casting is appropriate as long as it's lazy. I think the intention of these classes is to model the data, not the file.
Maybe a memoize approach? (I think I've read this as the correct term) It's basically your second approach... first you parse and save the string data with as little processing as possible, and then do this:
def parse @data['ions'] = "string of ions, unsplit" ... end def ions @ions ||= @data.delete('ions').split.cast endThat way you don't store the info twice, you can access it as a string if you like, and when you declare your intent to use the data as numbers (via a call to ions) you get back an array of numbers. In this system I think it's ok to lose the string data... I think it's probably quite rare to need the string and the numeric data at the same time.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.