HomeAboutSoftwarePublicationsPostsMicroBinfie Podcast

Lessons learnt about programming

Posted on August 29, 2023
an AI generated picture (Midjourney) with prompt; 'computer programming in the style of The Persistence of Memory by Salvador Dali'. You can share and adapt this image following a CC BY-SA 4.0 licence.

This post is part of a series that summarised a workshop we ran recently. We were discussing programming, discussing common pitfalls, and then looked at some fun python tricks.

There are several sections:

What does learning to program entail?

These concepts provide a strong foundation for understanding and creating software, regardless of the programming language or domain you're working in. Most self taught programmers (in my experience) stop at number 6. You can do a lot with that knowledge, but you will struggle with errors as your programs become more complicated if you are not familiar with the other topics.

  1. Variables and data types
  2. List item
  3. Variables and data types
  4. Control structures (conditionals and loops)
  5. Functions and methods
  6. Classes and objects -- Self taught stops here --
  7. Data structures
  8. Algorithms
  9. Object-oriented programming (OOP)
  10. Inheritance and polymorphism
  11. Abstraction
  12. Encapsulation
  13. Modularity
  14. Debugging and testing
  15. Version control (git, svn)
  16. Memory management
  17. Concurrency and multithreading
  18. File I/O
  19. Networking and APIs

Which of these topics are familiar to you?

Don't get caught up in the arguments

When you're learning to program, you'll hear lots of different opinions about some important ideas. These ideas can be really interesting if you're studying computer science, but they can also make things confusing for most people.

Here are a few of these ideas:

  1. Compiled and Interpreted Languages: People argue about whether it's better to write code that's checked before it runs (compiled) or code that's read and executed step by step (interpreted). Some say compiled languages are faster, while others think interpreted languages are easier to work with. But if you're new to this, it might just sound like a big fuss over something that's hard to understand.

  2. Strong and Weak Typing: This is about how strict a programming language is about the types of data it uses. Some folks like strict rules (strong typing) to catch mistakes, while others prefer more flexibility (weak typing). If you're not deep into programming, this might sound like arguing over tiny details.

  3. VI and Emacs: There's a never-ending debate about which text editor is better: VI or Emacs. Some people love VI for its quick shortcuts, while others adore Emacs because it can do a lot of things. But if you're just starting, this might seem like arguing about nothing important.

  4. High level versus low level langauges: This is discussed below.

Remember, these discussions can be fascinating for serious programmers, but for most people who are just trying to learn and use programming skills, it's okay to focus on the main ideas without getting too tangled up in the complex details.

Yes, there are too many layers

At its core, programming is like tackling a puzzle. You're aiming to make a computer do some computation or tasks for you, so you're spared from doing repetitive and tedious work yourself. This way, you make good use of technology. But, here's the catch: this solution creates a new problem. How do you take your vague ideas from your mushy meat brain and turn them into crystal-clear instructions that a machine can follow?

This is where programming languages step in to assist. Think of them as tools that make this translation process smoother. However, keep in mind that these languages are invented by groups of people who hold different viewpoints about how to do this effectively. Specifically, they have varying notions about how much the language should lean towards making things easier for the person writing the code versus making things easier for the machine to understand.

High-Level Programming Languages

High-level languages are designed to be more human-readable and user-friendly. They abstract away many of the complex details of the computer's hardware and operations, making it easier for programmers to write code without getting bogged down in the nitty-gritty technicalities. These languages are closer to human language and allow you to express your ideas in a way that's more intuitive and natural.

Examples of high-level programming languages include Python, Java, C#, Ruby, and JavaScript. These languages are often used for tasks like web development, software development, data analysis, and more. They come with built-in functions and libraries that simplify common tasks and allow programmers to focus on solving problems rather than managing low-level details.

Low-Level Programming Languages

Low-level languages, on the other hand, are closer to the machine's native language. They provide a more direct and granular control over the computer's hardware resources. Writing code in low-level languages involves understanding the computer's architecture, memory management, and other low-level details. This type of programming allows for highly optimized and efficient code but requires a deeper technical understanding and can be more error-prone.

There are two types of low-level languages:

  • Assembly Language: This is a step above machine code, where instructions are written using human-readable mnemonics that correspond to specific machine-level operations. Each assembly instruction directly corresponds to a machine instruction.
  • Machine Language: This is the lowest-level programming language and consists of binary code that the computer's central processing unit (CPU) can execute directly. It's not easily human-readable and is specific to the computer's architecture. Low-level languages are often used in system programming, device drivers, embedded systems, and other situations where precise control over hardware resources is critical.

Hello world example

This example is to highlight the differences between high and low level languages.

The "Hello, World!" program is simple, symbolic, and widely used to introduce programming basics. It is one of the simplest things you can do - print a message to the screen.

"Hello, World" in x86 Assembly Language for DOS2 length-delimited output

asm
; hello3-DOS.asm - single-segment, 16-bit "hello world" program
;
; Use DOS 2.0's service 40 to output a length-delimited string.
;
; assemble with "nasm -f bin -o hi.com hello3-DOS.asm"
org 0x100 ; .com files always start 256 bytes into the segment
; int 21h needs...
mov dx, msg ; message's address in dx
mov cx, len
mov bx, 1 ; Device/handle: standard out (screen)
mov ah, 0x40 ; ah=0x40 - "Write File or Device"
int 0x21 ; call dos services
mov ah, 0x4c ; "terminate program" sub-function
int 0x21 ; call dos services
msg db 'Hello, World!', 0x0d, 0x0a ; message
len equ $ - msg ;msg length

"Hello, World" in Python

python
print("Hello, World!")

If you find the assembly language example exciting, you will enjoy the computer game SHENZEN I/O from Zachtronics.

Questions or comments? @ me on Mastodon @happykhan@mstdn.science or Twitter @happy_khan

The banner image is an AI generated picture (Midjourney) with prompt; 'computer programming in the style of The Persistence of Memory by Salvador Dali'. You can share and adapt this image following a CC BY-SA 4.0 licence.