Giter VIP home page Giter VIP logo

clay's People

Contributors

grant-d avatar jcdickinson avatar k2oss avatar pbbadenhorst avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

clay's Issues

FNV needs unit coverage and cleanup

  • Ambiguous constructors (byte[], span, etc)
  • Null handling
  • Unit coverage - there were units at some stage, where are they now
  • Ensure Fnv(null) returns a consistent (chosen) value
  • Rationalize multiple unused overloads
  • Fix class name, and follow method naming convention from System.HashCode

Add method EnumConvert.Length

We use reflection elsewhere to get the number of members in an Enum.
Optimize this to use expressions and/or cached values.
See #90

Use existing/perf convention for Equals(object)

Please use the following convention for equality.
This pattern occurs in many places in OpenApi.

public override bool Equals(object obj)
    => obj is ApiKeySecurityScheme key // short-circuits if object is unexpected type
    && Equals(key);

This pattern incurs a similar cast, but does not short-circuit the nested call to Equals(T):

... => Equals(obj as ApiKeySecurityScheme)

EnumConvert

Create a class that allows converting between enums and integers.

OpenApi: Equals does not check null properly

For example, does not check for this == null:


        public virtual bool Equals(Contact other)
        {
            if (other is null) return false; // Existing convention is that equal(null, null) = true
            if (ReferenceEquals(this, other)) return true; // OK

            if (!StringComparer.Ordinal.Equals(Name, other.Name)) return false; // throws if other==null

Furthermore, the following checks should be included above (unless it's by-design to have different semantics here):

        public static bool operator ==(Contact contact1, Contact contact2)
        {
            if (contact1 is null && contact2 is null) return true;
            if (contact1 is null || contact2 is null) return false;
            return contact1.Equals((object)contact2);
        }

Rather, use a pattern like this:

        public bool Equals(ReadOnlyJsonObject other) => Equals(this, other);

        public static bool operator ==(ReadOnlyJsonObject x, ReadOnlyJsonObject y) => Equals(x, y);

        // Logic is in one method, not spread across two
        private static bool Equals(ReadOnlyJsonObject x, ReadOnlyJsonObject y)
        {
            if (x is null) return y is null; // (null, null) or (null, y)
            if (y is null) return false; // (x, null)
            if (ReferenceEquals(x, y)) return true; // (x, x)

            if (!x._json.NullableJsonEquals(y._json)) return false;

            return true;
        }

Add SourceCode.Clay.Json.DecimalValidator

  • SourceCode.Json needs a DecimalValidator to parallel the ones for double and int64
  • Per framework design guidelines, LongValidator should be called Int64Validator

OpenAPI Serializers

  • Json serializers for OpenApi
  • Json deserializers for OpenApi
  • Factor into partial classes (per #108 )
  • Units not working (#203)
  • Extra Units

Disambiguate Clay.Collections.NullableEquals

Several extension methods are called NullableEquals since they all deal properly with null values.
However the name is ambiguous both in terms of callsite intent and callsite overloads.
It is hard for a caller to choose which method they actually want and/or which overload has been resolved.

  • Rather name each method differently - eg ListEquals, DictionaryEquals and so on
  • Permit intermixed parameters: IReadOnly/List, IReadOnly/Collection, IEnumerable, ISet
  • Remove bool sequential parameter: Callers should use SetEquals for non-sequential comparisons

ListBufferComparer is YAGNI and somewhat duplicated

  • We have lots of complexity in ReadOnly/ListBufferComparer and EnumerableComparer. But they equality checks are already covered in Clay.Collections.NullableEquals.
  • HashCode.Fnv should not throw for null or empty inputs

Add Decimal to Clay.Number

Clay.Number is a union type, useful for scenarios (such as System.Json) where numeric fidelity is important but the system may return 1 of several different types of numerics.

In specific use cases we need to support Decimal as well as the int and real types already supported.
This will bloat the size of the union unfortunately.

Number should have a Kind property

enum Kind { Integer, Float, Null }

This can be used to disambiguate the general class of types encapsulated in the union - for example, Integer covers all 8 integer subtypes.

A Boolean would not suffice since Null is neither (a Nullable may work but is ugly to use)

Implement MemoryEquals<T> instead of SpanEquals<T>

PR #63 added support for SpanEquals<T>.
However, from the call site this is not straightforward to use since the following idiom needs to be in place:

  // Memory<T>.Span throws if IsEmpty == true
  if (x._nodes.Length != y._nodes.Length) return false;
  if (x._nodes.IsEmpty) return true;;

  return x._nodes.Span.SpanEquals(y._nodes.Span, true);

This idiom is non-obvious.
I suggest we replace these methods with MemoryEquals<T> that operates on ReadOnlyMemory<T>

Remove Cruft

There are many redundant and unused functions in Clay that in retrospect are solution-specific so don't belong in a general library.
Remove them; we can always revive if/when they are needed.

Number's nullablility semantics are ambiguous

Number already has the intrinsic ability to store null
But some callers instantiate an instance of Nullable<Number>

We either need to remove the intrinsic null, or change the callers.

For example, this seems ok:

var foo = new Number(...);
var valid = foo.HasValue;

But this is a problem:

var foo = new Nullable<Number>(...);
var valid1 = foo.HasValue;
var valid2 = foo.Value.HasValue; // Nooooo!

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.