This is a personal review of my post DBC work. After DBC I took time for family obligations and this is a review exercise. I’m going to point out the parts in which I had problems and my thought process behind some of the work. Please feel free to leave comments. Actually, I insist that you give advice.
First the code: https://github.com/ymeynot45/T3_trials
I’ll admit I found it really easy to figure out how to do the work, but I had more than one problem where I forgot terms. Those are the issues that always take the most time for me as they are the hardest to figure out what was wrong.
I started with the HTML, CSS and JS. I wanted to focus on the AJAX and knowing what data I was passing back and forth before I designed the backend to handle it. I had used AJAX for some minor things in the past but it was normally sending only one or two pieces of data.
So my first problem was
$(“#currentboard”).val(response.currentboard);
This code was to pass the current condition of the board back and forth. Simple, except when writing it I put .value as the code in sublime turned blue indicating that it was a keyword and it is also the name of the CSS location I’m trying to change. It’s one of those things when you haven’t done it in a while and it looks right, it sounds right, and it feels right… yet, it isn’t right. I fixed it by unhiding the field and seeing that it wasn’t changing. Then I threw a “puts” statement in the ruby right before sending back the info. That made it real clear that the Ruby was working but JS was broken. An easy fix once I knew where to look.
Next came an issue from the Ruby. My memory failed me as I used a .to_s like I would with an integer, on an array. The code,
cols = [firstcol.join, secondcol.join, thirdcol.join]
I forgot that when you .to_s an array it converts the brackets and quote marks in the array. I didn’t catch the error with a .class as it was supposed to be a string. I caught it with another print/puts line. The extra quotes didn’t standout enough for me to take note, but the escapes for each of the quote marks inside of the brackets were a big clue.
Structure… When I write code I like it when it reads like a book. The methods in the main body are all wrapped in ones that I create so it is explicit what each of them do, but I’ve never gotten a good read from my mentors as to when too much is too much. An example:
if board.include? “5”
return “5”
that is a simple piece of code. It is at the beginning of the process for the AI to choose a move. It is easy to understand that if there are a five in board return a 5, but it doesn’t tell you why. I like using method names to walk people through the code. I didn’t make a new method because it is such a simple piece of code. I look forward to having more mentors and teachers show me how to make my code more legible to programmers. How not to over complicate that which is already simple.
Another decision in my code was:
I originally had this as two separate methods: block_check & win_check. It include the line, but not the piece so it was practically the same method and only took one argument. I debated combining the two as it made it more likely to break and harder to track where the problem might occur. I eventually did because I know we remove repetition to make our code better but there are occasion where I’m not sure if it applicable.
The rest was easy, some planning & some trial in error. My next project for fun and as a refresher will be to convert a Lone Wolf book in to a web game. It will require basics like a login, sql storage of player & character info, a lot of AJAX when combat takes place and an improvement in my UX skills to make the HTML and CSS accessible and attractive to a larger audience. I hope that if I work hard that I could have it done with in two weeks. I need another DBC like project with a ticking clock. I do my best work under the gun.