我应该学会里用C实现面向对象?有没有在C OOP使用项目? [英] Should I learn to implement OOP in C? Are there projects that use OOP in C?

查看:115
本文介绍了我应该学会里用C实现面向对象?有没有在C OOP使用项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

近日,我读完K&安培; R与,几乎所有的,练习和示例。我正打算搬到加速C ++,我穿过<少时href=\"http://stackoverflow.com/questions/351733/can-you-write-object-oriented-$c$c-in-c/351756#351756\">Axel施赖纳的书与ANSI-C OOP

Recently, I finished reading K&R with its, almost all, exercises and examples. I was planning to move to "Accelerated C++" that I came across Axel Schreiner's book OOP with ANSI-C.

我感兴趣,并且想了解它。但投资于它之前,我想知道在C.执行OOP所以,我可以决定,我必须多少时间就可以花的值得。

I am intrigued and want to learn it. But before investing time in it, I want to know the worth of implementing OOP in C. So that I can decide how much time I must spend on it.


  1. 实现用C OOP,是不是真的用吗?或它只是脑力锻炼?

  2. 是其使用OOP?
  3. 任何现有的C项目
  4. 当它是在C使用OOP一个好主意?

  5. 我要投资我的时间吗?

  1. Implementing OOP in C, is it really used? Or its just for mental exercise?
  2. Are their any existing C projects that use OOP?
  3. When it is a good idea to use OOP in C?
  4. Should I invest my time in it?

我认为它恰当的我在这里提到我的背景,这样你们可以指导我更好的办法。我完成了C,C ++,Java和OOP理论大约一年前,已经找到了一份工作了。但随后乔尔的博客等使我意识到,我缺少了很多很多东西。于是我重新拾起书本,并开始正常学习他们。

I think its appropriate that I mention my background here so that you guys can guide me in a better way. I finished C, C++, Java and OOP theory about a year ago, have got a job too. But then Joel's blog and SO made me realize that I lack in a lot many things. So I picked up the books again and start studying them properly.

K&安培; R,加速C ++,算法在C ++和其他一些书籍是我的尝试,以提高我的技能。我不是新的OOP。

所以,你会建议?

K&R, Accelerated C++, Algorithm in C++ and some other books are my attempt to to improve my skills. I am not new to OOP.
So what would you suggest?

感谢您的时间。

推荐答案

OO在C经常需要使用。一般来说,我不认为一个人不能做OOP在C,只要你提供一套上你有OOP给定类型操作功能的意见达成一致。举个例子,你决定创建一个数据结构。如果您提供的功能来创建,添加,删除,并找到数据结构的元素是OO。一般其他语言的自动暗示一个实例变量,并自动在该实例的各种属性作用域提供语法糖。

OO is used in C as often as needed. Generally I don't agree with the opinion that one cannot do OOP in C, as soon as you provide set of functions that operate on a given type you have OOP. Take for example, you decide to create a data structure. If you provide functions to create, add, remove, and find elements of the data structure it's OO. Generally other languages provide syntactical sugar by automatically implying an instance variable and scoping in various properties of that instance automatically.


  1. 至于是不是真的用,答案是肯定的。这不是精神的运动,它在C的有效模式。

  2. 我想到的最好的例子就是 GObject的,通过GLib和GTK +和无关的GNOME很多项目使用。图形对象提供C.建筑对象的方法但是它没有必要在我看来,使用第三方的支持,有于二OO C.许多现有的项目有它,虽然它可能不会在接口present(一个伟大的事情),并在内部用于各种用途(清洁,数据保护,所有常用的OO理由)。

  3. 这是当你找到需要的群体行为和/或数据要在C OOP是个好主意。当你能证明在使用你的对象接口的一些额外的语法费用,花费不是实际完成您的解决方案的时间。不要侧钻得

  4. 您不应该浪费时间学习OO,因为你认为它是优越的,而是应该补充你的未来的解决方案,你应该把它添加到您的工具包。当它似乎做正确的事使用它。熟悉一个人如何做二OO C,最好的办法是做一些C ++,或检查使用一个小C风格的面向对象的好项目。之后,它会很自然的想到你。

  1. As far as "is it really used", the answer is yes. It's not for mental exercise, it's a valid paradigm in C.
  2. The best example that comes to mind is GObject, used by GLib, GTK+ and many projects unrelated to GNOME. GObject provides a way of building objects in C. However it's not necessary to use third party support to have OO in C. Many existing projects have it, although it may not be present in the interface (a great thing in my opinion), and used internally for various purposes (cleanliness, data protection, all the usual OO justifications).
  3. It is a good idea to use OOP in C whenever you find the need to group behaviours and/or data. When you can justify the little extra syntactic expense in using your objects interface, and the time spent not actually completing your solution. Don't get sidetracked.
  4. You should not waste time learning OO because you think it's superior, rather it should complement your future solutions, and you should add it to your toolkit. Use it when it seems the right thing to do. Become familiar with how one does OO in C, the best way would be to do some C++, or examine any good project that uses a little C-style OO. It will seem natural to you after that.

这篇关于我应该学会里用C实现面向对象?有没有在C OOP使用项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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