Download presentation
Presentation is loading. Please wait.
1
Programming Languages: Notes for Class Discussion: V22.0002 Deena Engel’s class
2
Programming languages and Natural Languages They both use: syntax (e.g. punctuation) grammar (“well formed sentences”) parts of speech (analogous to data types) Semantics (the meaning of symbols and words)
3
Natural Languages use: Syntax: punctuation and spacing Grammar: to create “well formed sentences” (e.g. subject-verb-object) Parts of speech: nouns, verbs, adjectives Semantics: the meaning of the words and what they represent (e.g. in English, “cat” refers to a furry, four-pawed mammal in the Great Cats family)
4
Programming Languages use: Syntax: punctuation such as parentheses, braces, brackets, semicolons, etc Grammar: well-formed structures such as blocks of code and statements within the blocks Parts of speech: can be viewed as the different data types such as integers, characters, text Semantics: the meaning of the symbols, e.g. =, + and others; or the use of reserved words.
5
Key words See Table 1-2 on page 18 One distinction between programming languages and natural languages is that programming languages contain key words – or reserved words. Each reserved word has a specific meaning and cannot be used for any other purpose. Python key words: anddelfromnotwhile aselifglobalorwith assertelseifpassyiel breakexceptimportprint classexecinraise continuefinallyisreturn defforlambdatry
6
Writing Steps in writing code in a programming language which gets compiled: Source code Compiler Machine language Python uses an interpreter.
7
Style Style counts … in both kinds of languages! In natural language … style is one way to distinguish the type of writing e.g. the differences between a sonnet by Shakespeare and a weekly shopping list… In a programming language, style is important to make the program both readable and more efficient.
8
Comments Programming languages allow us to document what we are doing … explaining how something works and what the most recent changes were. Like stage directions in a play, or one’s notes in the margins, programming languages allow us to separate out text from the body of the program.
9
How to use programming languages: Natural languages: can be used to tell a story … and other purposes … as well as to give instructions. Cookbooks and how-to books provide instructions in a natural language: “mix ½ cup of sugar into the butter” The instructions might include decisions: “if these are chocolate chip cookies, add chocolate chips and shredded coconut ; otherwise just add shredded coconut”).
10
Programming Languages... Give instructions to the computer… A computer program is like a recipe except that the computer follows the instructions.
11
Programming Languages (Page 17 - Table 1-1) Ada Basic Fortran Cobol Pascal C and C++ C# Java JavaScript Python Ruby Visual Basic
12
Programming Languages give instructions: Any series of repeated instructions can be called an algorithm. In many cases, the programming language mirrors what you would do if you were doing the task manually. For example: To keep a running total in a checkbook … First: order the amounts by the date of the check; then, if it’s a check, subtract the amount or if it’s a deposit, add the amount; then print the current total For example: To create an index of important terms in a book: First, read or scan the text; discard extra words (“the”, “and”); list the important terms and their pages; write it up as an index in alphabetical order.
13
“Bugs”! De-bugging a program is the process of finding and resolving errors. Errors fall into three general categories –Syntax errors: The code does not follow the rules of the language; for example, a single quote is used where a double quote is needed; a colon is missing; a keyword is used as a variable name. –Runtime errors: In this case, your code is fine but the program does not run as expected (it “crashes”). For example, if your program is meant to divide two numbers, but does not test for a zero divisor, a run-time error would occur when the program attempts to divide by zero. –Logic errors: These can be the hardest to find. In this case, the program is correct from a syntax perspective; and it runs; but the result is unanticipated or outright wrong. For example, if your program prints the line “2 + 3 is equal to “ … followed by a 6 … the answer is wrong!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.