Skip to content

Commit 5c8dc6a

Browse files
lesvaverikitsch
andauthored
Mention Streams and Lambda's (GoogleCloudPlatform#1828)
* Mention Streams and Lambda's Also mention java 8 / Java 11 * Update SAMPLE_FORMAT.md Co-Authored-By: Averi Kitsch <akitsch@google.com> * kurtis's and Averi's comments * Update SAMPLE_FORMAT.md Co-Authored-By: Averi Kitsch <akitsch@google.com>
1 parent cb61467 commit 5c8dc6a

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

SAMPLE_FORMAT.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ samples in this format are located
77
Larger sample applications should attempt to follow many of these guidelines as well, but some may
88
be ignored or waived as there can be many structural differences between applications and snippets.
99

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.
1013

1114
## Specific Goals
1215
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
194197
verify that it works correctly. See the tests in the canonical for an example of how to do this
195198
correctly.
196199

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+
197216
## Additional Best Practices
198217

199218
The following are some general Java best practices that should be followed in samples to remain
200219
idiomatic.
201220

202-
203221
### Style
204222
Wherever possible (and when not conflicting any of the above guidelines), follow the
205223
[Google Java Style Guide](https://google.github.io/styleguide/javaguide.html). It's encouraged, but

0 commit comments

Comments
 (0)