Practice some good programming style. Here are some of the tips for writing clean and readable MATLAB code for your group assignment:
-
Use descriptive names:
- Assign meaningful names to variables and functions, e.g.,
Height
instead ofh
. - For multi-word names, use capitalization or underscores for readability, e.g.,
CarSpeed
orcar_speed
.
- Assign meaningful names to variables and functions, e.g.,
-
Break long code into smaller pieces:
- Divide long code into smaller, single-function pieces using user-defined functions and code cells (
%%
). - User-defined functions are created with the
function
keyword. Each code cell can be run individually.
- Divide long code into smaller, single-function pieces using user-defined functions and code cells (
-
Comment your code:
- Use the single percentage sign
%
to add comments explaining the purpose of commands, variables, and functions. - Comments aid both your future self and others in understanding your code.
- Use the single percentage sign
-
Don’t write dense code. Allow empty lines between the commands to enhance code readability.
-
Use consistent indentation. For example, proper indentation improves the readability of code with multiple cycles of
for ... end
loops. -
Don’t make your lines too long. Split long commands and computations using triple dots ...
Remember, readability is crucial, as it makes understanding, maintaining, and debugging the code easier for everyone.
- Code correctness (20 pts) w: 40%
- Code solutions must run smoothly without errors
- Tasks completed correctly
- Output visuals (10 pts) w: 20%
- Interesting plots or animations
- Use of README to describe solutions to all tasks
- Creativity and innovation (10 pts) w: 20%
- Substantial coding effort
- Evidence of innovative techniques
- Code organization (5 pts) w: 10%
- Readability of code
- Organisation of code
- Use of GitHub (5 pts) w: 10%
- Commit often
- Commit messages
- Usage of PR feedback/issues