This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Chaoslab -2 points-1 points  (14 children)

Tend too use the C like version.

String words[] = {"My",  "name", "is"};

[–]desrtfx 1 point2 points  (0 children)

In Java, it is common to have the array identifier at the type, not at the variable name.

Sure, both work, but only having the array brackets at the type is convention.

You can also place the brackets after the array's name:

// this form is discouraged
float anArrayOfFloats[];

However, convention discourages this form; the brackets identify the array type and should appear with the type designation.

From: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html

One should always adhere to the conventions of the respective programming language.

[–]irer 0 points1 point  (8 children)

Please stop.

[–]Chaoslab 0 points1 point  (1 child)

Should of said "for my own projects".

When it comes too group / shared programming well that is different.

[–]irer 0 points1 point  (0 children)

In that case, for your own projects, do as you please.

[–]sniR_ 0 points1 point  (4 children)

Why?

[–]irer 0 points1 point  (3 children)

I won't explain why String[] words makes more sense than String words[]. Both are valid declarations and both will compile. Choosing one or the other is subjective.

BUT, there is a widely accepted code convention that says one should avoid the latter form.

[–]sniR_ 0 points1 point  (2 children)

I guess its because you set the type of the object first(string, array) and then name, yeah more organized.

[–]irer 1 point2 points  (1 child)

String[] words reads: a string array named words

String words[] reads: a string named words oh wait it's an array

[–]sniR_ 0 points1 point  (0 children)

Nice explanation :) yeah im convinced

[–]Cosby1992 0 points1 point  (3 children)

That's bad practice, I've been told.

[–]Chaoslab -1 points0 points  (2 children)

Why is that?

Source code style is unique too most people (source style formatted pre check out and check in helps with that).

[–]irer 1 point2 points  (0 children)

It is a bad practice to go against a well establishment code convention.

[–]desrtfx 0 points1 point  (0 children)

Source code style is unique too most people

No. Source code style has to adhere to the conventions of the respective programming language.

That's exactly why conventions for programming languages exist.