Giter Club home page Giter Club logo

Comments (3)

sunny avatar sunny commented on July 22, 2024

Hi @zhengpd! I didn’t think this would be useful, but I guess why not.

Suggestions:

  • Instead of introducing an extra has_run_args, perhaps we could use the order in which inputs are added in the first place? (Internally this would be the inputs method.)
  • Perhaps we don’t need to raise an error if less args are given, which would allow optional arguments.
  • I guess we should also add an extra run method with no ! that would call result instead of call.

I’m open for a PR \o/

from actor.

zhengpd avatar zhengpd commented on July 22, 2024

Hi @sunny , after a second thought, I think it's not much value in supporting positional arguments.

Case A: 4 and more inputs

It's not a good idea to define a method with so many positional arguments, so let's ignore this case.

Case B: 2 or 3 inputs

2 or 3 positional arguments seems reasonable. However, the implementation of positional method (eg. run!) could make the user's project code hard to maintain.

The implementation, going with has_run_args or relying on internal inputs order, would mean that developers have to carefully craft the order of defining inputs. If a developer re-sort the inputs in future, it might cause unnoticeable bug when inputs are the same type. For example:

class DivisionActor < Actor
  input :y
  input :x

  def call; y / x; end
end

Positional call is like Actor.run!(4, 2). Someday someone might think inputs should be defined in alphabetical ASC order and refactor to

class DivisionActor < Actor
  input :x
  input :y

  def call; y / x; end
end

Now the Actor.run!(4, 2) succeeds with incorrect resultπŸ’₯! Such change is easy to be overlooked because the logic is not changed and normally sorting code lines wouldn't cause error. It adds a burden to developers having to know inputs can't be rearranged or new input can't be inserted between old inputs' lines.

So, positional arguments like this just adds more complexity to coding 😞 .

Case C: 1 input

The difference between HiActor.run('Earth') and HiActor.run(planet: 'Earth') is pretty small. Not much value in supporting it by adding more complexity into Actor gem, which I prefer to avoid.

Conclusion

It's better to support positional arguments with some other new solution. I'll close this for now.

from actor.

sunny avatar sunny commented on July 22, 2024

I appreciate the awesome thought process behind this, and happy that you are considering keeping the codebase simple. I agree with your points! Thank you πŸŽ‰

from actor.

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.