Do You Think You Need to Learn to Code? It’s easier than you think

It’s easier than you thinkLearning to write simple programs is not so difficult, really.

Alan JonesBlockedUnblockFollowFollowingMay 1Photo by Chris Ried on UnsplashTo write reasonably simple programs, there are just a handful of basic concepts to get your head around.

The program in the image above is quite complicated but here is just about the simplest program that you can write:print(“Hello”)It’s a simple statement that, as you no doubt realise, prints “Hello” on the screen.

But it is a complete program in Python.

Not difficult!The best way of learning is by doing things but a little bit of theory can help put things into context.

So, here are just a few ideas that might help to get you into the swing of programming and see that, fundamentally, it’s not that complicated.

What is a program?Computer programs are made up of a sequence of statements that are instructions for the computer to do something (print on the screen, for example).

And these statements are executed one at a time — in sequence.

(In each of the screenshots, below, you can see a small Python program illustrating the concept, at the top, and the result of running the program, below.

)SequenceThere are other programming statements that let you make decisions.

If a certain condition is met then you do one thing, otherwise you do something else.

(For example, if you know someone’s name, you could print “Hello name”, otherwise just print “Hello”.

)SelectionAnother type of statement lets you repeat things.

So, you could perform the same operation on a range of values.

(For example, if you have a list of names, you could print “Hello name”, for each of them.

)RepetitionFormally, these three type of programming statement represent sequence, selection and iteration (or repetition).

Theoretically, you can write any program using combinations of these three types of statement.

There is a lot more to most programming languages than this, of course, but if you understand these three basic concepts, you are on your way to being a programmer.

Getting more complexAs the programs that you you write get more complex, you need to start using other features.

One of the most useful is the ability to create chunks of program code that perform particular tasks, or represent things.

These chunks are called functions and objects.

A function is a kind of sub-program that can be given a name and is invoked using that name, and an object is a different sort of chunk of code that can be duplicated and could represent a real-life entity, like a person, or a car or just about anything.

An object can incorporate functions and data.

Data: numbers, text and…Programs normally read in some sort of data, do something with that data and then produce a result.

There are two fundamental types of data, numbers and text.

They can take different forms and they can be combined into complex structures (think of tomorrow’s weather forecast, it would contain text to describe the conditions and numbers for the temperature or rainfall but can be thought of as a single item of data).

There is a third type of data is neither numeric nor text.

…booleansIf we want to describe whether a condition is correct or not we can say it is true or false.

These values are used a lot in programming, Is your name “Stephen”?.Is the the temperature less than zero?.In both cases the answer is, yes or no.

In computing, we makes statements, rather than ask questions.

Those statements are either true or false.

My name is “Fred”: false.

The temperature of boiling water is 100 degrees Celsius: true.

Although we represent these values with words (true and false), they are not textual values, nor are they numbers; we call them boolean values.

So, that’s a little theory and I hope you can see from this that programming is not really so complicated.

So why not give it a go?This post has been adapted from the first part of Just Enough Python, a quick and easy (and free) introduction to programming in the Python programming language.

.. More details

Leave a Reply