LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


View Poll Results: What curly brace style do you prefer?
Opening brace on same line 23 35.94%
Opening brace on its own line 41 64.06%
Voters: 64. You may not vote on this poll

Reply
  Search this Thread
Old 06-15-2010, 01:56 PM   #31
kaiser_suse
LQ Newbie
 
Registered: Nov 2006
Distribution: openSUSE, Ubuntu
Posts: 18

Rep: Reputation: 0

Quote:
Originally Posted by MTK358 View Post
Having the opening brace on the same line is more compact and neat, but I think it could become one solid, overwhelming block with no visual separation with a lot of code.

With the opening brace on its own line, you get good visual separation, but it looks wasteful and ugly, especially if there's only one or two lines of code in the block.
I prefer the braces on their own line so that each pair is horizontally aligned. Since I have worked in languages where "begin" and "end", which are on their own lines, are the semantic equivalent of braces, my personal preference partially derives from that.

But, there is an advantage to having the extra vertical space above the block if you have long parameter lists or multiple conditions spanning multiple lines. It helps to visually separate the action statements from the parameters or conditions.

Quote:
What do you think is the best tab size?
I use 4 spaces for any new code I write, since that is the default for most code editors and IDEs, and I am too lazy to navigate through their menus to change the preferences. Before wide flat panel displays became affordable, I used 3 spaces, so I use 3 spaces when maintaining my legacy code to remain consistent. I try to keep my indents as short as possible without compromising readability too much because I write for scientific applications where formulas tend to take up more horizontal space and loops are deeply nested for processing multidimensional data.

Quote:
Whether a space between a function call's name and parens makes it more readable?
Like many other responders, I only use a space between keywords and parens, not function names and parens. It helps a little to distinguish function calls from conditional statements.

Quote:
Whether you should use curly braces for blocks containing one statement?
Generally I don't, but for blocks that were reduced from multiple statements to one or blocks where I have reason to believe may contain multiple statements in the future, I leave them in.
 
Old 06-16-2010, 11:12 AM   #32
fractalizing
LQ Newbie
 
Registered: Jan 2010
Posts: 9

Rep: Reputation: 1
[/QUOTE]
I honestly cannot stand it when someone does not space function parameters.
[/QUOTE]

You, me and my 6th grade English Teacher, Mrs Schultz.
 
Old 06-16-2010, 11:20 AM   #33
fractalizing
LQ Newbie
 
Registered: Jan 2010
Posts: 9

Rep: Reputation: 1
Cool 5 to 3 we win

So did we settle things, or just make more embittered diehards?

CTRL+ALT+F fixes all your formatting errors ( with Neteans ).
 
Old 06-16-2010, 11:29 AM   #34
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by fractalizing View Post
So did we settle things, or just make more embittered diehards?
I'm still undecided. Maybe I should just use indent on large pieces of code and see.

Quote:
Originally Posted by fractalizing View Post
CTRL+ALT+F fixes all your formatting errors ( with Neteans ).
I hate those big, bulky IDEs!

On a related subject: I found that I really like Kate for coding, especially with plugins like Snippets, Terminal, Build Output, Symbol List, and occasionally vi input mode.
 
Old 06-17-2010, 06:30 PM   #35
fractalizing
LQ Newbie
 
Registered: Jan 2010
Posts: 9

Rep: Reputation: 1
Point Taken - Go kate!

Quote:
Originally Posted by MTK358 View Post
I'm still undecided. Maybe I should just use indent on large pieces of code and see.
I hate those big, bulky IDEs!

On a related subject: I found that I really like Kate for coding, especially with plugins like Snippets, Terminal, Build Output, Symbol List, and occasionally vi input mode.
I could name my first born son Quanta and my first born daughter Kate.
I use them a lot, and Kwrite ( with kate plugins ) often. (If it has red hair and is left handed, I'll name it Kwrite )
When I had windows I used SuperIDE. Powerful yet light weight.

Yep, sometimes Netbeans and Eclipse act like old timey 8 bit word processors - I'm 3 lines ahead of rendering keyboard buffer.
And another window running the loathsome flash burps or crashes.

Still I love and hate netbeans ...
sometimes it's easier to write a loop code to create a lot of guis than to work the gui editor.

I also hat that if the gui creates code, I have to use the gui editor to alter it. Sometimes it errs.

Kate offers a few nifty tricks that NetBeans should have:

Nestable code folds,
Easy case adjustment
It never crashes or does anything wrong.
 
Old 06-17-2010, 07:27 PM   #36
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
In KDE 4.3 Kate was horribly glitchy to the point of being almost unusable. Now it works good, though.

Reminds mr that when KDE4 first came out it was horrible. I decided to try it recently (it happened to be version 4.4.4) and it's quite nice, in fact I'm using it now.

Plasma is still a bit glitchy, though.
 
Old 06-17-2010, 07:44 PM   #37
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
FWIW, 'indent': http://linux.die.net/man/1/indent - for those, who can't decide and want to try.
 
1 members found this post helpful.
Old 07-04-2010, 01:43 AM   #38
pr_deltoid
Member
 
Registered: Jun 2010
Distribution: Fedora
Posts: 289

Rep: Reputation: 41
I've been using the opening brace on its own line, unless there's only one line in the block. I sort of prefer the more compact opening brace on same line still, but I guess it's not the best habit to get into. I prefer having everything compact, but I'm going to change my style.
 
Old 07-04-2010, 03:21 AM   #39
phil.d.g
Senior Member
 
Registered: Oct 2004
Posts: 1,272

Rep: Reputation: 154Reputation: 154
Style doesn't overly concern me, as long as it's neat. For new or my own projects I use the kernel coding guidelines for C and C++, the java guidelines for java and so on for python/ruby/perl/bash/whatever. The only thing I don't like about K&R are the 8 char tabs, but I always use tabs rather than spaces, and configure my editor to use a 4 char wide tab. Another non standard thing I do is, if you take this example:

Code:
void blah(int i, int j)
{
	if (this == that)
		then_some_very_long_function_call("Lorem ipsum dolor sit amet, "
		                   "consectetur adipiscing elit. Nunc vulputate");
   tabs here    |    spaces here   |
}
I tab to the correct level of indentation, then space to line up the wrapped call, this way people can configure their tab width to be anything without knackering the lining up
 
Old 07-04-2010, 07:35 AM   #40
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
I pretty much decided on "curly brace on its own line" now. It just seems less cluttered and more readable.

Also, I've laely been trying using spaces instead of tabs. Not sure which is better.
 
Old 07-05-2010, 04:16 AM   #41
MrCode
Member
 
Registered: Aug 2009
Location: Oregon, USA
Distribution: Arch
Posts: 864
Blog Entries: 31

Rep: Reputation: 148Reputation: 148
I know this thread is kind of old and dead (hey, that rhymes! ), but sometimes LQ doesn't tell me about new posts to it, even if there are...

Anyway, I read through this again, and I wanted to reply to this:

Quote:
Originally Posted by wje_lq
Um, MrCode, please please please tell me you meant this:
Code:
...
case 0: foo(); break;
case 1: bar(); break;
case 2: far(); break;
case 3: boo(); break;
...
Yes, I did mean that, and I screwed up because I wasn't thinking. Thanks for the subtle correction.

EDIT:
Quote:
Originally Posted by MTK358
Also, I've laely been trying using spaces instead of tabs. Not sure which is better.
I personally prefer tabs. Gives a better idea of the nesting, just as long as the tabs aren't ridiculously long. That's for another thread, though.

Last edited by MrCode; 07-05-2010 at 04:19 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash - brace expansion using variable student04 Linux - Software 3 03-07-2017 05:04 AM
[SOLVED] How to do auto brace in Emacs? cola Linux - Newbie 3 04-20-2010 07:43 AM
Brace expansion: does this kind exist? exscape Linux - Software 4 04-28-2009 03:45 AM
Kylix 3 and insert curly braket Dukov Programming 0 02-29-2004 01:01 PM
Curly Modem Problem stefanvg Linux - Hardware 0 04-28-2003 01:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration