2.9 Design Considerations and Programming Practices

2.9.1 Logical order of actions

Logical Order of Actions
Actions should be ordered logically so data is available when needed.

Purpose: To ensure programs run correctly and avoid errors.

Python example:

price = 10
quantity = 3
total = price * quantity
print(total)
        
The calculation happens only after values are assigned.

2.9.2 Order of operations

Order of Operations
Operations must follow the correct order (BIDMAS) to ensure accuracy.

Python example:

result = 10 + 2 * 5
print(result)

correct_result = (10 + 2) * 5
print(correct_result)
        
Brackets are used to control execution order and avoid errors.

2.9.3 Selecting suitable data structures

Choice of Data Structures
Data structures should be chosen based on efficiency and memory usage.

Example: A dictionary provides faster lookups than a list.

Python example:

scores = {"Alex": 85, "Sam": 92}

print(scores["Sam"])