Python Exploration Round 3
If you are new to this series of posts then here is what you missed: Nick is challenged by Jason to learn a programming language, Nick accepts challenge, chooses Python, and begins to explore, kids learn Python with Nick, and Steve Jobs speaks from the grave via a .swf video…okay not so sure about that last part.
So…where were we….oh yes
Programs
What are they really? Well, simply put:
[quote]A program is a sequence of instructions that specifies how to perform a computation. The computation might be something mathematical, such as solving a system of equations or finding the roots of a polynomial, but it can also be a symbolic computation, such as searching and replacing text in a document or (strangely enough) compiling a program.[/quote] [note] You don’t say?[/note]I was able to deduce from this section of the online book on Python that programs are really designed to break down the information of complex languages into simple languages that virtual machines can understand, which include: Input, Output, Math, Conditional Execution, and repetition.
[note]This is starting to sound like 6th grade science…very reminiscent of the scientific method.[/note]Input involves getting the data from some source, a keyboard, a file or other device. Output involves displaying or sending the data. Math…well, I never was good at math. Conditional Execution checks for conditions and executes sequences. Repetition essentially repeats the process with occasional variations.
[note]I am sure we are going somewhere with this…not sure where…but we are going.[/note]Evidently this is what every program boils down to in its rawest form. The gist of it is to break down information. We will learn more about this when we discuss algorithms.
Next we learned about Bugs.
[note]These are what Jason (our fearless C.T.O.) calls a “PEBKAC Error” which is an acronym for Problem Exists Between Keyboard And Chair” Which I hear quite often from Jason when trying a new trick that I learned in a cartoon or something.[/note]
Bugs are essentially errors made by people. Since programs can only do what we tell them to do the blame rests solely on the only factor that is capable of making a mistake: the human factor. What I learned from this section is that there are essentially (3) kinds of errors that are possible that are defined as bugs. The funny thing is that a lot of programmers will create a program full of bugs and work backwards to perfect a program through the process of eliminating bugs until they get the program they are looking for.
[quote]Three kinds of errors can occur in a program: syntax errors, runtime errors, and semantic errors. It is useful to distinguish between them in order to track them down more quickly.[/quote]Syntax errors are simply errors in the way the code is structured when it is written. Python will return an error message if every “i” is not dotted and “t” crossed. This tells me that learning syntax will be imparitive along the way. I am sure that there will be many a PEBKAC Error that will require me to debug!
Runtime errors don’t occur until after the program is executed. The program will throw and exception (which is a bad thing) and will not allow the program to perform its intended task.
Semantic Errors are the tomato/tomahto argument. You may get the code correct in a way that it does not throw syntax or runtime errors only to find that the program does not perform the way that you wanted it to. This is because programming is very literal.
[note]Reminds me of what Mitch Hedburg once said, “I once saw a forklift lift a crate of forks. And it was way to literal for ME.”[/note]And there it is…..my suspicions are well founded…the next section talks about experimental debugging.
[quote]One of the most important skills you will acquire is debugging. Although it can be frustrating, debugging is one of the most intellectually rich, challenging, and interesting parts of programming.[/quote] [note]Wow! I got really excited reading that quote! You? I mean…really….that was a compelling statement…I am up for the challenge.[/note]Essentially what this section is talking about is debugging will become natural and the more you program the less you will have to do it, since you will become better and better and less apt to make errors that need to be debugged. From what I gathered this is something that even the most astute programmer still has to do, and is really part of the fun of programming.
[note]The next section on formal and natural language is a bit esoteric for me but feel free to read it if you want (section1.8)[/note]On to the next section….
The next section is called the First Program. Usually the first program in any language is the “Hello World” program (as commonly seen in WordPress blogs) and programs are rated on how well their “Hello World” program runs.
The next section is a glossary of terms…you don’t have to go there as I am going to include it in the following quote:
[quote]- algorithm- A general process for solving a category of problems.
- bug- An error in a program.
- byte code- An intermediate language between source code and object code. Many modern languages first compile source code into byte code and then interpret the byte code with a program called a virtual machine.
- compile- To translate a program written in a high-level language into a low-level language all at once, in preparation for later execution.
- debugging- The process of finding and removing any of the three kinds of programming errors.
- exception- Another name for a runtime error.
- executable- Another name for object code that is ready to be executed.
- formal language- Any one of the languages that people have designed for specific purposes, such as representing mathematical ideas or computer programs; all programming languages are formal languages.
- high-level language- A programming language like Python that is designed to be easy for humans to read and write.
- interpret- To execute a program in a high-level language by translating it one line at a time.
- low-level language- A programming language that is designed to be easy for a computer to execute; also called machine language or assembly language.
- natural language- Any one of the languages that people speak that evolved naturally.
- object code- The output of the compiler after it translates the program.
- parse- To examine a program and analyze the syntactic structure.
- portability- A property of a program that can run on more than one kind of computer.
- print statement- An instruction that causes the Python interpreter to display a value on the screen.
- problem solving- The process of formulating a problem, finding a solution, and expressing the solution.
- program- a sequence of instructions that specifies to a computer actions and computations to be performed.
- Python shell- An interactive user interface to the Python interpreter. The user of a Python shell types commands at the prompt (>>>), and presses the return key to send these commands immediately to the interpreter for processing.
- runtime error- An error that does not occur until the program has started to execute but that prevents the program from continuing.
- script- A program stored in a file (usually one that will be interpreted).
- semantic error- An error in a program that makes it do something other than what the programmer intended.
- semantics- The meaning of a program.
- source code- A program in a high-level language before being compiled.
- syntax- The structure of a program.
- syntax error- An error in a program that makes it impossible to parse — and therefore impossible to interpret.
- token- One of the basic elements of the syntactic structure of a program, analogous to a word in a natural language.[/quote]
- Okay…so now I am going to spend some time reviewing these terms and memorizing them. If you are like me you will want to spend a bit of time now learning these terms so that you don’t have to constantly refer back to this section.
- So we will end our discovery for now and pick up again a little later
- Adwebvertising….signing out!