Fix lines to 150 line length for better tracking of future changes (#189)
parent
868cd2f3f4
commit
f61f2f40f0
@ -1,6 +1,7 @@
|
|||||||
# Anti-patterns
|
# Anti-patterns
|
||||||
|
|
||||||
An [anti-pattern](https://en.wikipedia.org/wiki/Anti-pattern) is a solution to a "recurring problem that is usually ineffective and risks being highly counterproductive".
|
An [anti-pattern](https://en.wikipedia.org/wiki/Anti-pattern) is a solution to a
|
||||||
|
"recurring problem that is usually ineffective and risks being highly counterproductive".
|
||||||
Just as valuable as knowing how to solve a problem, is knowing how _not_ to solve it.
|
Just as valuable as knowing how to solve a problem, is knowing how _not_ to solve it.
|
||||||
Anti-patterns give us great counter-examples to consider relative to design patterns.
|
Anti-patterns give us great counter-examples to consider relative to design patterns.
|
||||||
Anti-patterns are not confined to code. For example, a process can be an anti-pattern, too.
|
Anti-patterns are not confined to code. For example, a process can be an anti-pattern, too.
|
||||||
|
@ -1,9 +1,15 @@
|
|||||||
# Idioms
|
# Idioms
|
||||||
|
|
||||||
[Idioms](https://en.wikipedia.org/wiki/Programming_idiom) are commonly used styles and patterns largely agreed upon by a community. They are guidelines. Writing idiomatic code allows other developers to understand what is happening because they are familiar with the form that it has.
|
[Idioms](https://en.wikipedia.org/wiki/Programming_idiom) are commonly used styles and patterns largely agreed upon by a community.
|
||||||
|
They are guidelines.
|
||||||
|
Writing idiomatic code allows other developers to understand what is happening because they are familiar with the form that it has.
|
||||||
|
|
||||||
The computer understands the machine code that is generated by the compiler. The language is therefore mostly beneficial to the developer. So, since we have this abstraction layer, why not put it to good use and make it simple?
|
The computer understands the machine code that is generated by the compiler.
|
||||||
|
The language is therefore mostly beneficial to the developer.
|
||||||
|
So, since we have this abstraction layer, why not put it to good use and make it simple?
|
||||||
|
|
||||||
Remember the [KISS principle](https://en.wikipedia.org/wiki/KISS_principle): "Keep It Simple, Stupid". It claims that "most systems work best if they are kept simple rather than made complicated; therefore, simplicity should be a key goal in design, and unnecessary complexity should be avoided".
|
Remember the [KISS principle](https://en.wikipedia.org/wiki/KISS_principle): "Keep It Simple, Stupid".
|
||||||
|
It claims that "most systems work best if they are kept simple rather than made complicated;
|
||||||
|
therefore, simplicity should be a key goal in design, and unnecessary complexity should be avoided".
|
||||||
|
|
||||||
> Code is there for humans, not computers, to understand.
|
> Code is there for humans, not computers, to understand.
|
||||||
|
@ -1,21 +1,29 @@
|
|||||||
# Design Patterns
|
# Design Patterns
|
||||||
|
|
||||||
[Design patterns](https://en.wikipedia.org/wiki/Software_design_pattern) are "general reusable solutions to a commonly occurring problem within a given context in software design".
|
[Design patterns](https://en.wikipedia.org/wiki/Software_design_pattern) are "general reusable
|
||||||
Design patterns are a great way to describe some of the culture and 'tribal knowledge' of programming in a language.
|
solutions to a commonly occurring problem within a given context in software design".
|
||||||
Design patterns are very language-specific - what is a pattern in one language may be unnecessary in another due to a language feature, or impossible to express due to a missing feature.
|
Design patterns are a great way to describe some of the culture and 'tribal knowledge'
|
||||||
|
of programming in a language.
|
||||||
|
Design patterns are very language-specific - what is a pattern in one language may be
|
||||||
|
unnecessary in another due to a language feature, or impossible to express due to a missing feature.
|
||||||
|
|
||||||
If overused, design patterns can add unnecessary complexity to programs. However, they are a great way to share intermediate and advanced level knowledge about a programming language.
|
If overused, design patterns can add unnecessary complexity to programs.
|
||||||
|
However, they are a great way to share intermediate and advanced level knowledge about a programming language.
|
||||||
|
|
||||||
## Design patterns in Rust
|
## Design patterns in Rust
|
||||||
|
|
||||||
Rust has many very unique features. These features give us great benefit by removing whole classes of problems. Some of them are also patterns that are _unique_ to Rust.
|
Rust has many very unique features. These features give us great benefit by removing whole classes of problems.
|
||||||
|
Some of them are also patterns that are _unique_ to Rust.
|
||||||
|
|
||||||
## YAGNI
|
## YAGNI
|
||||||
|
|
||||||
If you're not familiar with it, YAGNI is an acronym that stands for `You Aren't Going to Need It`. It's an important software design principle to apply as you write code.
|
If you're not familiar with it, YAGNI is an acronym that stands for `You Aren't Going to Need It`.
|
||||||
|
It's an important software design principle to apply as you write code.
|
||||||
|
|
||||||
> The best code I ever wrote was code I never wrote.
|
> The best code I ever wrote was code I never wrote.
|
||||||
|
|
||||||
If we apply YAGNI to design patterns, we see that the features of Rust allow us to throw out many patterns. For instance, there is no need for the [strategy pattern](https://en.wikipedia.org/wiki/Strategy_pattern) in Rust because we can just use [traits](https://doc.rust-lang.org/book/traits.html).
|
If we apply YAGNI to design patterns, we see that the features of Rust allow us to throw out many patterns.
|
||||||
|
For instance, there is no need for the [strategy pattern](https://en.wikipedia.org/wiki/Strategy_pattern) in Rust
|
||||||
|
because we can just use [traits](https://doc.rust-lang.org/book/traits.html).
|
||||||
|
|
||||||
TODO: Maybe include some code to illustrate the traits.
|
TODO: Maybe include some code to illustrate the traits.
|
||||||
|
Loading…
Reference in New Issue