• Posted on April 14, 2014 10:17 pm

    Object Oriented Programming has been around for a while. When I began my career, I programmed using procedural methods until I learned about OOP. What is OOP really? When I began learning about OOP, it took me a bit to catch on to the concept. I found it to be somewhat of a large topic that at first was muddy. There are a lot of OOP principles to learn...more than can be explored within one blog post. I will periodically explore various OOP principles and you will find them scattered throughout my code projects. When I began programming with OOP principles, one of the first items I had to learn was what classes and objects are and how they work together. First...the definitions... Class – a set of functions that work together to accomplish a task. It can contain or manipulate data, but it usually does so according to a pattern rather than a specific implementation. An instance of a class is considered an object. Object - receives all of the characteristics of a class, including all of its default data and any actions that can be performed by its functions. The object is for use with specific data or to accomplish particular tasks. To make a distinction between classes and objects, it might help to think of a class as the ability to do something and the object as the execution of that ability in a distinct setting. Here is another way of thinking about it... Let's say you were going to build a brand new subdivision where all the houses look alike. You create the blueprints and build your first house. You then re-create the blueprints and build a second house that looks exactly like the first one. You then repeat this process throughout the subdivision. This would not be a very wise way to build your subdivision. Why re-create the blueprints if the houses are all alike? It is a waste. Instead, you would use the first set of blueprints to build all of the houses within the subdivision. Classes = Blueprints Objects = Houses So you create the class once and then can build a lot of objects from that class. Here is an example in Java... Happy Coding! Clay Hess

  • Posted on April 9, 2014 1:39 pm

    In any programming language, there are a group of words called 'Reserved Words' that are set aside for specific purposes within the given language. The developer needs to keep this in mind when they are writing code. If they use one of these reserved words within their code where it is not intended to be used, their programming could yield odd results. For example, the word 'function' in JavaScript is utilized to indicate a function/method is being constructed. If you use that word elsewhere, your code could break. There are also words that are not exactly on the reserved list, so to speak, but could cause issues. Let's take another example from JS. The word location. In JavaScript, the word location is a part of the DOM (Document Object Model) and is used to either direct an end user to another page or grab the current url... So if you use the word, 'location' in your could, you could inadvertently send the end user to a non-existent location, thus breaking your code. Here is a link to some reserved words. Now, beyond the use (or non-use) of reserved words is the concept of naming things intelligently. Please, for the love of all the sanity of developers everywhere, please name things that make sense. What I mean is name your pieces of code in a manner that is logical. Name variables with names that make sense. If you are getting a name from the end user, perhaps name it userName. Do not use any random or non-sensical verbiage. This practice goes hand in hand with proper comments. Happy Coding! Clay

  • Posted on April 2, 2014 6:13 pm

    Every developer out there has had the following scenario happen to them... You take over a project and begin to dive into the code to get a handle on the project. As you begin wading through the code, you begin to drown because there are no comments...or minimal ones. The variables are perhaps even named in an unusual fashion. So it takes you much longer than necessary to figure out the code and what it is even doing. This is even before you dive into the project updates that are on your plate. This ends up being costly and time-consuming. Additionally, you might even want to smack the previous developer for putting you through this torture. If only they would have commented their code, it would have made your life so much easier. So here is my question...Since every developer has been faced with this scenario, just who writes the poorly commented code that drains us of every ounce of energy? I would say that we all have. So we are all guilty. Here are some tips for you to avoid this bad behavior and save not only your sanity, but that of your fellow developers. Planning Lists Take time to write out planning lists that contain the following: Input variables - what variables are going to house data supplied by the end user? Output variables - what variables are going to be used to output information to the screen? Temporary variables - what variables are going to be used for processing? Global variables - what variables are going to be global, if any? Pseudocode Write out in simple, text format what is going to happen in your program. Describe the process and steps the code will go through and what you expect to occur. What is great about Planning Lists and Pseudocode is they can turn into your program comments. So while you are coding, you are following your plan. Following just these two tips will help out any developer who takes over your project and save your own sanity when you have to return to the project and forget how and why you built something. Happy Coding! Clay

  • Posted on March 23, 2014 3:28 pm

    In JavaScript, like many languages, there are built in functions/methods to make the developer's job easier. One that is highly useful is the alert() method. First, let me say that I do not typically use this method in production code because it tends to annoy end users (think pop-ups). With that said, it is highly useful during development to see how your code is functioning. So, let's dive in and take a look at how alert() works... Syntax All the alert() function does is create a pop-up window with whatever information you pass to the alert function. You can explicitly put content into the alert function or alert the value of a variable in the function. Here is the basic syntax... The aforementioned code yields the following results (in FireFox)... Usage So, as you can see, you can type text directly into the alert function and have it display that text in a message window. You can also do the same with variables...   The code above will return the same results as the earlier screenshot. The difference is that this time, we are alerting a variable and not the text directly. This allows us to see what values are in the variables. Here is an example where this might be useful in a development environment... Imagine you have a loop that is changing the value of a variable, then you are outputting that variable to the screen. When you run your code, the out put you are expecting is not what displays. You can use an alert to watch your variable value change while it is looping. The aforementioned code should loop three times and output the value of the firstNum variable. Since it runs three times, it will alert three times. The first alert displays '0' because the value of the firstNum variable is '0'. We are adding one (1) to it each loop. So the second alert displays '1'. The third time through, it displays '2'. So the alert function is a very useful function to be able to watch your variables and output the data within them so you can see how your code is functioning. Just a quick side note on using alerts in loops like I demonstrated...do not use it on large loops, unless you like clicking a lot! There are better ways to output that data (hint: console). Happy Coding! Clay Hess

  • Posted on March 22, 2014 2:14 pm

    Many times in my line of work, people have asked me questions like... "What is programming?" "Isn't it hard?" "How do I get started?" "What language(s) should I learn?" First off, programming is not that difficult. It only seems hard for those that have not learned how to program. All programming boils down to a few essential topics... Anticipation - you need to be able to put yourself into the shoes of your end user. Logic (critical thinking) - you need to be able to think logically through a problem. Problem simplification - most programs that seem complex are just a lot of problems that each have been broken down. A good programmer breaks down a project into little solvable problems. Programming is really taking something that is dumb and making it smart. Think about your computer. Without programming, it is simply a hunk o' junk. So...is it hard? Only if you try to tackle the entire 'mountain'. Start small and learn the basics of programming. As you learn the basic tenets of programming, you will find the entire programming picture coming together before too long. As to how someone might get started, I suggest beginning with some online tutorials and working through some hands on programming lessons. If you are looking to take some classes, we have some great ones that my colleagues and I teach at Northcentral Technical College. I suggest Introduction to Programming. As to what language(s) to learn, there are several great languages out there. So any of them would be a good choice, but if I would have to boil it down to one choice, then I would suggest JavaScript. The reasons are... Easy to get started Just need a text editor and a browser JS (JavaScript) is everywhere, even in enterprise environments Resources There are a lot of resources available (just Google and you can find tons of them)...here are some that might help you out... JSLint - JS code quality tool JSHint - JS code quality tool forked off of JSLint JSFiddle - - JS code quality tool that includes libraries, HTML and CSS W3schools - good beginner tutorial resource on various programming topics Codecademy - online programming training course. Some are paid. Codeavengers - online programming training course. Some are paid. Browsers - Chrome, FireFox, Safari and Internet Explorer Inspectors - all browsers have built in or add-on inspectors (FireBug) that allow you to debug/inspect your code when you have issues Text editors (IDE) - you will need a text editor to be able to write your code. There are a lot out there. Here are some of the more popular ones... Visual Studio (paid) Dreamweaver (paid) Edge Code (paid - built on Brackets) Brackets (open source) Eclipse (open source) I would encourage everyone to at least learn a little about programming, even non-programmers. If you think about it, nearly everything we do in our lives is touched by programming in some way...and most of us do not know how to code/program. It would benefit everybody to have at least a basic understanding of programming. If you are looking for a field to enter and wonder if programming might be for you. Well, I am not certain if it is for you or not. What I can tell you is that there will be many, many job opportunities for programmers now and in the future. It is estimate that by 2020, there will be one million more jobs than programmers (data). So start learning how to code/program today! Happy coding! Clay Hess