arXivDaily arXiv每日学术速递 周一至周五更新
arXiv cs/0001003cs.PL
收藏

为什么C++不适合GUI编程

Why C++ is not very fit for GUI programming

Oleg Kiselyov

摘要:

无意挑起一场圣战,本文列出了作者在开发GUI类库时遇到的几个恼人的C++胎记。C++的类、实例和层次结构的视图与GUI的控件、窗口小部件、窗口类和子窗口的概念非常接近。然而,C++和窗口系统的OO模型是不同的。C++被设计成一种“静态”语言,具有词法名称范围,静态类型检查和在编译时定义的层次结构。另一方面,屏幕对象本质上是动态的;它们通常存在于创建它们的过程/块之外;小部件的层次结构在很大程度上由布局,可见性和事件流定义。许多GUI基础,如窗口和控件的动态和几何层次结构,事件的广播和渗透,都不直接被C++语法或执行语义支持(或作为“异常”支持--双关语)。因此,这些功能必须在C++ GUI代码中模拟。这会导致图形工具包或窗口管理器功能的重复,代码膨胀,参与不安全的实践,并放弃许多强大的C++功能(如范围规则和编译时类型检查)。本文列举了几个主要的C++/GUI的伤口,并说明了他们的简单例子。

英文摘要:

With no intent of starting a holy war, this paper lists several annoying C++ birthmarks that the author has come across developing GUI class libraries. C++'s view of classes, instances and hierarchies appears tantalizingly close to GUI concepts of controls, widgets, window classes and subwindows. OO models of C++ and of a window system are however different. C++ was designed to be a "static" language with a lexical name scoping, static type checking and hierarchies defined at compile time. Screen objects on the other hand are inherently dynamic; they usually live well beyond the procedure/block that created them; the hierarchy of widgets is defined to a large extent by layout, visibility and event flow. Many GUI fundamentals such as dynamic and geometric hierarchies of windows and controls, broadcasting and percolation of events are not supported directly by C++ syntax or execution semantics (or supported as "exceptions" -- pun intended). Therefore these features have to be emulated in C++ GUI code. This leads to duplication of a graphical toolkit or a window manager functionality, code bloat, engaging in unsafe practices and forgoing of many strong C++ features (like scoping rules and compile-time type checking). This paper enumerates a few major C++/GUI sores and illustrates them on simple examples.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑