I wrote a program, put it on a github ( https://github.com/KaPaHgaIII/namegenerator ). Is there no place where you can show your code to more experienced people to point out shortcomings?
- To heaps, I note that committing the project files of your IDE ( .iml, .idea / ) to the repository is a bad practice. Committing library binaries (lib / *. Jar) is also not good (except when the binary is very unique), it is better to learn how to use maven. - Nofate ♦
- hashcode.ru is sending to ru.stackoverflow.com . So in essence, the issue is relevant. I have not found a suitable place. - Mikhail Danshin
- one@MikhailDanshin: Now the right place is Stack Overflow in Russian. Read more: stackoverflow.com/tags/… - Nick Volynkin ♦
2 answers
one)
cmdArguments.getGender().substring(0, 1).toLowerCase().equals("m") //жуть cmdArguments.getGender() == Genders.MALE //старые добрые enum but in getGender you need to write something like this
switch(gender) { case "male": return Gender.MALE; //и т.п. 2)
Random randomizer = new Random(System.nanoTime()); //мелкая придирка, но System.nanoTime() писать не обязательно 3) in
for (int i = 0; i < cmdArguments.getCount(); i++) { System.out.println(engine.generateName(cmdArguments.getLength())); } System.out.println is better to put in a separate method, and better in a separate class (rule mvc)
four)
catch (FileNotFoundException e) { System.out.println(e); } catch (IOException e) { System.out.println(e); } change to
catch (Exception e) { System.err.println(e); //обратите внимание на err } five)
readData("male_names.txt"); here, too, it would be good to use enum. What if in the future you will not read data from a file, but from the Internet? Will url each time specify?
6) a huge amount
s.substring(i, i + 2); And why +2, not +3? A small comment would not hurt
7) A separate text explanation of how the algorithm works. Otherwise, it will be clear only to you.
0) But most importantly, after my recommendations not to turn into Boris from a famous article. How two programmers were baking bread
- 4) Is catch all good practice? - VladD
- @VladD, well, if nothing is done in catch, except for how an error is printed, then why not? - kandi
- 2@danpetruk: in the old version of the exception, only those that could arise due to objective reasons were caught: no file, read error, etc. In the new version, accessing a nonexistent index or a similar bug in the program will not lead to an emergency exit, but calmly swallowed ignored.
ON ERROR RESUME NEXT. - VladD - Thanks for your time and valuable comments - sinedsem
Oh, I do not like all these telepathies of the level "enter that, enter it, enter the crap that exit". Than the standard command line did not please?
-g, --gender= m[ale], f[emale], b[oth] -l, --length= name length -n, --number= number of names to generate Clearly and without unnecessary gestures. Especially since the standard GNU getopt () for Java has been around for a long time .
- @klopp, thanks for the tip, redid, used args4j - sinedsem