-
-
Notifications
You must be signed in to change notification settings - Fork 695
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
New concept: Optional #2913
base: main
Are you sure you want to change the base?
New concept: Optional #2913
Conversation
… the stub implementation, the reference solution and other required files. Some files must be modified. This is a draft.
I just committed a first draft. Don't worry about the linting errors, I will sort them out during this week.
|
Thanks @josealonso! I plan to have a look at the draft soon. In regards to the |
… are not over yet.
Thanks for the link to the generic-types exercise!! Shame on me |
Which icon should I choose? |
Did you mean the icon for the exercise? They get added to exercism/icons repository, though that can be done after the exercise is added. We'll have to make one, but I think it will be the same icon as the original Tim From Marketing, but with a "2" in the top right corner. Compare Wizards and Warriors and Wizards and Warriors 2 for an example. |
|
||
|
||
class EmployeeService { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, I didn't quite get the purpose of these two methods (getAllTheEmployeesById
and getEmployeeById
) especially as we're not expecting the students to implement these and I don't think its clear when we expect them to call them.
Since the Employee
have methods that return Optional
objects, I'd suggest having the test pass Employee
objects or a List
of them instead.
Is it also worth having a task for where the student has to return an Optional
as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your feedback.
I agree, I did it like that because I had all the code in one single file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this has been resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had another thought - the getEmployeeById
could also be left up to the student to implement. We already have the foreach
concept, so they could use that to find the employee and that'll give them the chance to practice making an Optional
object (assuming they are looking through a List<Employee>
) and there would be no need for streams in the class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kahgoh, despite I spent many hours creating this exercise, I have to admit it's probably a bit complex for a learning exercise. This is what I propose:
- Leaving this one for a future practice exercise.
- Create a concept exercise for Streams first. And maybe another one for Suppliers or functional interfaces, based on my article or a similar one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll leave a longer answer tomorrow, but I just wanted to thank you for your support and clarify that my struggle is due to being my first exercise designed from scratch and also because I wasn't not very familiar with the Optional API.
I would cover more simple streams operations in a first Streams learning exercise, like map, filter and other simple operations.
@kahgoh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had another thought - the
getEmployeeById
could also be left up to the student to implement. We already have theforeach
concept, so they could use that to find the employee and that'll give them the chance to practice making anOptional
object (assuming they are looking through aList<Employee>
) and there would be no need for streams in the class.
Are you saying I can implement the same methods without using streams ? I'm not sure that's doable. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking the EmployService
could take in a List<Employee>
in the constructor, so then the students could be tasked with finding the Employee by id. I imagine the stub would like this:
class EmployeeService {
public EmployeeService(List<Employee> employees) {
throw new UnsupportedOperationException("Please implement the EmployeeService constructor");
}
public Optional<Employee> getEmployeeById(int id) {
throw new UnsupportedOperationException("Please implement the EmployeeService.getEmployeeById() method");
}
}
Students can still make a solution for this using a for
/ while
loop that goes through the list until it finds the Employee. Here's one rough way:
for (Employee candidate: employeesList) {
if (Objects.equals(candidate.getId(), Optional.of(id)) {
return Optional.of(candidate);
}
}
return Optional.empty();
Alternatively, I think passing the method a List<Employee>
to the method would also work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking the
EmployService
could take in aList<Employee>
in the constructor, so then the students could be tasked with finding the Employee by id. I imagine the stub would like this:class EmployeeService { public EmployeeService(List<Employee> employees) { throw new UnsupportedOperationException("Please implement the EmployeeService constructor"); } public Optional<Employee> getEmployeeById(int id) { throw new UnsupportedOperationException("Please implement the EmployeeService.getEmployeeById() method"); } }Students can still make a solution for this using a
for
/while
loop that goes through the list until it finds the Employee. Here's one rough way:for (Employee candidate: employeesList) { if (Objects.equals(candidate.getId(), Optional.of(id)) { return Optional.of(candidate); } } return Optional.empty();Alternatively, I think passing the method a
List<Employee>
to the method would also work.
Thanks @kahgoh. I'll try to change it this weekend. I was stuck, because I designed this exercise to try to mimic the access to a database. But you're right, I made it too complex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your help, @kahgoh. Take a look when you have a chance. I think I did it the way you suggested. I'm sure it can be improved, but streams are not used in the reference solution.
exercises/concept/tim-from-marketing-2/src/test/java/EmployeeServiceTest.java
Outdated
Show resolved
Hide resolved
Who can make that icon? I'm sorry I don't know how to edit a simple icon :( |
…ns have been added. The tests have been corrected and integrated in an IDE. What remains are the hints.md and the icon files, and the gradle files for this exercise.
I don't understand why the java-test-runner failed, @kahgoh. It probably has to do with some missing configuration files, |
That's fine, we can do that later. For now, let's just work on the concept content. |
Yes. |
Maybe this doc on configlet could be useful for you as well to check |
|
||
WIP | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@josealonso I suggest you to use this vscode extension for markdown linting, you will be able to solve them easily
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion!! I use Intellij, there might be a similar plugin for this IDE, I guess.
exercises/concept/tim-from-marketing-2/src/test/java/EmployeeServiceTest.java
Outdated
Show resolved
Hide resolved
Thanks, I went through it already. I'll have to read it again. |
Write explanation for the Optional concept, as well as the test file, the stub implementation, the reference solution and other required files. Some files must be modified. This is a draft.
This solves #2555
Reviewer Resources:
Track Policies