You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: SAMPLE_FORMAT.md
+19-1
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,9 @@ samples in this format are located
7
7
Larger sample applications should attempt to follow many of these guidelines as well, but some may
8
8
be ignored or waived as there can be many structural differences between applications and snippets.
9
9
10
+
## Java Version
11
+
12
+
All samples should be written to run on both Java 8 and Java 11, samples that don't run on Java 8 should clearly says so in their README and disable testing on Java 8. There should be a clear reason why Java 8 isn't supported.
10
13
11
14
## Specific Goals
12
15
This sample format is intended to help enforce some specific goals in our samples. Even if not
@@ -194,12 +197,27 @@ Snippets should have tests that should verify the snippet works and compiles cor
194
197
verify that it works correctly. See the tests in the canonical for an example of how to do this
195
198
correctly.
196
199
200
+
## Modern Java
201
+
Prefer using modern idioms / language features over older styles.
202
+
203
+
### Lambda's
204
+
Should be about 1-3 lines at most, otherwise it should be in a named method.
205
+
* Prefer lambdas to annonymous classes
206
+
207
+
### Streams
208
+
Streams can be extremely compact, efficient, and easy to use - consider using them.
209
+
* Avoid side effects (changes outside the scope of the stream)
210
+
* Prefer `for` each loops to `.foreach()`
211
+
* Checked Exceptions can be problematic inside streams.
212
+
213
+
### Parallel Streams
214
+
Parallel Streams make make sense in a few situations. There are many situations where there use is a net loss. Really think through your usage and consider what they might mean if you are already doing concurrent operations.
215
+
197
216
## Additional Best Practices
198
217
199
218
The following are some general Java best practices that should be followed in samples to remain
200
219
idiomatic.
201
220
202
-
203
221
### Style
204
222
Wherever possible (and when not conflicting any of the above guidelines), follow the
205
223
[Google Java Style Guide](https://google.github.io/styleguide/javaguide.html). It's encouraged, but
0 commit comments