472,365 Members | 1,263 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,365 software developers and data experts.

C is better than C++ for small projects, right?

You can scroll down to the last line of this post in order to find the
question I really want to discuss.

I was just pondering the competing applicability of C vs. C++ in certain
problem domains. Then I saw this as Stroustrup's FAQ of the day:

http://www.research.att.com/~bs/bs_faq.html#C-is-better
Q:"C is better than C++ for small projects, right?"

A:"Not in my opinion. I never saw a project for which C was better than C++
for any reason but the lack of a good C++ compiler."
What I was thinking about was not the size of the project, but rather the
level of the project in terms of abstraction. Here are some products I
know of which are written in C, and I wonder if there is any compelling
reason that C++ could not be used, or any significant advantage to using
C++.

DBus, OpenSSH, the Linux kernel, OpenGL, Emacs (first implemented in C by
James Gosling).

If I were asked what the biggest problem with using C++ for a project is, I
would say the difficulty in learning C++. Linus Torvalds has used some
strong words to state his opinion on using C++ in the Kernel.

<quote>
On Tue, 20 Jan 2004, Robin Rosenberg wrote:

This is the "We've always used COBOL^H^H^H^H" argument.


In fact, in Linux we did try C++ once already, back in 1992.

It sucks. Trust me - writing kernel code in C++ is a BLOODY STUPID IDEA.

The fact is, C++ compilers are not trustworthy. They were even worse in
1992, but some fundamental facts haven't changed:

- the whole C++ exception handling thing is fundamentally broken. It's
_especially_ broken for kernels.
- any compiler or language that likes to hide things like memory
allocations behind your back just isn't a good choice for a kernel.
- you can write object-oriented code (useful for filesystems etc) in C,
_without_ the crap that is C++.

In general, I'd say that anybody who designs his kernel modules for C++ is
either
(a) looking for problems
(b) a C++ bigot that can't see what he is writing is really just C anyway
(c) was given an assignment in CS class to do so.

Feel free to make up (d).

Linus
</quote>

OTOH, we have this more scientific sounding assessment suggesting there /is/
merit to using C++ in the kernel:

http://netlab.ru.is/exception/LinuxCXX.shtml
My own opinion is that I think C code is ugly. That really is a bit more
reasoned than it may sound. A good example is OpenGL and its hundreds of
flags used as parameters to functions all in one flat namespace. I will
however, concede that C++ programmers often fail to make effective use of
namespaces, especially when communicating with humans. I am at fault in
the area.

A good example of what I mean here is the common practice of talking about
"global" functions in the std namespace. There are many times when text,
or code could be made more clear by being explicit about, e.g., which
getline is being described or invoked. IOW, rather than writing getline in
a tutorial, or other context where the meaning may not be clear it may be
more effective to write std::getline. I sometimes get the sense that C++
programmers feel mildly embarrassed about namespaces. Many also fail to
see namespaces as a means of human-to-human communication. They think of
them exclusively as a means of avoiding naming collisions.

I do wonder if the abstractness of C++ does (or can) make C++ more difficult
to work with when it comes to code that's close to the metal. That is,
code which depends closely on the exact memory addresses being accessed,
and order of machine instruction invocation?

Is C++ a good language for writing device drivers and other OS components?

--
If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true.-Bertrand Russell
Jul 23 '05 #1
4 3004
* Steven T. Hatton:

Is C++ a good language for writing device drivers
C is, and C++ incorporates essentially all of C while
adding little or no overhead, and much better abstraction. But
that assumes a reasonable interpretation of the question. The
reasonable interpretation: we're talking about specific implementations
that provide the necessary functionality (types, linkage, and so on),
because standard C and standard C++ only allow _programs_ to be
created, and in that perspective it really boils down to QOI.

and other OS components?


A good part of Windows is, AFAIK, implemented in C++.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #2
Alf P. Steinbach wrote:
* Steven T. Hatton:

Is C++ a good language for writing device drivers


C is, and C++ incorporates essentially all of C while
adding little or no overhead, and much better abstraction. But
that assumes a reasonable interpretation of the question. The
reasonable interpretation: we're talking about specific implementations
that provide the necessary functionality (types, linkage, and so on),
because standard C and standard C++ only allow _programs_ to be
created, and in that perspective it really boils down to QOI.


It's conceivable that a compiler built strictly for C might use different
strategies more suited to low-level programs than a C++ compiler. But the
question of using C verses C++ is really a question of whether the C++
specific parts of C++ are useful or harmful in implementing low-level
components.

Another example I could have mentioned is sun's implementation of Java.
Much of that code is written in C. That is, it would compile with C
compiler.
and other OS components?


A good part of Windows is, AFAIK, implemented in C++.


Windows NT started out being written in C with special OO constructs. Where
it's gone since, I don't know. As to whether Windows is an example of the
right way to do things, that is a mater of opinion.

--
If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true.-Bertrand Russell
Jul 23 '05 #3
A good part of Windows is, AFAIK, implemented in C++.


I would say only Windows GDI, GDI+, and COM related portions (OLE, MTS,
DCOM, etc) are written in C++. Although, they use the same compiler for both
C and C++ source.

ben
Jul 23 '05 #4
Steven T. Hatton wrote:
DBus, OpenSSH, the Linux kernel, OpenGL, Emacs (first implemented in C by
James Gosling).
They lack a good C++ compiler. The authors of those systems started before
C++ had grown up and standardized. And we still don't have a
standards-compliant compiler.

The answer to your Subject line is that C++ is always better for small
projects with small markets, because when you use the Standard Library
correctly (and a little Boost) you can write code that looks just like it
was written in a Very High Level Language.
- the whole C++ exception handling thing is fundamentally broken. It's
_especially_ broken for kernels.
- any compiler or language that likes to hide things like memory
allocations behind your back just isn't a good choice for a kernel.
- you can write object-oriented code (useful for filesystems etc) in C,
_without_ the crap that is C++.
Linus likes to know what opcodes he's getting. But I don't see Bjarne with a
gun to his head forcing him to use those language features.

C++, ultimately, is nothing but C with the ability to call statically typed
virtual functions. If you don't need all the extra syntactic sugar and
exception-handling salt, you are free not to use them.

So Linus's argument is just "lack of a good C++ compiler".

A good counter example here is an ORB, such as COM/ActiveX. MS maps
published object methods onto their implementation of the C++ vtable system.
Because MS knows what opcodes they are getting (and because C++ provides
vtables robustly in a way that hides the fragile details), we have an aspect
of C++ pushed down to the kernel level. (ActiveX is indeed bloatware, but
you don't need to use all the extra stuff if you don't want it. IUnknown and
IDispatch are enough...)

So in between snarling and foaming at the mouth, Linus needs to confess how
ORBs on Linux typically work...
Is C++ a good language for writing device drivers and other OS components?


Those in love with C are really enamored of portable assembly. They like
knowing what opcodes they get at each juncture.

C++ has a different set of tricks and traps, but fundamentally it's also
portable assembly.

--
Phlip
http://www.c2.com/cgi/wiki?ZeekLand
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
1
by: broebel | last post by:
I'm just wondering, people tell me that helping to debug someone elses program is a really good way to learn to understand the language it's programmed in. My question is: from wich point of...
5
by: Hugo Elias | last post by:
Hi all, I have an idea for a better IDE. Though I don't have the skills required to write such a thing, if anyone's looking for a killer app, maybe this is it. If I'm typing at a rate of 10...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
1
by: Xiangliang Meng | last post by:
Hi, all. Recently, I find there is a way in our project to maintain a global set in many files by using preprocessing directives. I'm wondering if we could find a better method for this. Many...
11
by: Daylor | last post by:
hi. im using option strict on. im doing in ,from the simple reason ,to be warn when there are implict conversion like string to int ,int to string. BUT. the price ,(now i see ), is very bad....
22
by: JoeC | last post by:
I am working on another game project and it is comming along. It is an improvment over a previous version I wrote. I am trying to write better programs and often wonder how to get better at...
169
by: JohnQ | last post by:
(The "C++ Grammer" thread in comp.lang.c++.moderated prompted this post). It would be more than a little bit nice if C++ was much "cleaner" (less complex) so that it wasn't a major world wide...
6
by: Christopher Vogt | last post by:
Hej everybody, I built something for myself that might help some of you as well. Looking at a couple of PHP template engines made me think. I have two main requirements for a presentation...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.