Lesson 7 Flashcards
Syntax
The rule of a programming language. Computers cannot execute to a program with improper syntax.
Style
Writing code in a way that makes it clear and easy for human to read. Computers can execute programs written in poor style.
Why is good style important?
Code written in poor stylist to difficult to understand. Programmer spend most of their time updating maintaining or fixing existing code. Software is developed in teams and should not rely on a single developer.
Comments style convention
Include a header box at the beginning of a program containing basic information about the program use “”” to start and end comments”””
Internal comments
Write your program comments before you start writing code. This will help you organize the logical flow without worrying about syntax. Include comments, even for simple programs. Include comment boxes at the start of major sections of code. Use eye-catching formats as appropriate.
How long should lines of code be?
Lines should be less than 79 characters and comments less than 72
Style conventions
- use spaces around operators
-Use a snake case style for variable naming
-Use meaningful comments that explain why
-variables intended to be constant should be named with uppercase
Debugging
Debugging is the process of identifying, analyzing, and fixing errors in computer program.
Debugging process
1) bug, identification, detecting, unexpected behavior or errors in the program.
2) bug analysis, understanding the cause of the issue through testing and inspection
3) fixing, correcting the faulty code while ensuring it does not introduce new issues
4) verification to confirm the fix does not affect other parts of the program
The most basic debugging technique
Include print statements to display information at various points and program.
However, it’s not scalable for large programs and they may need to be removed later
Breakpoints
Breakpoints are a line of code where the python interpreter will pause the program until given permission to execute the line and proceed. To enable breakpoint, you must run the script with the D bugger.
Six common subclasses of exceptions
Syntax error
Name error
Type error
Value error
Key error
Zero division error
Syntax error
Incorrect python syntax
Name error
Using a variable that is misspelled or hasn’t been defined
Type error
Performing an invalid operation given the data type
Value error
Passing an invalid argument, or removing an item from a data structure that does not exist
Key error
Referring to a key that does not exist in the dictionary
Zero division error
Dividing by 0
Four blocks to handle exceptions
Try
Except
Else
Finally
Try
Where are you put your code that might cause an air
Except
Where are you put code to handle the error
Else
Code to run when no exceptions are raised
Finally
Code that runs no matter what happens