From: tamouse mailing lists Date: 2012-11-24T21:05:16+09:00 Subject: Re: Arrays with records as objects On Fri, Nov 23, 2012 at 6:49 AM, Steve Tucknott wrote: > Thanks for all the advice. My pleasure. :) > Bear in mind though, that in some cases (not all!) the poor coding was > simply because I cut and pasted a line (ie the build of addr_rec) - I > wouldn't write code like that in working code. That was understood -- I was merely trying to point out that such things do leak into "real" code. Even when we're just learning, or even playing around, it can help to keep the "discipline" if you will. But I'm glad you see the difference! > I'll make notes though to > the best practice in my test examples (actually it's now one example as > I thought I'd bolt all the examples into one module and use arguments > and a case to drive it - just to see how arguments and case worked! - > once I know how to create libraries, I'll split them back out again!) > > What I've found odd so far is that Ruby appears to have multiple ways of > doing the same thing Nearly every language I've come across this is true. The richness of expression is a good thing, in my view. > - so as you say, I could write: > line[i] = some_rec > or > line << some_rec > (assuming the index points to the next empty slot) > > ..and the examples don't appear (so far) to explain the why's and > where's and then best practices. It's somewhat a matter of taste, sometimes a real boon to programming. The latter is the classic "push" type of operation -- very useful when you just want to append without knowing the current end of the array. > Ditto for iteration. > > All this is my fault , as I was up to array handling, and then googled > something I didn't quite follow - and ended up at a site with a 'todo' > example that I thought would be good as a mini test module. So I jumped > ahead of myself and started faffing around with that and then hit > records in arrays etc. I wouldn't consider it a fault -- as in laying blame or guilt or anything like that. We all have our own learning style, and our own way of approaching things. Jumping around can be useful, or you can miss something, but it all works out, eventually. > Such is the learning curve. > > Thanks for your patience. > > -- > Posted via http://www.ruby-forum.com/. > I really hope I'm not discouraging you. This is actually fun stuff. Take my comments for what they are, merely trying to help you up the curve a bit. The best part about free advice is you don't have to take it.