$\require{cancel}$
Basic Programming
- This is section 1.3 of the book.
- Programs start out as source code.
- This is a set of instructions in a programming language.
- To create this you must know the language
- The syntax or the words, symbols and rules for combining those in the appropriate programming language.
- The semantics or the meaning of these words and symbols.
- If you look at English, we have a syntax rule that each sentence should have a subject, a verb, and an object. "Cows eat grass."
- As humans we are able to deal with sentences that do not follow the rules.
- As long as the sentences are close to the rules.
- Computers are not yet able to do so.
- When you violate a syntax rule, you produce a syntax error.
- Generally, the computer can tell you when a syntax error occurs.
- Frequently it will describe the error and provide a possible solution.
- These are difficult at first, but soon become commonplace.
- You can make a syntactically correct sentence that does not make sense
- "The cow drives the car."
- This is proper grammar (I hope) but the meaning is nonsense.
- In programming we will call these logical errors, or logic errors.
- The computer is not capable of detecting logic errors.
- This is up to the programmer, QA team, users, ...
- These remain the bane of computer programmers and users.
- Programming Languages
- There are many programming languages.
- If you take theory of languages or compilers you should be able to design and implement your own language if you wish.
- Many people have.
- Languages can serve different purposes.
- Designed for systems implementation (C++)
- Designed for security (RUST)
- Designed for wide availability (JAVA)
- Teaching Language (PASCAL)
- and many others.
- There are several basic types of programming languages
- Low Level: Machine language or assembly.
- These are very close to the hardware.
- When you change processors, (intel, atom, ....) you change languages
- These are somewhat difficult for humans to learn.
- High Level: most of the languages you will encounter.
- These are designed for humans to write and understand.
- These are generally similar, we will see this as time goes by.
- Special purpose:
- These are generally high level, but have a special purpose.
- SQL : Structured Query Language
- Designed for searching databases.
- HTML: Hypertext Markup Language
- Designed for specifying linked document (web page) layout.
- You will learn multiple high level general purpose languages in your life
- You will probably also learn a set of special purpose languages.
- You will be exposed to machine and assembly languages.
- Changing from a high level language to machine language can be done in several ways.
- A compiler is a program that takes a high level language and translates it into machine language all at one time.
- Think of translating a book from one language to another.
- It is a long process, but after it is finished you don't need to do it again.
- This is efficient when you have code you will run many times.
- It is slower when you run the code once.
- An interpreter interprets and executes the code one line at a time.
- Think of translating a speech as it occurs.
- Hear a sentence, convert it to another language.
- There are other ways to do this.
- Notably java compiles to a machine independent code.
- This code is interpreted by the JVM (Java Virtual Machine)
- These topics are covered more completely as we move through programming.