Writer/ToDo/Writer Refactoring/Writer Refactoring

From Apache OpenOffice Wiki
< Writer‎ | ToDo(Redirected from OOo Writer Refactoring)
Jump to: navigation, search

Writer Icon.png

Writer Project

Please view the guidelines
before contributing.

Popular Subcategories:

Internal Documentation:

API Documentation:

Ongoing Efforts:


Editing.png This page is in a DRAFT stage.

Problem statement

As Bertrand Meyer [1] describes external software qualities (experienced by the user of the software) like

  • Correctness - The ability of software products to perform their exact tasks, as defined by their specification.
  • Robustness - The ability of software systems to react appropriately to abnormal conditions.
  • Efficiency - The ability of a software system to place as few as possible demands on hardware resources, such as processor time, space occupied etc.

for instances are in direct relation to internal software qualities (experienced only by computer professionals with access to the source code of the software) like modularity, testability, maintainability.

The current Writer code base has some serious quality problems with regards to these internal software qualities what consequently leads to external quality problems like crash reports, malfunctions, performance problems, memory leaks. See [2] for some concrete examples otherwise use IssueZilla and search for defects in OOo Writer.

Some facts and numbers about the writer code and and the code quality (still) in random order

  • Build time - to build the Writer from scratch takes
  • Link time dependencies - linking the Writer roughly takes x minutes on a
  • Code not testable because of cyclic dependencies
  • No unit tests available - Until milestone SRC680m147 there exist not a single unti test for the Writer code
  • Code optimized for legacy computer systems e.g. Win16 - Example: BigPtrArray (see sw/source/core/bastyp/bparr.cxx)
  • Redundant code
  • Big and complex classes with multiple responsibilities - Example: SwDoc
  • No clearly designed and documented interfaces and abstractions
  • Hand crafted data structures (no STL)
  • Unwanted dependencies between UI, Core, Layout
  • Fragile code (Undo, Redlining, ...)
  • Base classes without virtual destructor
  • Single argument constructors are not declared 'explicit'
  • Wrong initialization sequence of class members
  • Lack of documentation
  • Duplicate code - Using CPD [3] with a minimum token count of 100 on SRC680m156 'sw/source' leads to the following results: 11324 duplicate lines of roughly 739620 overall lines of code which nearly amounts to ~1.53% duplicate code.

Goal statement

  • Prioritize problems
  • Break problems into pieces <= 3 man months


On cws writercorerefactoring the following steps are planned:

  • Removal of unused files
 Status: done Details: 19 files which were not build anymore have been removed
  • Removal of unnecessary includes of headers
 Status: done Details: 850 unnecessary includes of header files have been removed in the Writer code base
  • Removal of unused/inactive code (how many lines?)
 Status: in progress Details: There is a lot of code commented out via #if 0 ... #endif, /* */, or no longer used defines e.g. 'JAVASCRIPT'.
 Reason: Inactive code is a unnecessary burden and often confuses potential maintainer of the code. 
  • Minimize code duplication
 Status: new Details: Using CPD [3] with a minimum token count of 100 on SRC680m156 'sw/source' leads 
  to the following results: 11324 duplicate lines of code of roughly 739620 overall lines of code which nearly amounts to 
  ~1.53% duplicate code. Reason Less duplicate code means less code to maintain. Bugs in duplicated code need 
  to be fixed in all duplicate places which are hard to detect without the help of tools, so less duplicate code means 
  fewer redundant sources of bugs.
  • Write unit test
  Status: in progress Details: 1 unit test for BigPtrArray has been introduced
  • Make SwDoc interface based, changes clients of SwDoc to just include the header files for these interfaces instead of the whole doc.hxx
  Goal: Reduce unnecessary build time dependencies, first step to break SwDoc into managable and testable pieces
  Status: in progress 
  Details: SwDoc (see sw/inc/doc.hxx) is a huge class with more than 130 data members and hundreds of member functions. This class 
    has mutliple responsibilities this implies that SwDoc has a lot of different clients. Each of these clients usually requires just a small part 
    of the SwDoc interface. With SRC680m146 434 of 763 source code files directly or indirectly include doc.hxx in which the interface of 
    SwDoc is declared. This results in undesirable build times when changing doc.hxx. 
    X Interfaces for SwDoc have been introduced related code has been changed to use these interfaces instead of the whole doc.hxx
SRC680 m165 cws writercorehandoff
# SwDoc interfaces 0 15
doc.hxx includes 408 cxx + 7 hxx 368 cxx
# classes 2663 2624
# files 1464 1459
Lines of Code 306387 304770
Cyclomatic Complexity 68515 68109
    The interfaces are available at:
        SwNode: For use within the text directory
        SwFormat: For use within the layout directory
  • Replace Writer only OLE objects with Draw OLE objects
  • Replace hand-made bulk data types with STL means (e.g. BigPtrArray, SvPtrArr)


[1] Betrand Meyer, Object Oriented Software Construction, ISBN: 0-13-629155-4

[2] Long existing, hard to fix quality problems in OOo Writer (to be extended)

  • Cannot select whole document when table is at beginning
  • Backspace may take several seconds in documents with many hidden redlines
  • Undo-delete still doesn't work in all circumstances (section-to-section)

[3] Copy Past Detector (CPD) http://pmd.sourceforge.net/cpd.html

Personal tools