Design Principles
Learning Goals
Students will:
- Be able to define and discuss common programming principles.
- Research common programming principles and synthesize how they’ve been used in their programming studies so far.
Warm Up
Think about the industry or career you have the most experience in. Are there any “right ways” of doing something that basically everyone agrees on? What about basic safety guidelines?
Design Principles in Practice
Similar to most industries, when thinking about programming principles, developers are used to designing their code around accepted practices & industry standards. When applications follow these best practices, it helps to ensure that both developers and users have a smooth time of building & using the end product.
Why do we care?
In terms of programming, we care about best practices & design principles because they help our application code be more readable and maintainable in the long run, which means greater legibility and potentially greater efficiency.
There is also an aspect of programming that developers should espouse called “developer empathy”, meaning we should consider not only the user’s experience but also the developer that comes after you in maintaining and building off of your code. Who would want to inherit a mess? Not me!
Where do these design principles come from?
If you haven’t noticed yet, developers (and people in tech in general) have lots of opinions! Over the years, developers have written books, published papers, or even designed entire frameworks around specific principles that they think are the most important. Generally, it’s good to have a well-rounded knowledge of the most common principles in use today. Principles may go by many different names, but their content stays relatively the same between languages & frameworks.
What happens if I don’t follow one of these principles?
No one is coming to put you in “developer jail” if you don’t follow these principles! But remember, you may be asked to improve your code or you may also ask others to improve their code (we call this a code review and it is a standard practice). Just as “driving with both hands” and “don’t run with scissors” aren’t the law doesn’t mean they’re not good ideas to still follow!
Part 1: Research
In small groups, research each of the following topics:
- Code Smells
- Single Responsibility Principle (SRP)
- Abstraction
- Encapsulation
- Law of Demeter
- DRY vs. WET
- YAGNI (You Ain’t Gonna Need It)
Part 2: Solidify & Communicate
In your group, take your research of each above topic and summarize why it’s important, including examples, and optionally including analogies and/or diagrams.
Part 3: Share
After your group has a summarization of each topic, come back together to discuss each topic individually, using some of the following guidelines:
- What is it?
- Why is it important?
- Have you seen this used in your coding journey so far?
- Or, do you have an example of how this principle could be used?
- Do you have any remaining questions about this design principle?