LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Are you a C, C++, or C/C++ developer? (https://www.linuxquestions.org/questions/programming-9/are-you-a-c-c-or-c-c-developer-626531/)

JMJ_coder 03-07-2008 10:59 PM

Are you a C, C++, or C/C++ developer?
 
Hello,

Do you focus on just one language or do you focus on both languages?

Do you feel that they automatically go together? That they are mutually exclusive? That one doesn't necessarily imply the other? Other?

Wim Sturkenboom 03-08-2008 12:47 AM

I do not focus on one language, but in the C family it's only C (and in general it's not OOP).

jlliagre 03-08-2008 03:42 AM

I love C but avoid C++ like plague. I stick with Java for OO programming.

graemef 03-08-2008 05:03 AM

Whilst I occasionally use C most of my work is in OO and thus when I want a compiled end product I look towards C++.

brianL 03-08-2008 07:12 AM

I'm trying to teach myself several programming languages at once, trouble is I'm a bad teacher and a worse pupil.

dmail 03-08-2008 07:28 AM

I use C++ more than C, I just find it harder and less productive to programme without the use of such things as templates and overloading.

ta0kira 03-08-2008 10:31 AM

I use 100% C++ when I'm writing something with no target OS. When I write for *nix, though I generally have to use libc which is C, and I also try to make my library APIs C if they aren't an object libraries. I guess a more accurate way to say it is that if I want to write a "real" program that deals with files, threads, and processes then I'll make it for *nix because I don't want to determine what's POSIX and what's C89/99.

I generally program in terms of objects, so I use a lot of dynamic lists of objects and encapsulated or embedded objects, so I have to write those in C++. Most of my C++ sources in a dual project have both a C "include" header and a C++ local header.

I'll make as many sources C as possible and I greatly prefer the C I/O API to that of C++. For one, it seems like the C++ I/O system is only designed so that one has the option to avoid classic C, and also you don't have control over low-level things such as fcntl with C++. Overloaded std::ostream operator << are extremely useful, but ultimately impractical unless you're debugging a C++ command-line tool.
ta0kira

shambler 03-09-2008 12:16 AM

I prefer C++ so I can do OO with objects and inheritance - makes a lot of work I do so much easier. As do namespaces and a few other goodies. Being able to do C style i/o or C++ style i/o is particularly helpful, especially if porting C code to C++. Partial ports or mixed C/C++ programming using extern "C" { .. } is a good thing as well.

However, I stay away from some C++ language "features" such as templates. I need to do both C and C++, plus php, python, xhtml. css, javascript and a bunch more, and could do without cluttering up my brain any more than necessary.

ta0kira 03-09-2008 01:09 AM

Quote:

Originally Posted by jlliagre (Post 3081850)
I love C but avoid C++ like plague. I stick with Java for OO programming.

I don't know that I've ever heard it put that way before. Most people who use C choose C++ over Java as far as I can tell (to include me.) You really lose a lot of functionality with OO in Java because:
  • Single-inheritance only
  • No non-abstract members allowed in abstract classes
  • No virtual inheritance
  • No direct interface with C
(Again with no evidence) it seems to me that the Java->C++ barrier tends to be the complexity of memory management in C++ or maybe just the simplicity of GUIs in Java. Since you're a C user, does that mean the GUI does it for you?
ta0kira

fantas 03-09-2008 01:28 AM

Mixture of both. Probably something like C with classes.

I love the C++ language features (especially templates, inheritance etc.) but can easily live without stuff like e.g. the iostreams or static_cast (or even STL) which seem to me very convoluted (they have their purpose of course, but it seems only to those people who need the extra safety belt).

Dan04 03-09-2008 03:28 AM

Quote:

Originally Posted by ta0kira (Post 3082719)
You really lose a lot of functionality with OO in Java because:
  • No non-abstract members allowed in abstract classes

Not true. I think you're confusing abstract classes with interfaces.

Quote:

Originally Posted by ta0kira (Post 3082719)
  • No virtual inheritance

I'm curious: What do you use it for? I never have.

Dan04 03-09-2008 03:36 AM

Quote:

Originally Posted by JMJ_coder (Post 3081712)
Hello,

Do you focus on just one language or do you focus on both languages?

I focus on C++ because that's what they make me write at work.

Quote:

Originally Posted by JMJ_coder (Post 3081712)
Do you feel that they automatically go together? That they are mutually exclusive? That one doesn't necessarily imply the other? Other?

They're two very different, though related languages.

C++ adds convenience, but also lots of ugliness.

Nylex 03-09-2008 08:34 AM

I learnt C++ and haven't really bothered learning C as there's no need for me to. I don't usually use classes, but I make use of STL stuff (vectors, for example).

sci3ntist 03-09-2008 09:57 AM

C is the best, I always prefer to write in c and perl, they are the best.

ta0kira 03-09-2008 10:48 AM

Quote:

Originally Posted by Dan04 (Post 3082747)
I'm curious: What do you use it for? I never have.

Normally if a class inherits a base class more than once it will contain that many independent copies of it. Virtual inheritance merges those copies into one:
Code:

              +--> class middle1 --+
class base1 --|                    |--> class final1
              +--> class middle2 --+

final1 will only have one copy of base1 if middle(1|2) use virtual inheritance, whereas it would have 2 if one or both didn't. This helps in 2 ways:
  • Allows e.g. class dog to be created from class mammal and class domestic, both of which inherit class animal individually.
  • Allows abstract functions to be defined by other classes that are inherited:
    Code:

    struct abstract
    {
            virtual void function() = 0;
    };

    class defines_abstract : virtual public abstract
    {
            void function() { }
    };

    struct uses_abstract : virtual public abstract
    {
            inline void something()
            { this->function(); }
    };

    class steals_abstract : public uses_abstract, public defines_abstract
    {
            //no definition of 'function' needed
    };

    int main()
    {
            steals_abstract abstractness;
            abstractness.something();
    }

ta0kira


All times are GMT -5. The time now is 06:35 PM.