Skip to content

Commit 7f4f0c8

Browse files
committed
Doc polishing
1 parent 9a4340b commit 7f4f0c8

File tree

3 files changed

+22
-29
lines changed

3 files changed

+22
-29
lines changed

src/site/markdown/docs/codingStandards.md

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,32 @@ This library is coded in the pseudo-functional style that has become possible wi
66
these general principles for functional style coding in Java:
77

88
- Immutability is the core concept of functional programming
9-
- Use private constructors for most classes
10-
- Use a static "of" method as a builder method if there are one or two attributes. If there are two attributes,
11-
they may not be of the same type. A Builder class is preferred with two attributes, but "of" may be used to make
12-
the code more compact or readable in some cases.
13-
- Generally use a static Builder class if more than one attribute is required to initialize a class
14-
- Builders only have a zero argument constructor. All attributes set with "with" methods.
15-
- When using a Builder, private class constructors take the Builder as the only argument
16-
- Class constructors using a Builder should check for null if an attribute is required.
17-
- Avoid direct use of null. Any Class attribute that could be null in normal use should be wrapped in a
18-
java.util.Optional
19-
- In Builders, Lists should be initialized and then populated with add or addAll. Classes
20-
may directly reference the list in the builder.
21-
- In Builders, Maps should be initialized and then populated with put or putAll. Classes
22-
may directly reference the map in the builder.
23-
- Builders may be mutable, other classes may not be mutable.
24-
- Classes never expose a modifiable List. Lists are exposed with an unmodifiable List, or a Stream.
25-
- Classes never expose a modifiable Map. A Map may be exposed with an unmodifiable Map.
9+
- Use private constructors for most classes
10+
- Use a static "of" method as a builder method if there are one or two attributes. If there are two attributes, they may not be of the same type. A Builder class is preferred with two attributes, but "of" may be used to make the code more compact or readable in some cases.
11+
- Generally use a static Builder class if more than one attribute is required to initialize a class
12+
- Builders only have a zero argument constructor. All attributes set with "with" methods.
13+
- When using a Builder, private class constructors take the Builder as the only argument
14+
- Class constructors using a Builder should check for null if an attribute is required.
15+
- In Builders, Lists should be initialized and then populated with `add` or `addAll`. Classes may directly reference the list in the builder.
16+
- In Builders, Maps should be initialized and then populated with `put` or `putAll`. Classes may directly reference the map in the builder.
17+
- Builders may be mutable, other classes may not be mutable.
18+
- No setters
19+
- Classes never expose a modifiable List. Lists are exposed with an unmodifiable List, or a Stream.
20+
- Classes never expose a modifiable Map. A Map may be exposed with an unmodifiable Map.
21+
- Avoid direct use of null. Any Class attribute that could be null in normal use should be wrapped in a `java.util.Optional`
2622
- Avoid for loops (imperative) - use map/filter/reduce/collect (declarative) instead
2723
- Avoid Stream.forEach() - this method is only used for side effects, and we want no side-effects
28-
- The only good function is a pure function
29-
- Classes with no internal attributes are usually a collection of utility functions. Use static methods in an
30-
interface instead.
24+
- Avoid Optional.ifPresent() - this method is only used for side effects, and we want no side-effects
25+
- The only good function is a pure function. Some functions in the library accept an AtomicInteger which is a necessary evil
26+
- Classes with no internal attributes are usually a collection of utility functions. Use static methods in an interface instead.
3127
- Remember the single responsibility principle - methods do one thing, classes have one responsibility
3228

3329
## Clean Code
3430

3531
We are committed to clean code. This means:
3632

3733
- Small methods - less than 5 lines is good, 1 line is ideal
38-
- Small classes - less than 50 lines is good, less than 20 lines is ideal
34+
- Small classes - less than 100 lines is good, less than 50 lines is ideal
3935
- Use descriptive names
4036
- Comments are a last resort - don't comment bad code, refactor it
4137
- No nested control structures - ideal cyclomatic complexity of a function is 1

src/site/markdown/docs/extending.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ The SELECT support is the most complex part of the library, and also the part of
99

1010
| Interface | Purpose|
1111
|-----------|--------|
12-
| org.mybatis.dynamic.sql.BasicColumn | Use this interface if you want to add capabilities to a SELECT list or a GROUP BY expression. For example, creating a calculated column. |
13-
| org.mybatis.dynamic.sql.BindableColumn | Use this interface if you want to add capabilities to a WHERE clause. For example, creating a custom condition. |
12+
| `org.mybatis.dynamic.sql.BasicColumn` | Use this interface if you want to add capabilities to a SELECT list or a GROUP BY expression. For example, creating a calculated column. |
13+
| `org.mybatis.dynamic.sql.BindableColumn` | Use this interface if you want to add capabilities to a WHERE clause. For example, creating a custom condition. |
1414

1515
See the following sections for examples.
1616

src/site/markdown/docs/howItWorks.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,9 @@ is designed to be the one single parameter for a MyBatis mapper method.
8484
## What About SQL Injection?
8585

8686
It is true that mappers written this way are open to SQL injection. But this is also true of using any of the
87-
various SQL provider classes in MyBatis (@SelectProvider, etc.) So you must be careful that these types of mappers
88-
are not exposed to any general user input.
87+
various SQL provider classes in MyBatis (`@SelectProvider`, etc.) So you must be careful that these types of mappers are not exposed to any general user input.
8988

90-
If you follow these practices, you will make the SQL injection possibility less obvious:
89+
If you follow these practices, you will lower the risk of SQL injection:
9190

9291
1. Always use MyBatis annotated mappers
93-
2. Use the SqlProviderAdapter utility class in conjunction with the MyBatis provider annotations (@InsertProvider, @SelectProvider, etc.)
94-
95-
This is, admittedly, only security through obscurity.
92+
2. Use the `SqlProviderAdapter` utility class in conjunction with the MyBatis provider annotations (`@InsertProvider`, `@SelectProvider`, etc.)

0 commit comments

Comments
 (0)