ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
View Poll Results: What curly brace style do you prefer?
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.
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
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.
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.
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.
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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.