Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

C programming in 2011 inspired me to ask this. I did C++ for Windows 5 odd years ago and since then it has been "advanced" languages. I am about to start on a c++ project soon, for linux. So what should I know to write good clean code?

Also, are there popular unit-testing frameworks for c++ like nunit? What's a good ide other than vi for the same? How different is c++ on linux from c++ on windows?

share|improve this question
2  
I think it is funny that you think C++ is not advanced? Was the term you were thinking of "Managed" – Loki Astari May 26 '11 at 14:20
1  
A poor joke:( - hence the quotes – Subu Subramanian May 26 '11 at 14:47
3  
"Advanced" doesn't seem like the right word for C++. I think the word you're looking for is "complicated". – tylerl Jun 7 '11 at 18:22

6 Answers

IDEs:

  • KDevelop — this is IDE by KDE. KDE is mainly C++, so they know what they're doing. This is the one to use, if you're gonna do anything with KDE GUI or libs.
  • Eclipse CDT — cross-platform classic, but works much snappier on Linux than on Windows, not to mention OSX.
  • Anjuta — this IDE is part of GNOME project, so this is the one to use if you're gonna do anything with GTK+.
  • Qt Creator — another cross-platform one. This one is specifically for Qt, supports Qt 4.7's QML language. This is probably the thing to use if you're developing Qt apps, especially for platforms like MeeGo.

Except cases noted above, choosing either one is really matter of personal preference.

share|improve this answer
3  
Qt Creator is also nice. – Vitor Braga May 26 '11 at 12:55
@Vitor: is it a full-fledged IDE now? – vartec May 26 '11 at 12:57
@vartec Yes. Qt Creator always has been a full-fledged IDE, you may be confusing it with Qt Designer. – Vitor Braga May 26 '11 at 13:03
+1 for Qt Creator – Nathan Osman May 26 '11 at 20:11
2  
You could add Emacs. – Ubiquité May 27 '11 at 11:14
show 8 more comments

This SO discussion, over a year old, talks about C++ unit testing on Linux. I hope it is not too dated for your needs.

Other than Vi, one comparable program that comes to the top of the mind is, Emacs of course :) But again another discussion on SO appears to have covered many IDEs for C++ on Linux.

Standard C++ should be same on both. The differences could show when the program interacts closely with the platform and the OS. So, what you have learned in C++ on Windows should be fine to get going on Linux.

share|improve this answer
+1 for the answering with answers – tylermac Jun 8 '11 at 13:49

So what should I know to write good clean code?

The code itself is about the same. In fact, while I haven't used recent versions of Visual Studio, my experience with gcc is that its support for the C++ and C0X standards is superior to VS 2005.

Also, are there popular unit-testing frameworks for c++ like nunit?

Oh, definitely. There are a ton of them, and more all the time.

What's a good ide other than vi for the same?

The IDE du jour on Linux is Eclipse, but I find it complicated to set up. Mostly, I use a command line to do builds, and a combination of gedit and kate for text editing. There are various other new text editors coming out all the time, too.

How different is c++ on linux from c++ on windows?

Here are a couple of things:

  • gcc's pragmas don't give you the same fine-grained control over the compiler errors and warnings that Visual Studio does.
  • One of my favorite tricks on Windows and Mac OS doesn't work on Linux. That trick is to write a DLL/dylib using C++ internals, export a C API, and then be able to call into it from C programs. Linux shared objects (the local equivalent of a DLL) can't really do that easily, because the C++ standard library .so isn't in the default search path. If you don't do a bunch of weird stuff to your C program, it will fail as soon as it dynamically loads your .so at runtime: your .so will try to dynamically load the standard library .so, it won't find it, and then your program will exit.
share|improve this answer
VS2005 is now the version before last. VS2008 was pretty good at doing C++03, and VS2010 includes a lot of C++0x stuff that I'm looking forward to when we switch over sometime this summer. I like having Herb Sutter in charge of VC++. – David Thornley Jun 7 '11 at 13:41
@David: Glad to hear it. The one legacy Windows project I support is stuck on VS2005 for organizational reasons. – Bob Murphy Jun 7 '11 at 16:14
@David - the vs2010 IDE is a bit slower, intellisense is better but finally it has a world class c++ compiler. – Martin Beckett Jun 7 '11 at 18:56

I would say the first thing to do is get comfortable using an IDE like eclipse and set up the build environment first. If you wish to develop using C++ on linux,I highly recommend Eclipse as IDE and CMake based build for your projects. It might take time to get used but beleive me: in the long run, you will get very comfortable.

what exactly do you mean by "clean code": that is upposed to be the same, whether linux or windows? Is nt it? I think you should google for best practices for C++ coding on linux, if thats what you meant by clean code.

share|improve this answer

Ok. I think this is what you are looking for.. http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml

share|improve this answer
That guide has some good points, but much of is only good for Google's legacy code-base which is clearly not exception safe. On new code it's better to make it exception-safe and use exceptions when it makes sense. – Dirk Holsopple Aug 24 '12 at 17:47
@DirkHolsopple: if it has some good points, then why downvote? – MhAcKNI Aug 25 '12 at 18:27
who said I downvoted? – Dirk Holsopple Aug 25 '12 at 19:35

"So what should I know to write good clean code?"

  • In C++, try to use always a new namespace per file (Modular Programming), even if is not required. In C#, you have to use namespace always, altought it already exists. In Java and Delphi, namespaces are mandatory. Namespace or modules, help you to group code.

  • Do you know O.O.P. well, in C++ ?

  • Have you ever use Software Patterns in C++, in a practical matter ?

"What's a good ide other than vi for the same?"

  • I haven't use "vi", but, you may want to learn to use a text editor and a compiler from the command line, first, in both platforms, for simple examples. And if you want to develop G.U.I. apps., then you have to use some frameworks, like QT, Eclipse, wxWidgets, Codeblocks.

"How different is c++ on linux from c++ on windows?"

  • Learn to access and perform operations on the filesystem, thru the command-line, see the differences in path syntax, access rights. Try simple examples of how to access a file, how to read and write a text file in C++, how to create or delete a folder, in both platforms.
share|improve this answer
1  
-1: Because of one-namespace-per-file. Namespaces are for grouping things, even in C# wisdom you don't create a new namespace for every single file. That defeats the purpose of naming classes appropriately. Instead, group things that logically belong together, for example in some graphics application, put together "Rgb", "Yuv", "Cmyk" into a namespace color. – phresnel Aug 31 '11 at 8:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.