
-----------------------------------
Aziz
Fri Sep 02, 2005 11:42 am

Coding preferences
-----------------------------------
This is more of a discussion, so if it needs to be moved please any mod do so :P

But anywho, there are several coding preferences that differ but don't really make a difference. One I've been thinking about lately is this: Brackets {}

For example, two ways I've seen of coding is:

public class MyClass {
	public static void main(String

VS

public class MyClass
{
	public static void main(String

I know the code doesn't matter each way, but what do you guys do and why?

Another thing that's poked my curiosity is the array brackets

Do they go after the identifier, this this:

String

or to they go after the variable name, like this, and whats the difference?

String names

(This always has annoyed me) is it main(String[] args) or main(String args[]) =\

I suppose it would be more effecient to do this: String[] names1, names2, names3; so it might answer my own dilemna. Anyways, I guessm discuss?

-----------------------------------
rizzix
Fri Sep 02, 2005 11:56 am


-----------------------------------
array brackets "should" always go after the Type. like this:Stringif you do it the other way... well let's just say no one's gonna consider you a java programmer... no really! you see.. java supported the other syntax so it would be easier for C programmers to adopt the language (back in those days). it continues to support it.. cuz not supporting it coud break legacy code.. anyways.. you are expected to use the syantax i mention above.. ALWAYS!

as for the braces.. well the standard java convention is to do it like this:void something() {
    return;
} yea we follow the standard C convention... it's usually the c++ programmers who do it the other way (where u open it in a new line)..

but then again.. no one's forcing you to do anything ;) they are just conventions..

-----------------------------------
wtd
Fri Sep 02, 2005 6:26 pm


-----------------------------------
I find I prefer the style with braces on their own line.  I like the extra space.

-----------------------------------
[Gandalf]
Fri Sep 02, 2005 7:21 pm


-----------------------------------
I always put the braces on a seperate line.  It makes it way more readable, and it makes me hate Java for having a weird convention.  Actually, I see many C, C++, and Java programs that use the 'Java' way, but I really dislike it :).

-----------------------------------
[Gandalf]
Fri Sep 02, 2005 8:34 pm


-----------------------------------
What do you think on conventions of naming variables/functions/etc.?

Generally, for myself...

Variables - variableName
Functions - Function_Name
Class' - ClassName

-----------------------------------
wtd
Fri Sep 02, 2005 8:37 pm


-----------------------------------
"]What do you think on conventions of naming variables/functions/etc.?

Generally, for myself...

Variables - variableName
Functions - Function_Name
Class' - ClassName

For these the Java conventions are very good to follow.

variableNames
methodNames
CONSTANT_NAME
ClassName

-----------------------------------
Aziz
Fri Sep 02, 2005 10:22 pm


-----------------------------------
Another thing, I've heard the expression "expression > statement" or so i think at least. Now, this means like this, right:

names = sort(names);

is more effiecient than

sort(names);

-----------------------------------
rizzix
Fri Sep 02, 2005 10:37 pm


-----------------------------------
no not necesaritly efficient.. just the better way of going about with things.... as far as possible never ever modify the state of the objects passed as arguements to your methods or constructors.... it's just not the standard way of going about with things.. and it's not what would be considered.. expected behaviour... especially if sort is not a static method..

-----------------------------------
wtd
Fri Sep 02, 2005 10:38 pm


-----------------------------------
The difference between expressions and statements is an important one.

An expression is a piece of code which takes one or more values and generates a new value.  

Consider:

int a = 5;

a + 2

Is an expression which generates the value 7.

a = a + 5;

Is a statement.  It changes the value of the variable "a".  Of course, this statement incorporates an expression.

Statements may contain expressions.  Since expressions don't change existing values, they cannot include statements.
