These are chat archives for dry-rb/chat

2nd
Dec 2015
Piotr Solnica
@solnic
Dec 02 2015 10:20 UTC
morning
Hannes Nevalainen
@kwando
Dec 02 2015 10:21 UTC
hola!
Piotr Solnica
@solnic
Dec 02 2015 10:21 UTC
how would you call an object that is a result of running validation?
@AMHOL @timriley ^^ ???
hola @kwando :)
leaning towards Schema::Outcome
Hannes Nevalainen
@kwando
Dec 02 2015 10:23 UTC
whats wrong with Schema::Result?
Piotr Solnica
@solnic
Dec 02 2015 10:23 UTC
we have Validation::Result already
which is a result-per-rule
and we have Validation::Result::Set which is a result per rule-set
I actually need another concept, an array of result objects
no idea how to call it either
ok I know what to do
Tim Riley
@timriley
Dec 02 2015 10:28 UTC
“Result” seems most natural, but since it’s already in use, “Outcome” isn’t too bad.
Piotr Solnica
@solnic
Dec 02 2015 10:28 UTC
Validation::Result will become the enumerable containing Result::Value and Result::Set
Tim Riley
@timriley
Dec 02 2015 10:29 UTC
“Product” is another possibility but it’s a term that’s already too loaded
Piotr Solnica
@solnic
Dec 02 2015 10:29 UTC
question is, how to call abstract class for value and set lol
damn
it’s gonna be silly to have Schema::Result containing a…validation result
NAMING
;(
otoh it should be private
we want access to successes and failures
@timriley btw how does successes sound?
Tim Riley
@timriley
Dec 02 2015 10:32 UTC
Sounds fine to me.
Piotr Solnica
@solnic
Dec 02 2015 10:32 UTC
ok :)
Tim Riley
@timriley
Dec 02 2015 10:32 UTC
It’s clear.
Piotr Solnica
@solnic
Dec 02 2015 10:42 UTC
I’m about to break things /cc @timriley @kwando
timriley @timriley stops upgrading ;)
Piotr Solnica
@solnic
Dec 02 2015 10:43 UTC
schema.messages(input) => schema.(input).messages
YOU CAN UPGRADE USING sed OK?!
Tim Riley
@timriley
Dec 02 2015 11:05 UTC
oh, this is a nice upgrade!
Piotr Solnica
@solnic
Dec 02 2015 11:07 UTC
almost there with refactor
Piotr Solnica
@solnic
Dec 02 2015 11:28 UTC
so, for fun, I stubbed I18n in AM::V and ran the benchmark
Calculating -------------------------------------
ActiveModel::Validations
                       628.000  i/100ms
      dry-validation     1.948k i/100ms
-------------------------------------------------
ActiveModel::Validations
                          5.933k (± 1.5%) i/s -     30.144k
      dry-validation     20.386k (± 7.6%) i/s -    103.244k

Comparison:
      dry-validation:    20385.8 i/s
ActiveModel::Validations:     5932.6 i/s - 3.44x slower
this is AM::V WITHOUT COERCION AND WITHOUT I18n
BUT
dry-v is WITH coercion and WITH message compilation
and it’s ~3.5x faster :joy:
Tim Riley
@timriley
Dec 02 2015 11:29 UTC
:tada:
Piotr Solnica
@solnic
Dec 02 2015 11:37 UTC
@timriley @AMHOL dryrb/dry-validation#23
as discussed with Andy we will be able to configure error compiler per schema, so ie you can set up a schema with I18n-compatible compiler and your localized errors will be used
Tim Riley
@timriley
Dec 02 2015 11:41 UTC
This makes a lot of sense.
Piotr Solnica
@solnic
Dec 02 2015 11:42 UTC
there’s a bit more to it, but it’s a bigger subject: validation hints :)
in the near future we’re gonna have a way to generate user-friendly representation of validation rules, even for those that were not used in the validation process
Tim Riley
@timriley
Dec 02 2015 11:43 UTC
Yeah, that sounds handy!
Piotr Solnica
@solnic
Dec 02 2015 11:43 UTC
so ie when you have age.int? & age.gt?(18) and it turned out to be an empty string we still need to provide meaningful info to the user
since we have access to all the rules we can simply use the same technique to produce validation hints (as I call it)
we can automatically drop type expectations, since it’s too low level IMO, and just do things like gt?(18) => “age must be greater than 18”
Tim Riley
@timriley
Dec 02 2015 11:45 UTC
Wonderful :)
Piotr Solnica
@solnic
Dec 02 2015 11:45 UTC
we can actually be pretty precise here, and take into consideration whether or not a value was present
so ie pattern match on input and have things like “oops, you forgot to fill in age"
or “hey, sorry but your age must be greater than 18, you gotta wait 2 years” :D
hints will be useful when there are many rules though, so we want to be smart and display only what’s relevant to the user
ie displaying ‘age can’t be blank’ and ‘age must be greater than 18’ is redundant from the user pov
I mean the former msg is redundant
since the latter implies the former
Tim Riley
@timriley
Dec 02 2015 11:49 UTC
Yeah. Many of those decisions you could make programatically, but in some schemas, it may be hard to guess correctly.
Piotr Solnica
@solnic
Dec 02 2015 11:50 UTC
common stuff should be simple
filled? vs more specific predicates is a good example, I think
so ie if filled? failed but we have more rules, then we’re gonna be interested in error msgs for the other rules
or I should say, validation hints, those won’t be errors since filled? failure is the only error when a value is blank, the rest is just providing hints for the value and its constraints
actually, it’s probably a good idea to always ignore filled? failure when there are other rules, can’t think of any reason why you would want to display age cannot be blank + more info about other rules
Tim Riley
@timriley
Dec 02 2015 12:01 UTC
Yeah.
Filip Bartuzi
@Bartuz
Dec 02 2015 12:12 UTC
hello
Piotr Solnica
@solnic
Dec 02 2015 12:13 UTC
hey ho
Filip Bartuzi
@Bartuz
Dec 02 2015 12:13 UTC
have you already started working on i18n support? Is there dedicated branch for that?
Piotr Solnica
@solnic
Dec 02 2015 12:14 UTC
not yet
Filip Bartuzi
@Bartuz
Dec 02 2015 12:14 UTC
Ok, great. I would like to contribute
Piotr Solnica
@solnic
Dec 02 2015 12:15 UTC
cool! I gotta clean up current error compiler and come up with some common interface so that buiding new compilers will be simple
we talked with @AMHOL that maybe it’s gonna be possible to only have Messages and its sub-classes for specific backends
so that we only have one compiler and it calls messages#lookup and passes all the info that might be needed to get a string message from some backend
Filip Bartuzi
@Bartuz
Dec 02 2015 12:19 UTC
Piotr, you use dry-validation is rails based projects, right?
Piotr Solnica
@solnic
Dec 02 2015 12:19 UTC
no, I don’t use it yet in anything ‘real'
I started using it in rodakase-blog sample app though
but nothing fancy yet
Filip Bartuzi
@Bartuz
Dec 02 2015 12:25 UTC
I will appreciate any kind of example. I'll have a look on https://github.com/solnic/rodakase-blog later
Piotr Solnica
@solnic
Dec 02 2015 12:30 UTC
@Bartuz what kind of examples?
Andy Holland
@AMHOL
Dec 02 2015 12:31 UTC
@solnic nice work xD
What was the thinking with going with Schema#call(data).messages rather than just having Schema#call(data) return formatted messages?
Piotr Solnica
@solnic
Dec 02 2015 12:46 UTC
@AMHOL you’re gonna need more info than just messages
errors vs hints etc
also, some people may want to take that and process further (ie in reform)
so I’m taking those use cases into consideration already
Andy Holland
@AMHOL
Dec 02 2015 12:49 UTC
Ahh, OK, cool :)
Piotr Solnica
@solnic
Dec 02 2015 12:54 UTC
@AMHOL mergy-mergy? :joy:
Hannes Nevalainen
@kwando
Dec 02 2015 13:29 UTC
@solnic should one prefer call_sheet over transflow? Seems to be quite similar
Piotr Solnica
@solnic
Dec 02 2015 15:03 UTC
I pushed i18n branch to dry-validation, gonna “prepare the ground” there, maybe add some super basic functionality too, happy to get some help later on with it /cc @AMHOL @Bartuz
lots of things to consider, so I’ll open a PR early so we could discuss in async mode too
Andy Holland
@AMHOL
Dec 02 2015 15:06 UTC
@solnic not sure what you think, but we could avoid symbolize_keys by using :key: value in YAML files?
Piotr Solnica
@solnic
Dec 02 2015 15:07 UTC
more typing in yaml, I think it’s valuable to simply convert to symbols, it’s not too complex
alternatively we could lookup by strings
Andy Holland
@AMHOL
Dec 02 2015 15:10 UTC
That could work
Then we can use a namespace separator like in dry-container/i18n
Symbolize keys is complicated when it comes to nested arrays of hashes and stuff
Piotr Solnica
@solnic
Dec 02 2015 15:43 UTC
I’ve NO IDEA how to use I18n
trying to figure it out from the API docs, w/o success
that’s just sad
Piotr Solnica
@solnic
Dec 02 2015 16:01 UTC
def initialize
  @t = I18n.method(:t)
end

def lookup(predicate, arg)
  t.("errors.#{predicate}")
end
they see me callin, they hatin
Andy Holland
@AMHOL
Dec 02 2015 16:05 UTC
:joy:
Piotr Solnica
@solnic
Dec 02 2015 16:22 UTC
ok, I got it working, the same functionality is covered as with the built-in YAML messages
I need to…dry it up
there’s a bit of common, abstract functionality there
one interesting thing is that it is possible to provide error compiler that will convert our error representation to an AM-compatible structure so that in theory existing AM-based error message translations will work with it
ain’t gonna do it, just saying it’s possible ;)
Andy Holland
@AMHOL
Dec 02 2015 16:33 UTC
:laughing:
Piotr Solnica
@solnic
Dec 02 2015 16:39 UTC
Calculating -------------------------------------
ActiveModel::Validations
                       143.000  i/100ms
      dry-validation   927.000  i/100ms
-------------------------------------------------
ActiveModel::Validations
                          1.495k (± 7.3%) i/s -      7.579k
      dry-validation      9.429k (± 1.6%) i/s -     47.277k

Comparison:
      dry-validation:     9428.8 i/s
ActiveModel::Validations:     1494.6 i/s - 6.31x slower
this is AM+I18n-coercions vs dry-validation+I18n+coercions
Andy Holland
@AMHOL
Dec 02 2015 16:40 UTC
:clap:
@solnic out of interest, how come you did class Messages::I18n rather than the usual nesting?
Piotr Solnica
@solnic
Dec 02 2015 16:41 UTC
I really don’t know
I guess I’m inspired by current polish gov, so from now on “it’s just how it’s gonna be, because"
Andy Holland
@AMHOL
Dec 02 2015 16:42 UTC
lol
Piotr Solnica
@solnic
Dec 02 2015 16:42 UTC
the people want it, don’t you know
seriously though, just trying to avoid nesting
but it comes with the cost of having to require things in diff order
Andy Holland
@AMHOL
Dec 02 2015 16:45 UTC
Yeah, I guess the loading errors come sparsely without Rails
Andy Holland
@AMHOL
Dec 02 2015 16:54 UTC
@solnic 100 stars for dry-validation :D
Piotr Solnica
@solnic
Dec 02 2015 16:54 UTC
I know, I wrote a script that notifies me via sms whenever it’s starred #noididnt
Andy Holland
@AMHOL
Dec 02 2015 16:54 UTC
:joy:
I would've believed that you know
Too gullible
Luca Guidi
@jodosha
Dec 02 2015 16:55 UTC
:100: :star2: :confetti_ball:
Piotr Solnica
@solnic
Dec 02 2015 16:56 UTC
@jodosha :dancers:
Piotr Solnica
@solnic
Dec 02 2015 17:10 UTC
@AMHOL thoughts on how to tackle complex error messages when you need more data than just input for a rule?
Andy Holland
@AMHOL
Dec 02 2015 17:11 UTC
Not sure I understand fully, do you have an example?
Piotr Solnica
@solnic
Dec 02 2015 17:12 UTC
ie you want to generate a message and provide a list of possible values that are dynamic, so you can’t hardcode it in the schema
basically every use case where a message needs data that come from some external source
Andy Holland
@AMHOL
Dec 02 2015 17:12 UTC
I don't think we should do that
Piotr Solnica
@solnic
Dec 02 2015 17:12 UTC
but it’s needed :)
Andy Holland
@AMHOL
Dec 02 2015 17:12 UTC
lol
Piotr Solnica
@solnic
Dec 02 2015 17:13 UTC
I told you I have all kinds of validation use cases :)
I have a couple of messages that need to do extra db lookups to provide meaningful feedback
Andy Holland
@AMHOL
Dec 02 2015 17:14 UTC
What if there's a list of 500 values returned?
Piotr Solnica
@solnic
Dec 02 2015 17:14 UTC
don’t get stuck on this silly example :)
it’s your job to construct that message, not dry-v's
but we need an interface to allow that
that’s what I’m asking
basically an equivalent of :message option in AM::V
with the exception of “option” part, because options in dsl are a horrible horrible idea (I’ll be repeating that all the time)
Andy Holland
@AMHOL
Dec 02 2015 18:13 UTC
Shouldn't they be custom validations/integrations?
Piotr Solnica
@solnic
Dec 02 2015 18:15 UTC
well, you could provide your own Messages implementation, subclass one of the built-in ones, and have a customized lookup (or whatever it’s gonna be called eventually)
Andy Holland
@AMHOL
Dec 02 2015 18:17 UTC
Sorry, think I still don't understand exactly what you're asking :laughing:
Piotr Solnica
@solnic
Dec 02 2015 18:25 UTC
@AMHOL you define a rule ie key(:book) { |book| book.publish? } and that predicate returns false when a system-level setting “publishing_turned_off” is set and it needs to set a message “sorry, but book publishing is turned off until %{date}” and date is retrieved from the database.
so it’s a dynamic validation that changes over time and needs a completely dynamic error message that requires data from an external system (a db)
Andy Holland
@AMHOL
Dec 02 2015 18:30 UTC
Hmm, not sure without options hash lol
Piotr Solnica
@solnic
Dec 02 2015 18:41 UTC
@AMHOL I’ll figure something out :muscle:
Andy Holland
@AMHOL
Dec 02 2015 18:48 UTC
:)
I'm sure you will