From: Edward Faulkner Date: 2006-02-14T03:56:14+09:00 Subject: Re: tree structures --oyUTqETQ0mS9luUI Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Feb 14, 2006 at 03:13:25AM +0900, frank wrote: > But it seems like there is a huge gulf between my procedural > thinking and an OO thinking with regard to this tree structure. How > would you represent a linked list in Ruby? Why do you really want a "linked list"? Just use an Array and stop worrying about how it's implemented. This is an example of thinking too low-level. But more importantly, why use lists at all to represent a tree? Why not just build a tree? Trees are recursive. Your data structure isn't. No wonder the code to navigate it is complicated. I would go farther and say that your parser should probably be recursive too. Your problem is not with "OO" vs "procedural" thinking. I'd say it's more "low-level abstractions" vs "high-level abstractions". =20 And even if this code was translated to C, I'd still consider it wrong, because you've chosen the wrong structures. It's just that Ruby is such a clear languages it makes bad choices more painfully obvious. Learning to think recursively isn't easy, but it's incredibly valuable for solving problems like this. best regards, Ed --oyUTqETQ0mS9luUI Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFD8NX6nhUz11p9MSARAsrKAKCSMGR5kwZYnQrMBfWMoXsd1iAgzwCfYoQX buci5HVx8mznOqcvB3POQ0c= =NVAw -----END PGP SIGNATURE----- --oyUTqETQ0mS9luUI--