Hello JavaScript | Programming Fundamentals: Learn to program with JavaScript (2016)
The Art and Science of Programming
Computing is changing; prices of computers are going lower and lower every single year. This is due to Moore’s law, which says:
Over the history of computing hardware, the number of transistors in a dense integrated circuit has doubled approximately every two years. src
Which has allowed programmers like your self to develop applications that expand millions of lines of code, with teams created all across the world. In fact some programs are so large that not one single person can comprehend everything that is going on.
So what, exactly, is programming? Programming is the process of giving the computer detailed instructions to perform a specific task. What type of tasks? Anything from computing a natural number to creating the next great game. Who, exactly, gives these commands? Those are called programmers. They are responsible for creating instructions that the computer can understand. What type of instructions? This can vary from an implementation of an algorithm to custom definitions that the programmer decides to create. What are algorithms? Algorithms are a sequence of instructions that you follow for a certain outcome. The outcome can be figuring out a problem or just carrying out a procedure. Algorithms can be simple or complex.
That’s great, but what do transistors have to do with software and JavaScript? Everything! JavaScript was once a small language that was only used in browsers to provide interactivity for web pages. This was one of the main reasons programmers did not consider JavaScript to be a complete programming language. All of this has since changed. You see, JavaScript can be found in Robotics, Real Time Systems, Banking, Internet of Things, Web Browsers, Mobile Applications, Server Applications, Custom Command Line Tools, and even Text Editors. JavaScript is no longer just a web browser language; it’s actually “THE” language to know.
When exploring a new programming language such as JavaScript, it’s always a good idea to take a look around and see what others are doing with the same language. Githut provides a visual of the complexity of programming languages across 2 million active repositories hosted on GitHub. The number one most active language is JavaScript with Java not falling far behind; making programmers with a background in JavaScript in high demand. This is great news for you!
Where is the art and science? In this chapter, we will be exploring how programmers have to be creative, intuitive, and most importantly persistent in order to solve a problem. What type of problems? We will explore how problems are translated from a verbal conversation to a formal document, and then to actual code. I will provide you with a framework that you can follow to solve any type of problem. The science of programming will help you narrow down your options for a solution, and the art of programming will help you to choose a beautiful solution.
The Art of Programming
“I can’t define it, but I know it when I see it.”
If you hold up a flower and take a look at the flower, you will say “what a beautiful flower”. A painter might take that flower and put it into a painting, a biologist can take the flower and take a look at the cells of the flower. A programmer can take that very same flower and create a program to model the structure of the flower, examine it and understand its process of the flower. You see, programming can help you explore the real world around you, or it can help you create new worlds that you might imagine. There is no limit unless you strictly put it there.
Programming is more than just the lines of code that you write; programming gives you the ability to take an idea you have and quickly bring it to reality. That could be a mobile application or an elegant algorithm. Whatever the case may be, you will have to be creative and use your artistic taste to find a beautiful solution.
The true art of computer programming is being able to understand the problem at hand and coming up with a solution. Just like problems in the real world, computer problems have more than one solution. It’s your job as a programmer to be able to navigate this world of solutions and find the most elegant solution that you can find.
Programming requires the use of Art, Science, and Engineering. Later in this book we will be taking a closer look at the “sugar syntax” and we will explore different parts of programming where you will have to be creative.
What type of creativity? Take for example some of the choices programmers have to consider when designing a program.
· The structure and layout
· Design decisions on the type of code convention to use
· Deciding on an algorithm to use
The Science Programming
What if I told you I can show you a framework that can solve just about any problem that you might encounter? Does that even sound possible? What if it is? What do you think it would look like? Could you guess how this framework might look or be? How can we test the framework to see if we have achieved success?
If you noticed from the above sentence, I’m clearly applying such a framework to find the framework. Here it is the Scientific Method, which has taken us across the ocean, across different medical breakthroughs, across multiple species, into outer space, and so much more.
1. Ask a question
2. State your assumptions
3. Conduct the experiment
4. Analyze results
5. Make a conclusion src
The Scientific Method will be necessary throughout your career as a programmer. It will help you in ways you never thought possible. For example, it can help you increase the speed of your program, eliminate errors, solve problems, avoid security failures, and most importantly, avoid looking at your text editor with a blank stare.
Throughout the book we will be using this method to solve all types of problems. But first, let’s take a closer look at each of the steps.
1. Ask a question
The question that you decide to ask will determine the entire process. Make sure that you take the time to clearly state the question, and avoid answering multiple questions at the same time. Focus on just one question then move on to the next one.
2. State your assumptions
Now that you have clearly stated your question, come up with some assumptions. What do you think will happen? Why would that happen? More than likely you will come up with multiple assumptions. Some of them might be wrong, but eventually you will find the right answer. Here is where you are encouraged to use your creativity. Now that you have all your assumptions, it’s time to predict what will happen in your experiment. Write this down, it’s important for the next step.
3. Conduct the experiment
What do you expect to happen? Actually sit down and conduct the experiment. This would include writing code, editing existing code, or going back to step one for more information.
4. Analyze results
Having implemented the experiment it’s time to reflect on the reasons why it was a success or a complete failure. Your interpreter Node.js will either throw an error or report the results back to you. Take the time and understand why you got the results that you did. Was it what you’re expecting? What assumption failed? Will you need to create another experiment?
5. Make a conclusion
Now that you have analyzed the results from your experiment, you are ready to make a conclusion about the results. Will you need to recreate the experiment again? What went wrong? What can you definitely say is true? Depending on how many times you have gone through the above steps, this will become second nature to you when programming.
Using the Scientific Method will advance you leaps and bounds beyond the common programmer. You will never have to copy and paste another line of code from the internet again. You can say goodbye to trying to make a program work, and say “hello” to a working program every single time.
Enter the Programmers Mindset
Learning anything new is a challenge, especially computer programming. As with any good thing in life, it takes training and practice with a long commitment to follow through. This includes changing the way you think about your current world. Why? Because you will have to push yourself to be more creative in order to think about new ways to solve problems.
Most computers can’t understand or comprehend any human languages like English or Spanish. This is both an advantage and a disadvantage. Computers don’t care about your feelings; they can’t read in-between the lines. The sooner you come to this understanding, the closer you will be to knowing the “Mindset” of a true programmer.
As you may know at this point, computers don’t think like you and I. Computer programs must have a high level of detail and precision when trying to carry out a solution to a problem. That means you must be able to give those exact instructions without a single miss. Don’t worry. There are plenty of tools that we will use to make this process easier. Take the following list as an example:
· Designing - The act of creating a plan for the construction of a program.
· Testing - The process of measuring quality, performance, and reliability of a program.
· Debugging - Finding and removing errors from a program.
I don’t want you to be just a programmer; I want you to be a GREAT programmer. We will get to that goal by understanding the problems in front of us and translating them into something the computer can understand. The tools that we use to accomplish this will be the Scientific Method along with your design skills. Soon enough you will be off to creating amazing programs.
The rest of this book is dedicated to helping you learn how to think like a computer, be more of a creative problem solver, and learn to love or hate programming.
Challenge
Now that you know programming is more than just “working with computers”, I want to give you a taste of what you’re getting into so that you’re prepared. Some of the general ideas that float around the programming community are “you are a programmer” or “you’re simply not”. Due to these types of ideas floating around a lot of new programmers tend to be turned off, and one can see why. Let me be the one to tell you that programming is not easy, and if you find someone that tells you that programming is the easiest thing in the world, that doesn’t make them an expert.
An expert is a person who has made all the mistakes that can be made in a very narrow field ―Niels Bohr
Let’s take a closer look at “What is Programming?” The entire point of programming is to tell a computer what to do. So it comes down to: can you command your computer to do your bidding? Here is where the ego comes into play. YES!
Male Human - “oh computer make me cup of coffee”
Computer – “Coming right up sire”.
This cannot be stressed enough. If you are not good at giving commands in the real world then programming is going to be even more of a challenge to get started with. This is where being bossy really pays off! However, as a programmer it’s better to call it “attention to details”.
Programming is time-consuming! There is no way of getting out of it. The best example that I can think of is related to that of a math problem or writing a novel. Some parts of programming can take hours on hours to figure out and, to add onto this entire thing, the problem could end up being a single missing semicolon. It is just like spending hours on a tedious math problem and getting the wrong answer because one of the signs got messed up along the way. Be ready to spend hours in front of a text editor trying to figure out a solution.
Needless to say, it will take courage, persistence, and most importantly determination in order to become a programmer. It’s not just a big salary.
Figuring out if programing is for you. “You get it” or “you don’t”. Deciding to make programming your career requires a large shift in thinking, both in what has been done in the past and what will be done in the future. This is why older people tend to have a larger learning curve when learning to program. “But I have always done X!” If you are shifting from your current profession to programming, letting go of X can be challenging, but it must be done before something new (programming) can become a reality.
Once that barrier is removed, go over and take a personality test. This is just a rule of thumb, and it should give you a bit of a window into the type of personality you have. This is a good idea because if the personality that you have does not match with that of a programmer, an inner conflict will arise. This step is important, so don’t skip it.
What to do if my personality is not of a programmer? Don’t give up! If the role you carry is that of a project manager, or a CEO and understanding programming is a vital part to what you do. Then the sacrifice must be made (consuming resources) take a deep breath and get ready to learn an amazing way of thinking.
I have what it takes! If you fall into this bucket, then you are extremely young (7-13 years old) or you are a veteran in a profession that requires the same traits as a programmer, giving you a leg up on everyone else. These types of careers are musicians, mathematicians, scientists, or other strongly analytical professions. In the other case of a young programmer (7-13 years old), then you are in great shape to start learning programming.
Have fun! A programming career can be one of the most rewarding, fun accomplishments that you undertake in your lifetime. So have fun! Don’t take every single project too seriously; joke around. Break your code, fix it, fork off to different possibilities, improve your tools, but most importantly CODE.