Saturday, July 26, 2014

The "ABL's" of Programming

For anybody familiar with Sales, you've probably heard of the "ABC's" of selling which stands for "Always Be Closing". For people not familiar with sales, its basically the concept that if I were trying to sell you a tennis ball, and you objected and said you really don't like green tennis balls, I would ask you a clarifying question to understand what colors you might like, and then I go right back to the close with something like "so which would you prefer, a tennis ball of color 'x' or color 'y'?" Basically, as you uncover information about your prospect, you're still pushing for the close every step of the way.

As I was driving home yesterday and thinking about a good topic to write about, the ABC's kind of popped into my head and it made me think of a good acronym that applies to anybody that codes, "Always Be Learning" or as I titled it, the "ABL's" of Programming. I thought of this both because of some of my recent struggles, but it's also been a consistent theme on a Ruby Rogues podcast I've been listening to recently.

So how does it apply to me recently? A few weeks back, I had this idea to try and program a basic Text based adventure game in JavaScript that would present you with various scenarios and options, and based on your choices you'd progress through the game. I knew it would test my knowledge of several concepts like For Loops, While Loops, Iterations, etc. Well the first weekend I dove head first into the game and felt like I made a ton of traction. It almost seemed like a relatively easy concept that I would be able to finish and release within maybe a week's time frame. Well here I am about 3 weeks later, and still no working version of the game!

While I made a lot of progress that first weekend, my code gradually became more complex, and it started getting harder to keep things straight or decide how to pull the information I needed. After getting some advice from a developer that sits by me, and studying further into the CodeAcademy JavaScript tutorial, I then realized I could re-structure my game to follow a more traditional "Object-oriented" fashion and take advantage of JavaScript's Prototypal/inheritance nature. That led to a whole weekend of diving in, getting really confused, and then slowly figuring out how to once again structure my game and make it work. However, I learned a ton and my code was far better off because of it!

Well now I've run into another issue where one of my iterators keeps looping and is not escaping, so I worked briefly with another of our Software Engineers yesterday, and he mentioned that an "alert" method I'm using does not work well with browsers, and that I should strongly use jQuery for what I was trying to do. So now after about two weeks, I'm diving into a completely different area and once again deciding to re-structure my game to make it work better and become easier to work with moving forward.

I spent yesterday researching how to implement the jQuery library, which then also led me to pull in HTML/CSS and changing my game to a more graphical nature in the browser rather than being completely text based from JavaScript functions. While it's not absolutely necessary that I do this, I do envision where this is going to make certain aspects of my game a lot easier and a lot more efficient to code. I even learned how to make my page somewhat "responsive"! That basically means that if you were to start with a full screen, and start to shrink the screen, the elements will shrink along with it so that the page remains readable and functional. Especially since a web page can be accessed by so many devices including tablets, phones, laptops, etc. all of which have different size screens, implementing responsive design is an absolute must.

So basically what started as a simple JavaScript program with basic "for loops" & "iterators" has now evolved to be so much more. At least I've learned concepts and a little bit about other languages & libraries that I've been able to apply to my code. I've faced some type of challenge on an almost daily basis, but I've learned something new every step of the way and feel so much more confident today than I did a few weeks back when I started the game!

Software Engineering is definitely a field and skill set that requires you must "Always be learning!".


Sunday, July 13, 2014

Lessons learned

I've recently been working through the CodeAcademy JavaScript tutorials, so I randomly decided on Friday I would try to build a text based RPG game using the stuff I've been learning. Mainly, I've been learning about functions, arrays, objects, for loops, while loops, etc. I figured what better way to see what I've actually absorbed than to push my skills to the max by building a simple game that leverages these concepts. (If you aren't familiar with an RPG game - it means Role Playing Game. Essentially, my program provides you with a Scenario and then gives you various options. Depending on what option you choose, your game can have different outcomes). 

Here are some things I've learned this weekend:

  1. The internet is such a huge resource when you get stuck! I ran into an issue on Saturday that I worked and worked on, but could not figure out how to solve. I posted my question on Twitter and within 10 minutes had a conversation going with 4-5 other developers and I learned a few possible ways to solve it. The nice thing though, apparently my question wasn't a complete newbie question and actually posed some challenges to think about.
  2. While programming, when working on logic and flow statements, it's IMPERATIVE that you read your code with an empty & fresh mindset with no preconceived notions. If you think you know what the outcome should be, it can make it very difficult to effectively follow along in your code and troubleshoot.

    I'll try to give an example in layman's terms, which is actually the problem mentioned above:

    A user is presented with options 1, 2, 3, and 4 and each option routes to a different scenario. I wanted to ensure they selected one of the four options and didn't try to select 5 for example. My logical flow was:

    if userOption is not equal to (1 OR 2 OR 3 OR 4) then that is a bad result

    I spent at least 30 minutes reviewing through this line of code and trying to figure out why it was not working. And then finally the light bulb went off! My program was checking to see if userOption was not equal to any of those options; so for example, if I selected 3 (which I wanted to give a good result), it still compared it to 1, saw it was not equal to, and returned a bad result.

    The correct logic is .... ("userOption is not equal to 1" AND "userOption is not equal to 2" AND "userOption is not equal to 3" AND "userOption is not equal to 4") then it returns a bad result.

    That may look confusing, but the first one returned a bad result if "ANY" of the four were true (i.e. 3 is not equal to 1 --> true) and the second returned a bad result only if "ALL" of the four were not true.

  3.  I learned how to use the "Inspect Element" to see where I was having issues with my JavaScript. Ok so this wasn't something completely new to me. I had been told about this feature and have used it some to review my HTML. However, after struggling all weekend to figure out which part of my code I broke, it finally hit me Sunday morning to review the "Inspect Element logs" which tell me exactly which line my error was on. This would have saved me a considerable amount of time if I had used it all weekend. Live and learn right?

Well that's about it for this weekend. Stay tuned for my CodeNinja Adventure RPG game! I've finished a lot of the basic flow but still have a lot to build out. I'm hoping to wrap up the game within the next week or so and I'm going to try to embed the code within my blog so you could just click a link and launch the game. 

I definitely feel like my knowledge of JavaScript and troubleshooting errors has come A LONG way this weekend. Overall, I'd consider this weekend a success!! 

Thursday, July 10, 2014

Episode #57

For anyone that watched Seinfeld, it was always famous for being about "absolutely nothing"! I thought that was kind of convenient for this post, because I really do not have a specific topic to write about, but it's been awhile since I've written and I want to try to stay consistent. So I'll just write about a few random things...

First & foremost, hopefully everyone had a wonderful 4th of July weekend! Some of my brothers and sisters came in town to go camping out at Stone Mountain. Thankfully we had nice cool weather for July and it was a very enjoyable trip. Here are a few pics from the trip:


We hiked up Stone Mountain around dusk and I got this picture with the Atlanta skyline in the distant background


View of the water from near our campsite


  My nephew is definitely cooler than yours! This picture is from the Ride the Ducks trip at Stone Mountain and he was not liking the life vest.


Ok so on to a few things development related:

Coding is not like riding a bike

As much as I'm wanting to spend plenty of time working on my coding, I haven't had as much time to dedicate to it as I would like, especially this most recent week while I was out at Stone Mountain. One thing I've learned, if you aren't coding on a daily basis, you FORGET stuff! Things like "for" loops or "do while" loops, and "functions", etc. I learn how to do them, and then go back a week later and forget little tidbits of the syntax. Overall though, I am learning more every day and getting a lot faster on how to structure all of these coding fundamentals. I'm trying to bunker down and spend as much time as possible studying or practicing in one way or another.

Resources I'm using

I've been bouncing back and forth between a few resources lately, but the two most prominent are the work I'm doing on my Rails app, and then working through JavaScript tutorials on CodeAcademy. Overall Code Academy is a great resource for learning syntax; my biggest complaint is that I feel it breaks the problems down too much for you, and doesn't allow you to really push yourself on how to solve a complex problem. I am getting to a few parts in the tutorial where it offers some additional challenges to figure out on your own.

Status of my Rails App

I ran into a hiccup on my App. If you haven't been reading along, rather than doing the e-commerce app in the book, I'm trying to do an app where I can upload recipes I like and then pull them back up at random to help me decide what to make. I realized after the first main section that I was designing the wrong part of my app with their tutorial. I was designing the front end piece that you view the recipes from, whereas I was supposed to be designing the backend storage space where you can "Add, Edit, or Delete" new recipes and it also shows a view of all of the recipes (see snapshot below).


Once I realized the direction they were going, I changed up the CSS so the view would look like the picture above. It's not pretty yet, but a basic view for adding new recipes.

I think what I'm going to do now is dive into CodeAcademy to finish working through the JavaScript tutorial while reading ahead in the Rails book. Once I see how they plan to work through the e-commerce site, I think I'll have a slightly better idea on how to translate it to what I'm trying to do.


Well that's about it for tonight. Once again thanks for reading along!