Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java/gigasecond: Update mentoring.md #1988

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion tracks/java/exercises/gigasecond/mentoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,19 @@ class Gigasecond {
- Use [constructor chaining](https://beginnersbook.com/2013/12/java-constructor-chaining-with-example/) to avoid code duplication.
- Use [`LocalDate.atStartOfDay()`](https://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html#atStartOfDay--) to convert a `LocalDate` to a `LocalDateTime`.


## Talking points

### Eager computation

A student can choose to compute the result for `getDate()` in the constructor. It is a really good optimization. In that case, it should be noted that it is possible because the `birthDate` is only provided in the constructor and is immutable.

### Exception handling

`plusSeconds` can throw a `java.time.DateTimeException`.
A student may choose to catch this exception in the constructor, but this results in `birthDateTime` being null, so the class won't have been instantiated properly.
There's no sensible default value that be stored in `birthDateTime`.
It's better to let the exception be thrown, failing fast, and let calling code deal with it.

### Type safety

We can add more type safety by using the class `java.time.Duration` for the gigasecond constant.
Expand Down
Loading