wiki:CodingPatterns

Version 2 (modified by mdavis, 2 years ago) (diff)

--

GEOS Coding Patterns

This page documents coding patterns followed in the GEOS codebase.

The patterns are intended to improve the following:

  • Understandability
  • Performance
  • Memory safety

Older GEOS code may not adhere to all patterns, but the goal is to update it when possible. New code should follow the patterns given here, unless this is not possible for compatibility reasons.

  • Created objects should be returned as a std::unique_ptr<Object>
  • Taking ownership of a returned object should be done as a std::unique_ptr<Object>

Investigations =

Geometry Factory improvements

  • Add createXX methods returning std::unique_ptr<XX>
  • Remove old create methods once all code is switched to using std::unique_ptr

Unique_ptr typedefs?

  • To reduce boilerplate perhaps define typedefs for common types: UP_Geometry, UP_CoordinateSequence, etc

Coordinate Sequence improvements

Goals:

  • Improve performance by avoiding virtual function calls
  • Support immutable use of external coordinate sequence formats

Issues

  • Virtual functions
    • Are they really a performance hit?
    • Use templates?

Tasks

  • Remove mutating methods where not strictly needed
  • Mark non-mutating methods as const to allow immutable use of external coordinate sequence formats
    • Will this work?