01:53
mistergibson has joined #crystal-lang
03:49
chemist69 has quit [Ping timeout: 264 seconds]
03:51
chemist69 has joined #crystal-lang
05:09
<
FromGitter >
<sam0x17> set containment assertions / `ContainsAssertion` or maybe `IncludesAssertion`maybe
05:11
<
FromGitter >
<sam0x17> `SortedAscendingAsserting`
05:11
<
FromGitter >
<sam0x17> `SortedDescendingAssertion`
05:14
<
FromGitter >
<sam0x17> `RaisesErrorAssertion`
05:16
<
FromGitter >
<sam0x17> also `NotIncludesAssertion` for the negation of `IncludesAssertion`
05:17
<
FromGitter >
<sam0x17> that's all I can come up with @Blacksmoke16, your list is pretty good
05:19
<
FromGitter >
<sam0x17> `ElementOfAssertion` `NotElementOfAssertion` but depending on how you do includes assertions those could do the same thing
06:00
alex`` has joined #crystal-lang
06:54
ht_ has joined #crystal-lang
07:16
Seich has quit [Read error: Connection reset by peer]
07:16
Seich has joined #crystal-lang
10:24
Groogy has quit [Quit: WeeChat 2.5]
12:15
lvmbdv has quit [Ping timeout: 246 seconds]
12:22
lvmbdv has joined #crystal-lang
12:49
alex`` has quit [Ping timeout: 245 seconds]
12:51
alex`` has joined #crystal-lang
13:10
<
FromGitter >
<Blacksmoke16> @sam0x17 what about`Choice`
13:16
<
FromGitter >
<Blacksmoke16> How would the error and element of ones work?
14:37
<
FromGitter >
<asterite> what are the assertions for/
14:37
<
FromGitter >
<asterite> ?
14:38
<
FromGitter >
<Blacksmoke16> a shard im working on
14:38
<
FromGitter >
<Blacksmoke16> for example
14:38
ht_ has quit [Quit: ht_]
14:39
<
FromGitter >
<asterite> Cool!
14:53
<
FromGitter >
<Blacksmoke16> thanks :)
17:29
<
FromGitter >
<sam0x17> nice that works
17:29
<
FromGitter >
<sam0x17> I was just blurting out assertion types without thinking about contex
17:30
<
FromGitter >
<Blacksmoke16> :P
17:36
sorcus has quit [Quit: WeeChat 2.5]
18:20
dannyAAM has joined #crystal-lang
18:52
lkw has joined #crystal-lang
20:03
<
FromGitter >
<Blacksmoke16> new one
20:04
<
FromGitter >
<Blacksmoke16> makes the parent class invalid if any object(s) are invalid
20:30
<
FromGitter >
<asterite> Out of curiosity: why would you want an instance var to always equal a value? Isn't that a constant?
20:31
<
FromGitter >
<Blacksmoke16> its just representing a state to show that its valid
20:31
<
FromGitter >
<Blacksmoke16> vs having to pass everything to `#new`
20:33
<
FromGitter >
<asterite> Sorry, I don't follow. What's the purpose of the int32 variable always equal to 100? Is that based on some use case?
20:34
<
FromGitter >
<Blacksmoke16> its just an example class to show how assertions work
20:34
<
FromGitter >
<Blacksmoke16> not really meant for anything else
20:34
<
FromGitter >
<Blacksmoke16> otherwise you would have to define an initializer and do like `Example.new(100, Foo.new(50), [Foo.new(50), Foo.new(50)])`
20:35
<
FromGitter >
<asterite> Aaaah... okay. So EqualTo is just the simplest assertion to try the library but will never be used in real code, right?
20:35
<
FromGitter >
<Blacksmoke16> yea i dont really know what you would use it for
20:36
<
FromGitter >
<Blacksmoke16> im sure someone can think of something p
20:37
<
FromGitter >
<Blacksmoke16> that example was mainly trying to show `Valid`
20:40
<
FromGitter >
<Blacksmoke16> same can be said about the like `IsBlank` assertion, why you would always want a property to be blank is beyond me :p
21:07
<
FromGitter >
<absolutejam_gitlab> What about a way for people to create their own assertion sets?
21:07
<
FromGitter >
<Blacksmoke16> already a thing
21:08
<
FromGitter >
<absolutejam_gitlab> `@[Assert::Custom(Something)]`
21:08
<
FromGitter >
<Blacksmoke16> yes
21:08
<
FromGitter >
<absolutejam_gitlab> Or a group
21:08
<
FromGitter >
<absolutejam_gitlab> Those are the exciting examples
21:10
<
FromGitter >
<j8r> why it's a class?
21:10
<
FromGitter >
<Blacksmoke16> ATM since the `valid?` method can change the message ivar
21:10
<
FromGitter >
<j8r> I mean, we won't have to pass it by reference?
21:11
<
FromGitter >
<Blacksmoke16> which if its a struct, it doesnt get set correct, since its a copy im thinking?
21:12
<
FromGitter >
<Blacksmoke16> actually nvm, i think i can change them to structs
21:13
<
FromGitter >
<Blacksmoke16> previous implementation required them to be classes, but guess not anymore
21:14
<
FromGitter >
<j8r> the best would be to include a module
21:14
<
FromGitter >
<Blacksmoke16> cant
21:14
<
FromGitter >
<j8r> maybe not possibl
21:14
<
FromGitter >
<j8r> that what I was thinking
21:14
<
FromGitter >
<j8r> :)
21:14
<
FromGitter >
<Blacksmoke16> it uses the subclasses macro method
21:15
<
FromGitter >
<Blacksmoke16> would be possible if you could do that for modules, or all types annotated with x tho
21:15
<
FromGitter >
<j8r> struct is fine, no overhead
21:15
<
FromGitter >
<Blacksmoke16> plus there is some inheritance stuff going on so parent struct with abstract defs and such works well
21:16
<
FromGitter >
<Blacksmoke16> made a macro to make it easier, for example that custom assertion initializer could also be written as
21:16
<
FromGitter >
<absolutejam_gitlab> Is there a good guide to struct vs classes?
21:17
<
FromGitter >
<Blacksmoke16> and
21:21
<
FromGitter >
<absolutejam_gitlab> ah so they're not actually immutable
21:21
<
FromGitter >
<absolutejam_gitlab> but just due to how they're passed by value, they're usually used for immutability
21:21
<
FromGitter >
<Blacksmoke16> yea, and no i tested it, they have to be classes :/
21:21
<
FromGitter >
<Blacksmoke16> seems i need to add a spec for that behavior
21:22
<
FromGitter >
<Blacksmoke16> since the message template can change within the valid? method, it doesnt update the template correctly
21:23
<
FromGitter >
<Blacksmoke16> was thinking about, what if instead of returning a bool, it just returned Nil, but had some class be passed to everything
21:23
<
FromGitter >
<Blacksmoke16> like `builder.add_error("some message")`
21:23
<
FromGitter >
<Blacksmoke16> so assertions themselves could be structs, and use that vs including the message stuff within the assertion
21:32
<
FromGitter >
<Blacksmoke16> would that be better?
21:33
<
FromGitter >
<j8r> strange,why classes?
21:33
dingenskirchen has quit [Quit: dingenskirchen]
21:34
<
FromGitter >
<j8r> :/
21:34
<
FromGitter >
<Blacksmoke16> so that you can change the `message` from within the `valid?` method
21:34
<
FromGitter >
<Blacksmoke16> otherwise only gets set on the copy
21:35
<
FromGitter >
<Blacksmoke16> guess the question now is, is them being classes a big enough detriment to performance to change the implementation a bit?
21:36
<
FromGitter >
<j8r> don't know, are we supposed to use lots of assertions in lots of objects?
21:37
<
FromGitter >
<j8r> we can use it to validate JSON, or is it CrSerializer?
21:38
<
FromGitter >
<Blacksmoke16> that was the idea, you could make it runs validations after deserializing
21:39
<
FromGitter >
<Blacksmoke16> depends how you set it up, way i been imagining it, you would use them on like ORM models, so every ORM model would be able to be validated
21:39
<
FromGitter >
<Blacksmoke16> i dont really see you having to validate an obj more than once or twice
21:40
<
FromGitter >
<j8r> If we use it and handle lots of requests with complex objects, the performance would be noticeable. Needs to be measured
21:41
<
FromGitter >
<Blacksmoke16> let me benchmark it real quick
21:43
<
FromGitter >
<Blacksmoke16> didnt expect that
21:43
<
FromGitter >
<Blacksmoke16> granted it was only 1 class with 1 assertion...
21:45
<
FromGitter >
<j8r> it consumes less memory
21:46
<
FromGitter >
<Blacksmoke16> how did you tell?
21:48
<
FromGitter >
<j8r> and also fastest, certainly due to the allocation.
21:48
<
FromGitter >
<Blacksmoke16> wait, am i missing something here? class has 8m which is more than struct's 5.5m?
21:48
<
FromGitter >
<j8r> You can use `Benchmark.memory`
21:52
<
FromGitter >
<j8r> in your results `struct` is better
21:52
<
FromGitter >
<Blacksmoke16> how? class has more iterations? and im assuming used less bytes per operation?
21:54
<
FromGitter >
<j8r> more throughput (B/op), and a total of less operations done
21:55
<
FromGitter >
<j8r> I think it's what `mean` means?
21:57
<
FromGitter >
<Blacksmoke16> i always assumed higher is better on iterations and B/op lower is better
21:57
<
FromGitter >
<j8r> yeah, that's the opposite
21:58
<
FromGitter >
<Blacksmoke16> 😕
21:58
<
FromGitter >
<j8r> lol
21:58
<
FromGitter >
<Blacksmoke16> that makes no sense to me
21:59
<
FromGitter >
<Blacksmoke16> then why is the one with more iterations marked as the fastest?
22:00
<
FromGitter >
<j8r> hum maybe you are right
22:00
<
FromGitter >
<j8r> let me check
22:00
<
FromGitter >
<Blacksmoke16> 😆
22:00
<
FromGitter >
<Blacksmoke16> oh boy
22:01
<
FromGitter >
<j8r> you are right yes sorry
22:01
<
FromGitter >
<j8r> haha
22:02
<
FromGitter >
<Blacksmoke16> all good
22:02
<
FromGitter >
<Blacksmoke16> so i guess based on that i wont worry about it for now
22:02
<
FromGitter >
<j8r> I confused myself
22:02
<
FromGitter >
<j8r> yes, such optimizations can wait
22:03
<
FromGitter >
<Blacksmoke16> indeed
22:03
<
FromGitter >
<Blacksmoke16> its example is missing the bytes per operation
22:04
<
FromGitter >
<j8r> the with real world applications, we will be able to see the real impact
22:07
<
FromGitter >
<Blacksmoke16> works for me
22:10
dingenskirchen has joined #crystal-lang
22:42
<
FromGitter >
<watzon> It would be really nice if documentation generation could work with external shards
22:43
<
FromGitter >
<watzon> I'm splitting cadmium into several smaller libraries which the `cadmium` shard itself will then import just in case people don't want to bother with importing smaller pieces. The one thing that smaller libraries makes difficult is documentation generation.