Software design
- Useful cuz code may not just be yours / other people are reading it!
The central idea of software engineering is modularization
- small chunks that do 1 thing, and are combined into a big thing we want!
What makes good software:
- Modularity
- The ability to reduce duplicate code
- Enabling reuse
- Correctness
- To write “bug free” code, you gotta test
- The best we can do is say “we have no issues at the moment”, so at that point the program is “bug-free”
- Maintainability
- Easy to understand
- Clearly/cleanly written
- Well-documented
- Efficiency
- The complexity should be good
- it should be well-implemented depending on your language
-
Privacy
- Reusable
- Abstraction
- Extendable
- extendable = if behaviour isn’t added, it should be easy to add
- Openness
- FOSS ⇒ Easy to edit, hard to hide evilness
- Proprietary ⇒ Easy to hide evilness
Modules
Each module in C has these things:
- One header file (.h)
- Contains function declarations (but not their implementations)
- i.e.
int BFS_find_path(float Adj[][], int i, int j, int visited[]);is a function declaration
- i.e.
- Contains constants
- The compile needs these from headers like
stdio.hso that it knows the functions “exist” and will do something about it.
- Contains function declarations (but not their implementations)
- One/more implementation files (.c)
- These implement what is given by the header file.
- All of these combined should implement every function used by the application
todo when using headers, does the compiler somehow know the .c exists too? Or is that part of the linking? uhhh idrk.
An example
We are making a program with
- Module for DFS
DFSgraphs.hDFSgraphs.c- This will have
#include "DFSgraphs.h"
- This will have
- PacMan
Pacman.hPacman.c- Compiling
Pacman.handPacman.ctogether gets you aPacman.o, but this “object file” cannot run by itself (even if it has amain(), it will never be called by itself)
- Compiling
Linking the files (Pacman.o, DFSgraphs.o, and maybe main_game.c (which may contain the actual main()) via a makefile) will get you your Pacman.exe
More specific
To build it, you do these steps:
- Compile each module (the .h and .c combined) into an object file
.o- Contains executable code for functions of
DFSgraphs- ”has placeholders for functions from other modulestodo”
- You cannot run the
.ocuz there is no process to run it, and there is nomain() - Even when you compile
pacman.owe cannot run it even if it has a main function
- Contains executable code for functions of
- Link the object files to make
pacman.exe- It goes into
pacman.o, sees what functions it needs fromFPSgraph.h, grabs the implementations fromDFSgraphs.c, and use that - The linking process is what replaces the placeholder implementation with the real deal
- It goes into