Function Name Conventions(Any Kind of PL) [closed] - java

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
Is it bad to use Underscores in Function Names? Can I know the reason why?
ie:
Function GET_NAME(byval sword as string) as string

Not at all. The coding convention is a very subjective term. One might feel one coding style great and another find it worse. The key point is maintain one coding style only throughout your code for ease of upcoming developers and maintainers.
However, avoid all caps for function names (as shown in your example). It's generally reserved for macros (C/C++) / constants.

I would use them sparingly in my own API, but to say that they are bad is simply untrue. If so, .NET specifically would have problems with default naming for event handlers!
void Form_Load( //...
void Page_Load( //...
void btn_Click( //...
// etc.

In this specific case, all caps with underscore separators are generally understood to be constant values.

Firstly, its very subjective matter and depends from Person to Person. One may feel like using _ in function, others may not. There's no harm if you use it.
Frankly speaking, you don't usually use _ sign. But, you can to use this '_' in the variable declaration.
Note : You can check out the msdn link ( atleast for C#,
Visual Basic, C++ )

Related

Class name convention in java [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
What is the naming convention of classes in java, for example should all classes be in upper case like MYCLASS.java ?
as some classes like com.sun.org.apache.bcel.internal.generic. ANEWARRAY. can be found in Sun's library as well
Note: I have read all naming convention from Oracle but I could not find anything which says we should name a class with All Uppercase.
Class Names should be in CamelCase. Try to use nouns because a class is normally representing something in the real world.
The Documentation states the following:
Class names should be nouns, in mixed case with the first letter of
each internal word capitalized. Try to keep your class names simple
and descriptive. Use whole words-avoid acronyms and abbreviations
(unless the abbreviation is much more widely used than the long form,
such as URL or HTML).
Java has a very well described naming / coding convention.
You can look it up here http://www.oracle.com/technetwork/java/javase/documentation/codeconvtoc-136057.html
Technically it doesn't matter how you name you classes as long as public classes are in a .java-source file with the same name as the class.
The quoted class com.sun.org.apache.bcel.internal.generic.ANEWARRAY looks to be from the deep innerworking of Java (internal.generic), i.e. not for developer use. As such its really outside of the naming convention. I can only speculate as to why its all in capitals, perhaps to emphasise this point that it shouldn't be used.
Usually the best practise is to use Upper CamelCase.anyway there will be no compilation issues with other conventions.see more details about conventions
After browsing through many links I came to know there is no java convention which suggests us to name a class in all uppercases. However we do so there will not be any error.
One appropriate reason is mentioned by CloudyMarble that we can use this convention if the abbreviation is more famous like HTML.
Also I would like to add some info about ANEWARRAY, this class comes under Apache license Source and Create new array of references.

Proper Java classes structure [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I'm currently in the process of cleaning up a a large Java code base, and I was wondering what was the proper (standard?) structure/ordering of a Java class.
What I mean is:
Should public static final fields be first among the fields of a Class?
Where should a static initializer be?
Where should private static helper methods be?
Also, as a side question: is it a good idea to have large harcoded SQL queries for PrepareStatements in the code?
You should be more worried about naming convention, clear code documentation and overall the correctness of the program (i.e. no bugs), after this you can worry about the order of defining variables, methods etc
This is the code convention for Java
To answer (some) of your points:
static initializer usually appears in the begining of your classes, after the variables if it happen to come first.
private methods can go to the end of your class (before variables if they are at the end), but it is matter of preference, because usually the one who reads the code care more about the public methods that the class expose to the rest of the program
Having the SQL statement inside the program or stored externally (e.g. properties file) depends on how often they are changing; but as long as you are using PreparedStatement you should be OK.
Well, here you're gonna find Java code conventions: Java Code Conventions
I really don't like harcoded SQL statements. But, sometimes they are necessary. See if you can encapsulate that on a library (like hibernate or something), or if at least you can break it into minor sql codes.
Adding
I would also take a look at: How to Write Doc Comments for the Javadoc Tool to mantain your code well documented.

Why should I use encapsulation vs abstraction? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I have always gone with the popular convention of using access modifiers and encapsulation in order to make sure a class wouldn't break if it was implemented wrong. However, I have noticed that OOP really doesn't need encapsulation and that using access modifiers actually induces more headaches than benefits. Additionally, by not using access modifiers you are being more of an OO programmer. My reasoning is listed below.
Python supports OOP yet it does not use access modifiers or encapsulation. Showing that in OOP languages access modifiers are not mandatory.
Although compilers are more advanced are still nano-second differences between using accessor method versus variable access. In restricted systems like Android this would affect a games FPS drastically. (Although using the final modifier on methods would reduce the nano-second difference significantly in most cases)
By not using private or package modifiers coding gets simpler and faster for the original coder. Future user of the class would still be able to use public interfaces without breaking or playing with the class implementations. Furthermore, if he wishes to modify or upgrade the class he may still do so and access the private modifiers. In an analogy, when you decide to modify a car you know there is a possibility that you may break something, but if you're willing to take the risks and know what you're doing being allowed to open a lock that has a clear sign saying (open at your own risks) is better than having to replace the unbreakable lock, locking the part you wish to modify.
What I do now is a mix of public modifiers for public interfaces and protected modifiers for implementation details so users can do their risk-taking by sub-classing. Is there any reason why I should reconsider doing this instead of conventional encapsulation?

Good name for a list variable in java [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
What of the following is used popularly or is the standard :
private List<String> names ;
OR
private List<String> listOfNames ;
OR
private List<String> namesList ;
Once upon a time we had Hungarian notation, because IDEs didn't provide intellisense and programmers were too dumb to realise that having a 30,000 line long block of code was unreadable*. Nowadays IDEs are friendly, programmers have started using small, neat classes, we have JavaDoc and things in genral are easier to read.
So, just name your variable for its usage. i.e. names. I'm no fan of pre/post-fixing variables as it often makes them harder to understand.
(*) i.e. Me, there's probably some deeply shameful code out there with my name on it.
Depends on the use case.
names
If this is the only "names" variable
namesList
If therr are other names collestions (e.g. namesSet) in your code.
private List<String> listOfNames
Is wrong; if you will be so specific you should write listOfStrings or
private List<Name> listOfNames
redefine your type (whatever Name is).
The conventional name will be namesList.
PS : If you use auto complete in Eclipse you'll see that.!
Regarding variable name, you can use anything.
My team says after reading variable name, one should understand what that variable will hold data BUT variable name should be as per Java naming convention.
In your case I would go with listOfNames, because it will say the variable is of type list and it has names.
Also read Java naming convention.
whatever is suitable for you and your team go with that.
IDEs are very smart they will take for everything else like what a given name stands for, type, permissions etc.

Keyword arguments for java? What do you think? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
This really isn't so much an answerable question as a 'What do you think' question.
In python, the programmer has the option to use keywords arguments in their function calls. For example
def doSomething(test=True, numBacon=5, ...):
Does any one other than me think that would be a fantasic idea for java? I know that varargs can do a lot, but it doesn't come close to being as useful are keyword arguments. So I ask the world, what do you think?
It might - if you could pass a map into a method, which would look up the map's keyed entries. It would require an inline, typeless map declaration, which wouldn't be very useful outside of this kind of limited scope - and since it'd be very limited, I'd end up saying "No, not required." If you want the facility, use Python. If you want the capability in a JVM, use Jython or JRuby.

Categories