Comments (8)
@pdrum generic.Number
is currently an alias for float64, as mentioned in the ticket float64 can't be used as a slice index or len argument in make()
.
generic.Integer
could be replaced with int
, int8
, int16
, int32
, int64
, uint
, uint8
, unit16
, uint32
, uint64
I don't think it is any less meaningful than generic.Number
, having said that I believe (I didn't test it) not using generic.*
and just assigning the custom type to int
would just work, so I'm thinking that creating generic.Integer
would be just for completeness sake, since we already have generic.Number
assigned to float64
from genny.
I would like to see "Integer" added instead changing Number to int.
Integers support more operators than floats, which means "type Integer int" is necessary if you want to use those operators.
Similar to how "type Type interface{}" is useful for indicating and ensuring support for a less specific set of types than "type Number float64", the latter is useful for indicating and ensuring support for integers and floats.
from genny.
I don't understand what generic.Integer
is good for. As far as I understand this type can only be replaced with int so how is it different with just using int
instead of sth like generic.Integer
in templates? Will you elaborate please? @rwl
from genny.
IIRC, I was trying to support generating different types of int
e.g. int32
, int64
etc. In the end I dropped genny and just used text/template
directly.
from genny.
Something like this would be useful for generating code for enum-type constants.
from genny.
@takeda — So I just tried this, and naively assigning the custom type to int
(or uint32
or what have you) gets you an extra type declaration that you may not want — type T generic.Type
gets deleted, type T int
gets transformed to type MyType int
.
As a workaround, if what you want is for your templates to compile, behave well in your IDE, etc., you can put the type declarations in a separate file in the same directory. As far as I can tell this just works—which is interesting, because it suggests the whole generic.Type
mechanism is unnecessary.
from genny.
Ah I see, I forgot that genny removes it. In that case I agree that Integer
type should be included. The workaround you gave is still a workaround and generic.*
is more elegant I wouldn't call it unnecessary.
from genny.
It does make the templates more readable and more obviously templates.
from genny.
Related Issues (20)
- Imports not generated correctly HOT 3
- Separate generated code in multiple files HOT 3
- Flags usage not correct in README HOT 1
- Suggestion: make the genny project visible to Hacktoberfest searches. Add a contributing.md file too.
- Is this project still maintained? HOT 2
- wordify breaks calls to APIs made while generating
- -pkg doesn't appear to work HOT 2
- code cleanup in parse.go drops all import statements and is potentially buggy in other infrequent scenarios HOT 1
- Lowercase replace in strings? HOT 6
- Collect generics into composed interface HOT 2
- Switch to a standard codegen comment marker
- Are slices supported? HOT 1
- Allow generation of exported and non exported types from the same generic code.
- TestCustomTypesMap test fails on some systems
- running "genny": exec: "genny": executable file not found in $PATH HOT 3
- Check if specific type name has a valid syntax
- Drops imports on github actions HOT 1
- import stmt removed in output (sometimes) HOT 2
- Please create a new tag for the latest master branch
- generic.Type support function definition ?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from genny.