You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is little to no input verification on the arguments passed to functions, it seems as if invalid inputs are attempted to be handled further down in the code. It is typically good practice to verify the input to a function before doing anything else. This leaves less strange cases to handle later and assists in debugging. This is especially important for an untyped language such as python
For example, see the function orient_to in the branch commutersAsObjects:
# Initialize the bearing, needed for relative instructions
def orient_to(commuterName, direction):
# Orient_to(commuterName, direction)
# commuterName: commuter object to change bearing
# direction: Direction in degrees or cardinal directions
# Start with a bearing of due north
bearing = 0
# if the direction is in degrees
# isReal tests is the obj is not NaN or inf
if isReal(direction):
commuterName.direction = direction;
return direction
# Set the bearing based on cardinal/relative dir
if direction.upper() == "NORTH":
bearing = 0
elif direction.upper() == "EAST":
...
The commuterName should be verified as a commuter object, and direction should be verified as a valid bearing, cardinal direction, or right/left. Something similar to this could be used
def orient_to(commuterName, direction):
# Orient_to(commuterName, direction)
# commuterName: commuter object to change bearing
# direction: Direction in degrees or cardinal directions
# PRECONDITIONS:
# commuterName must be a valid commuter object
# direction must be a vaild bearing or a cardinal direction, or left/right
# Check to make sure commuter is the correct object
if type(commuterName) is not commuter:
return -1;
# Verify the direction is valid
if not (direction in ["NORTH","EAST","SOUTH","WEST","LEFT","RIGHT"] or not (isReal(direction) and direction > 0 and direction < 360))
return -1
# Start with a bearing of due north
bearing = 0
The text was updated successfully, but these errors were encountered:
There is little to no input verification on the arguments passed to functions, it seems as if invalid inputs are attempted to be handled further down in the code. It is typically good practice to verify the input to a function before doing anything else. This leaves less strange cases to handle later and assists in debugging. This is especially important for an untyped language such as python
For example, see the function orient_to in the branch commutersAsObjects:
The commuterName should be verified as a commuter object, and direction should be verified as a valid bearing, cardinal direction, or right/left. Something similar to this could be used
The text was updated successfully, but these errors were encountered: