Code formatting conventions

This question isn't really specific to java, but where did the convention to format code in following form come from?
if (something) {
   statement;
   statement;
}surely laying out code in the following format is far more readable:
if (something)
   statement;
   statement;
}In the second way, it's easy to match up the braces and see if and where any are missing (particularly in more complex code), so what's the point in the first (and more commonly used) convention???

my question was, "Where did the first style come
from?" as it is the convention most often seen in
tutorials (such as at java.sun.com), but is less
readable than the second example.
This statement is all about perception. When I first started with Java, I used to use your second example costantly. I don't know how it happened, but after some time, I started using K&R all the time (there was a short period where I would use both, even in the same program, I was very confused back then).
A few weeks ago, I went back to look at a one of the first programs I ever wrote in Java, and I about puked on the screen when I saw how the braces were layed out. I had an adverse physical reaction to something that I did, that at the time, I thought was perfectly acceptable and very readable.
Because I realize that I've used both and at one time or another thought both were perfectly acceptable, I try not to have an opinion one way or the other, but I know what I like so that is what I use.

Similar Messages

  • My auto-indent and code formatting is not working.

    Usually on dreamweaver CS5.5 my code (html) would indent my <div> tags and align them up with the end div </div>. Not only were the <siv> tags formateed but various of others tags were as well.
    How Dreamweaver used to format my code:
    <head>
              <title>Example</title>
              <link rel="stylesheet" href="style.css" type="text/css" media="screen" />
    </head>
    <body>
    <div id="outside_container">
              <div id="container">
                        <a href="#"><img src="images/logo.jpg" id="logo" /></a>
            <ul id="menu">
                      <li><a href="#"></a></li>
                      <li><a href="#"></a></li>
                      <li><a href="#"></a></li>                   
                        </ul>
            <ul id="right_menu">
                      <li><a href="#">t</a></li>
                      <li><a href="#">t</a></li>
            </ul>
            <img src="images/panel_home.jpg" id="panel" />
                        <div id="content">
                      <div class="column1">
                          <h2>Text</h2>
                    <p>Text Here</p>
                </div>
    Now it does not even format it so all of my code aligns on the left like so:
    <head>
    <title>Example</title>
    <link rel="stylesheet" href="style.css" type="text/css" media="screen" />
    </head>
    <body>
    <div id="outside_container">
    <div id="container">
    <a href="#"><img src="images/logo.jpg" id="logo" /></a>
    <ul id="menu">
    <li><a href="#"></a></li>
    <li><a href="#"></a></li>
    <li><a href="#"></a></li>                   
    </ul>
    <ul id="right_menu">
    <li><a href="#">t</a></li>
    <li><a href="#">t</a></li>
    </ul>
    <img src="images/panel_home.jpg" id="panel" />
    Can anybody please help me?

    Did you try Edit > Preferences > Code Format > Indent?
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists 
    http://alt-web.com/
    http://twitter.com/altweb

  • Code Formating after Forum Software Upgrade

    Hello SCN Forum Administrators,
    it seems that all code formating which was done with the
    [code]
    Tags was not automatically converted during the Forum Software Upgrade. What can I do to correct my code in the Forum Topic Re: Display ALV GRID with PHP? The message was posted by myself but I can't edit it.
    Best regards
    Gregor

    Hi all,
    the new forum version does contain a filter that can handle the old &#91;code&#93; tags. The problem was that we had to turn it off because it permanently ran into Stackoverflow errors and thus bringing the whole landscape into trouble.
    Now we have to convert all the old &#91;code&#93; markup in all messages with the new &#123;code&#125; markup. We are currently testing this.
    In other words: &#91;code&#93; is no longer supported, the usage of &#123;code&#125; is recommended.
    Regards,
    Michael

  • Code formatting, indenting, and commenting

    This question was posted in response to the following article: http://help.adobe.com/en_US/flashbuilder/using/WSe4e4b720da9dedb5-25a895a612e8e9b8c8e-7fff .html

    MXML code formatting options are very limited in Flash Builder 4.5. Compare that to the vast amount of options you have to format Java code in Eclipse. I would expect more from a proprietary software.

  • Code formatting made thing worse

    After CTRL+ALT+L (Code Reformat) in JDeveloper 11g, things got worse:
    Eg.:
    http://i.imgur.com/pEKtS.png
    Normally it should like this (at least this is how other IDEs are reformatting code):
    http://imgur.com/MRSW0
    or this:
    http://i.imgur.com/Dkyry.png
    I've tried to fine-grain code formatting from: Tools -> Preferences -> Code Style but the results weren't satisfactory .
    Does anyone know where i can find a Code Style profile .xml file that won't mess the looks of my code, just like the default one did ?

    Hi,
    in 11.1.1.5, I quickly created
        public void mytest() throws FileNotFoundException {
            List credentialFiles = null;
            for (File f: credentialFiles){
               fis = new FileInputStream(f);
               String name = f.getName();
    new Departments(new Long(2236),
                    "Sales 33",
                    new Long(100),
                    new Long(200),
                    new EmployeesList());
    }Then I hit ctrl-alt-l and the outcome s
        public void mytest() throws FileNotFoundException {
            List credentialFiles = null;
            for (File f : credentialFiles) {
                fis = new FileInputStream(f);
                String name = f.getName();
                new Departments(new Long(2236), "Sales 33", new Long(100),
                                new Long(200), new EmployeesList());
        }Its not really what I would call worse
    Frank

  • Code Formatting Instructions for Developer Forums

    Although this topic only applies to the two Developer forums, the need for some upfront code formatting instructions in those forums is desperate. There may be hundreds of threads which include one or more messages on this subject. In my case alone, I've posted at least a dozen messages each containing these three lines:
    Paste your code here.
    Of course a quick search of either Dev forum on the keys +code formatting+ will find the above right away, but those who need help the most don't know code requires special formatting so won't be making that search. For the same reason, neither the excellent instructions in the User Tips Library nor the pertinent threads in this forum are likely to be discovered before they're needed. The +Help & Terms of Use+ FAQ might seem to be a good place for the instructions, but this has been proposed so many times before I'm sure it will never happen. The need is confined to the Dev forums afterall.
    I think the solution would be a permanent post (similar to +How to Post a new Topic+ in this forum) at the top of both Dev forums. I don't think most developers want to see instructions on any other topic at the top of the forums, but a brief note titled +How to Post Code+ might make everyone's life easier.
    Assuming most of the other developers agree, how could we make this happen?

    Thanks so much for helping with this, Nubz!
    Joerg's instructions are excellent. I refer to them often and I've had them bookmarked since I found Apple Discussions last year. The new Code section is great!! Very clear!
    Now we just need to find a way to get users to that page. Our problem has never been with users who are interested enough in Apple Discussions to visit the Tips Library. The unformatted code is coming from first-time users--not necessarily novice coders, but programmers of all skill levels who aren't coming here to learn about the forums or relate to the community. These folks are focused on their current project, may have found no answers anywhere else, and arrive here with tunnel vision. Often there's a language problem as well.
    The newly arrived OP will often start the thread with a page of unformatted code. Those of us with eyes used to filling in the missing brackets, indentation etc. can sometimes decypher the mess, but usually we need to give formatting instructions and ask the OP to repost. The frequency of this scenario has been increasing. Lately I've been posting those instructions almost once every day.
    Of course that's a good sign! We've been giving good service down there and the number of newcomers seems to be reflecting that. A big percentage have turned into regulars, so I think we have a very healthy forum. It's just the formatting cycle gets old, and the time and bytes add up too.
    My suggestion is this:
    One yellow moderator announcement that stays in the first position on the topic page for both dev forums. The subject line is:
    To format code: Paste your code here
    The user doesn't even need to open the message. Only developers will see this. No change to the page header is needed. If the user does open the message, a link will be provided to Joerg's tips.
    - Ray

  • Code formatting problem

    Is the code formatting buggy or is it just that I cannot seem to find the correct mix of settings? I hope it is the latter and that someone here may know how to get it
    After setting the settings I think I want I get a simple SQL formatted like this.
    {noformat}
    select username
    ,sid
    ,serial#
       from v$session
      where sid  = 11
      and(status = 'ACTIVE'
      or status  = 'INACTIVE')
    {noformat}Ignore the fact that the actual query may not be logical...
    The first problem is that the different columns are lined up to the left and not indented lika I would like them to be.
    The second (and much less important) is that the and/or are not indented like the keywords. I'd like to get the SQL to be formatted like this.
    {noformat}
    select username
           ,sid
           ,serial#
       from v$session
      where sid    = 11
        and(status = 'ACTIVE'
         or status = 'INACTIVE')
    {noformat}How can I make the code formatting result in the above SQL (especially the aligning of the columns)?

    Turloch,
    Thank you for the reply. I figured this may be a bug, so it is nice to have it confirmed. I can live with it not being correct as long as a fix will show up eventually.
    The problem with using tabs or large settings for space is that it causes other parts of PLSQL to look to spread out. One thing that happens is that the right justification of the keywords gets messed up. But I can make soem SQL look OK with it, but that is at the expense of getting other ones to not look good. For example if I get the columns to line up with a leading comma, the concatenation is not correct and vice versa. I also get SQL to look better, but then indentation in PLSQL is too agressive and looks very bad.
    I would like to be able to set and/or to be set to be handled as keywords so they too can be right justified. Columns (whether or not concatenated or separated with a comma) should be possible to align with the column in which the first column starts.
    While I'm at it, there seems to be an issue with the formatting of keywords such as inner join. I think inner too should be considered keywords so it can be right justified with other keywords. Same thing with subselects, they end up the the left of the right column of the keywords.
    I think the formatting features are really good now. There is still room for improvement to be able to control it enough to make it look exactly like I want, but it is getting close and flexible enough to allow many different ideas of how the template should be to be configured.
    Thanks,
    Mathias

  • Dreamweaver CS3 Code Formatting broken

    Hello, I am experiencing a huge deal of frustration with the
    way Dreamweaver improperly formats code. In particular, the UL / LI
    tags do not format correctly. Here is what I am trying to achieve:
    <ul>
    <li>
    TEXT
    </li>
    </ul>
    Now this pattern seems to correspond exactly to the preview
    that you see when you go to Preferences > Code Format > Tag
    Libraries, select the LI tag and choose Line Breaks: Before,
    Inside, After and Contents: Formatted and Indented.
    I have done this. I have also manually checked the .vtm file
    in username > Application Data > Adobe > Dreamweaver >
    Configuration etc.... and it corresponds to what I have set in the
    Prefs.
    However, when I use Design View to create the unordered list,
    OR even if I just TOUCH a properly formatted list in Design View,
    everything gets squeezed onto one line. I get this sort of thing:
    <ul> <li>TEST</li> <li>MORE
    TEST</li> </ul>
    Here is what I have tried unsuccessfully to date:
    1. Prefs > Code Formatting > Edit Tag Libraries...
    2. Prefs > Code Format > UNCHECK Do not include a break
    inside TD tag (I know, that's for TD, but I'm just trying
    everything(
    3. Prefs -> line breaks (tried Unix, Windows)
    4. Commands > Apply Source Formatting (messes up my entire
    code by putting everything inside the BODY tag on one line - in
    other words, my entire page goes on one line now!)
    5. Automatic Wrapping After Column 76 - this one is really
    stupid, it just does a HARD break on each line so when you turn it
    back off you have to go in and manually delete all these hard
    breaks now...
    There's a bunch of other small things I have tried, but
    needless to say, nothing appears to be working.
    Has no one else experienced this? Can you get Design View to
    properly format UL / LI tags? If so, then something on my computer
    is messed. But when I look at code generated by DW on some of my
    co-workers' computers, they also have the same problem - I just
    guess their tolerance for crappy code is higher than mine.
    I'm using DW 9.0 (CS3) build 3481.
    Please help! I have no hair left on my head to tear out and I
    may have to go further afield.... ouch!
    Thanks,
    Tom

    I just checked on DW CS4 and it's working as expected. If I
    change my LI
    entry in the Tag Libraries to Line Breaks: Before, Inside,
    After and
    Contents like you, I get your desired effect. Moreover, it
    doesn't revert -
    or worse if any changes are made, whether in Design or Code
    view. I know
    this doesn't help you verify or correct your CS3 issue, but
    at least you
    know there is an upgradeable light at the end of the tunnel.
    Best - Joe
    Joseph Lowery
    VP of Product Management, WebAssist -
    http://www.webassist.com
    Author, Dreamweaver CS3 Bible -
    http://www.idest.com/dreamweaver/
    "tomaugerdotcom" <[email protected]> wrote
    in message
    news:[email protected]...
    > Hello, I am experiencing a huge deal of frustration with
    the way
    > Dreamweaver
    > improperly formats code. In particular, the UL / LI tags
    do not format
    > correctly. Here is what I am trying to achieve:
    >
    >
    > TEXT
    > </li>
    >
    >
    > Now this pattern seems to correspond exactly to the
    preview that you see
    > when
    > you go to Preferences > Code Format > Tag
    Libraries, select the LI tag and
    > choose Line Breaks: Before, Inside, After and Contents:
    Formatted and
    > Indented.
    >
    > I have done this. I have also manually checked the .vtm
    file in username >
    > Application Data > Adobe > Dreamweaver >
    Configuration etc.... and it
    > corresponds to what I have set in the Prefs.
    >
    > However, when I use Design View to create the unordered
    list, OR even if I
    > just TOUCH a properly formatted list in Design View,
    everything gets
    > squeezed
    > onto one line. I get this sort of thing:
    >
    TEST</li>
    MORE TEST</li>
    >
    > Here is what I have tried unsuccessfully to date:
    >
    > 1. Prefs > Code Formatting > Edit Tag Libraries...
    > 2. Prefs > Code Format > UNCHECK Do not include a
    break inside TD tag (I
    > know,
    > that's for TD, but I'm just trying everything(
    > 3. Prefs -> line breaks (tried Unix, Windows)
    > 4. Commands > Apply Source Formatting (messes up my
    entire code by putting
    > everything inside the BODY tag on one line - in other
    words, my entire
    > page
    > goes on one line now!)
    > 5. Automatic Wrapping After Column 76 - this one is
    really stupid, it just
    > does a HARD break on each line so when you turn it back
    off you have to go
    > in
    > and manually delete all these hard breaks now...
    >
    > There's a bunch of other small things I have tried, but
    needless to say,
    > nothing appears to be working.
    >
    > Has no one else experienced this? Can you get Design
    View to properly
    > format
    > UL / LI tags? If so, then something on my computer is
    messed. But when I
    > look
    > at code generated by DW on some of my co-workers'
    computers, they also
    > have the
    > same problem - I just guess their tolerance for crappy
    code is higher than
    > mine.
    >
    > I'm using DW 9.0 (CS3) build 3481.
    >
    > Please help! I have no hair left on my head to tear out
    and I may have to
    > go
    > further afield.... ouch!
    >
    > Thanks,
    >
    > Tom
    >

  • Jdeveloper: Tool Preferences Code Editor Save Actions. Why no code format?

    For me Format and Organize Imports are the 2 main save actions?
    Can I write a plugin or something to have the code format working for me?
    Best Regards,
    JP

    Which version of jdev you are talking about?
    In 11.1.1.2.0 I can select reformat as save action.
    Timo

  • PLSQL Editor Code Formating Rules

    Hi,
    In the past I have used a tool for plsql development called PL/SQL Developer by AllAround Automations. It has a great "beutifier" featur that would allow me to customize some of my own code formatting rules. I've found a similar feature in jdeveloper for java code, but I would like to use the capabilities of jdev to do my pl development as well (just use one tool).
    If anyone has any insights into knowing if the rules can be modified so that when I choose the menu option "format sql", it allows me to customize as I don't like the default behavior.
    THanks

    Hi,
    which JDeveloper version are you on? I am asking because in JDeveloper 11 we use a snapshot of SQL Developer for PLSQL editing in JDeveloper. Can you have a look at this tool to see if the formatting is a you need it. If not, please post suggestions to
    http://www.oracle.com/technology/software/products/sql/index.html
    Frank
    Ps.: I checked teh formatting options in JDeveloper 11 and there are plenty of them

  • [bug] SQLDeveloper 1.5.4.59.40 - Code Formatting problem

    I've installed SQLDeveloper 1.5.4.59.40 and I have found that the code formatting does not format the query with the right case that I choose. I mean, in the option I set to put "SQL words" in uppercase but the formatter ignore this and do not change any case in the query.
    Beretta Costantino

    Hi this works for me.
    -Are you using SQL Formatter Other -> Force formatter on difference ?
    -Are you non USA, there could be a problem with USA strings being assumed and being wrongly used internally?
    --Turloch                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Code format options ---Version 1.5.1.

    Hi all,
    I am new to SQL Developer tool.
    Want to know where I can find settings for code formating options, like PL/SQL developer-Beautifier.
    Also, can we generate E-R diagram like in Toad.
    Tool Version 1.5.1.
    Thanks in advance.

    Better get version 2.1.1 or the latest 3.0 EA for more formatter options (inside the Preferences - Database - SQL Formatter).
    The EA's also have the Data Modeler incorporated, but you can get the last production version in stand-alone too.
    Read the online help inside sqldev for more info.
    Have fun,
    K.

  • ZIP code format for each country in SAP

    Please provide me the way to retrieve ZIP code format for each country in SAP.....

    Well Yash
    You might have noticed the checking rules in the same place. They are the ones which is used for checking formats. I don't know which internal table  (I doubt if there is one) holds the format data per country.  There are formal format checks for few specific countries like Canada, the Netherlands, Poland, Sweden, Slovakia, the Czech Republic, South Korea, and Portugal and I guess they are hardcoded.  Another thought is that Regional Structure Group related tables may hold this.
    If you have ABAPer by your side, check out Function module POSTAL_CODE_CHECK which is used in conjunction with the checking rules mentioned. This may provide you some clues.
    I am wondering why you need this info.
    If you need to set up your own config in Address Management than what is supplied in the standard,  then use the following path:
    SPRO/IMG/SAP NetWeaver/Application Server/Basis Services/Address Management
    Also go through the following OSS notes:
    1123588 - Postal code check for different countries
    1381564 - Postal codes

  • FM to covert Number into EAN 128 (Bar code format)

    Hi Experts,
                    Is there any FM available that can get input as a Number & convert it into Bar code format?
    <REMOVED BY MODERATOR>
    Thanks,
    neo
    Edited by: Alvaro Tejada Galindo on Jan 11, 2008 5:15 PM

    Thanks for the response Gordon.  I investigated your suggestion to use the barcode field on the item master and I get the same result.  In this scenario the barcode field would contain the same information as the item code field.  I am working on the B1 system remotely and do not have access to actually print the document.  Is it possible that the print preview actually shows the numbers but the printout will display the barcode?  I am going to have the group in India print the document to see if that is the issue.  Thanks for the help.  I am using the "user reports" pld.
    Edited by: Jordan Simons on Jan 22, 2009 11:45 PM

  • Convert message content to base64 code format.

    Hi,
    While sending the file to the target directory ,need to convert the content to base64 code format.How we  can achieve this.
    Regards,
    Hymavathi

    this is a duplicate thread :convert message content to base64 code format.
    Please close this one.

Maybe you are looking for

  • Order by clause  Dynamic in Oracle function

    How can i get order by Clause Dynamic in Oracle function My function Returns sql query with SYS_REFCURSOR . and i will pass the order by column as input parameter   create or replace FUNCTION TEST_SSK         p_srot  number RETURN SYS_REFCURSOR AS C_

  • Idoc sender issue

    Hi, I have an issue in Idoc sender scenario. The flow is Idoc to BPM to Flat file. Idoc is triggered from R/3 system via RFC port. It enters XI which is visible in Moni. But data is not there. Which transaction to use to trace Idoc in XI? I can see t

  • Mountain Lion Message Not Working

    I have messeage connected to all my apple products.  So does my wife.  But I cant send a messeage using Mnt Lion messeage to any of my contacts from my or to my mac book pro.  any ideas?

  • ORA-01722: invalid number caused with SQL using bind variable

    Hi, Im am hoping that someone can help me resolve a problem thats only just services and is being experienced on quite a few clients. our application uses C++ exes and makes OCI calls to the database. what has happened in the last week or so, there h

  • HTTP 400 Bad Request Error

    Application Express 3.1.1.00.09 We have some users who are experiencing what appears to be a browser problem in one of our APEX applications. When clicking on any button that does an insert or update to the database some users get an HTTP-400 Bad Req