Giter VIP home page Giter VIP logo

Comments (4)

dantswain avatar dantswain commented on May 20, 2024

It actually doesn't look like const values are generating any code at all?

from elixir-thrift.

dantswain avatar dantswain commented on May 20, 2024

I have a POC solution for this. The approach I took was, given a file "foo.thrift" with a non-empty set of constants, generate a module called FooConstants that defines a function for each constant that returns the value of the constant. Is this a reasonable approach? A couple alternatives I thought of:

  • Generate Foo.Constants instead of FooConstants (FooConstants seems consistent with the way other thrift libs work and we don't nest any other modules aside from namespacing)
  • Generate macros instead of functions (this could get hairy with quotes/unquotes and compilation order?)

from elixir-thrift.

pguillory avatar pguillory commented on May 20, 2024

It definitely should generate something for constants -- only reason it doesn't is that we hadn't gotten to it.

Naming it is tricky. Using the filename as you suggested, foo.thrift and subdir/foo.thrift would both generate a FooConstants module. Using the namespace, same thing, multiple thrift files can contain the same namespace. I think I favor generating a module based on the namespace though because we have more control over it. We have a bunch of thrift files that we can't easily move around or rename, but all these other systems depend on them and they include each other, but we can add elixir namespaces to them to control what gets generated.

I know you have the separate issue with Apache raising errors about unrecognized namespaces. We need to fix that somehow.

Regarding macros vs functions, I liked macros for enums because they're so often used for matching. For constants, maybe it doesn't make as much difference. You can always put the function call in a variable or module attribute or unquote if you really need to match it, but it seems like it would happen less often. What do you all think?

from elixir-thrift.

jparise avatar jparise commented on May 20, 2024

I'm seeing some of the issues that @pguillory mentions in the previous comment with the current approach to generating constants.

Start with a file named userservice.thrift that includes some constants and a service UserService definition. The generator will produce a file named userservice.ex (defmodule Userservice) containing the constants and a file named user_service.ex (defmodule UserService) containing the service definition.

I'm not quite sure what should change, but it's a bit confusing, and I suppose we could run into problems on case-insensitive file systems.

I suppose we could look at merging the constants into user_service.ex (defmodule UserService) because it's the most similar name. But that's more of a coincidence with the service name matching the name of the .thrift file.

from elixir-thrift.

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.