Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2004

Tip: Looking for answers? Try searching our database.

What's wrong with this code?

Thread view: 
Paul - 28 Jun 2004 04:03 GMT
Considering all aspects like style, naming conventions, logic etc...
Is this code OK? Please comment...

public void ReadMyData(string myConnString)
{
        string mySelectQuery = "SELECT OrderID, Customer FROM Orders";

        SqlConnection myConnection = new SqlConnection(myConnString);
        SqlCommand myCommand = new SqlCommand(mySelectQuery,myConnection);
           
        myConnection.Open();
           
        SqlDataReader myReader = myCommand.ExecuteReader();
           
        while (myReader.Read())
        {
    Console.WriteLine(myReader.GetInt32(0) + ", " +            myReader.GetString(1));
        }
       
        myReader.Close();
        myConnection.Close();
}

Thanks,
Paul.
Liz - 28 Jun 2004 04:23 GMT
> Considering all aspects like style, naming conventions, logic etc...
> Is this code OK? Please comment...
[quoted text clipped - 21 lines]
> Thanks,
> Paul.

I cut and pasted your offering and ran a tool "jcsc" on it. This tool
is supposed to see if your code matches the Sun coding standards for java.
Here is the output. Note that the NCSS = lines of code = 0, so it thinks
what you have is not valid enough to count it.
---
C:\tmp>jcsc test1.java
Encountered "void" at line 1, column 8.
Was expecting one of:
   "abstract" ...
   "interface" ...
   "public" ...
   "strictfp" ...
   "final" ...
   "class" ...

File: test1.java

Violations:

test1.java:1:1:interface Declaration JavaDoc does not provide the required
'@author' tag:TypeDeclarationAuthor:3
test1.java:1:1:interface Declaration JavaDoc does not provide the required
'@version' tag:TypeDeclarationVersion:3

2 violation(s) found

Metrics:

Total NCSS count      : 0
Total Methods count   : 0
Sudsy - 28 Jun 2004 04:30 GMT
> Considering all aspects like style, naming conventions, logic etc...
> Is this code OK? Please comment...
<snip>

How are we to know? There are methods you haven't included so we
don't know their signatures, specifically what exceptions can be
thrown.
Variable names are copacetic although the method names shouldn't
have a leading capital letter. I prefer the K&R style of braces
but this has always been a contentious issue.
I'm not about to enter into a religious discussion on that topic...
Roedy Green - 28 Jun 2004 05:34 GMT
>public void ReadMyData(string myConnString)
>{
[quoted text clipped - 14 lines]
>        myReader.Close();
>   

You could have discovered some of the errors with JavaC or better
Jikes in pendant mode.  See also http://mindprod.com/jgloss/lint.html

The things that stand out for me is the violation of the caps
conventions. See http://mindprod.com/jgloss/codingconventions.html

You are writing "string" for "String" which is not only a sylistic
error, but a syntax error as well.


Signature

Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

Roedy Green - 28 Jun 2004 05:41 GMT
>You could have discovered some of the errors with JavaC or better
>Jikes in pendant mode.

rather "pedant" mode.

Signature

Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

Christophe Vanfleteren - 28 Jun 2004 09:21 GMT
> Considering all aspects like style, naming conventions, logic etc...
> Is this code OK? Please comment...
[quoted text clipped - 21 lines]
> Thanks,
> Paul.

Why are you posting C# code on a Java newsgroup? They don't have the same
naming conventions anyway.

Signature

Kind regards,
Christophe Vanfleteren



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.