Git Product home page Git Product logo

Comments (3)

tomerfiliba avatar tomerfiliba commented on June 2, 2024

Thanks for the feedback! At the moment, nothing is finalized and there's still way to go. That's exactly why I wanted to bring this to discussion with the community.

I'll give you my take on it, but anyone is welcome to join the discussion:

  • aliases are cheap and painless; there may be too many of them at the moment, so it's likely some of them will be removed before the final release, but
  • you should think of construct as a in-language DSL. many languages like Haskell and Scala have built-in support for this, while in the Python world it's quite rare, but DSLs are a good thing. especially when construct 3 is going to be compiled, you should think of the definition of data structures as a different language although it's contained in the same file as your python code.
  • i completely agree that the "multiline" version is more pythonic, and it's quite possible i'll drop >>, but the subscript notation and "slash operator" are more than just "stylistic choices". too many parentheses are a real problem, as exemplified by LISP and scheme. consider large data structures such as these - having tuples everywhere would cripple the code. i find the slash readable and "worthwhile", but any other operator is just as good. as for the syntactic sugar for arrays -- it's much more convenient and familiar this way. also, and that's the real gem, you can use slices instead, e.g., byte[4] means an array of 4 bytes, while byte[4:8] means "a range of at least 4 bytes, up to 8". of course you can use any contextual expression instead of constants, or just omit one end, e.g., byte[4:] -- i find this very pythonic actually. in construct 2 we have GreedyRepeater (at least one element) and OptionalGreedyRepeater (zero or more elements); using slicing, we can neglect all these specialized constructs.

but again, nothing is finalized as of yet.

from construct3.

keleshev avatar keleshev commented on June 2, 2024
  1. Ok, what about the following syntax for sequences:

You know that strings allow the following operations:

4 * 'a' + 4 * 'b' + 2 * 'c' => 'aaaabbbbcc'

Binary data (and patters) are somewhat similar to strings, why not allow:

4 * uint8 + 4 * int8 + 2 * float32 => Sequence(uint8, uint8, uint8, uint8, int8, int8, int8, int8, float32, float32)

Maybe + makes more sense in this case than >>?

I understand the flexibility of byte[4:8] notation, though.

  1. And maybe something along the lines of construct2 for structs:
Struct(int8.first_byte, uint8.second_byte)
Struct(int8['first-byte'], uint8['second-byte'])
Struct(int8('first-byte'), unit8('second-byte'))

from construct3.

tomerfiliba avatar tomerfiliba commented on June 2, 2024

addition is taken to be commutative, but here a + b != b + a. it's true that strings work that way, but then again string formatting operators (% or format) are preferred to this.

i had thoughts about using multiplication for arrays, but as i explained, slices are a necessary feature. besides, C uses subscripts for arrays, which is quite familiar:

struct foo {
    int bar;
    char data[100];
}

the >> operator also comes from C (C++ actually), as in cout << "foo" << bar << "\n";. on the other hand, i'm not sure it's a useful at all; perhaps an explicit Struct() or Sequence() would be better.

as for the / operator, i need to think about it some more. thanks for the input.

from construct3.

Related Issues (6)

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.