So You Want to Code

Over the past few years, there has been a lot of emphasis on encouraging people to learn to code. Anybody can learn to code, they say.



Is that true though? Personally, I both agree and disagree. It really depends on whether we're talking about the capacity to write code or the mindset of solving problems though code. Is programming something that you really want to get into? Let's find out!

Is programming for you?

This is the first question you need to ask yourself. Of course, it might be tempting to answer this hastily and without knowing the thrills and challenges you will experience, so let me give you a preview of what will be frequent occurrences in a life of coding:

  • You will spend hours or more trying to figure out why something isn't working, only to find out that you made a very minor typo (: instead of ;).
  • You will spend a lot of time on Stack Exchange and other tech forums. You will become frustrated that answers given are specific to languages or libraries which you are not using (you are searching for how to do something in JavaScript, and the answers are all for jQuery).
  • You will encounter bugs where the error's output is misleading, overwhelming, or too lacking in detail to make use of.
  • That thing you expect to be simple will cause you more trouble than anything else.
  • You will feel triumphant over achievements few can appreciate. All of the frustrations of tracking down bugs, digging through log files, searching the forums in vain for hours will fuel your sense of accomplishment.
  • Your journey will never end. Just when you think you know something fairly well, a new version with new features will be released. There will be incompatibilities, depreciated features, major changes, etc. You will also be required, from time-to-time, to learn something entirely new.
  • You will deal with those who don't know the complexity of what they're asking for and who won't understand why something is taking so long.
  • You will feel stupid, not just for your mistakes, but because, as with most things worth learning, you will begin to find out just how much you don't know.

A little learning is a dangerous thing;
drink deep, or taste not the Pierian spring:
there shallow draughts intoxicate the brain,
and drinking largely sobers us again.Alexander Pope

Anybody can write something that prints Hello World! onto a screen, but not many have the creativity, ingenuity, organizational and problem solving skills, and patience required to be successful.

Where to start

There are plenty of places to learn different programming languages. There's Codeacademy, Khan Academy,  Libraries (buildings or eBook stores), and many others. Where and what you learn is a choice you will have to make after deciding exactly what you want to do, but it is important to realize that most courses offered will only introduce you to the concepts of programming. If the course you take doesn't seem to relate to what you want to do, or even if it's the wrong programming language, what it really teaches will be concepts that are almost universal in programming — types of data (strings, integers, arrays, etc), for loops, conditional statements, the flow of data, the importance of descriptive naming of functions and variables, etc. The only programming class I ever took was C++, and because of that, I was able to teach myself JavaScript, PHP, and a few others (CSS and MySQL don't really relate) fairly easily.

My suggestion for anyone who wants to learn a programming language is to take something that teaches you the concepts and syntax, come up with something you want to build or design for yourself, and start working on it.

Seeing the big picture

It's one thing to know the concepts of a language and it's syntax, another thing to know how to put your knowledge to use, but it's something else entirely to have a plan and to know what you want to achieve. Taking the time to plan in some detail what the desired outcome should be is one of the most important steps in getting the results you want.

Start by imagining the finished product without worrying about how you can do that… That comes later, and worrying about how you will do everything at the beginning of a project makes it seem overwhelming.

With some experience in the planning phase, you will begin to think of programming for what it really is — Input and output. Any individual part in and of itself is usually not that complicated, but making everything work together can be. Plan well, and save yourself the frustration.

Solve one problem at a time

Here, you will begin to convert your statements from planning of I need something that does this into reality. Think of each problem in its most basic (and ideally generic) form. As I said above, programming is essentially input and output, and here is where you convert input into output. If and when you find a problem which presents another problem, start the process over.

For example, you might determine that you need a function which uploads an image to another server, and realize half way through that it might be a good idea to resize the image that you're working with before uploading it. What I would do in this case is to leave a comment (//@todo test image size and convert if needed), finish writing the upload code without worrying about the resizing, then come back and write a separate function to test and resize images.

There are a variety of approaches and styles to coding to solve any problem, but the important thing is to start with a plan (this function receives a path to an image and an address to a server to upload it to, uploads it, and returns its new location). Pick one thing at a time to solve, be clear on what goes into and out of a function, and don't worry about anything else. You would be amazed at how easily you can tackle a problem you believed to be beyond you by breaking it down into a series of tasks which you can accomplish!

Be organized!

Programmers are supposed to be lazy… It's actually recognized as a virtue. This does not mean that the programming world celebrates poor work ethic, but rather that it recognizes the value of simplicity and the waste of repetition. The purpose of writing code is to do something once and to never have to do it again, so it's important to be organized and make the most of the code that you write.

First, whenever possible, you should write your functions in such a way that they are as generic as possible. For example, instead of writing a function which squares a number, write one that can return a number raised to any power (even though such a function almost certainly already exists in whichever language you're using). This might make writing the function a little bit more difficult, but it will save you a whole lot of time later on when you need a function that is very similar.

In order to make the most effective use of this, you should not dump all of your code into a single file! Put your math functions in one, generic miscellaneous in another, and always keep project specific code separate from code which can be used elsewhere. When writing code, be on the lookout for something that can be reused.

Also, be consistent throughout your work. Try to avoid naming one function myFirstFunction and another my_nth_function. If you are consistent in naming variables, functions, etc, then you won't have the additional headache later on of trying to remember which one to use later on. Most languages have commonly accepted practices for naming things, and I suggest that you follow such conventions as best as possible. On the topic of naming things, try to set names by finding a balance between descriptive and simple. Nobody wants to use a function named function_to_convert_an_array_of_integers_to_strings(), but you usually shouldn't use names like funct() either because there's no telling what it does from its name.

Don't forget to document your work! I know… Believe me, I know how tempting it can be to rush through something and think that documenting your work is a waste of time. I especially hate it when I spend more time writing the documentation than the function itself. But your code will (hopefully) be around for a while, and it is extremely important that you leave behind the information necessary to use your work. Maybe someday you will look back at something you wrote while trying to track down a bug and not have a clue what you were doing. Most of us will also have to deal at some point or another with another developer. As an example, documentation will save you a whole lot of headache if you have a function named squareIt(), and declare in the the documentation that it receives a number but returns a string (squareIt(5)//Returns "25").

Documentation should, at minimal, provide three important pieces of information:

  1. The function's input (including type).
  2. The function's output or return (including type).
  3. A brief description of the purpose and usage of the function.

If you put in the extra effort to keep your work clean, organized, and well documented, then you will save yourself from having to start over on your next project. For programmers, laziness means doing it right the first time so you don't have to do it again.

Other suggestions for getting started

I'm pretty sure that there is a common misconception amongst those new to programming that they have little use for or cannot afford the tools used by professionals. Obviously, you will need to install any software such as compilers that are absolutely required.

I would strongly suggest to beginners that they at least start with a good editor. You might not yet need something with advanced features, but the importance of your editing software is not to be underestimated. Your editor will become more than just a program to you. You will develop a relationship with it; you'll have to invest time to learn its ins and outs, get to know its quirks, love it for all the little things that others don't see or appreciate, have conflicts, possibly break up and either try something new or return to something familiar. Don't waste your time on something that is just convenient (pre-installed), but instead invest in something that will work well with you. I would suggest you start with either Atom or Brackets, both of which are free, available on most Operating Systems, provide a decent set of built-in features, and can adapt to your needs though add-ons.

Another suggestion I would make that is that you start using version control software like Git as soon as you start writing code. Not only is it a tool that applies to every branch of programming, but it provides beginners with an easy way to recover from rookie mistakes (via checkout or reset), forces better organization by requiring commit messages, makes it easier to find when a bug was introduced through log and blame, gives you the ability to view and contribute to the development of real projects, encourages experimentation of new features in branches, and quite a bit more. Learn Git and it will be with you for the rest of your programming career, even if you decide to change paths and work in a different language.

Welcome to the terrible and wonderful world of programming

I hope that you enjoy it!

Programming can and will be frustrating at times. While the concepts of it can be learned by almost anyone, it takes a lot of time and hard work to make it rewarding. It takes critical thinking, an analytical mind, and a lot of dedication to be successful.

It may be difficult at first, but the satisfaction you get from being able to say, I made that is well worth the effort. And once you taste the achievement of something simple and begin to have confidence in yourself, there is nothing quite like having the knowledge that you are capable of creating whatever you want or desire.

My last bit of advice to those new to programming is to not give up! If you haven't gotten there already, you will soon reach a point where you think you lack the ability to solve something, or you think that it's just too difficult. But until you have overcome this and found what you are capable of, and the satisfaction of having done what you thought was beyond you, you are thinking only from lack of experience. Plan well, work hard, don't give up, and you'd be amazed at what you can accomplish and at how great it feels to have that kind of confidence.