Giter Site home page Giter Site logo

缺少使用的example about plooc HOT 1 CLOSED

gorgonmeducer avatar gorgonmeducer commented on July 28, 2024
缺少使用的example

from plooc.

Comments (1)

GorgonMeducer avatar GorgonMeducer commented on July 28, 2024

几个问题:
1、“define init、define cfg、 define interface” 这几个都不是必须的,例子代码只是展示了如果你需要的时候,可以这么用,这也是例子代码的意义——尽可能的展示全部用法。

如果只是要简单继承和派生,你要用的只是
dcl_class()
def_class()
implement()
inherit()
class_internal()

而已。其它关于构造函数,析构函数,接口定义都不是必须的。

2、“我希望有个简单的OOC,让我方便继承,方便调用member function”——你可以看这篇文章 https://aijishu.com/a/1060000000291175
文章里介绍的内容是让你“按需使用”的,用到多少,就做多少,而不是为了OOC就要全部都做的。

截取文章中的一段话:

……帮助大家在偶尔需要用到“面向对象”概念的时候,能简便快捷的使用C语言“搞定”面向对象开发。
在开始后续内容之前,我们需要约定和强调一些基本原则:

  • “零消耗”原则:即,我们所要实现的所有面向对象的特性都应该是“零资源消耗”或至少是“极小资源消耗”。这里的原理是:能在编译时刻(Compiletime)搞定的事情,绝不拖到运行时刻(Runtime)。
  • 务实原则:即,我们不在形式上追求与C++类似,除非它的代价是零或者非常小。
  • “按需实现”原则:即,对任何类的实现来说,我们并不追求把所有的OO特性都实现出来——这完全没有必要——我们仅根据实际应用的需求来实现最小的、必要的面向对象技术。
  • “傻瓜化”原则:即,类的建立和使用都必须足够傻瓜化。最好所见即所得。

提示:如果你日常应用中确实没有涉及到OO的部分,完全没必要去使用PLOOC。这个模板是给那些确实需要用OO,但又必须用C语言的人使用的——意图帮助大家按照“要用多少OO特性就仅仅实现多少OO特性“的方式来部署面向对象。

3、不用传递 this 指针在原理上是做不到的。即便是 C++也只是编译器帮你做了这一步,如果你看汇编会发现,C++仍然在每个方法调用的时候,用第一个参数传递了this指针。遗憾的是C语言无法做到这一点。

如果还有什么疑问,可以在这里留言。

from plooc.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.