Git Product home page Git Product logo

Comments (4)

dmitshur avatar dmitshur commented on August 15, 2024

There's also go generate to consider.

from mathgl.

UserAB1236872 avatar UserAB1236872 commented on August 15, 2024

That's coming in 1.4, right? I'm not too familiar with it, but the proposal I read simply allowed it to run arbitrary user-written code generation scripts, right? So doing this would still be necessary.

from mathgl.

dmitshur avatar dmitshur commented on August 15, 2024

Yes, go generate is just a standard way for Go packages to run some commands to update their source code.

It's nice because it's a standard that's easy to follow and makes contributing to various Go packages easier. You know it's always go generate, rather than make or update_code.sh or run_regen or something else custom and non-standard.

See here for an example of replacing a bash file with go generate directives: gopherjs/websocket@c80adc1.

from mathgl.

alexvasi avatar alexvasi commented on August 15, 2024

I tried to rewrite genprog using text/template. Only vectors for now. Here is the result:
alexvasi@1ed7256

The main idea was to place all crucial information directly in the template and not in the program that generates code. I know, I could have passed meta info about types and functions to template. Or I could have used sub-templates for each function for example. In the end I decided against it. Template almost looks like a go code, if you squint hard enough. And that's a good thing, I guess. Except maybe there will be float32/64 flag later.

First of all it works. It is a zero-diff change... well, not actually. The order of functions in vector.go is different now. It takes 10 or so additional lines in template to make the order the same. I dumped them. But that's how I tested new generator.

Here is some caveats:

  • text/template is sloppy with whitespaces. I abused gofmt and it's called after template rendering.
  • I changed template separators from {{ to <<. It is too many curly brackets in go code already.
  • The readability of vector.tpl is not perfect.
  • Broken diff. It is hard to validate new generator with changed functions order. I should add some tests for each vector function to vec_test.go anyway.

from mathgl.

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.