Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Portage & Programming
  • Search

C++ Naming Conventions

Problems with emerge or ebuilds? Have a basic programming question about C, PHP, Perl, BASH or something else?
Post Reply
Advanced search
12 posts • Page 1 of 1
Author
Message
wswartzendruber
Veteran
Veteran
User avatar
Posts: 1261
Joined: Tue Mar 23, 2004 1:16 am
Location: Idaho, USA

C++ Naming Conventions

  • Quote

Post by wswartzendruber » Sat Jan 02, 2010 9:07 am

So I'm working on a class library that uses Qt4 exclusively. QCA does this, and all of its classes have their own namespace. Qt4 itself doesn't put things in a namespace (it seems), but instead chooses to prefix everything with the letter Q. Which way is proper?
Top
drescherjm
Advocate
Advocate
Posts: 2792
Joined: Sat Jun 05, 2004 5:46 am
Location: Pittsburgh, PA, USA

  • Quote

Post by drescherjm » Sat Jan 02, 2010 5:10 pm

Which way is proper?
Both ways are fine.

There is some information about coding standards here:

http://www.parashift.com/c++-faq-lite/c ... #faq-27.12
John

My gentoo overlay
Instructons for overlay
Top
Mad Merlin
Veteran
Veteran
Posts: 1155
Joined: Mon May 09, 2005 7:37 pm
Contact:
Contact Mad Merlin
Website

Re: C++ Naming Conventions

  • Quote

Post by Mad Merlin » Sun Jan 03, 2010 9:35 am

wswartzendruber wrote:So I'm working on a class library that uses Qt4 exclusively. QCA does this, and all of its classes have their own namespace. Qt4 itself doesn't put things in a namespace (it seems), but instead chooses to prefix everything with the letter Q. Which way is proper?
Both and neither. The best part about standards is that there's so many to choose from!
Game! - Where the stick is mightier than the sword!
Top
dmitchell
Veteran
Veteran
User avatar
Posts: 1159
Joined: Sat May 17, 2003 4:51 pm
Location: Austin, Texas

  • Quote

Post by dmitchell » Tue Jan 05, 2010 7:38 pm

I suggest you use a namespace.
Your argument is invalid.
Top
doubleagent
Guru
Guru
User avatar
Posts: 444
Joined: Fri Apr 15, 2005 4:12 am
Location: 127.0.0.1

  • Quote

Post by doubleagent » Wed Jan 06, 2010 6:22 am

dmitchell wrote:I suggest you use a namespace.
Seconded.
shickapooka wrote:i think they programmed [otw] based on a right-wing jewish-nigger-nazi, his gay, retarded, left-wing love slave with webbed feet, and their three headed cat that poops uncontrollably. the cat is also an apple fanboy
Top
drescherjm
Advocate
Advocate
Posts: 2792
Joined: Sat Jun 05, 2004 5:46 am
Location: Pittsburgh, PA, USA

  • Quote

Post by drescherjm » Wed Jan 06, 2010 5:23 pm

doubleagent wrote:
dmitchell wrote:I suggest you use a namespace.
Seconded.
Although I have used this in the past one disadvantage is this makes your identifier names even longer well unless you use

Code: Select all

using namespace namespace_name
And it does not solve the problem of having multiple files of the same name.

On my latest 2 projects I have ditched using namespaces and moved to the vtk approach. I mean prepending the some short identifier to the beginning of all class and file names.

http://www.vtk.org/Wiki/VTK_Coding_Standards

In this my current Qt project is called StudyManager. And so all filenames and classes start with sm. So in one of the libraries of this project I have a class smStudy with its filenames Include/smStudy.h and src/smStudy.cxx
John

My gentoo overlay
Instructons for overlay
Top
Earthwings
Bodhisattva
Bodhisattva
User avatar
Posts: 7753
Joined: Mon Apr 14, 2003 8:13 pm
Location: Germany

  • Quote

Post by Earthwings » Wed Jan 06, 2010 8:36 pm

Using short namespaces without unnecessary nesting is the way to go in my opinion. Long/nested namespaces lead to -- in my opinion -- unreadable header files (where you really should not put any using declaration). At work I have to prefix everything with a 't' for "historic reasons", and I hate it with a passion :twisted:
KDE
Top
Voltago
Advocate
Advocate
User avatar
Posts: 2593
Joined: Tue Sep 02, 2003 1:54 pm
Location: userland

  • Quote

Post by Voltago » Wed Jan 06, 2010 8:56 pm

Earthwings wrote:At work I have to prefix everything with a 't' for "historic reasons", and I hate it with a passion :twisted:
tUh... twhat tgood tis ta tprefix tif tyou tprefix teverything? That's exactly as braindead as that Microsoft-ish prefixing of all member variables with m_. How about somebody with time on their hands writes a little library to represent C/C++/Java in a canonical form and the option to apply coding and tabbing style as well as naming conventions like stylesheets... (of course the editor of choice then in turn would have to enforce that set of conventions to retain bijectivity)? Or is there something like that out there already?
Last edited by Voltago on Wed Jan 06, 2010 9:06 pm, edited 2 times in total.
Top
drescherjm
Advocate
Advocate
Posts: 2792
Joined: Sat Jun 05, 2004 5:46 am
Location: Pittsburgh, PA, USA

  • Quote

Post by drescherjm » Wed Jan 06, 2010 9:02 pm

braindead as that Microsoft-ish prefixing of all member variables with m_.
Hmm.

Even though I program in Qt now instead of MFC I still do that.

m_ = Class Member
g_ = Global or Static class variable

local does not have m_ or g_
John

My gentoo overlay
Instructons for overlay
Top
Voltago
Advocate
Advocate
User avatar
Posts: 2593
Joined: Tue Sep 02, 2003 1:54 pm
Location: userland

  • Quote

Post by Voltago » Wed Jan 06, 2010 9:05 pm

But do you really have that many variables (that of course have speaking names) around that you need that? And if you need a distinction for members, why not use the instance name as prefix? With IntelliSense (or whatever you call that functionality that pops up a list of choices as soon as you type 'this->' in most IDEs) that would probably ease coding as well.
Top
dmitchell
Veteran
Veteran
User avatar
Posts: 1159
Joined: Sat May 17, 2003 4:51 pm
Location: Austin, Texas

  • Quote

Post by dmitchell » Wed Jan 06, 2010 9:59 pm

Also, be aware of the possibility of namespace aliases:

Code: Select all

namespace long_namespace_name { ... }

namespace lnn = long_namespace_name;
Your argument is invalid.
Top
drescherjm
Advocate
Advocate
Posts: 2792
Joined: Sat Jun 05, 2004 5:46 am
Location: Pittsburgh, PA, USA

  • Quote

Post by drescherjm » Wed Jan 06, 2010 10:02 pm

Also, be aware of the possibility of namespace aliases
Thanks I was not aware of that. Thanks.
But do you really have that many variables (that of course have speaking names) around that you need that?
Probably not. Force of habit after writing somewhere between 600K and 800K lines of MFC code over the last 12 to 13 years...

I have dropped the C prefix from all classes but that was long ago even when writing MFC code. At some point I realized that was pointless and stopped that. :lol:
John

My gentoo overlay
Instructons for overlay
Top
Post Reply

12 posts • Page 1 of 1

Return to “Portage & Programming”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy