Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #1324

Re: Sorry for disturbing this page.....I need help Again

From Lew <lewbloch@gmail.com>
Newsgroups comp.lang.java.help
Subject Re: Sorry for disturbing this page.....I need help Again
Date 2011-11-11 07:18 -0800
Organization http://groups.google.com
Message-ID <19992967.114.1321024688323.JavaMail.geo-discussion-forums@prmf13> (permalink)
References <508339c1-3b13-4c0f-a2b4-d3af4be61ab6@e2g2000vbb.googlegroups.com>

Show all headers | View raw


I don't have your answer yet, but I do have advice about posting.

1) Fix your indentation and follow the conventions for it.

If you want people to help you analyze your code, you should make the effort to make your code readable.

2) The subject line should summarize the problem or insight contained in the body.

"sorry for disturbing this page" is a weak title.  It says nothing about what you're going to ask or say, there's no need to apologize anyway, and this isn't a "page".

2) Follow the Java code conventions.

Class names should start with an upper-case letter, non-constant variables and methods should start with a lower-case letter.

If you want people to help you analyze your code, you should make the effort to make your code readable.

The Java code conventions are available on the Oracle website.

3) Constructors are for construction.

You do a lot of logic in the constructor.  That's a very bad practice.  You are doing logic in an incomplete object.  That can lead to weird bugs.  Probably not the one you're facing now, but why take chances?

Constructors should only do the business of creating a complete object in a valid initial state.  That can involve some hairy logic occasionally, for example opening a remote resource, but that should be rare and only when justified in terms of establishing a valid initial state.

Everything else, nearly all action, should happen only after the constructor completes.

This is especially important in multi-threaded code such as yours.  All kinds of concurrency guarantees are null and void until construction completes.

4) Don't declare unnecessary variables, and don't declare them only at the front.

Variables, if and when needed, should be declared in the narrowest appropriate scope and near the point of use.

This is covered in Joshua Bloch's /Effective Java/ (2nd ed.), which no one should skip if they dare to call themselves a Java programmer.

These cleanup steps at a minimum will help make it easier to spot where things go wrong.

-- 
Lew

Back to comp.lang.java.help | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Sorry for disturbing this page.....I need help Again Michael Adedeji <yankosmgt@gmail.com> - 2011-11-11 01:31 -0800
  Re: Sorry for disturbing this page.....I need help Again Lew <lewbloch@gmail.com> - 2011-11-11 07:18 -0800
  Re: Sorry for disturbing this page.....I need help Again "John B. Matthews" <nospam@nospam.invalid> - 2011-11-12 07:29 -0500
    Re: Sorry for disturbing this page.....I need help Again Lew <lewbloch@gmail.com> - 2011-11-12 10:01 -0800
      Re: Sorry for disturbing this page.....I need help Again "John B. Matthews" <nospam@nospam.invalid> - 2011-11-12 22:38 -0500

csiph-web