From: Robert Klemme Date: 2010-04-19T18:51:25+09:00 Subject: Re: Writing a parser 2010/4/17 Martin Hansen : >> And you chose ruby? Ruby isn't exactly known for speed. And I can >> practically guarantee you that the syck parser will be faster for hashes >> of strings than your parser (as it is currently written and several >> minor iterations out). >> >> But no, what you described IS yaml, it is just a subset of yaml. You can >> enforce the subset-ness if you feel like it, but I'm not a big fan of >> static typing, so I don't recommend it. > > Yes, for I want to use Ruby to juggle the records - and then let's see > about the speed :o). I know from Perl that there is a quite a difference > between a home rolled parser and YAML-syck (I never saw any subset-ness > features). > > Also, I am learning here. This OO thinking is very exotic ... Yeah, it took me a while as well to grok it initially. I think it's worthwhile, once simply because OO is mainstream nowadays but even more importantly because it is a very powerful concept which lends itself very well to modeling problems - especially in a language with a clean and nice syntax as Ruby. >> At the very least, you should look at StringScanner and a full rewrite, >> drop the silly Record class entirely and build up proper hashes of >> strings. And don't leave those dangling File objects everywhere. Read >> the whole file or use the block form of file.open. > > I will gladly consider a rewrite - I am afraid that I find Robert's > contribution confusing (am I unfair?). You have every right to be confused. If you continue the thread at the other end and point out which of my attempts to explain what's going on caused you trouble, I can try to refine the explanation and help clear things up. > Why is the Record class silly? Not sure which remark you are referring to. I said that inheriting core classes is rarely a good idea and if Hash functionality is all you need for your records then you can simply use a Hash and just need some other place to put the parsing / reading functionality. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/