<p>The Gang of Four's <a href="http://en.wikipedia.org/wiki/Design_Patterns" rel="nofollow noreferrer">Design Patterns</a> uses a word processor as an example for at least a few of their patterns, particularly Composite and Flyweight.</p>

<p>Other than by using C or C++, could you really use those patterns and the object-oriented overhead they entail to write a high-performing fully featured word processor? </p>

<p>I know that Eclipse is written in Java but I haven't used it much so I don't know if it's all that fast or as polished as something like Visual Studio, which has a C++ based text editing system.</p>

<hr>

<p>I only used C++ and Java as examples. The question has more to do with the overhead of having a lot of in-memory objects like you would in an application such as a word processor or even a game. </p>

<p>Design patterns promote abstraction at the expense of parsimony even though they usually point out when you might take some kind of performance hit. Word processors and especially games get the most benefit from being as close to the metal as possible. </p>

<p>I was just wondering if anyone knew of an fast object-oriented word processor or text editor that wasn't written in C++, and whether they'd build one using patterns or would they forgoe a lot of the abstracting away of things?</p>

[{'answer_id': 15653, 'author': 'eplawless', 'author_id': 1370, 'author_profile': 'https://Stackoverflow.com/users/1370', 'pm_score': 0, 'selected': False, 'text': '<p>This question actually seems to be about Java vs. C++ performance, and that\'s not the object orientation so much as running on a virtual machine with garbage collection and such.</p>\n\n<p><a href="http://scribblethink.org/Computer/javaCbenchmark.html" rel="nofollow noreferrer">This whitepaper</a> on Java vs. C++ performance might be worth a read.</p>\n'}, {'answer_id': 15660, 'author': 'Josh', 'author_id': 257, 'author_profile': 'https://Stackoverflow.com/users/257', 'pm_score': 2, 'selected': False, 'text': '<p>Well, <a href="http://en.wikipedia.org/wiki/Flyweight_pattern" rel="nofollow noreferrer">flyweight</a> is a ridiculous pattern to use in a word processor.  IIRC, they had each character being referenced as a object [note: it was for each <em>glyph</em>, which is still crazy because your OS will happily draw that for you].  With a pointer being wider than a character and all the processing associated with indirection, you\'d be mad to use that particular pattern that way in a word processor.</p>\n\n<p>If you\'re interested in the design of word processors, I found an article that doesn\'t address patterns but does look at some of the <a href="http://www.bluemug.org/research/text.pdf" rel="nofollow noreferrer">data structures underlying word processor design and design considerations</a>.</p>\n\n<p>Try to remember that design patterns are there to make your life easier, not for you to be pure.  There has to be a reason to use a pattern, it has to offer some benefit.</p>\n'}, {'answer_id': 15667, 'author': 'maetl', 'author_id': 14446, 'author_profile': 'https://Stackoverflow.com/users/14446', 'pm_score': 4, 'selected': True, 'text': "<p>Flyweight really is just a way of conserving resources in situations where there are thousands of objects with intrinsic shared state, so it could be useful in higher level languages than C/C++. Maybe the GoF's example using glyphs in a document was not the best choice to illustrate this pattern.</p>\n\n<p>I think there's a lot more to building a high performance word processor than just these basic patterns though - not sure whether there is anything in GoF that rules out being able to successfully do this.</p>\n\n<p>Generally, Visual Studio (VS) is more advanced and performs significantly better than Eclipse - at least, the versions of VS that I have seen. Eclipse is one of the most impressive Java applications out there though, it runs quite well on more recent machines with lots of RAM.</p>\n"}, {'answer_id': 15750, 'author': 'graham.reeds', 'author_id': 342, 'author_profile': 'https://Stackoverflow.com/users/342', 'pm_score': 0, 'selected': False, 'text': '<blockquote>\n  <p>One of the things you have to remember was that the GoF book was written in the early 90s, when the prevalent OSes did not have extensive graphic libraries. Even Windows was not yet an OS at that time.</p>\n</blockquote>\n\n<p>IIRC GoF was released in 1994. Even in 1994 Windows 95 Beta was available (and running on my 486DX33) and Windows 3.x had been around since roughly 1990.</p>\n'}, {'answer_id': 15796, 'author': 'Michael Neale', 'author_id': 699, 'author_profile': 'https://Stackoverflow.com/users/699', 'pm_score': 0, 'selected': False, 'text': "<p>Eclipse + netbeans + IntelliJ all are written pretty much all in java or <em>something</em> that runs on the JVM (not C++). In at least 2 of those IDEs I have spent some time with the editor code, so I can assure you its all java (and its not easy either). </p>\n\n<p>VS 2005 was my last experience of visual studio, and even then I thought eclipse was much more responsive (intelliJ doubly so given time to warm up and index). </p>\n\n<p>Not sure how thats relevant but thats my experience. But I am surprised visual studio is still today written in C++ - I would think that it would be in Microsoft's interest to use C# - if nothing else it would really push its performance hard, nothing like eating your own dog food !</p>\n"}, {'answer_id': 193441, 'author': 'Draemon', 'author_id': 26334, 'author_profile': 'https://Stackoverflow.com/users/26334', 'pm_score': 1, 'selected': False, 'text': '<p>The point of GoF and patterns in general is to talk about how to do things "right" as in correct, not necessarily "right" as in right for the circumstances. Where performance is an issue, and you find that no named pattern gives adequate performance, then perhaps you can justify going your own way. But a good knowledge of patterns gives you a "sensible default" and will probably mean that you sacrifice clarity / SoC / etc only so much as is necessary to give adequate performance.</p>\n\n<p>Feeling that you are "deviating" from the norm encourages you to a) think twice, and b) comment the non-idiomatic code well.</p>\n\n<p>Patterns are vital knowledge, but nothing is gospel and you must always apply judgement.</p>\n\n<p>Having said all that - I can\'t think of any reason why you couldn\'t write a decent text editor using patterns and a modern JDK</p>\n'}, {'answer_id': 359765, 'author': 'Stephan Eggermont', 'author_id': 35306, 'author_profile': 'https://Stackoverflow.com/users/35306', 'pm_score': 0, 'selected': False, 'text': '<p>Yes, current machines are fast enough and have enough memory that that is possible. If you take a look at Squeak, you see a Smalltalk IDE written in Smalltalk, significantly slower than Java, but still fast enough. HD video editing on the other hand is something that currently has a need for some lower-level support.</p>\n'}]
['https://Stackoverflow.com/questions/15649', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1659/']