Giter Site home page Giter Site logo

Comments (11)

xtagon avatar xtagon commented on April 28, 2024 3

I would much prefer a simple {:ok, events} or {:error, reason} vs having four different return types @drozzy

Receivers that still want to match on whether there are zero, one, or multiple can still do that with pattern matching but aren't forced to implement 4 different matches if they don't care how many events were returned (e.g. they just process all or none of them)

from commanded.

slashdotdash avatar slashdotdash commented on April 28, 2024 3

I'm proposing that the change would be backwards compatible, so you can still choose to return just an event, or list of events. The {:ok, events} is in addition to what's currently allowed.

Aggregate return value Events produced
:ok, nil , [] none
event , {:ok, event} one event
events , {:ok, events} list of events
{:error, reason} an error occurred

@astery The with special form can also sometimes be used to declutter such code.

from commanded.

astery avatar astery commented on April 28, 2024 1

Recently, I tried to write tests with {:ok, ..}, {:error}, and change my mind about it. Code become cluttered with :ok tuples. With current manner aggregate and their tests are clearer. Adding :ok tuples brings no real benefit except being "idiomatic", but some kind of unneeded complexity which is harder to read.

So I would prefer not to change anything.

from commanded.

xtagon avatar xtagon commented on April 28, 2024

What would be the benefit of using {:ok, _} tuples? Is there an {:error, reason} case as well?

from commanded.

slashdotdash avatar slashdotdash commented on April 28, 2024

Using {:ok, events} and {:error, reason} tagged tuples would make it consistent with idiomatic Elixir code. Commanded already supports {:error, reason}.

from commanded.

astery avatar astery commented on April 28, 2024

It's controversial. On one side it's bring a need of code change and extra keystrokes. On over side then I see function returning {:error, _}, I expect to see {:ok, _} as success; and if function return struct, I expect it either return nil or throw an error.

I support this.

from commanded.

drozzy avatar drozzy commented on April 28, 2024

I was going to suggest something like {:events, [Event]}, but after thinking about it, the ok/error combination would be more idiomatic (in fact, I was briefly puzzled by the lack of :ok when first learning commanded - since I didn't know how to indicate an error):

  • :ok - In the event command was accepted and no events were produced
  • {:ok, event} - In the event command was accepted and one event was produced.
  • {:ok, events} - In the event command was accepted and one or more events were produced.
  • {:error, Reason} - In the event of the command for rejected for a given reason.

I am not a fan of throwing. Let's not resort to that please.

from commanded.

drozzy avatar drozzy commented on April 28, 2024

Alternatively, we could use something more semantic instead of ok and error, like accepted and rejected.

from commanded.

drozzy avatar drozzy commented on April 28, 2024

I'd rather leave it as is @slashdotdash, that looks you're asking for confusion later on.

from commanded.

Papipo avatar Papipo commented on April 28, 2024

Idiomatic in this case just means more verbose, I don't see the point.

from commanded.

Freyskeyd avatar Freyskeyd commented on April 28, 2024

@slashdotdash are we ok to leave the current implmentation as it is?

Or do we need to add those new format?

from commanded.

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.