On Fri, Aug 22, 2008 at 9:59 AM, Sean Owen <[EMAIL PROTECTED]> wrote:

>
> One never needs to use this String constructor -- actually I am not
> sure why it exists:
> new String("foo")
> All it does is make a String that != "foo" (though it .equals("foo"))


This can be very important because strings can share structure.  I once had
a program that read a large file as a string and then used a construct like

     map.put(key, new String(s.substring(...)))

because otherwise the map would have a reference to s via the substring.

I agree about the string constructor applied to a constant.

main() can just "throws Exception" -- while normally bad practice to
> expose an API that throws so broad an exception signature, nobody
> should invoke main() in a program.


No.  Don't declare exceptions until they are thrown.  At the least, it
throws off the IDE's.

And mains shouldn't normally exist in this container-ized world.  If they do
exist, then they should be tested.  IF they are tested, then it helps to
know precisely what they might throw.  Besides, this saves you nothing.


> We should use Java-style array syntax instead of C-style: String[] foo
> instead of String foo[]. I always thought the latter was weird and not
> sure why Java preserved it.


this is a religious question without benefit.  You see it as weird.  That is
about all you can say about it.

Leave these alone.  The original author might have the opposite religion.

Another point of syntax: always use { and } even when the body is one
> line? I tend to favor it as it avoids this bug:
> if (...)
>  statement1;
>  statement 2 added sometime later but is not actually in the if statement;
> ... and also because it naturally adds a nearly-blank line after the
> body of the block


This is one of the few religious style issues I feel strong enough about to
change, at least if I have to work on that bit of code.

I would worry about the social consequences of changing all of them.

Where possible I think we should declare variables and arguments by
> interface, like:
> Map map = new HashMap();
> instead of
> HashMap map = new HashMap();


Strong +1.

Reply via email to