Computer Science Canada Coding preferences |
Author: | Aziz [ Fri Sep 02, 2005 11:42 am ] | ||||||||
Post subject: | Coding preferences | ||||||||
This is more of a discussion, so if it needs to be moved please any mod do so ![]() 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:
VS
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:
or to they go after the variable name, like this, and whats the difference?
(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? |
Author: | rizzix [ Fri Sep 02, 2005 11:56 am ] | ||||
Post subject: | |||||
array brackets "should" always go after the Type. like this:
as for the braces.. well the standard java convention is to do it like this:
but then again.. no one's forcing you to do anything ![]() |
Author: | wtd [ Fri Sep 02, 2005 6:26 pm ] |
Post subject: | |
I find I prefer the style with braces on their own line. I like the extra space. |
Author: | [Gandalf] [ Fri Sep 02, 2005 7:21 pm ] |
Post subject: | |
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 ![]() |
Author: | [Gandalf] [ Fri Sep 02, 2005 8:34 pm ] |
Post subject: | |
What do you think on conventions of naming variables/functions/etc.? Generally, for myself... Variables - variableName Functions - Function_Name Class' - ClassName |
Author: | wtd [ Fri Sep 02, 2005 8:37 pm ] |
Post subject: | |
[Gandalf] wrote: 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 |
Author: | Aziz [ Fri Sep 02, 2005 10:22 pm ] |
Post subject: | |
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); |
Author: | rizzix [ Fri Sep 02, 2005 10:37 pm ] |
Post subject: | |
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.. |
Author: | wtd [ Fri Sep 02, 2005 10:38 pm ] | ||||||
Post subject: | |||||||
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:
Is an expression which generates the value 7.
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. |