Projects, projects and more projects

I had decided to take my mostly finished project, the backgammon game, and use the One Game a Month challenge to keep me moving forward. Things haven’t exactly worked out that way. Time has been at a premium lately and, while the game is mostly finished, in a lot of ways it is holding me back. I have been spinning my wheels trying to accomplish the final tasks in the scraps of time I have had. Progress is slow and it is sapping my motivation.

While all of that has been going on, I have been given a few leads that could, in the long run, lead to actual, paying work. A friend of mine who works at a small start-up told me that he might be able to hire me in the future if I can get a handle on all the basics (HTML, CSS JavaScript) AND if I know Angular. To that end, I have started hitting the AngularJS tutorials and online class type stuff, mostly the great series at code school.

Seizing on that, my mentor has decided that we are going to work on a project together. He will handle the back end and give me an api, and I will do everything else (with guidance where needed). We started Sunday evening with a long discussion about the functionality he’s looking for. Yesterday I worked on getting some bare bones of HTML and CSS going, along with a little itsy bitsy piece of JS/jQuery that performs some useless DOM manipulation. This morning I plopped together the Angular, dummied up some data (in JSON format, of course) and got it to appear on the page via an expression. Yay!

Even though it is at the earliest of stages and none of the code I have written does anything useful at all, it feels good to be putting all this learning into practice. I am still slow and have to reference my notes and the tutorials and the docs and bug my friends for help, but I’m getting there. I am learning the tools (I have maybe temporarily switched to VS Community, don’t worry JetBrains, I’ll be back, I promise!)

Advertisements

Finally, code samples!

I guess I have put it off long enough. At some point I knew I would have to show other pfilledBoardeople my code, as embarrassingly naive and novice as it is. So let’s get it out of the way in one fell swoop. Here is everything I have done. It is sloppy, messy, not well commented, hacked together and sometimes difficult for no reason. And I’m okay with that.

My earliest work is in the index.html and the top of the css file. It is basically me working through the battleship game in the Head First book, with some added flourishes. The meat of my own work is in the two backgammon files. That is where, so far, I have made my most creative mistakes.

Here is my board with some, uh…, test features turned on. The board itself is an image and the playing field is composed of several tables that I have aligned to the board. Then each celcellCSSl of the table has one of three css classes applied to it. .fillWhite uses an image, confusingly enough, an orange checker. .fillBlack, even more confusingly, makes the entire cell white (note to self, change that to a black fill… done). Finally there is .empty that, for testing purposes makes the cell grey.

movedBoard

After moving some of the checkers a few times.

Aside from setting up the board, the user can also move checkers using an input box. This is another stepping stone/test function while I work out the real input scheme. I just recently got the move function to turn the origin cell to empty instead of just “adding” a new checker to the board in the destination position. I also have the moves hardcoded to 2 spots and flipping between the players every move. It’s confusing, but it works for now.

There are a lot of things to talk about with even just this early stage and simplistic implementation. Design and decision choices. A couple questions I can answer easily together. Why am I using a table for the board? Why am I using an input box to move the checkers? Because I ripped those ideas right from the battleship game. I, essentially, don’t know of another way to do it. In fact, this is a good time to talk about my overarching design philosophy for this particular project. I aim to get it done and make it work however I can. I can always rewrite, but for now I just want to see this through.

I do try to keep my functions small and simple whenever I have the brainpower to do so. One place that shows well is in the functions to fill and empty cells. I pass in the minimum amount of information the need and update the view. Here they are:

fillEmpty

That’s it. I have run into some issues. To clear the entire board with the emptyCell function, I need to feed it the id of every cell. That means either storing all of the cell values in an array or building a function to create those values and feed them to emptyCell. Also, who knows how many other creative solutions I haven’t thought of. What I have decided to do instead is utilize jQuery, with mixed success. I’ll figure it out. At least half of the “fun” of coding for me has been troubleshooting. I see a lot of troubleshooting in my future!

An introspective interlude

Getting a late start tonight. In the future I intend to utilize my downtime a little better and take advantage of the ability to load some articles up for publishing in the future! In a minute I will talk a little about the details of writing my backgammon game, but something happened to me today that made me take stock of some of my programming behaviors.

For a very brief time, and through no fault of their own, Cloud9’s workspaces were unavailable. It was somewhere around 30 minutes and I was hardly even inconvenienced. I was wondering why a certain piece of my code worked while another piece I was hoping to use as a more elegant solution to the same problem didn’t. Not pressing, but a bit of a shock.

“But you use source control, why not just pull down the code and look at it somewhere else?” an astute reader might ask. I do, and I could have… except I hadn’t pushed my code in a day or so. There are certainly a couple of lessons to be learned here, for me. In a wider sense, I need to have a backup plan. What that means specifically, is first, to keep my repository (more) up to date. With my code available, I would have been able to pop open another IDE and keep coding. To that end, I will be investigating the other cloud IDEs as backups. On the PC I will probably just rely on Visual Studio.

(I want to say, “lesson learned,” but at the time of this writing, I still haven’t pushed my changes up.)

On to code. A bit of (hopefully brief) background first. The exercises in the Head First JavaScript book have certain quirks for ease of publishing. They throw the JavaScript inside a script
wrapper in the HTML (and use inline CSS). I figured it wouldn’t be much more difficult to separate the css and JS into their own files and link them in the HTML. It generally wasn’t any more difficult. The other thing I wanted to do was set up a simple “webpage” that would hold the exercises and any of my projects. This actually did cause a little more cognitive overhead.

At first I was keeping it all on one page and all the JavaScript on one .js file. There came a point where I felt that was too cluttered and so I pulled my backgammon stuff onto its own page and the JavaScript into its own file. Not a completely clean break, all of my CSS is in one place. It works. That’s probably the best thing I can say about it at this point.

I am aware that most of what I am doing at these stages is “ugly” code. There are probably better, cleaner and more efficient ways to do nearly everything I am attempting to do. I don’t know those things yet, so I work with what I have. I am under no illusions that I am writing masterpiece software. I even had the idea that I would do this first with vanilla JavaScript and then dive into things like Bootstrap and jQuery for a total rewrite. I have already trashed that plan and started to incorporate jQuery. I am just not sure I see the value in making things harder for me than they need to be.

Next time, I’ll show you some of my code and talk about the reasons I made the decisions I made.

Staying on the branching path.

Looking through book after book after book, I had no idea how to evaluate their potential usefulness. I didn’t know what aspects were going to be important to me and what methods would work best for me. After I left the bookstore, I felt a little discouraged and overwhelmed. All the work I had done, all the progress I felt I had made, and I still felt like I was at square one. How could I keep moving forward? What was my next step?

I woke up feeling a lot more hopeful and decided to jump into some of the more “advanced” topics at Codecademy. The lessons didn’t always make sense, but I figured some of the knowledge would trickle in and, more importantly, I was just getting familiar with the entire process. Familiarity felt like an important goal. I thought back to my friend’s advice, “… start there.” I had started there, right? I mean, here I was, learning, but was that really starting?

Up to this point, I had done all my work inside the Codecademy lessons. It really is an incredible site, with a built in IDE and a test window. Maybe, however, it was time I started writing code in my own “space.” It was time to find an IDE that I could use, and wow are there a lot to choose from. Off the top of my head, there are: Visual Studio Community, JetBrain’s WebStorm, Sublime Text, and Eclipse, and that’s just the ones I knew about before I really started looking. I settled on none of these, but that was only because I had an additional requirement that I hadn’t given any though to until that moment.

I do most of my work from a desktop PC running some flavor of windows. I have no special preference for them, and would gladly try any of those IDEs from the list above. But occasionally, I am away from my desk, and that means I am working on a Chromebook. Once again with help from my friends, I discovered the world of cloud IDEs. It turns out there is actually a lot of choice here too. I quickly chose two tools in this category and haven’t spent much, if any, time examining the other options. The two I latched onto are Cloud9 and JSFiddle. I also jumped into one more piece of software, even though I didn’t then understand why I needed it, GitHub. There’s a lot to say about these tools, and some day I will. For now it’s enough to say they work very well.

I spent the next week or so reviewing my lessons and trying to apply them in new and creative ways. Patching code together helped me push against the constraints of my knowledge, and there were many times I was running a few steps ahead of reasonable. I made a lot of mistakes. Logical mistakes. Syntactical mistakes. Spelling mistakes. Creative mistakes. I wish I could say I learned from every mistake, but I did learn from enough of them. Most importantly, I started to understand what I needed. What would keep me motivated and progressing.

So, back to the bookstore I went, and this time I was confident enough to buy a couple of books to take home with me. “Head First JavaScript Programming” by Freeman & Robson, and “Sams Teach Yourself jQuery and JavaScript”. From skimming through the Head First book, I saw that it had some projects to build. That appealed to me, as well as the less formal writing style. Having now progressed through the book, I can say that it does a really good job of building concepts and reinforcing the knowledge at every step. Like the software tools above, there is a lot to say about both of these books, and I hope I will get a chance to review them in the future. This is also the first time I have even mentioned jQuery, so maybe it seems a bit strange to jump right into buying a book about it, but I knew it was time to explore the world of JavaScript libraries in general and jQuery specifically.

Next time, I’ll talk about putting all of this together and actually “getting started”!