UNIHIVE

Study Hub UNIPORT ENG 213.1

ENG 213.1 · Computer Programming for Engineers

Computer code security and good practice

Protecting programs and data: input validation, backups and version control, access, licences, and writing maintainable code.

Our notes

1 min read

Why code security matters to engineers

Engineering programs control machines and produce design figures. A program that accepts bad input, is changed without record, or is lost, can cause unsafe designs, wrong reports or plant failures.

Validate input

  • Check ranges and types: a negative diameter, zero thickness or a letter where a number is expected should give a clear message, not a crash or a silly answer.

if (d <= 0.0) then
  print *, 'Diameter must be positive'
  stop
end if

  • Check iostat on reads and opens.

Protect against errors in calculations

Avoid division by zero and square roots of negatives; limit iterations; use double precision where accuracy matters; check results against simple limits.

Keep code and data safe

  • Backups: at least one copy away from your laptop (flash drive or cloud storage).
  • Version control (for example Git): every change is recorded with who made it and why; you can go back to a working version.
  • Access control: passwords and permissions on shared computers; do not leave sensitive data (client designs, personal data) in public folders.
  • Malware: only install compilers and libraries from official sources; scan flash drives.
  • Hard-coded secrets: never put passwords or keys inside program files that others may see.

Integrity and ownership

  • Licences: respect the licence of code you reuse; credit the author. Copying a classmate's assignment is academic misconduct.
  • Documentation: a header comment with the author, date, purpose, units and method; comments explaining non-obvious steps.

Maintainable code

  1. Meaningful names and consistent indentation.
  2. IMPLICIT NONE always.
  3. Named constants instead of "magic numbers" (g = 9.81 declared once).
  4. Small procedures, each doing one job.
  5. A test case with a known answer kept with the program.

Safety-critical programs

Software that controls machines (PLCs, robots, lifts) must be tested, reviewed and have safe fail states: if a sensor reading is impossible, stop the machine safely rather than carry on.

Exams usually ask

  • Explain what is meant by computer code security and how to achieve it.
  • List good programming practices.

Common mistake

Thinking security only means passwords. For engineering code it also means correct input checks, a record of changes and safe behaviour when things go wrong.

Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.

Read

Watch

We link to free material and never copy it. Every link was opened by our team before it went up; video data is a rough guide at 360p.

All ENG 213.1 topics

Report

Sign in to report this. It is free.

Is this your work (a lecturer, author or publisher)? Ask us to take it down.