Jump to content

Syntax Structure For Brackets


mobone

Recommended Posts

Well which is it. In my C class our teacher wants use to use

		if (r==0) 		{			//Do this			//And this		}		else			//else do this

But I think that is HORRIBLE to read. My way.

		if (r==0)		{			//Do this			//And this		} else {			//else do this		}

What's it like in the 'real' world.

Link to comment
Share on other sites

Most is personal preference, but I'd say your way is better. Not only is it more readable, but it also helps when you decide to change your code. If it becomes more than one line, you won't need to remember to add brackets.

Link to comment
Share on other sites

I would either put the else-controlled statement on the same line as the else itself, or use braces.

if (r==0) {	do_this();	and_this();} else do_other_thing();

http://en.wikipedia.org/wiki/Indent_style

Link to comment
Share on other sites

I prefer to always put brackets on their own line, and I typically leave out the brackets if there's only one line in the block. All of this is personal preference though.

  function do_edit_news()  {	if (Ext.getCmp("edit_news_form").getForm().isValid())	{	  Ext.getCmp("edit_news_form").getForm().submit(	  {		method: "POST",		waitTitle: "Connecting",		waitMsg: "Sending Information...",		url: "io.php",		scope: this,		success: function(frm, act)		{		  Ext.getCmp("edit_news_win").close();		  Ext.getCmp("news_tree").getLoader().load(Ext.getCmp("news_tree").root, Ext.emptyFn);		  Ext.getCmp('news_tree').root.expand();		},		failure: this.submit_failure	  });	}	else	  Ext.Msg.alert("Warning", "Please fill out all required fields.");  }

Link to comment
Share on other sites

What's it like in the 'real' world.
Not sure what you mean by that, if you mean how is it written professionally, then you write it however your employer's coding practices say. In my own projects I tend to do pretty much the same as justsomeguy, but you don't always get to choose in the real world.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...