Coder Social home page Coder Social logo

immu's People

Contributors

hf avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

immu's Issues

Express type wrappers

Type wrappers usually serve the purpose of wrapping an existing type with a different type in order to better convey meaning. For example, if an object has a unique identifier, usually that would be a String. However, it is a special kind of String. Using it all over the place to refer to the unique identifier is a code smell: it can lead to errors (what id was it?), and it is not descriptive. One can utilize a type wrapper around that String to standardize the usage of the unique identifier as a UniqueIdentifier.

@Immu
interface UniqueIdentifer {
  @Required String identifier();
}

It is slightly bothersome to write UniqueIdentifierBuilder.create().identifier(theIdentifier).build() to create an instance of UniqueIdentifier.

Use UniqueIdentifierBuilder.create(theIdentifier) => UniqueIdentifier for this use case:

  • the Immu has only one property
  • the property is marked as Required

Add support for Optional

Add support for Optional-like types in interfaces. Those will not be compatible with @Required.

Add lazy checked creator to the generated builder

Currently all @Required properties will be present, in order, in the generated builder's creator as parameters. This has a few drawbacks:

  • if many of the properties are @Required then the argument list is too long
  • if you change the order of same-type properties, the order in the creator will be reversed and noticing the change may become challenging for users

A solution to this would be to generate a parameterless create() method and lazily verify that the @Required properties have been supplied to the builder when build() will be called.

An efficient implementation would be to store an array of ints. Each int is a bit-field representing at most 32 properties. The ints are initialized to ~0 and each property gets a unique bit in a specific int position. The first time a property is set on the builder, its bit is flipped to 0. Upon build() iterate over the few integers representing all required properties and throw an exception if not all ints are 0.

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.