Basic Programming 2 – Learn about functions

Reading Time: 3 minutes

Why are functions important?

Functions are how programs do work. Think of them as the action that is to be performed by code. Functions can return variables, perform calculations, or draw images on the screen. They are essential to creating applications in that they can define something to be done and to them over and over.

In fact, this is the proper use of a function. Imagine that you need to convert ounces to cups or inches to feet over and over. You could create an application that performs this conversion for you and use the program whenever you need to do the conversion.

How are functions created?

To get started (most languages) use the function key word. A keyword is a word that is pre-defined in a coding language that represents an action. In this case, the function keyword tells the chosen programming language that we are about to create a subroutine of code (an action that will be stored in memory as a variable)

Let’s take a look at a function and break it down.

function nameOfFunction() {
    let result = 1000
    return result
}

As we talked about earlier, we start with the function keyword. This keyword tells the language that the following code is a block of code that does something.

After the function keyword, we have the name of the function. I have chosen to call it nameOfFunction just to help describe what it does, but it would be any combination of characters we choose. For example, we could give the function a name of asdf123 instead. The program will not care what you name as long as it is within your chosen language’s guidelines for function names.

The next part we see that we should note are the parenthesis characters.

()

These parenthesis will not do anything for our basic example. However, calling attention to them is important as we will use them in a more advanced form of functions later. So take note of them, but don’t worry that they don’t seem to do anything right now.

The next part of our function to take note of are the curly brackets.

{}

These are very important. They define what is called a code block or block of code. Code blocks signify the start and end of a named space. You can think of this area as a separate universe or country. Within this code block whatever we put in it exists between those curly brackets ONLY. So in this example, as we keep moving forward with our function, you can see that we are using the let keyword to make a variable named result and assigning it a value of 1000.

Since result is inside of our curly brace code block it does not exit before or after the curly braces. This helps us make sure that we don’t accidentally assign it a different value in another function and ruin the nameOfFunction routine that we just wrote.

Side note: Don’t worry if this doesn’t make total sense right now. My intention is to start to introduce concepts that we can build on later. Not to introduce a concept like name spaces and have you understand everything about them right away.

The last part of the function that to cover is the line that reads

return result

The return word is also a keyword. This keyword allows messages to be sent outside of the universe we created between our curly brackets. This line tells the program to take the result variable and send it back to whoever (or whatever line of code) called it.

To use our new function, we would do something like the following code.

nameOfFunction()

This tells our program to look for something that we saved named nameOfFunction and do whatever that thing does.

So in our case:

  • Set a variable named result and give it a value of 1000
  • (on the next line) return the value of result

So in with our function, running it would return 1000. Alternatively we could have written the function as:

nameOfFunction() {
    return 100
}

This would have returned the exact same result as our original function, but would not have let us talk about as many concepts. So for teaching and example purposes being a little less efficient helps us learn more.

Next we will talk about more complex functions an the usage of the parenthesis as mentioned earlier.

Basic Programming 1 – Learn about variables

Reading Time: 2 minutes

Curious about programming?

Programming isn’t as difficult as it used to be. Languages have evolved to be more easily understood. This means good things for technology and advancement in general.  You don’t have to spend years learning a programming language. In fact, there are key concepts that are used in each language. You can concentrate on these main concepts to help get up to speed with any coding language that you want to learn. 

Setting a Variable

The first concept that you will need is the ability to set a variable. A variable is a way to assign something (a value or way of doing things) to a reference or place holder. This is a bit like calling something an automobile a Car rather than saying something like, “That large red thing over there with four wheels sitting by the curb”. By calling it a car we are creating something we both can use to refer to something (a reference).

This is an important concept in programming in that the things that we need to “remember” or “refer to” are often hard to describe. For example, a large number (3.14159265359) or a bit of code such as () => { return true }. ( try describing that to someone!)

 Example

Here is an example of how a variable is set in the JavaScript language (very popular these days).

cost footInInches = 12

Let’s break this down.

  • First is const this is short for constant (a value that will not change)
  • Second, footInInches is the name of the reference
  • Third is the = this assigns or equates the name with the thing to the right of the equal sign
  • Fourth, the assignment value or thing we are referring to

As a side note, the fourth part of the line of code (the value) doesn’t have to be a number. It could be a word, a equation, or even refer to another code file. This is the first concept that starts to open up the world of programming to endless possibilities.

Next concept we will talk about functions (article coming soon)

1 Hour of Code | A Great Idea

Reading Time: 3 minutesThe Hour of Code has come up as a topic of conversation a few times recently in my daily routines. The ‘Hour of Code’ is a nationwide idea (by Computer Science Education Week and Code.org) to introduce people to coding and programming. It’s a great concept and I suspect will be a great help as we keep moving forward in terms of the technologies of the future. It is essentially an event that will be held world wide to introduce people to the world of coding.

A Worthy Goal

The chief aim of an hour of code, it would seem to me, is to introduce new people to programming and prime new generations to idea of coding and creation outside of the normal physical creation patterns. Growing up it is common for children to be introduced to paint, pencils, paper, and other physical mediums of creation canvases. But, if you were born in a generation where programming and applications where not part of daily life, you might not even be able to introduce this path to the future generations. This is not your fault, but it would seem coding and programming is here to stay. The Hour of Code is a great concept to introduce the concept of programming to new generations where their older influencers might not be able to (experience wise or socio economically). This could give a needed introduction to a new minds that could transform or even push forward our advancements in technology. As with any skill or ability some take excel more than others in various areas. This might help expose a new mind to a place where they naturally excel.

summarize arrange catalogue classify collect condense digest order organize tabulate

Time Boxing – the difficulty of the task

As a programmer and thinking about the task of an our of code, this is no easy undertaking.  Each language has a base to learn. Even as I think about how to explain this the complexity makes my head to circles. I’ve been thinking about a good analogy for a  few minutes now. Here is the best description that I can think of… off the cuff. Teaching a new person about programming is like acquainting a person with new world. You need to find concepts that they are familiar with and relate them to the new world that you are trying to introduce. There are laws that can’t be broken. Not the kind of laws that come with punishment but laws that ensure that things actually work and don’t “fall apart”. One these are understood then you need to teach the person how to use concepts together cohesively so that they work in the way they are designed. If you are going to truly understand and be able to create in the programming head space you need to have the appropriate experience in hours and taking your lumps and stumbles.

I don’t think that the Hour of Code will be able to accomplish this in the time allotted. However, it should be able to guide very large groups of people through examples of how things are done. This would be much like taking a person on a guided tour of a forrest. You will be able to see the great sights and experience the space, but you should probably not be left along in the middle of the tour. This being said if you have the curiosity and the time, I would highly recommend trying to participate in the event. You might find a new area for your mind where you can excel where you never thought that you could, and although the Hour of Code is currently planned for certain days the intention is that it will live on (and hopefully help people keep learning)

Worried About Having the right Equipment?

If your interested in participating with your family (as this is mainly aimed towards children) check out the following map. I would also urge you to not just think of this as child’s play. If your interested in programming but have never taken the time or have not had the opportunity I would urge you to attend. You might be the mind that some company or innovation has been waiting for to help push towards the future!

Coding vs Programming

Reading Time: 3 minutes

If you have ever thought about building and application, or have spoken to anyone that has, you have probably use the words coding and programming. These words are often used interchangeably and often are confused into seeming like they mean the exact same thing. These two words actually have different contextual meaning in the realm of software development.

What is the difference?

To understand the differences it’s worth talking about the thinking that happens when looking to build a useful application. Technology, in general, is created to help solve problems and even further usually for a very specific problem. These problems can be a business, social, physical, or just solving the problem of everyday boredom. At the core of building an application is the problem that the software is seeking to help or fix outright.

In corporations / companies there are groups of people with the sole purpose of defining the problem and proposing solutions to that problem. These employees are titled business analysts, the are totally separate from the programmers that put fingers to keyboards and write the actual code. These employees help define the actions and behavior that is needed for the software. These can be things like does the application require a login, does it require payment through credit cars, and are there any analytics or reports that are needed once the program is up and running.

After the business analyst has gathered enough of the particulars (called requirements) the ideas can then be discussed with a programming team (or lead programmer). Here the team will look at the requirement and determine the IF the functionality can be created and what has been asked for can be done within the proposed deadline. These negotiations can weeks depending on the complexity of the problem and the programming language that has been chosen

Programming

Here is where the differences between programming and coding begin to make themselves more clear. After the problem is well defined and it has been determined that the program can be feasibly created it comes time to actually plan how the data flows and the program methodologies that will be used. This is where the programming CAN begin. When a season programmer is giving a problem to be solved they have the acumen and experience to see the needed functions and behaviors to appropriately employ patterns and tools to get the job done. This means they can and have been empowered to make these types of decisions. Programming is more than just typing or putting thoughts to paper. It is implementing known patterns and algorithms that other developers can understand such that the solutions can be expanded upon and maintained later.

Coding

The other way that the program can get written is to contract out the actual fingers to keyboard out to contract company or possibly outsource the work (sometimes in another country). This requires that the corporation (often the lead programmer) take the time to plan and detail all the parts of the program that need to be created. This means down to the detail of something like this bit of code should accept only money values and return a value +/- an expected result of so many dollars. Another example would be written in a specific language and the result that comes out be in an agreed upon format that is well known throughout the industry. These types of specifications should be easily measured and easily determined if they task has been completed or not. For example, this program accepts a date from an emulated calendar. This date can only be accepted if it is in the future (not today or yesterday) in the forma mm/dd/yyyy and not more than 30 days ahead of tomorrow. Executing on these types of requirement is referred to as coding. There ideally no guesswork and it can be broken down into very small tasks. This is the coding aspect of a project. This requires less creativity in description but much more specificity in what is wanted and can be accepted.

A decision based on your needs

Both programming and coding require high amounts of skill, creativity and critical thinking. However, the programming type is trusted with much more autonomy and creativity. The coding style is less interpretive but you typically know exactly what you are getting (if the requirements are met). Programming is great if you already have a team that you trust and know they can fulfill your needs. My advise in deciding what type you should hire would be if you already have the resources hire developers that can handle making good programming decisions about scalability and future use. If you are on a limited budged and don’t have a team. You can leverage a the coding style coder to get your application done. However, without a team of programmers you will need to clearly defined everything that is needed BEFORE the project begins. If you start this process after you being your costs will be much higher that you could ever expect.