Back to Basics: How Programming Languages Work

And now, a short diversion on the road to learning Objective-C.

Warning: Extremely technical information follows. Feel free to skip this section for now, but make sure you do read it sometime. It’s important enough to know, but not vital for you to begin programming.

A computer only understands a string of commands in a very basic format—machine language. At the lowest level, a computer can only process 0s and 1s—off, or on. In effect, computer is just a huge collection of billions of switches, rapidly turning on and off. A typical command that the computer understands may look like this:

  1. 00101011 11110111 10000100 01010110 00000110 10001001

Of course, having to program like this would not be very easy, and it is easy to loose track of what you’re doing. To fix this, chip makers created what is called assembly language—a language that chips understand, and will get translated to machine language, independently of the programmer. A typical command in assembly might look like this:

  1. l_objc_msgSend_fixup_alloc:
  2. .quad   _objc_msgSend_fixup
  3. .ascii "long int"
  4. .byte   0x4
  5. .byte   0x8
  6. .byte   0x7
  7. .byte   0x2
  8. .byte   0x1
  9. .byte   0x6
  10. .ascii "char"

Better than machine language, but still not too useful. In addition, the programmer is still interacting directly with the hardware, which increases the chances of mistakes.

Both machine language and assembly are specific to the hardware. Different hardware involves different machine and assembly code.

Higher-level languages were invented to solve of these problems. The “height” of these languages varies, but they all involve English-like syntax, and are hardware-independent. Objective-C is one such language.

The majority of these languages are passed through a compiler—a program that converts the code into assembly. Compilers are usually provided with a system; Xcode, Apple’s native development program, includes gcc, one of the most prominent compilers, as well as LLVM, an Apple-developed compiler that offers many benefits over gcc, all of which are beyond the scope of this book.

Higher-level languages allow programmers to focus on their task, and not on writing obscure code.

For anyone who’s interested in learning more, an even more technical and low-level approach will be coming. When? I don’t know.

This post is part of the Learn Objective-C in 24 Days course.

Author: Feifan Zhou