1. Post #41
    Gold Member
    ROBO_DONUT's Avatar
    March 2005
    3,028 Posts
    -I didn't read-
    Reply With Quote Edit / Delete Reply Linux Show Events Dumb Dumb x 1 (list)

  2. Post #42
    Gold Member
    Blueridge's Avatar
    July 2008
    2,222 Posts
    Formatting gave me hard time so I grabbed a class I was working on:

    package miles.entity 
    {
    	import flash.geom.Point;
    	import flash.geom.Rectangle;
    	import net.flashpunk.Entity;
    	import net.flashpunk.masks.Pixelmask;
    	
    	/**
    	 * An entity that is affected by gravity and friction.
    	 * All movement variables are points to indicate x and y. For instance,
    	 * acceleration(5, 3) means that x acceleration is 5 and y acceleration is 3.
    	 * @author Miles Hearn
    	 */
    	public class PhysicsEntity extends Entity 
    	{
    		/* Accleration is applied every keypress. */
    		protected var acceleration:Point;
    		/* Slows the entity down if no keypresses are made. */
    		protected var friction:Point;
    		/* Also referred to as speed. */
    		protected var velocity:Point;
    		/* The maxium movement speed that this entity can reach. */
    		protected var maxSpeed:Number;
    		/* Which direction the entity is facing. 0 is left, 1 is right.*/
    		protected var facing:uint;
    		/* The position that the entity will go to after the frame change. */
    		protected var delta:Point;
    		/* The position the entity was at last frame that wasn't colliding with the level. */
    		protected var last:Point;
    		
    		/* Instead of having to remember if 0 was left or right, use these consts */
    		protected static const LEFT:uint = 0;
    		/* Instead of having to remember if 0 was left or right, use these consts */
    		protected static const RIGHT:uint = 1;
    
    
    		protected var pixel:Pixelmask;
    		
    		/**
    		 * Sets acc, vel, frc, delta and last to (0, 0) and makes the entity.
    		 * @param	x the coordinate of the entity to the x-axis
    		 * @param	y the coordinate of the enetity to the y-axis
    		 */
    		public function PhysicsEntity(x:Number, y:Number) {
    			super(x, y);
    			acceleration = new Point;
    			velocity = new Point;
    			friction = new Point;
    			delta = new Point;
    			last = new Point(x, y); //set to current position
    			pixel = new Pixelmask;
    			facing = RIGHT;
    		}
    	}
    }

  3. Post #43
    Gold Member
    atl101's Avatar
    March 2008
    539 Posts
    public class Thing {
    
        public int Foo1 = 2;
        public long Foo2 = 5;
    
        private bool add = false;
    
        public Thing(int foo1, long foo2) {
            this.Foo1 = foo1;
            this.Foo2 = foo2;
        }
    
        public int DoStuff() {
            int result;
    
            if (add || Foo1 < 5) {
                result = Foo1 + (int)Foo2;
            }
            else {
                result = Foo1 * (int)Foo2;
            }
    
            return result;
        }
    }
    
    //This is how I like to format stuff

    Open bracket on first line master race
    Reply With Quote Edit / Delete Reply Mac United States Show Events Disagree Disagree x 10Dumb Dumb x 1 (list)

  4. Post #44
    Gold Member
    Mr_Razzums's Avatar
    December 2005
    4,260 Posts
    public class Thing {
    
        public int Foo1 = 2;
        public long Foo2 = 5;
    
        private bool add = false;
    
        public Thing(int foo1, long foo2) {
            this.Foo1 = foo1;
            this.Foo2 = foo2;
        }
    
        public int DoStuff() {
            int result;
    
            if (add || Foo1 < 5) {
                result = Foo1 + (int)Foo2;
            }
            else {
                result = Foo1 * (int)Foo2;
            }
    
            return result;
        }
    }
    
    //This is how I like to format stuff

    Open bracket on first line master race

    why do you put braces on the first line? if you're so strapped for linespace why don't you delete the braces on the if/else?

    That formatting style is grandpa status.
    Reply With Quote Edit / Delete Reply Windows 7 United States Show Events Agree Agree x 1 (list)

  5. Post #45
    Der FΓΌhrer
    Quark:'s Avatar
    January 2011
    3,154 Posts
    nobody else really reads my code so i just make it simple to read, so i don't have trouble navigating through my own monstrous code

  6. Post #46
    Other people reading your code is a great reason to make it simple to read.
    Reply With Quote Edit / Delete Reply Mac United States Show Events Useful Useful x 1Agree Agree x 1 (list)

  7. Post #47
    phazmatis's Avatar
    December 2009
    67 Posts
    Formatting only matters when more than one person is working on a project.
    Reply With Quote Edit / Delete Reply Windows 7 United States Show Events Disagree Disagree x 15Optimistic Optimistic x 1 (list)

  8. Post #48
    Follow me on github
    Ziks's Avatar
    June 2011
    805 Posts
    I put my open brackets on a new line so they match with the close bracket horizontally.
    Reply With Quote Edit / Delete Reply Windows 7 United Kingdom Show Events Agree Agree x 9 (list)

  9. Post #49
    ryansworld10's Avatar
    January 2012
    34 Posts
    Formatting only matters when more than one person is working on a project.
    This is so unbelievably wrong. A project can quickly become hell to work on when you get buried under unreadable code.
    Reply With Quote Edit / Delete Reply Windows 7 United States Show Events Agree Agree x 6 (list)

  10. Post #50
    Gold Member
    robmaister12's Avatar
    January 2008
    4,747 Posts
    Formatting only matters when more than one person is working on a project.
    If you work on your projects for more than a month, you'll realize that there are parts of your code that go untouched and unviewed for long periods of time. When you finally go back to look at it you might as well be another person looking at your code for the first time. Which is why you should always format things nicely and leave comments where you do something non-obvious.
    Reply With Quote Edit / Delete Reply Windows 7 United States Show Events Agree Agree x 6 (list)

  11. Post #51
    JohnnyOnFlame's Avatar
    February 2011
    1,424 Posts
    Mine's nearly like NPerez, but with a few changes where the vars are declared and such.

    Code:
    public class Thing {
        public int Foo1 = 2;
        public long Foo2 = 5;
        private bool add = false;
     
        public Thing(int foo1, long foo2) {
            this.Foo1 = foo1;
            this.Foo2 = foo2;
        }
        public int DoStuff() {
            return (add||Foo1<5) ? Foo1 + (int)Foo2 : Foo1 * (int)Foo2;
        }
    }
    /*This is how I like to format stuff*/
    Edited:

    This is so unbelievably wrong. A project can quickly become hell to work on when you get buried under unreadable code.
    Then when you're working on that huge project and you need to fix a bug, you won't ever find that pesky minus that should be a plus.

  12. Post #52
    Code:
    typedef struct Thing_Tag {
        int foo1;
        long long foo2;
        int add;
    } Thing;
    
    /* What an useless function. I'd write
    
    Thing something;
    something.foo1 = number1;
    something.foo2 = number2;
    
    instead of
    
    Thing something;
    Thing_New(&something, number1, number2); */
    void Thing_New(Thing *this, int foo1, long long foo2)
    {
        this->foo1 = foo1;
        this->foo2 = foo2;
    }
    
    int Thing_DoStuff(Thing *this)
    {
        if (this->add || (this->foo1 <= 4))
            return this->foo1 + (int)(this->foo2);
        return this->foo1 * (int)(this->foo2);
    }
    /* This is how I like to format stuff */
    Opening curly brace is on the same line for data and on the next line for subroutines (functions, if, for, while).

  13. Post #53
    Gold Member
    Lexic's Avatar
    March 2009
    5,782 Posts
    class Thing {
    public:
        Thing(int foo1, long foo2);
        int DoStuff() const; 
    
        int  Foo1 = 2;
        long Foo2 = 5;
    private:
        bool add  = false;
    }
    
    Thing::Thing(int foo1, long foo2)
    : Foo1(foo1), Foo2(foo2)
    {
    }
    
    int Thing::DoStuff() const
    {
        int result;
        if (add || Foo1 < 5) {
            result = Foo1 + (int)Foo2;
        } else {
            result = Foo1 * (int)Foo2;
        }
        return result;
    }
    
    // This is how I like to format stuff
    

    K&R + 4 space soft tabs.

    Incidentally, the if/else statement was presumably to see how you format your if brackets.
    Therefore if you compressed the if when you pasted your snippit, you've kind of missed the point.

  14. Post #54
    ryansworld10's Avatar
    January 2012
    34 Posts
    Then when you're working on that huge project and you need to fix a bug, you won't ever find that pesky minus that should be a plus.
    That doesn't make sense. So because I like to format my code nicely and keep it organized, it becomes harder to find something that needs fixing? It seems like it should be the other way around.

  15. Post #55
    Gold Member
    marvincmarvin's Avatar
    January 2011
    755 Posts
    Am I the only one who prefers his public and privates indented?

    class Thing {
         public:
              int Foo1;
              int Foo2;
         private:
              int Foo3;
              int Foo4;
    }
    
    Reply With Quote Edit / Delete Reply Linux United States Show Events Agree Agree x 4Useful Useful x 1 (list)

  16. Post #56
    Gold Member
    Lexic's Avatar
    March 2009
    5,782 Posts
    Am I the only one who prefers his public and privates indented?

    class Thing {
         public:
              int Foo1;
              int Foo2;
         private:
              int Foo3;
              int Foo4;
    }
    
    I used to do it like that when I used notepad++.
    But when I started using editors with smart-indenters they always put them put them at the same level as the class declaration so I figured it'd be less fuss to just get used to that.
    Reply With Quote Edit / Delete Reply Mac United Kingdom Show Events Agree Agree x 2 (list)

  17. Post #57
    Gold Member
    DoctorSalt's Avatar
    January 2009
    2,314 Posts
    Am I the only one who prefers his public and privates indented?

    class Thing {
         public:
              int Foo1;
              int Foo2;
         private:
              int Foo3;
              int Foo4;
    }
    
    I usually indented them, as you do, until I started C#, which I don't think has categories of public and private.

  18. Post #58
    ryansworld10's Avatar
    January 2012
    34 Posts
    Am I the only one who prefers his public and privates indented?

    class Thing {
         public:
              int Foo1;
              int Foo2;
         private:
              int Foo3;
              int Foo4;
    }
    
    TIL that you can group publics and privates like that!

    Edit: Nvm, didn't know that was only in C++

  19. Post #59
    Gold Member
    Lexic's Avatar
    March 2009
    5,782 Posts
    TIL that you can group publics and privates like that!
    That's C++. You can't in C# and Java.
    Reply With Quote Edit / Delete Reply Mac United Kingdom Show Events Agree Agree x 3 (list)

  20. Post #60
    Gold Member
    Darkimmortal's Avatar
    April 2009
    2,535 Posts
    Code:
    public class Thing {
    
        public int Foo1 = 2;
        public long Foo2 = 5;
    
        private bool add = false;
    
        public Thing(int foo1, long foo2){
            this.Foo1 = foo1;
            this.Foo2 = foo2;
        }
    
        public int DoStuff(){
            int result;
    
            if(add || Foo1 < 5){
                result = Foo1 + (int)Foo2;
            } else {
                result = Foo1 * (int)Foo2;
            }
    
            return result;
        }
    	
    }
    Seems to be somewhat unique

  21. Post #61
    RUBY OVERLORD
    swift and shift's Avatar
    November 2011
    2,117 Posts
    where are your accessors boy
    Reply With Quote Edit / Delete Reply Mac Australia Show Events Agree Agree x 2 (list)

  22. Post #62
    Bluefire's Avatar
    August 2007
    303 Posts
    Open bracket on first line master race
    I have tried on multiple occasions to understand how this actually makes stuff easier to read, and I always find it makes code look more convoluted than it need to be.

    I find :


    Code:
    public int AddExample(int x, int y)
    { 
        return (x + y);
    }
    Looks much easier to read (for me, that is) than:


    Code:
    public int AddExample(int x, int y) { 
            
        return (x + y);
    }
    When you get into long methods, it gets to be a royal pain to see where they actually end. Since you have to look diagonally to find where the open-close brace pair.

    But in the first example, its just a simple up - down movement to view them.
    Reply With Quote Edit / Delete Reply Windows 7 Canada Show Events Agree Agree x 5 (list)

  23. Post #63
    Stonecycle's Avatar
    September 2011
    3,282 Posts
    Code:
    public class Thing {
        public int Foo1 = 2;
        public long Foo2 = 5;
    
        private bool add = false;
    
        public Thing(int foo1, long foo2) {
            this.Foo1 = foo1;
            this.Foo2 = foo2; }
    
        public int DoStuff() {
            int result;
    
            if (add || Foo1 < 5) {
                result = Foo1 + (int)Foo2; }
            else {
                result = Foo1 * (int)Foo2; }
    
            return result; }}
    
    // This is how I like to format stuff
    Managed to pack in a few more lines.
    Reply With Quote Edit / Delete Reply Windows 7 United States Show Events Disagree Disagree x 2 (list)

  24. Post #64
    Gold Member
    iPope's Avatar
    October 2008
    1,732 Posts
    Code:
    # I format my code the only way it will fucking work - <3 Python
    
    class Lol():
        def __init__(self, a, b, c):
            self.a = a
            self.b = b
            self.c = c
    
        def sum(self):
            return self.a+self.b+self.c
    
    c = Lol(1,2,3)
    print c.sum()
    Reply With Quote Edit / Delete Reply Windows 7 United Kingdom Show Events Funny Funny x 2 (list)

  25. Post #65
    inconspicious's Avatar
    February 2012
    2,271 Posts
    Code:
    public class Thing
    {
        public int Foo1 = 2;
        public long Foo2 = 5;
        private bool add = false;
        public Thing(int foo1, long foo2) {
            this.Foo1 = foo1;
            this.Foo2 = foo2;
        }
    
        public int DoStuff() {
            int result;
            if (add || Foo1 < 5) {
                result = Foo1 + (int)Foo2;
            } else {
                result = Foo1 * (int)Foo2;
            }
            return result;
        }
    }
    
    //This is how I like to format stuff

  26. Post #66
    Follow me on github
    Ziks's Avatar
    June 2011
    805 Posts
    Code:
    public class Thing {
        public int Foo1 = 2;
        public long Foo2 = 5;
    
        private bool add = false;
    
        public Thing(int foo1, long foo2) {
            this.Foo1 = foo1;
            this.Foo2 = foo2; }
    
        public int DoStuff() {
            int result;
    
            if (add || Foo1 < 5) {
                result = Foo1 + (int)Foo2; }
            else {
                result = Foo1 * (int)Foo2; }
    
            return result; }}
    
    // This is how I like to format stuff
    Managed to pack in a few more lines.
    Python mode?
    Reply With Quote Edit / Delete Reply Windows 7 United Kingdom Show Events Informative Informative x 1 (list)

  27. Post #67
    ~ ducks ~
    Kwaq's Avatar
    April 2011
    1,850 Posts
    public class Thing{
        public int Foo1 = 2;
        public long Foo2 = 5;
        private bool add = false;
        public Thing(int foo1, long foo2){
            this.Foo1 = foo1;
            this.Foo2 = foo2;}
        public int DoStuff(){
            int result;
            if (add || Foo1 < 5){
                result = Foo1 + (int)Foo2;}
            else{
                result = Foo1 * (int)Foo2;}
            return result;}}
    
    // this is how I like to format stuff
    

    im so sorry
    Reply With Quote Edit / Delete Reply Windows 7 United Kingdom Show Events Optimistic Optimistic x 1 (list)

  28. Post #68
    Gold Member
    atl101's Avatar
    March 2008
    539 Posts
    I have tried on multiple occasions to understand how this actually makes stuff easier to read, and I always find it makes code look more convoluted than it need to be.

    I find :


    Code:
    public int AddExample(int x, int y)
    { 
        return (x + y);
    }
    Looks much easier to read (for me, that is) than:


    Code:
    public int AddExample(int x, int y) { 
            
        return (x + y);
    }
    When you get into long methods, it gets to be a royal pain to see where they actually end. Since you have to look diagonally to find where the open-close brace pair.

    But in the first example, its just a simple up - down movement to view them.

    I don't think it's necessarily better, but more of a preference thing - that's how I learned when I started and have been formatting that way ever since. The goal of this style of indentation is so the closing bracket is the only thing matching the indentation of the opening statement, e.g. the while and if below. That makes it easier to see in my opinion

    Code:
    - (int) foo (int:number) {
    
         int x = 5
         int y = 6
         int number = 1
    
         while (x > y) {
         x += 1
         }
    
         if (x > y) {
         number += 5
         }
    
         return number
    }

  29. Post #69
    AtomiCasd's Avatar
    June 2011
    588 Posts
    Is there a vs2012 c++ plugin that autoformats your code?
    Reply With Quote Edit / Delete Reply Windows 7 Norway Show Events Funny Funny x 1 (list)

  30. Post #70
    dajoh's Avatar
    March 2011
    564 Posts
    Ctrl+K Ctrl+F
    Reply With Quote Edit / Delete Reply Windows 8 Sweden Show Events Agree Agree x 1 (list)

  31. Post #71
    cis.joshb's Avatar
    January 2011
    1,248 Posts
    Code:
    public class Thing 
    {
    	public int Foo1 = 2;
    	public long Foo2 = 5;
    	private bool add = false;
    	
    	public Thing(int foo1, long foo2) 
    	{
    		this.Foo1 = foo1;
    		this.Foo2 = foo2;
    		
    	}
    	
    	public int DoStuff() 
    	{
    		int result;
    		
    		if (add || Foo1 < 5) 
    		{
    			result = Foo1 + (int)Foo2;
    			
    		}
    		
    		else 
    		{
    			result = Foo1 * (int)Foo2;
    			
    		}
    		
    		return result;
    		
    	}
    	
    }
    
    //This is how I like to format stuff
    I put a space between anything and an if statement or class or function. I also put an extra tabbed line before ends or }s.

  32. Post #72
    MyBigBoner.com
    fritzel's Avatar
    March 2009
    3,066 Posts
    Code:
    <?php get_header(); ?>
    
    <div class="headshare">  </div>
    
    	<div id="content">
    
    	<?php if (have_posts()) : ?>
    
    		<?php while (have_posts()) : the_post(); ?>
    		<div class="entry">
    			<div id="post-<?php the_ID(); ?>">
                            <div class="date"><span><?php the_time('M') ?></span> <?php the_time('d') ?></div>
    				<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    				<abbr title="<?php the_date('D dS M, Y'); ?><?php //the_time('Y-m-d\TH:i:sO'); ?>"><?php unset($previousday);?> Scribbled on <?php the_time('l, F jS, Y'); ?> </abbr> <!-- by <?php the_author() ?> -->
                        <br /><br />	
                        <?php the_content('Read on...'); ?>
    		    	
                        <?php the_meta(); ?>
                                    
    				<p class="postmetadata">Posted in <span class="cty"><?php the_category(', ') ?></span> | <?php edit_post_link('Edit', '', ' | '); ?>  <span class="cmt"><?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></span></p>
    				</div></div>
    
    		<?php endwhile; ?>
    		<!--<div class="navigation">
    			<div class="alignleft"><?php next_posts_link('<span class="prev"> Previous Entries</span>') ?></div>
    			<div class="alignright"><?php previous_posts_link('Next Entries <span class="next">&nbsp;</span>') ?></div> 
    		</div>-->
               <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>  
    		
    		<div class="post-audits">
                  
                  <div class="post-recents">
                   <ul><h2>Recent Posts</h2>
    			   <?php $query='showposts=5&offset=0'; 				
    					 $recent = new WP_Query($query); 
    					 while($recent->have_posts()) : $recent->the_post(); 
    				?>
    
    				<li><a  target="_blank" href="<?php the_permalink(); ?>" title="<?php the_date('D dS M, Y'); ?>"><?php the_title(); ?></a></li>
    
    				<?php endwhile; ?>
    				
    				
    				
    				
    				
    				
    				
    				
    		
               <br/> <br/>
         <?php endif; ?>
    
    </div> </div>
                          
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
    Reply With Quote Edit / Delete Reply Windows 7 India Show Events Artistic Artistic x 2 (list)

  33. Post #73
    Speedfalcon's Avatar
    December 2009
    1,082 Posts
    Code:
                             public class Thing{
        public int Fo
    o1 = 2;public long Foo2 = 5;private bool add 
    = false;
    
        public Thing(int foo1,long foo2){
            this.Foo1 
    = foo1;
            this.Foo2 = foo
    2;} public in
    t DoStuff(){int r
    e
    s
    ult;if (add || Foo1 < 5) result = Foo1 + (int)Foo2;
     else result = Foo1 * (int)Foo2;return result;
        }
    }
    
    //This is format how like I stuff.
    Reply With Quote Edit / Delete Reply Windows 7 United Kingdom Show Events Disagree Disagree x 2Artistic Artistic x 2Dumb Dumb x 1Funny Funny x 1 (list)

  34. Post #74
    ArgvCompany's Avatar
    June 2012
    448 Posts
    C#:
    public class Thing
    {
        public int Foo1 = 2;
        public long Foo2 = 5;
    
        private bool add = false;
    
        public Thing(int foo1, long foo2)
        {
            this.Foo1 = foo1;
            this.Foo2 = foo2;
        }
    
        public int DoStuff()
        {
            int result;
    
            if (add || Foo1 < 5)
            {
                result = Foo1 + (int)Foo2;
            }
            else
            {
                result = Foo1 * (int)Foo2;
            }
    
            return result;
        }
    }
    
    // This is how I like to format stuff
    

    Java:
    public class Thing {
        public int foo1 = 2;
        public long foo2 = 5;
    
        private bool add = false;
    
        public Thing(int foo1, long foo2) {
            this.foo1 = foo1;
            this.foo2 = foo2;
        }
    
        public int doStuff() {
            int result;
    
            if (add || foo1 < 5) {
                result = foo1 + (int)foo2;
            } else {
                result = foo1 * (int)foo2;
            }
    
            return result;
        }
    }
    
    // This is how I like to format stuff
    
    Reply With Quote Edit / Delete Reply Windows 7 Germany Show Events Funny Funny x 2 (list)

  35. Post #75
    Anthos's Avatar
    April 2012
    153 Posts
    #@@
    0123
    1E
    Reply With Quote Edit / Delete Reply Windows XP Netherlands Show Events Dumb Dumb x 3Programming King Programming King x 1 (list)

  36. Post #76
    Gold Member
    dije's Avatar
    December 2008
    4,336 Posts
    Code:
    public class Thing
    {
        public int Foo1 = 2;
        public long Foo2 = 5;
    
        private bool add = false;
    
        public Thing(int Foo1, long Foo2)
        {
            this.Foo1 = Foo1;
            this.Foo2 = Foo2;
        }
    
        public int DoStuff()
        {
            if (add || Foo1 < 5)
                return Foo1 + (int)Foo2;
    
            return Foo1 * (int)Foo2;
        }
    }
    
    //This is how I like to format stuff
    Reply With Quote Edit / Delete Reply Windows 7 Sweden Show Events Agree Agree x 2 (list)

  37. Post #77
    Gold Member
    Hypershadsy's Avatar
    February 2008
    2,296 Posts
    How would you even format an assembly document? If I'm not mistaken, scope isn't a factor, which would mean there's a lot of opportunity to get lost.

  38. Post #78
    Gold Member
    Lexic's Avatar
    March 2009
    5,782 Posts
    line breaks and comment banners.
    Reply With Quote Edit / Delete Reply Mac United Kingdom Show Events Agree Agree x 1 (list)