Giter Site home page Giter Site logo

simplify API's with isSlice about dcv HOT 6 CLOSED

timotheecour avatar timotheecour commented on August 24, 2024
simplify API's with isSlice

from dcv.

Comments (6)

9il avatar 9il commented on August 24, 2024

Why this should be simplified?

from dcv.

timotheecour avatar timotheecour commented on August 24, 2024

Figure plot(S)(S slice, GGPlotD gg, string title = "") if(isSlice!S)

is arguably more readable than

Figure plot(SliceKind kind, size_t[] packs, Iterator) (Slice!(kind, packs, Iterator) slice, GGPlotD gg, string title = "")

  • shorter
  • doesn't leak Slice internals
  • hides all the logic inside the existing isSlice
  • if Slice ever changes, it won't affect this function signature.

from dcv.

9il avatar 9il commented on August 24, 2024

The older style should be used. After your change the following code would not work for example:

    import mir.ndslice;
    const s = slice!double(2, 3);

    auto foo(SliceKind kind, size_t[] packs, Iterator) (Slice!(kind, packs, Iterator) slice)
    {
        slice.popFront;
    }

    foo(s);

from dcv.

9il avatar 9il commented on August 24, 2024

I agree that (S) is simpler. But a DIP that strip const should be implemented first .

from dcv.

timotheecour avatar timotheecour commented on August 24, 2024

isSlice has a confusing name, isX should always be bool-return.

how about:

// before:
template isSlice(T) {
    static if (is(T : Slice!(kind, packs, Iterator), SliceKind kind, size_t[] packs, Iterator))
        enum size_t[] isSlice = packs[];
    else
        enum size_t[] isSlice = null;
}

// after: rename isSlice to getSlicePacks (and update code using it) and define:
template isSlice(T) {
    enum isSlice = is(T : Slice!(kind, packs, Iterator), SliceKind kind, size_t[] packs, Iterator));
}

would that be acceptable? at least as PR?

from dcv.

9il avatar 9il commented on August 24, 2024

isSlice behaves as boolean if it is used as boolean. It just stores additional information that is very useful for generic code

from dcv.

Related Issues (20)

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.