Git Product home page Git Product logo

refactoring-puzzle-cpp's Introduction

Refactoring puzzle

This is an attempt at a C++ implementation of the refactoring puzzle by Tony Morris based on his original C# implementation.

C++11 is unapologetically used. There is no reason to suffer with older versions of the C++ language.

Setup

The project uses CMake to build.

googletest is used for testing. It is not distributed in this repository. You need to download it and put it at subdirectory gtest.

To run the tests:

$ mkdir build
$ cd build
$ cmake ..
$ make
$ test/TestRefactoringPuzzle

Notes

Memory management

In the absence of automatic garbage collection, I used std::shared_ptr to prevent memory leaks.

Algebraic data types

As with the C# code, I use the most "obvious" simulation of algebraic data types using an abstract base class with subclasses.

No type erasure

Since C++ templates do not operate by type erasure, virtual member function templates are semantically impossible in C++. The simplest (not fastest) workaround was to use dynamic_cast to handle all branches from a member function template in the base class.

Templates

Since templates are not compiled until an attempt at instantiation of use, only exhaustive testing of specific instantiations can provide confidence that templated code actually does what we mean it to do.

refactoring-puzzle-cpp's People

Contributors

franklinchen avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.