200sc/bebop

Add flag to disable datatype exports?

mjmar01 opened this issue · 4 comments

When compiling into an existing package it might be desirable to not export any functions or datatypes. This would be usefull in cases where the functions only get used inside the package or if I want to write my own wrapper functions to convert between types or similar.

200sc commented

Sounds reasonable and happy to add this, but until then as workarounds:

For the former case you could put it into an internal subdirectory so its API was only exposed to a parent package.

For the latter case, in the past I've added converters.go or etc files sitting along side generated files in the same package for that purpose.

But again, not an unreasonable ask.

200sc commented

@mjmar01 Feel free to check out the above PR and confirm it works for you

A few things. Most of them relate to sub types and slices of sub types.

  1. There is a little typo in the parameter -private-defintions :)
  2. Type declarations are now lower case, references are still upper case in some places:
type block struct {
    a string
    b string
} // Correct

type body struct {
    c Block
} // Block not found
  1. Point 2 also applies when pre allocating space for arrays using make(). So something like this might occur:
bbp.block = make([]Block, iohelp.ReadUint32Bytes(buf[at:])) // Block not found
  1. The functions maketype and maketypeFromBytes are called like MakeType... which will say unknown function
  2. Relating to 4 the new functions are not properly camelCase so maketype instead of makeType
  3. Finally it might be good to run a go fmt over the output

Functionality it works tho. Does what I wanted it to

200sc commented

Did a more thorough look through with additional tests. I thought about adding a --format option to the CLI, but it's not a great experience:

  • If you don't have gofmt installed, the program will error (and so we cannot just run gofmt always)
  • If you want to use a formatter that doesn't accept -w $file to rewrite a file in place, you can't
  • bebopc-go ... --format "gofmt" is not an improvement over bebopc-go ...; gofmt -w ...; the latter has the benefit that you can use whatever formatter accepting whatever arguments you want.