You are not logged in.

#26 2009-02-12 14:36:37

mrunion
Member
From: Jonesborough, TN
Registered: 2007-01-26
Posts: 1,938
Website

Re: Anyone who write in C/C++

I kinda agree with dav7's thrust.

A few years ago for a 6-moth period in my past programming ventures, I used nothing but a PLAIN text editor. No code completion, no syntax highlighting, etc. I did this so I would be sure I KNEW what I was doing, and not relying on the IDE to "make suggestions" for me. If I were ever called to a client's site (has happened), or had to remote in to a server (also happens), I could only assume there there would be a text editor of some kinds available. then I was still able to work normally, and know what was going on.

Doing that paid HUGE dividends in the long run!


Matt

"It is very difficult to educate the educated."

Offline

#27 2009-02-12 14:44:19

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: Anyone who write in C/C++

Well, there's a difference between using auto-indent feature of a certain editor, and relying on code-completion.  I use VIM without code-completion, but the indenting is a huge time-saver in the long run, and configurable enough to conform to my company's coding standards.

Offline

#28 2009-02-12 17:05:57

ezzetabi
Member
Registered: 2006-08-27
Posts: 947

Re: Anyone who write in C/C++

namespace example
{
int sum(int lhs, int rhs)
  {
    return lhs + rhs;
  }

int deference(int* pi)
  {
    return *pi;
  }
}

A part of namespaces I put the brackets on the same column and in their own indentation.
I use 4 as indentation, spaces only.

I split the classes implementation in at least three files.
Being X the class name (or a reasonable name):
X.types.hh with class forward declarations, functions prototypes and enum definition,
X.defs.hh with class (but not members) definition,
X.cc with member and function definition,
X.impl.hh with inline and template function definitions.
the inclusion guard are usually needed only for the .defs.hh file, are needed also for the .types.hh if it cantains enum definitions.

X.defs.hh includes X.types.hh,
X.cc includes X.defs.hh,
and if needed (it means I have at least one template or inline function) X.impl.hh is included at the end of X.defs.hh.

So I need only forward declarations of a class (I need a pointer for example) I include types.hh, otherwise I include defs.hh .

Offline

#29 2009-02-14 02:25:08

aquila_deus
Member
From: Taipei
Registered: 2005-07-02
Posts: 348
Website

Re: Anyone who write in C/C++

rson451 wrote:
aquila_deus wrote:

Don't rely on simple indent features in emacs, vim...

Wait. What?  Vim for sure has more than simple indent features,  I'm sure emacs is the same.

It is still indent. There is a difference between "indent" and complete code formatting, including to change the brace styles, adding spaces between function parameters etc, and it'd be much better if the tools can be launched independently because someday you need to reformat tons of files wink

I think astyle can do that on linux. Similar features also exist in slickedit, eclipse and vs.net (2005+) but not standalone tool. However, you still need to setup the editors to have the same indent configuration, so it's a bit more work.

shining wrote:
rson451 wrote:
aquila_deus wrote:

Don't rely on simple indent features in emacs, vim...

Wait. What?  Vim for sure has more than simple indent features,  I'm sure emacs is the same.

I am quite sure many people would disagree with what aquila_deus said so I didn't even bother commenting smile

Well obviously most people (that you think of) have never heard of code beautifiler before. If they're not willing or incapable to learn then I shouldn't bother commenting either. lol

Last edited by aquila_deus (2009-02-14 02:29:31)

Offline

#30 2009-02-14 10:17:36

shining
Pacman Developer
Registered: 2006-05-10
Posts: 2,043

Re: Anyone who write in C/C++

aquila_deus wrote:

It is still indent. There is a difference between "indent" and complete code formatting, including to change the brace styles, adding spaces between function parameters etc, and it'd be much better if the tools can be launched independently because someday you need to reformat tons of files wink
<...>
Well obviously most people (that you think of) have never heard of code beautifiler before. If they're not willing or incapable to learn then I shouldn't bother commenting either. lol

I personally find indent very annoying to do manually, so very practical to rely on the editors for doing that. It's a not too complicated task so several editors can do it right.
For the rest, brace style and adding space, this is very easy to do manually while writing the code, you just have to get used to the style but that's usually ok.


pacman roulette : pacman -S $(pacman -Slq | LANG=C sort -R | head -n $((RANDOM % 10)))

Offline

#31 2009-02-14 10:25:08

daf666
Member
Registered: 2007-04-08
Posts: 470
Website

Re: Anyone who write in C/C++

shining wrote:

I personally find indent very annoying to do manually

Me two.. I messed with the 'indent' utility for a while, but it allways messes my code..
I usually write in Geany, so when I need indenting, I open the file in Anjuta, use the auto indent feature on the file, and refresh it in Geany.
sux..  but I dont think there is an alternative? (except of *using* Anjuta or Kate.. etc.)

Offline

#32 2009-02-14 17:57:04

aquila_deus
Member
From: Taipei
Registered: 2005-07-02
Posts: 348
Website

Re: Anyone who write in C/C++

daf666 wrote:
shining wrote:

I personally find indent very annoying to do manually

Me two.. I messed with the 'indent' utility for a while, but it allways messes my code..
I usually write in Geany, so when I need indenting, I open the file in Anjuta, use the auto indent feature on the file, and refresh it in Geany.
sux..  but I dont think there is an alternative? (except of *using* Anjuta or Kate.. etc.)

"indent" is rather outdated, even emacs can do better I think. It sounds like you have chosen an unsuitable editor....

Using free software, emacs does the best indenting/formatting as far as I know, but I guess few would want to learn it for a few of the advanced features that are rather common today. Or you could get slickedit or real IDE like eclipse which can do automatic code formatting - it is very useful when you work with others' code, or when you paste snippets (format on paste).

It surprises me that after so many years the usual C/C++ development environement on linux seems to remain unchanged...

Offline

#33 2009-02-16 19:08:21

daf666
Member
Registered: 2007-04-08
Posts: 470
Website

Re: Anyone who write in C/C++

aquila_deus wrote:

...

Just for the sport.. I tried eclipse-cdt yesterday, I spent 2 hours playing with it trying to adapt my projects to it..
It is amazing and comprehensive, but its a 60MB mammoth with a lot of overhead.. and way to complex for my simple projects.
I really love Geany, all I wanted was auto indenting smile (which eclipse does amazing btw *drool*).

Edit: lol.. I am sticking with eclipse... using the WhiteSmiths style..

Last edited by daf666 (2009-02-20 11:07:51)

Offline

#34 2009-02-16 21:13:49

Berticus
Member
Registered: 2008-06-11
Posts: 731

Re: Anyone who write in C/C++

I can never use code completion in IDE's, which is why I switched to text editors. It breaks the rhythm too much. By the time I notice I can use that feature, I'm already done typing what I need to type.

Anyway, I don't follow #1 (4 spaces), #2 (Always separate line), or #7. Maybe I'm just weird, but when my eyes see the words true or false, my brain automatically interprets 1 or 0, respectively. So when testing for 0, my natural tendency is to use !0, seeing == 0 looks odd and unnatural to me. Of course when working in a group where the style is agreed upon, I'll follow it.

Offline

#35 2009-02-16 23:48:30

dsr
Member
Registered: 2008-05-31
Posts: 187

Re: Anyone who write in C/C++

Berticus wrote:

Maybe I'm just weird, but when my eyes see the words true or false, my brain automatically interprets 1 or 0, respectively. So when testing for 0, my natural tendency is to use !0, seeing == 0 looks odd and unnatural to me. Of course when working in a group where the style is agreed upon, I'll follow it.

I think you're talking about the opposite scenario. Judd said to use the explicit "expr == 0" rather than "! expr" to test for success with functions that specifically return 0 upon success (as opposed to failure) because "! expr" could be misinterpreted more easily to mean that the function failed.

Offline

#36 2009-02-17 04:51:46

fumbles
Member
Registered: 2006-12-22
Posts: 246

Re: Anyone who write in C/C++

.

Last edited by fumbles (2020-09-26 11:59:11)

Offline

#37 2009-02-18 05:20:49

r6
Member
From: Melbourne
Registered: 2008-07-02
Posts: 156

Re: Anyone who write in C/C++

dsr wrote:

Judd said to use the explicit "expr == 0" rather than "! expr" to test for success with functions that specifically return 0 upon success (as opposed to failure) because "! expr" could be misinterpreted more easily to mean that the function failed.

Even better is to use "0 == expr". Makes it clearer that you're not assigning a value, and also the compiler picks up errors if you mistakenly use one equals instead of two.

Offline

Board footer

Powered by FluxBB