grzesiek-galezowski / tdd-ebook

Test-Driven Development - Extensive Tutorial. Open Source ebook
https://leanpub.com/tdd-ebook
Other
361 stars 57 forks source link

Java Code Convention - methods #97

Closed sandarovich closed 6 years ago

sandarovich commented 6 years ago

It's confusing to read examples with upper-cased method name. Could you please clarify why such convention was used.

According to classic school: Methods | Methods should be verbs, in mixed case with the **

first letter lowercase,

** with the first letter of each internal word capitalized.

http://www.oracle.com/technetwork/java/codeconventions-135099.html

grzesiek-galezowski commented 6 years ago

Hi, the programming language of choice for the book is C#, which has the convention of pascal case method names. I only used Java code twice in the book and in both places the method names begin with lowercase.

As much as I try to avoid C#-specific syntax (such as properties, events and so on) in the examples to make it as readable as possible to Java users, the two communities decided to adopt different conventions and there is not much I can do about it :-(. Personally, I try to honor the conventions of the language I use, e.g. Ruby has ClassName and method_name (is you look at rake scripts in this repository, they follow this convention), Java has ClassName and methodName and C# has ClassName and MethodName.

grzesiek-galezowski commented 6 years ago

Hypothetically, nothing stops one from creating a fork with examples in Java (the license is CCPL), but no one has stepped up yet :-)

sandarovich commented 6 years ago

Thank you for detailed feedback. I see what you mean. Now I realized this language convention trade-off. From this point of view this issue is no longer relevant. So I am closing issue.

grzesiek-galezowski commented 6 years ago

Thanks, by the way, thanks to you I noticed one java code fragment where I mistakenly used a capital letter. And I may probably add some small disclaimer at the beginning of the book to make it clear that C# is the language for examples and to explain some core differences between Java and C# that would make it easier for Java users to take advantage of the book.

Thank you for your feedback!! 👍

grzesiek-galezowski commented 6 years ago

I wrote https://github.com/grzesiek-galezowski/tdd-ebook/blob/master/manuscript/017_CodeExamples.md

Can you take a look and let me know what you think?

sandarovich commented 6 years ago

Everything is seems to be Ok. One small thing is need small polish. In this example: public class User { private final int DEFAULT_AGE = 15; private final List<Integer> MARKS = new ArrayList<Integer>(); }

should be

private static final int DEFAULT_AGE = 15; private static final List<Integer> MARKS = new ArrayList<>(); you can avoid specifying generic, modern Java will understand and get type automatically.

grzesiek-galezowski commented 6 years ago

Sure, thanks for catching the unnecessary type. And I messed up the naming convention for final fields - I'll improve this example.

grzesiek-galezowski commented 6 years ago

Pushed 0405fcf22e51ef2ad0c30c7df7106ac6dcc7cc14 - should be more correct.

grzesiek-galezowski commented 6 years ago

and 842ca5e1d5959dda136d13956558fb2c08f3b1e8

martinmoene commented 6 years ago

This is in order to allow users of other languages (especially Java) to benefit from the book.

This is in order to allow This allows users

while in C# it is defined like this:

Whereas in C#

grzesiek-galezowski commented 6 years ago

Thanks - will fix it! By the way, I'm looking for a better way to write this sentence:

"The other difference is that in C# there is no type erasure as there is in Java." It seems clumsy to me.

TiburonzinGT commented 6 years ago

@grzesiek-galezowski Hello, I would like to translate to Spanish but I do not know how. I would like to do it by means of pull request :)

grzesiek-galezowski commented 6 years ago

@shadowz10 please take a look at #92 . Unfortunately, I already gave away the spare book slot I was talking about somewhere in that issue, but otherwise, it's up to date.

grzesiek-galezowski commented 6 years ago

Closing this. By the way, @shadowz10 , Leanpub changed their pricing plans, so creating a new book is free again. You can check it out.