How do I learned programming

Published in 2023-07-07, last edition in 2023-10-26.

I started programming in 2019, not far back in time, and despite some learning mistakes I feel ready to share some experience with people who are starting.

In this article I discuss about the learning process of computer programming, what programming is, places where you can start and some additional information.

Index

  1. What is a computer program?
  2. How those programs are written?
  3. What's the best way to learn programming?
  4. What's the best progamming language to start?
  5. What's the best programing language? Is there any supreme language, the best-of-all, the king, able to solve every problem?
  6. I want the best way to start...there must be the best way, the PERFECT way!
  7. I'm still undecided
  8. Recommend me a text editor :D
  9. And what is the best text editor?
  10. Where do I start learning?
  11. Last considerations
  12. Notes

What is a computer program?

The same way a person can follow the instructions inside a cookbook to bake a cake, a computer can read the instructions inside a program and execute them to perform tasks like process texts, numbers, audio and images.

A program is essentially a set of instructions that are executed by a computer, and program a computer is basically design, write, test and maintain those groups of instructions.

From that browser you are using right now to games, operating systems and cellphone apps, all those programs are just sets of instructions written by a programmer and executed by a computer.

How those programs are written?

The only language that computers really understand is machine code, a language composed only of zeros and ones, based on the binary numeral system. In the end that's what a program is, a bunch of zeros and ones, and most electronic computers work that way.

Develop a program using pure machine code is possible but very complicated (some would say insane), so high-level programming languages is what most programmers use nowadays for that task. They are much easier to read and write than machine code. A programmer writes the instructions of the program in a high-level language and later those instructions are translated to machine code. The process of translation may involve two programs:

  • Compilers: translates the instructions written in a programming language directly to machine code, generating a program that can be executed natively by the computer. Native programs tends to be fast and have optimized consumption of computer resources (memory, processing, etc). Native programs, however, will work only in one processor architecture and operating system, requiring modifications and a new compilation if the programmer aims to run the program on another operating system or processor architecture.

  • Interpreters: directly execute the instructions written in a programming language, without the need of compiling. Interpreters allows the execution of programs on any operating system where the interpreter for the programming language is available. Interpreted programs are faster to write and test since you don't have to compile before run it. Interpreted programs, however, tends to have slower execution speed and consume more computer resources than compiled programs.

Simplified model of a program compilation and interpretation processes.

What's the best way to learn programming?

Practice, practice and practice again. The practice and experimentation through projects and problem solving is essential to computer programming, there is no other way to learn it. Some may learn the theory first, but the practice is still the cornerstone of software development skills.

The first step is to ask yourself what goals you want to achieve using programming skills. Is it a new hobby? A job? Do you simply like computers and want to explore? Do you want to make a cool website, cellphone app or game?

Once you find out what you want, you choose a programming language compatible with your goals to start. Choose a book, course or workshop that teaches the basic programming concepts using that language. The first programming language is always the hardest to learn, but any other after that will be easier because the same basic principles can be applied to each programming language.

After the basics, it's pretty possible that you'll feel kinda lost, not knowing what to do next. Take what you learned and start making personal projects with it, follow tutorials on internet, learn how to solve specific problems, explore the libraries and documentations of your language, and the list goes on...your imagination is the limit.

There are plenty of problems to be solved out there, and many of them can be solved with programming. Find problems that interest you, break them into smaller sub-problems and solve them one by one. With time you'll realize that even big programming projects are composed of small solutions that you connect together, and those small solutions are composed of basic logic blocks of code that get repeated along the source-code.

A tip based on personal experience: at least in the beginning, the frequency that you practice programming is more important than the quantity. It's better to devote 30 minutes a day consistently over several days than 4 hours in a single day, that way you learn better and develop the habit of programming easier.

Another interesting way to keep learning after the basics is to explore the source code of open source programs. Like the name suggests, the code of open source programs are publicy available so anyone can run, edit, and share that code, that way you can look directly at the source and find out how those programs work. Be careful tho: some projects are monstrous in terms of size and complexity, so choose smaller projects like language libraries and snippets to start.

It's important that you stick with the languages and tools you choose to do some projects with them before jump to learn another language. The programming knowledge comes from the experiences you have with each project.

What's the best progamming language to start?

This question is pretty hard to answer because it depends a lot on the student needs. In my case, for example, it was Python. I tried to learn programming using C, Pascal and Javascript, but the language that really kept me on the right track was Python. Python is a pretty clear and straightfoward language that allowed me to make useful tools and quick experiments early on.

Other people I know learned programming using C, PHP and other languages. Each person should choose a way that fits better their own personality, goals and learning needs.

Remember that once you learn the fundamentals, other languages will be easier to learn and you can always change the technology you use. Technologies born and get deprecated very often, but the fundamentals of programming remain and can be applied to new languages again.

Here are some language options to get you started:

  • Javascript: typically interpreted and the world's most popular programming language, it's essential for front-end web development (client side) along with HTML and CSS, but can be used in the back-end (server side) as well with technologies like NodeJs. Most modern browsers (Chrome, Firefox, Safari, Opera etc) are capable of run javascript code, so you'll need only a modern browser and a text editor to start. Despite it's name, javascript have nothing to do with java.

  • Python: typically interpreted language with focus on readability, clarity and code elegance, therefore good for beginners. It became very popular in the last years and is used for many tasks like back-end development, task automation, data science and machine learning. Python's official website provides documentation, guides and the main interpreter of the language (called CPython).

  • PHP: typically interpreted language created for the clear purpose of back-end development, it's the main reference when it comes to server-side web development and it's one of the most used languages for that purpose. The back-end of many websites are developed with this language.

  • Pascal: typically compiled language whose initial focus was to make learning programming easier and encourage good programming practices using structured programming. Despite not being so popular nowadays, it's still a very capable language for both education and production purposes, as it generates programs that are fast and efficient. Its most known implementation is Delphi, but others like FreePascal are available and open-source. Along with Lazarus, FreePascal can be used to easily build desktop applications with graphical interfaces.

  • Java: illustrated by the the slogan "write once, run anywhere", the language combines traits of both compiled and interpreted languages, which allows high portability and intermediate performance. It's the official language for android development along with Kotlin and is used a lot for the development of corporate software. It's a tricky language for beginners as they'll have to deal with programming basics, OOP (Object Oriented Programming) paradigm and the language verbosity at the same time.

  • C: typically compiled language with focus on execution speed and efficiency. It allows the direct manipulation of the hardware and can be a very powerful tool in the hands of experienced programmers. Learn C, however, takes more time than other languages because it doesn't hide from the programmer aspects of computation that are typically abstracted in other languages. Many tasks that are performed automatically in other programming languages, like memory management, must be done manually in C. The language is used in situations where speed and low use of computer resources are critical like in operating systems, compilers, interpreters, embedded systems, driver development etc.

  • C++ (or C plus plus): it's a typically compiled language that started as an extention of the C language. It was called C with classes duo to it's support for OOP (Object Oriented Programming), but as the time passed the language accumulated so many features that became an entirely new technology. The language have very powerful abstraction tools, but like C it doesn't hide the intricacies of computer operations from the programmer. It's used in any situation where abstraction power, execution speed, and low use of computer resources are critical.

What's the best programing language? Is there any supreme language, the best-of-all, the king, able to solve every problem?

The best tool to put a nail in a wall is a hammer, isn't it? You may use a rock, a pan or a knife and still get the job done, but a hammer or a nail gun will make the job easier and faster. The same way, every programming language has its strengths and weaknesses, and the best programming language depends on the problem you have to solve.

It's normal to feel more affinity for some languages than others, but professional projects requires languages that best suits the project problems.

I want the best way to start...there must be the best way, the PERFECT way!

Bad news: there is no perfect way, you'll have to make a choice and deal with both the good and bad outcomes that may result from it. It's quite unusual for a choice to bring only pleasant results, most of the time the unpleasant results comes together and we gotta have patience and perseverance to deal with them. To make good choices we need experience, and experience mostly comes from mistakes and bad choices. We learn by making mistakes.

I'm still undecided

The American psychologist Barry Schwartz coined a very interesting concept called "the paradox of choice", which is used to describe a phenomenon where consumers who are confronted with too many choices might find it hard to make a decision or to be happy with the decision they make. Have choices is good, and it's natural to wish for options that brings us the best outcomes, but get caught up in analysis paralysis is a waste of precious time that should be used for programming.

Remember that your choice is not permamnent, once your learn the basics you can learn new languages and tools easier than your first language, not to mention that learn more than one language is a must as you'll face challenges that will require different languages.

Recommend me a text editor :D

In theory any text editor (even the notepads that usually comes with operating systems) can be used to write code, but good editors must have, at least, two features: syntax highlighting and automatic indentation. Those features makes the code more readable and provides a much better visualization of the code structure.

  • Syntax highlighting: this feature highlights different parts of the code with different colors.

  • Automatic indentation: an indentation is an empty space at the beginning of a line to mark the start of a new paragraph (and in computer programming to mark a nested block of code).

Example of code without syntax highlight and indentation:

# (Python version 3.7.3) Function to identify even numbers.
  
def num_even(num):
if num % 2 == 0:
print(num, "it is an even number.")
else:
print(num, "it is an odd number!")

num_even(2)

Example of code with syntax highlight and indentation::

# (Python version 3.7.3) Function to identify even numbers.
  
def num_even(num):
  if num % 2 == 0:
    print(num, "it is an even number.")
  else:
    print(num, "is is an odd number!")

num_even(2)

Geany is an excelent text editor with the basic qualities of a good text editor. It runs in the main desktop operating systems (Linux, MacOS and Windows), it's easy to use, fast, open source, free, supports many programming languages and have many other features. You can download it in this link.

And what is the best text editor?

Seriously? After everything I've said?!

Where can I start learning?

Below are some of the sites I personaly used to start learning:

freeCodeCamp: a non-profit organization created to make the learning of programming accessible to anyone. It consists of an interactive learning web platform, a forum, chatrooms, video courses, and online publications. The interactive lessons introduce the student to web development with Javascript, HTML, CSS and project assignments using those languages. The content of the platform is free but you can make donations that will help them improve their services.

Green Tea Press: a publisher of programming e-books available in a a variety of electronic formats. Their most remarkable book is "Think Python: How to Think Like a Computer Scientist", an introduction to programming using Python and computer science concepts. All books on their website are under free licenses that allow anyone to download, copy and distribute the texts, but they sell physical copies of the books and accept donations.

Automate the Boring Stuff With Python: an online book with a pragmatic approach towards programming. The book focus on the basics of Python programming and the use of that knowledge to perform task automation involving files, webscrapping, Excel spreadsheets, PDFs, emails etc. The website also provides other interesting Python books, offer physical copies of the books for purchase and accept donations.

W3schools: an online platform full of interactive programming lessons and examples. The website is very usefull not only to learn programming basics but also to learn how to perform specific tasks and build components with Javascript, HTML and CSS.

Last considerations

  • Debugging usually takes more time than writing code: debugging is the process of finding and correcting bugs, which are defective pieces of code that causes the program to throw errors or work in ways it was not supposed to. Bugs are inevitable, newly written code will rarely run on the first try, and it's normal to spend a good portion of development time in the debugging process.

  • Math beyond basics is not strictly necessary in programming: except in situations that requires specific math knowledge to solve problems (science, economy, enginering etc), being a programmer doesn't require more than basic aritmethics. However, duo to it's logical nature and roots on mathematics, the programming field benefits greatly from it because many solutions can be optimized using mathematical techniques, so math gives more power to programmers.

  • Be careful with tutorial hell: tutorials can be a good way to learn programming concepts and tools, but if you keep doing them continually without getting your hands dirty with real projects you may get trapped in tutorial hell. The main skill of a programmer is problem solving, you don't learn it much with tutorials because they are made to work without problems, unlike real projects where you must solve many problems that will inevitably arise (and by "real projects" I mean any meaningful project, be it personal, professional or both).

  • Break problems into smaller parts: break a problem into smaller parts and solve them separately is an efficient approach to programming problems, smaller problems are less complex and it's solutions are easier to express through code and algorithms.

  • Frequency is better than quantity: devote small ammounts of time everyday to program is better than practice a lot for a few days. The cognitive load per practice session is lighter, the knowledge sticks better in the head and the motivation comes easier.

  • Don't promote language wars: there's no problem in enjoying/disliking programming languages or give them constructive criticisms, but promote language wars is not only pointless but counterproductive. In the end of the day, languages are just tools and we should harness the best in each one of them to achieve our goals.

  • Learn to keep the code clean: maintain code written by other programmers is common routine in software development, so keeping the code clean and readable helps other team members to understand what your code does and how to correct problems faster, it's an essential skill. As a friend of mine once said: "Always assume that the programmer who will maintain your code is a violent sociopath who knows where you live".

  • Don't be evil: computer programming is a powerful skill that should require lots of responsibility, prudence and goodwill. In a world that is being shaped by computers, you can and SHOULD make a positive difference cultivating ethical values and acting for the benefit of people.

Notes

  • Programming languages and implementations are two different things: from a strictly technical perspective there's no such thing as "compiled language" and "interpreted language", that's why I used the terms "typically compiled language" and "typically interpreted language". The development of a programming language specifications is different from the development of its implementations (compilers and interpreters), and one language may have more than just one implementation. It's possible, for example, to develop a compiler and an interpreter separately for the same programming language. The terms "compiled language" and "interpreted language" usualy comes from a widespread and known implementation of that language.

  • Some implementations can interpret compiled programs: the world of software development became very sophisticated in the last decades and some implementations include a virtual machine that can interpret programs that were previously compiled. This process allows a combination of portability (the program can run in any platform where the virtual machine is available) and intermediade performance. The main implementations of languages like Java and C# belongs to this category. I did not delve into the subject throughout the text in order to make understanding easier.