C与C ++ [英] C versus C++

查看:73
本文介绍了C与C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想说,一般来说,在学习C ++之前你不需要学习C语言。事实上,我会说,确实没有理由学习C语言。在我看来,大多数编程任务都更好用C ++处理
。但是有一个重要的例外

我认为。


我相信这里有很多人不同意我,但它

在我看来,C编程风格比C ++更适合数据库和/或文件系统编程。当然,你可以用C ++对数据库或文件系统进行编程,但在实践中,它主要是用纯粹的C语言完成的。


原因与语言能力无关。作为C的超集

,显然C ++能够做任何C能做的事情。

但是C ++鼓励某种风格。或心态或编程,

这与C风格的编程完全不同。


C ++程序员倾向于用对象思考 - 非永久性的,

存储在内存中的动态数据结构。 C程序员,然而,b $ b,往往会考虑原始数据:连续指针

内存块,结构等等。对象并不总是很好地翻译

涉及永久存储的概念,如磁盘块等。

这就是为什么主要文件系统如XFS,reiser等,以及

数据库系统通常用C编程,即使它们*可以*

也可以用C ++编程。


只是为了避免混淆:我不是*不是说C比C ++更好

。我在说,在实践中,C风格的编程

通常更适合于操作原始数据的程序,例如文件系统或数据库而不是C ++风格

编程,通常围绕内存中的对象。

解决方案

2007 -07-14 16:40, ch******@gmail.com 写道:
< blockquote class =post_quotes>
我会说,一般来说,在学习C ++之前你不需要学习C语言。事实上,我会说,确实没有理由学习C语言。在我看来,大多数编程任务都更好用C ++处理
。但是有一个重要的例外

我认为。


我相信这里有很多人不同意我,但它

在我看来,C编程风格比C ++更适合数据库和/或文件系统编程。当然,你可以用C ++对数据库或文件系统进行编程,但在实践中,它主要是用纯粹的C语言完成的。


原因与语言能力无关。作为C的超集

,显然C ++能够做任何C能做的事情。

但是C ++鼓励某种风格。或心态或编程,

这与C风格的编程完全不同。


C ++程序员倾向于用对象思考 - 非永久性的,

存储在内存中的动态数据结构。 C程序员,然而,b $ b,往往会考虑原始数据:连续指针

内存块,结构等等。对象并不总是很好地翻译

涉及永久存储的概念,如磁盘块等。



我没有查找任何数据库代码,但大多数操作系统代码我都是已经看到了

非常面向对象,结构是对象和函数

对它们进行操作的方法,并且有构造函数和

析构函数。但是由于C中缺少OO支持,所有数据都是公共的,而且方法不是成员,构造函数必须是手动调用的

< blockquote class =post_quotes>
这就是为什么像XFS,reiser等主要文件系统以及

数据库系统通常用C编程的原因,即使它们*可以*

也可以用C ++编程。



我会说它们是用C语言编程的,因为它们必须是用C语言编写的操作系统的一部分(用于FS)并且因为如果用C语言写的东西是
,它可以从几乎任何其他语言调用(对于DB

应用程序)。那个以及大多数数据库项目都是几十年或者从代码中得到的事实,重写一些仅仅用于改变语言的东西通常不是一个流行的想法。


为了避免混淆:我不是*说* C比C ++更好

。我在说,在实践中,C风格的编程

通常更适合于操作原始数据的程序,例如文件系统或数据库而不是C ++风格

编程,它通常围绕内存中的对象。



说过我确实认识到所有问题都不是最好的事实

用OO设计解决了,程序编程也有它'的位置。

我个人发现当你混合几个

样式时你会得到最好的效果(模板和OO就是一个很好的例子)。


-

Erik Wikstr?m


ch ****** @ gmail.com 写道:


我会说,一般来说,你不要

学习C ++之前需要学习C语言。事实上,我会说,确实没有理由学习C语言。在我看来,大多数编程任务都更好用C ++处理
。但是我认为有一个重要的例外




定期,一些白痴会想出这个话题。这是非常没有意义的,而且之前已经被淘汰了。您正在从Google网上论坛发布

,了解如何搜索过去的讨论。


Brian


7月14日下午5:13,Erik Wikstr?m< Erik-wikst ... @ telia.comwrote:


2007-07- 14 16:40,chsal ... @ gmail.com写道:



[...]


虽然我已经认识到所有问题都不是最好的事实使用OO设计解决了b $ b,程序编程也有它的位置。



当你使用C和程序

编程时,你做的第一件事是什么。你定义了一个结构,一组函数,它们操纵它,并且交叉你的手指没有客户代码

操纵它而不是通过你的结构。


或者您使用C ++,因此您可以将数据成员声明为私有。


封装是一件好事,无论您的范例是什么? >
使用。


-

James Kanze(Gabi Software)电子邮件: ja ********* @ gmail.com

Conseils eninformatiqueorientéeobjet/

Beratung in objektorientierter Datenverarbeitung

9placeSémard,78210 St.-Cyr-l''coco,France,+ 33(0)1 30 23 00 34


I would say that, in general, you don''t need to learn C before
learning C++. In fact, I would go as far as saying that there''s
really no reason to learn C at all. Most programming tasks are better
handled in C++, in my opinion. But there is one significant exception
I think.

I''m sure there are many people here who will disagree with me, but it
seems to me that the C programming style is somewhat more well suited
to database and/or file-system programming than C++. Of course, you
*could* program a database or a file system in C++, but in practice,
it''s mostly done in pure C.

The reason has nothing to do with language capability. As a superset
of C, C++ is more than capable of doing anything C can do, obviously.
But C++ encourages a certain, "style" or "mindset" or programming,
which is totally different than C style programming.

C++ programmers tend to think in terms of objects - non-permanent,
dynamic data structures which are stored in memory. C programmers,
however, tend to think in terms of raw data: pointers to contiguous
memory blocks, structs, etc. And objects don''t always translate well
to concepts involving permanent storage, like disk blocks, etc.
That''s why major file systems like XFS, reiser, etc., as well as
database systems are usually programmed in C, even though they *could*
just as well be programmed in C++.

Just to avoid confusion: I''m *NOT* saying that C is better than C++
for anything. I''m saying that, in practice, C-style programming
usually lends itself better to programs which manipulate raw data on
disk, such as file-systems or databases, rather than C++ style
programming, which usually revolves around objects in memory.

解决方案

On 2007-07-14 16:40, ch******@gmail.com wrote:

I would say that, in general, you don''t need to learn C before
learning C++. In fact, I would go as far as saying that there''s
really no reason to learn C at all. Most programming tasks are better
handled in C++, in my opinion. But there is one significant exception
I think.

I''m sure there are many people here who will disagree with me, but it
seems to me that the C programming style is somewhat more well suited
to database and/or file-system programming than C++. Of course, you
*could* program a database or a file system in C++, but in practice,
it''s mostly done in pure C.

The reason has nothing to do with language capability. As a superset
of C, C++ is more than capable of doing anything C can do, obviously.
But C++ encourages a certain, "style" or "mindset" or programming,
which is totally different than C style programming.

C++ programmers tend to think in terms of objects - non-permanent,
dynamic data structures which are stored in memory. C programmers,
however, tend to think in terms of raw data: pointers to contiguous
memory blocks, structs, etc. And objects don''t always translate well
to concepts involving permanent storage, like disk blocks, etc.

I have not looked one any DB code but most OS code I''ve seen have been
quite object oriented, with structs being the objects and the functions
that operate on them the methods, and there are both constructors and
destructors. However due to the lack of OO support in C all data is
public and the methods are not members, and constructors have to be
called manually.

That''s why major file systems like XFS, reiser, etc., as well as
database systems are usually programmed in C, even though they *could*
just as well be programmed in C++.

I''d say that they are programmed in C because either they have to be
part of an OS written in C (for the FS) and because if something is
written in C it can be called from almost any other language (for the DB
application). That and the fact that most DB projects are either decades
old or derived from code that is, rewriting something that works just to
change the language is usually not a popular idea.

Just to avoid confusion: I''m *NOT* saying that C is better than C++
for anything. I''m saying that, in practice, C-style programming
usually lends itself better to programs which manipulate raw data on
disk, such as file-systems or databases, rather than C++ style
programming, which usually revolves around objects in memory.

Having said that I do recognise the fact that all problems are not best
solved with an OO design, procedural programming also have it''s place.
Personally I find that you get the best effect when you mix a couple of
styles (templates and OO is a good example).

--
Erik Wikstr?m


ch******@gmail.com wrote:

I would say that, in general, you don''t need to learn C before
learning C++. In fact, I would go as far as saying that there''s
really no reason to learn C at all. Most programming tasks are better
handled in C++, in my opinion. But there is one significant exception
I think.

At regular intervals, some idiot will come up with this topic. It''s
pretty pointless, and it''s all been hashed out before. You''re posting
from Google Groups, learn how to search for past discussions.

Brian


On Jul 14, 5:13 pm, Erik Wikstr?m <Erik-wikst...@telia.comwrote:

On 2007-07-14 16:40, chsal...@gmail.com wrote:

[...]

Having said that I do recognise the fact that all problems are not best
solved with an OO design, procedural programming also have it''s place.

And what''s the first thing you do when you use C, and procedural
programming. You define a struct, a set of functions which
manipulate it, and cross your fingers that no client code
manipulates it other than through your struct.

Or you use C++, so you can declare the data members private.

Encapsulation is a good thing, regardless of the paradigm you''re
using.

--
James Kanze (Gabi Software) email: ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l''école, France, +33 (0)1 30 23 00 34


这篇关于C与C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆