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

isogram : add to track #311

Merged
merged 10 commits into from
Mar 17, 2017
Merged

Conversation

Kai-Shiro
Copy link
Contributor

@jtigger jtigger changed the title isogram : add-to-track isogram : dibs on adding to track Feb 22, 2017
@jtigger
Copy link
Contributor

jtigger commented Feb 22, 2017

Renamed to make clear the status of this PR. @Kai-Shiro, when you're ready for a review, please rename it back to bookstore : add to track or the like. Thanks!

@Kai-Shiro Kai-Shiro changed the title isogram : dibs on adding to track isogram : add to track Mar 3, 2017

public static boolean isIsogram(String word){

Set<Character> charset= new HashSet<Character>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just use the diamond operator for your HashSet declaration like this:

Set<Character> charset = new HashSet<>();


Set<Character> charset= new HashSet<Character>();
String[] words = word.split(" ");
String newword = concat(words);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Java, the convention is to use camelCase, as in newWord.

public static String concat(String[] words){
String newword = new String("");
for(int i = 0; i < words.length; i++)
newword = newword + words[i];
Copy link
Contributor

@matthewmorgan matthewmorgan Mar 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you like, you could replace this with:

String newWord = "";
for (String word: words){
    newWord += word;
}

No need for the index variable.

Or, for some extra-delicious Java 8:

public static String concat(String[] words){
    return stream(words).collect(joining());
}

To use the Streams version you'll need to import:

import static java.util.Arrays.stream;
import static java.util.stream.Collectors.joining;

newword = concat(words).toLowerCase();

for(int i = 0; i < newword.length(); i++)
charset.add(newword.charAt(i));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually we like to be explicit with our curly braces, even in short blocks like this.

@matthewmorgan
Copy link
Contributor

@Kai-Shiro thanks for doing this! We really appreciate the work.

in the spirit of challenging each other to produce the best possible product, I have made a couple of suggestions that are primarily stylistic. I also threw out a couple of alternative implementations that I thought might be interesting to you. Please feel free to use them, or not, as you prefer.

Finally, there's a merge conflict with config.json that was created when we merged some older PRs. Would you mind fixing that, or letting me know if you would like help doing it?

Thanks again.

@Kai-Shiro
Copy link
Contributor Author

@matthewmorgan Thanks for the advices! I have applied some changes to the code and i think i have fixed the merge conflict with config.json

@matthewmorgan
Copy link
Contributor

Nice work @Kai-Shiro ! This implementation is looking much cleaner-- concise, yet still easy to read.

If you're up for it, I would like to suggest a couple more changes.

  1. We're trying to move away from static methods for problems like this. Please see the discussion about the Pangram exercise here: pangram: add starter implementation and make object-based #344 Two things to really pay attention to in the above discussion are the conversation around the semantics of the class and method names, and the preference for instance methods over class methods.

  2. It doesn't appear that your concat method needs to be public. Since it's only used internally by the Isogram class, you can (and should) make it private.

  3. Small nit: the charset variable should be camelCased.

Please let me know if you have any questions, or if you would like help with any of the details.

@Kai-Shiro
Copy link
Contributor Author

@matthewmorgan I have applied some changes.

  • There is no longer statics methods
  • I change charset to charSet
  • I change the code to use instance methods

Copy link
Contributor

@matthewmorgan matthewmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kai-Shiro this is looking great. I have some minor changes that to request, otherwise bien fait!

@@ -0,0 +1,37 @@
package exemple;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have a typo here, should be:

package example;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, french mistake!

import static java.util.Arrays.stream;
import static java.util.stream.Collectors.joining;

public class Isogram {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am thinking that the semantics are very close on this class, but not quite right. Think of it this way: what is the purpose of this class? What do the methods do? What if, for example:

IsogramChecker isogramChecker = new IsogramChecker();
String word = "isogram";
boolean result = isogramChecker.isIsogram(word);

assertTrue(iso.isogramChecker());
}

@Test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll want to annotate all tests except the first one with @Ignore, so the users can explore their solution using each test as a goalpost.

@matthewmorgan matthewmorgan merged commit 6dd6ed6 into exercism:master Mar 17, 2017
@matthewmorgan
Copy link
Contributor

Nicely done!

@Kai-Shiro Kai-Shiro deleted the isogram-add-to-track branch March 17, 2017 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants