Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
We are writing a hierarchy of classes that implement various ways to represent languages. There is a base LanguageCode class with several subclasses, including ISO1LanguageCode for ISO 639-1 codes (example: 'en'), ISO2LanguageCode for ISO 639-2 codes (example: 'eng'), and HumanReadableLanguageCode (example: 'English'). At any time, we need to be able to convert between any two of the subclasses. Is there some design pattern magic we could use here to help?
Note:
Our first idea was to standardize the base class and make each subclass write a conversion routine between itself and the standard on the base class. That way, to convert between ISO2LanguageCode and HumanReadableLanguageCode, use LanguageCode as a bridge.
There is only one set of languages. Each language has an -1 code, a useless -2 code, and a -3 code. And a human-readable name. So make one enum with accessors to return the different codes, and multiple lookup static methods.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I'm a little confused with the naming conventions used in default functional interface names available in javax.util.function package:
For instance, primitive specialization of Function have names like:
IntFunction/LongFunction/DoubleFunction in which argument type is of specified type
But primitive specialization of Supplier have names like:
BooleanSupplier/DoubleSupplier/LongSupplier/IntSupplier in which return type is of specified type.
If you compare the name and functionality of other interfaces in java.util.function, shouldn't the names have been like:
ToBooleanSupplier/ToDoubleSupplier/ToLongSupplier/ToIntSupplier?
The word "to" in ToIntFunction, ToDoubleFunction, et al indicates that something is being converted to something else. The function's input parameters are being converted into an int/double/whatever.
The word "supplier" denotes a function that takes no input and returns some value. It supplies values. There's no input, only output.
Adding "to" would be redundant and/or misleading: redundant because the fact that it returns values is already indicated by the word "supplier"; misleading because there's no conversion. The values are generated out of thin air.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I was wondering what is the reason behind this and why we cannot use any symbol than those two, I think I never use a variable with those symbols but it is worth to know the cause
The $ in variables is a historical convention that is commonly used in Linux systems (among other languages) to call variables. In a Linux system, if I set a variable, I call it with this key (i.e. x = 4, echo $x).
Underscores and Camel Case are 2 common ways to identify multi-word variables. If I want to declare the variable iLoveJava or I_Love_Java, both are easily readable.
Of course, all of this is a rationalization of stylistic choices made by Sun Microsystems when they made the language, but I think it's a fair interpretation ;). If you want more details on why the others aren't used in detail, the link posted by Sercan is excellent information as well.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
If I split a String permIp, Is there a specific naming convention that is considered to be correct that I should follow for the String[] that I create, such as permIps, permIpSplit or splitPermIp? Or is this a matter of personal preference?
permIpSplit seems fine. The naming convention should be camel casing and ensuring that it conveys the correct meaning to the people reading it apart from you. So including split in the variable name should do.
That all depends on what code style you have decided to go with. There is no set rule for naming conventions. There are lots of examples of different code styles but they are all just guidelines. A good place to start might be googles though.
https://google-styleguide.googlecode.com/svn/trunk/javaguide.html#s5.2.7-local-variable-names
There is no naming convention for the spiltted String[] array. Use usual java naming convention for variable name which is suitable for array and also suitable for the original String which is being splitted.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I have to deal with a domain object that's real name is 351K-Report. According to the Java naming convention its forbidden to use a number at the beginning of an identifier.
I don't want to fully spell out the number. And, I also think that it's a bad idea to place an underline in front of the number.
But what is the recommended alternative?
UPDATE
There are also other reports, like SpecReport, TopReport, LF10Report and so on. So I'm very doubtful that inverting parts of the noun changes the meaning of the whole project.
Maybe reverse it. For example:
report351K
That would be very bad..
Imagine this:
int 1d = 3;
double d = 1d * 2;
What would be d?
Alternatives:
Since variables that begins with _ usually indicates for class member, I would use report351K.
if you really want to do this then _351KReport but I don't think you should do this. try to make something meaningful of it and at the same time is convineient to Java
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
In Java, there's a naming convention for classes, interfaces, packages, methods, variables and constants. I'm just wondering if there is a naming convention for JSF XHTML pages.
Here are a few variants that came up to my mind:
MyPage.xhtml
myPage.xhtml
my-page.xhtml
mypage.xhtml
There's no need to think of xhtml pages as something different from plain html pages. In the end, if a user has to type it out, then it would help to have a simple page name (just like we would name any html page).
To give you an example, even a company like Apple who are so specific about using the correct case for their products, still maintain a URL such as http://www.apple.com/iphone! (iPhone is written as iphone)
To summarize I would say, don't use capital letters in URL, and try not to use special characters either.
Camel-case starting with a lowercase letter is good, I use hyphens to distinguish modules/ subpages/ subelements.
For example:
productList.xhtml
productEdit.xhtml
productEdit-buttons.xhtml
productReport.xhtml
customerAddress.xhtml
customerAddress-map.xhtml
Not a formal convention, but it works well. Being able to modularize or identify fragments or sub-functions is useful.