Can you create a fast word processor with GoF design templates?

The Gang of Four Design Patterns uses a word processor as an example, at least for some of their patterns, especially composite and flies.

Besides using C or C ++, can you really use these templates and object-oriented overhead, should they write a high-performance, full-featured word processor?

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


As examples, I used only C ++ and Java. This question is more related to the overhead of having a large number of objects in memory, for example, in an application such as a word processor or even a game.

Design patterns promote abstraction at the expense of strengths, even if they usually indicate when you can get some kind of performance hit. Word processors and especially games get the most benefit from being as close to metal as possible.

I'm just wondering if anyone knew about the speed of an object-oriented text editor or a text editor that was not written in C ++, and whether they would build one using templates or whether they would not abstract from things

+4
source share
7 answers

Flyweight is just a way to save resources in situations where thousands of objects have an internal common state, so it can be useful in languages ​​of a higher level than C / C ++. Perhaps the GoF example using glyphs in a document was not the best choice to illustrate this template.

I think that there is much more to creating a high-performance word processor than just these basic templates, although I’m not sure that there is anything in GoF that precludes the possibility of successfully doing this.

As a rule, Visual Studio (VS) is more advanced and works much better than Eclipse - at least the versions of VS that I saw. Eclipse is one of the most impressive Java applications, although it works pretty well on later machines with lots of RAM.

+5
source

Well, flyweight is a funny template for use in a word processor. IIRC, each character had an object [note: it was for every glyph that is still crazy because your OS would love to bring this to you]. If the pointer is wider than the character and all processing associated with indirection, you would be insane to use this template in a text editor.

If you are interested in the design of word processors, I found an article that does not affect templates, but looks at some data structures for the basic design of a word processor and design considerations .

Try to remember that design templates are designed to make your life easier, not to keep you clean. There must be a reason to use the template, it should offer some benefit.

+4
source

The point of GoF and templates in general is to talk about how to do things “right”, as in the right, not necessarily “right”, as in the right to circumstances. In cases where performance is a problem and you find that not a single named template provides adequate performance, perhaps you can justify your path. But a good knowledge of templates gives you a "reasonable default" and probably means that you sacrifice the clarity of / SoC / etc only as much as is necessary to ensure adequate performance.

The feeling that you are “deviating” from the norm encourages you to: a) think twice and b) comment well on the non-idiomatic code.

Templates are important knowledge, but nothing is the gospel, and you must always use judgment.

Having said all this - I can’t think of why you couldn’t write a decent text editor using templates and modern JDK

+1
source

This question, apparently, is related to the performance of Java and C ++, rather than object orientation, just like working on a virtual machine with garbage collection, etc.

This white paper on Java and C ++ performance may be useful for reading.

0
source

One of the things you should remember was that the GoF book was written in the early 90s when there were no extensive graphics libraries in common OSs. At that time, even Windows did not have an OS.

IIRC GoF was launched in 1994. Even in 1994, Windows 95 Beta was available (and runs on my 486DX33), and Windows 3.x has been around since 1990.

0
source

Eclipse + netbeans + IntelliJ all are written almost everything in Java or something that works in the JVM (and not in C ++). In at least 2 of these IDEs, I spent some time with the editor code, so I can assure you all my java (and this is also not easy).

VS 2005 was my last experience in visual studio, and even then I thought that the eclipse was much more responsive (intelliJ is doubly, so there was time for warming up and index).

I don’t know how important this is, but this is my experience. But I’m surprised that the visual studio is still written in C ++ - I would have thought that Microsoft would be interested in using C # - if nothing else had a big impact on its performance, nothing like eating your own dog food!

0
source

Yes, current machines are fast enough and have enough memory that this is possible. If you look at Squeak, you will see the Smalltalk IDE written in Smalltalk, much slower than Java, but still fast enough. High-definition video editing, on the other hand, is something that currently needs some lower-level support.

0
source

Source: https://habr.com/ru/post/1276369/


All Articles