Refactor Going Well

I got a good amount done on the Connect! refactor last night and this morning.  It has gone from a single source file with 523 lines to 10 source files with 509 lines.

I am reminded of numerous new developers I’ve seen over the years. Typically one of the hallmarks of  new developers is the “one big honking source file”, which I found myself doing here until yesterday, when I got fed up and was reminded of why it is a bad idea to do that.

One, things were getting hard to find.  Where was the function that creates the buttons again? Oh! There it is, stuck amidst the code that animates and hides the cheerleader.

Now I simply look in buttons.js.

The largest section of code is board,js with 270+ LOC.  It still needs some work.  While I managed to combine the saved state into the board (before they were separate), the board data representation is coupled too tightly to the rendering, meaning that the board class itself is making calls to document.getElementById and setting the src member of an <img> (which is what passes for “rendering” when you are using javascript to manipulate the HTML DOM objects).

The likely next step is to split out the rendering stuff into a boardView class.

I also need to change the general layout.  Right now, everything gets placed into a single <div>, which would make it a pain to resize and move stuff around when it comes time to change the size of the board. The next idea for that is to put <div>s inside of the big <div>, and move the little <div>s around, which means the stuff *INSIDE* the <div>s don’t have to worry about the positions of things outside of their <div>.

(Basically, I’m implementing subframes).

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: