Results 1 to 9 of 9
  1. #1
    gib65 is offline Member
    Join Date
    Jun 2010
    Posts
    86
    Rep Power
    0

    Default question about coding conventions

    Hello,

    I'm not exactly new to Java, but I'm new to some of the more recent coding conventions. Specifically, I want to ask about this:

    </title> <script language="JavaScript" type="text/javascript" src="/ocom/groups/systemobject/@mktg_admin/documents/webcontent/oraclelib.js"> </script> <style type="text/css"> HTML,BODY,TD,H1,H2,H3,H4,OL,UL,DL,LI,DT,DD {font-family:arial,helvetica,san

    It says that the proper way of writing an if statement is as follows:

    if (

    condition) {


    statement;
    }

    It says something similar for for statements:

    for (

    initialization;

    condition;

    update) {


    statements;
    }

    Now, I've been coding in Java for a long time and have seen a lot of other people's Java code, and I've never seen if or for statements in this form. It seems especially strange that they would insert a blank line, sometimes two, separating each component of the statements (not to mention a lack of indentation where there would usually be one).

    What I'm wondering is, even if this is technically the best or proper way to write these statements, would it really be frowned upon to write them in the more common way (at least, that I'm familiar with):

    if(condition) {
    ....statement;
    }

    for(initialization; condition; update) {
    ....statement;
    }

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Your formatting is right! I assume that the formatting of the code conventions was messed up in the Sun-Oracle transition.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    There is no technical way to write your statements in Java (actually in any other language too). It's matter of how far clear enough your code to others, all about readability. It's a general practice actually.

    The way you mentioned initially is a real hack to me. It's not organized at all. The second ways is the most common way to use in Java. But in .Net it's something like this.

    Java Code:
    if(condition)
    {
           // body
    }

  4. #4
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    I've never seen anyone write code like that, including example codes in Sun's Tutorial.
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    That pattern is using more in JavaScripts. I don't know why it is really, but with the simple syntax that JS has it's much clear in that format. But not in Java at all.

  6. #6
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    I've filed a complaint at Oracle and requested a clean up.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  7. #7
    gib65 is offline Member
    Join Date
    Jun 2010
    Posts
    86
    Rep Power
    0

    Default

    Thanks everyone. That clears up a lot of confusion for me.

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by PhHein View Post
    I've filed a complaint at Oracle and requested a clean up.
    Sounds good. ;)

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by gib65 View Post
    Thanks everyone. That clears up a lot of confusion for me.
    If you search the forum, it's possible to find quite similar discussions in our forum.

Similar Threads

  1. A difficult question - efficient coding?
    By tyang in forum Advanced Java
    Replies: 3
    Last Post: 02-05-2010, 03:48 PM
  2. Coding help
    By Java_Fanatic in forum New To Java
    Replies: 7
    Last Post: 10-15-2009, 05:37 AM
  3. Naming conventions
    By tim in forum Forum Lobby
    Replies: 10
    Last Post: 11-16-2008, 10:27 PM
  4. Naming conventions
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-03-2007, 10:53 AM
  5. namespace conventions from sun....
    By money123 in forum New To Java
    Replies: 3
    Last Post: 07-31-2007, 06:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •