mobone Posted June 28, 2009 Report Share Posted June 28, 2009 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 More sharing options...
boen_robot Posted June 28, 2009 Report Share Posted June 28, 2009 (edited) 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. Edited June 28, 2009 by boen_robot Link to comment Share on other sites More sharing options...
duncan_cowan Posted June 28, 2009 Report Share Posted June 28, 2009 I agree that your way is better as i find that it is easier to identify which code is ran in which outcome, especially as my editor program highlights brackets around code. Link to comment Share on other sites More sharing options...
Synook Posted June 29, 2009 Report Share Posted June 29, 2009 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 More sharing options...
justsomeguy Posted June 29, 2009 Report Share Posted June 29, 2009 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 More sharing options...
AElliott Posted June 30, 2009 Report Share Posted June 30, 2009 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 More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now