Giter VIP home page Giter VIP logo

task-list's Introduction

Task List   Build Status

This is an example of code obsessed with primitives.

A primitive is any concept technical in nature, and not relevant to your business domain. This includes integers, characters, strings, and collections (lists, sets, maps, etc.), but also things like threads, readers, writers, parsers, exceptions, and anything else purely focused on technical concerns. By contrast, the business concepts in this project, "task", "project", etc. should be considered part of your domain model. The domain model is the language of the business in which you operate, and using it in your code base helps you avoid speaking different languages, helping you to avoid misunderstandings. In our experience, misunderstandings are the biggest cause of bugs.

Exercise

Try implementing the following features, refactoring primitives away as you go. Try not to implement any new behaviour until the code you're about to change has been completely refactored to remove primitives, i.e. Only refactor the code you're about to change, then make your change. Don't refactor unrelated code.

One set of criteria to identify when primitives have been removed is to only allow primitives in constructor parameter lists, and as local variables and private fields. They shouldn't be passed into methods or returned from methods. The only exception is true infrastructure code—code that communicates with the terminal, the network, the database, etc. Infrastructure requires serialisation to primitives, but should be treated as a special case. You could even consider your infrastructure as a separate domain, technical in nature, in which primitives are the domain.

You should try to wrap tests around the behaviour you're refactoring. At the beginning, these will mostly be high-level system tests, but you should find yourself writing more unit tests as you proceed.

Features

  1. Deadlines
    1. Give each task an optional deadline with the deadline <ID> <date> command.
    2. Show all tasks due today with the today command.
  2. Customisable IDs
    1. Allow the user to specify an identifier that's not a number.
    2. Disallow spaces and special characters from the ID.
  3. Deletion
    1. Allow users to delete tasks with the delete <ID> command.
  4. Views
    1. View tasks by date with the view by date command.
    2. View tasks by deadline with the view by deadline command.
    3. Don't remove the functionality that allows users to view tasks by project, but change the command to view by project.

Considerations and Approaches

Think about behaviour attraction. Quite often, you can reduce the amount of behaviour that relies upon primitives from the outside world (as opposed to internal primitives stored as private fields or locals) simply by moving the behaviour to a value object which holds the primitives. If you don't have a value object, create one. These value objects are known as behaviour attractors because once they're created, they make it far more obvious where behaviour should live.

A related principle is to consider the type of object you've created. Is it a true value object (or record), which simply consists of getFoo methods that return their internal primitives (to be used only with infrastructure, of course), or is it an object with behaviour? If it's the latter, you should avoid exposing any internal state at all. The former should not contain any behaviour. Treating something as both a record and an object generally leads to disaster.

Your approach will depend on whether you learn toward a functional or an object-oriented style for modelling your domain. Both encourage encapsulation, but information hiding techniques are generally only used in object-oriented code. They also differ in the approach used to extract behaviour; functional programming often works with closed sets of behaviour through tagged unions, whereas in object-oriented code, we use polymorphism to achieve the same ends in an open, extensible manner.

Separate your commands and queries. Tell an object to do something, or ask it about something, but don't do both.

Lastly, consider SOLID principles when refactoring:

  • Aim to break large chunks of behaviour into small ones, each with a single responsibility.
  • Think about the dimensions in which it should be easy to extend the application.
  • Don't surprise your callers. Conform to the interface.
  • Segregate behaviour based upon the needs.
  • Depend upon abstractions.

task-list's People

Contributors

antoinecezar avatar arnaudruffin avatar benoitmasson avatar carlklagba avatar dependabot[bot] avatar esandre avatar gemcfadyen avatar hilton avatar martinsson avatar mbirtwell avatar neomatrix369 avatar samirtalwar avatar sandromancuso avatar xstrengthofonex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

task-list's Issues

Kotlin Tests not working

Hello,

after checking this repo out and trying to start the kotlin tests you receive the following message:

Kotlin: Language version 1.1 is no longer supported; please, use version 1.3 or greater.

Typescript tests failing

It seems like the tests are expecting an 'end' event on the output, it never happens. I have no idea why there is a assertion failure like if too much input was received.

Full test failure

Assertion Message: Got more output than expected proabably didn't quit
AssertionError: false == true
    at Object.ok (/Users/johan/js-projects/task-list/typescript/node_modules/nodeunit/lib/types.js:83:39)
    at PassThrough.<anonymous> (/Users/johan/js-projects/task-list/typescript/tests/application_test.js:33:28)
    at emitNone (events.js:67:13)
    at PassThrough.emit (events.js:166:7)
    at emitReadable_ (_stream_readable.js:419:10)
    at emitReadable (_stream_readable.js:413:7)
    at onEofChunk (_stream_readable.js:398:3)
    at readableAddChunk (_stream_readable.js:130:5)
    at PassThrough.Readable.push (_stream_readable.js:111:10)
    at PassThrough.Transform.push (_stream_transform.js:128:32)
    at done (_stream_transform.js:191:17)
    at PassThrough.<anonymous> (_stream_transform.js:122:7)
    at PassThrough.g (events.js:260:16)
    at emitNone (events.js:67:13)
    at PassThrough.emit (events.js:166:7)
    at prefinish (_stream_writable.js:471:12)

node v4.4.7
typescript 2.1.5
I tried a few combinations actually

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.