Code refactoring: request for comment

A

Aldric Giacomoni

D

David A. Black

Hi Aldric --

Hi all,
I've just finished doing some pretty heavy refactoring on a method. I'd
like to know if anyone can offer any suggestions or feedback.

This is the old one:
http://github.com/Trevoke/SGFParser...3f6a96efa7aa1101/lib/sgf/parser/tree_parse.rb

This is the new one:
http://github.com/Trevoke/SGFParser...f8fe9e837e151579/lib/sgf/parser/tree_parse.rb

In short, I am parsing an SGF file.
The basic important characters which delimit the nodes are (, ), ;, [
and ].

In looking it over, the one place where it was hard to see what was
going on was:

when '['
get_property
@content[@identity] ||= ""
@content[@identity] << @property
@identity = ""

It's not clear that get_property does anything to @property. I mean,
it's clear once you look at get_property, but not from the calling
context.

Could you do this instead...

when '['
@content[@identity] ||= ""
@content[@identity] << get_property
@identity = ""

and then retool get_property to use a temporary buffer instead of
@property? If so, you could probably get rid of @property entirely.

Now, just for fun, and because I'm a bit of a compulsive refactorer,
I've created this: http://gist.github.com/384362 which probably uses
totally wrong method names but which paints a pretty good picture of
what would happen if you wanted to push all the busy work out of the
case statement entirely and let the instance variables and so on talk
to themselves elsewhere. (You'll see what I mean :) I don't know the
SGF format myself, and haven't subjected the code to any reality
checks beyond making sure your specs pass.


David

--
David A. Black, Senior Developer, Cyrus Innovation Inc.

THE Ruby training with Black/Brown/McAnally
COMPLEAT Coming to Chicago area, June 18-19, 2010!
RUBYIST http://www.compleatrubyist.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top