ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.30.1 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
mistergibson has joined #crystal-lang
chemist69 has quit [Ping timeout: 264 seconds]
chemist69 has joined #crystal-lang
<FromGitter> <sam0x17> set containment assertions / `ContainsAssertion` or maybe `IncludesAssertion`maybe
<FromGitter> <sam0x17> `SortedAscendingAsserting`
<FromGitter> <sam0x17> `SortedDescendingAssertion`
<FromGitter> <sam0x17> `RaisesErrorAssertion`
<FromGitter> <sam0x17> also `NotIncludesAssertion` for the negation of `IncludesAssertion`
<FromGitter> <sam0x17> that's all I can come up with @Blacksmoke16, your list is pretty good
<FromGitter> <sam0x17> `ElementOfAssertion` `NotElementOfAssertion` but depending on how you do includes assertions those could do the same thing
alex`` has joined #crystal-lang
ht_ has joined #crystal-lang
Seich has quit [Read error: Connection reset by peer]
Seich has joined #crystal-lang
Groogy has quit [Quit: WeeChat 2.5]
lvmbdv has quit [Ping timeout: 246 seconds]
lvmbdv has joined #crystal-lang
alex`` has quit [Ping timeout: 245 seconds]
alex`` has joined #crystal-lang
<FromGitter> <Blacksmoke16> @sam0x17 what about`Choice`
<FromGitter> <Blacksmoke16> How would the error and element of ones work?
<FromGitter> <asterite> what are the assertions for/
<FromGitter> <asterite> ?
<FromGitter> <Blacksmoke16> a shard im working on
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d629d69c8228962acc1181c]
<FromGitter> <Blacksmoke16> for example
ht_ has quit [Quit: ht_]
<FromGitter> <asterite> Cool!
<FromGitter> <Blacksmoke16> thanks :)
<FromGitter> <Blacksmoke16> @sam0x17 ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d62b8c1dbf5ae2d42c24101]
<FromGitter> <sam0x17> nice that works
<FromGitter> <sam0x17> I was just blurting out assertion types without thinking about contex
<FromGitter> <Blacksmoke16> :P
sorcus has quit [Quit: WeeChat 2.5]
dannyAAM has quit [Quit: znc.saru.moe : ZNC 1.6.2 - http://znc.in]
dannyAAM has joined #crystal-lang
lkw has joined #crystal-lang
<FromGitter> <Blacksmoke16> new one
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d62e9abdbf5ae2d42c38e8b]
<FromGitter> <Blacksmoke16> makes the parent class invalid if any object(s) are invalid
<FromGitter> <asterite> Out of curiosity: why would you want an instance var to always equal a value? Isn't that a constant?
<FromGitter> <Blacksmoke16> its just representing a state to show that its valid
<FromGitter> <Blacksmoke16> vs having to pass everything to `#new`
<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?
<FromGitter> <Blacksmoke16> its just an example class to show how assertions work
<FromGitter> <Blacksmoke16> not really meant for anything else
<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)])`
<FromGitter> <asterite> Aaaah... okay. So EqualTo is just the simplest assertion to try the library but will never be used in real code, right?
<FromGitter> <Blacksmoke16> yea i dont really know what you would use it for
<FromGitter> <Blacksmoke16> im sure someone can think of something p
<FromGitter> <Blacksmoke16> that example was mainly trying to show `Valid`
<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
<FromGitter> <absolutejam_gitlab> What about a way for people to create their own assertion sets?
<FromGitter> <Blacksmoke16> already a thing
<FromGitter> <absolutejam_gitlab> `@[Assert::Custom(Something)]`
<FromGitter> <Blacksmoke16> yes
<FromGitter> <absolutejam_gitlab> Or a group
<FromGitter> <absolutejam_gitlab> Those are the exciting examples
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d62f900022dba538e5db404]
<FromGitter> <j8r> why it's a class?
<FromGitter> <Blacksmoke16> ATM since the `valid?` method can change the message ivar
<FromGitter> <j8r> I mean, we won't have to pass it by reference?
<FromGitter> <Blacksmoke16> which if its a struct, it doesnt get set correct, since its a copy im thinking?
<FromGitter> <Blacksmoke16> actually nvm, i think i can change them to structs
<FromGitter> <Blacksmoke16> previous implementation required them to be classes, but guess not anymore
<FromGitter> <j8r> the best would be to include a module
<FromGitter> <Blacksmoke16> cant
<FromGitter> <j8r> maybe not possibl
<FromGitter> <j8r> that what I was thinking
<FromGitter> <j8r> :)
<FromGitter> <Blacksmoke16> it uses the subclasses macro method
<FromGitter> <Blacksmoke16> would be possible if you could do that for modules, or all types annotated with x tho
<FromGitter> <j8r> struct is fine, no overhead
<FromGitter> <Blacksmoke16> plus there is some inheritance stuff going on so parent struct with abstract defs and such works well
<FromGitter> <Blacksmoke16> made a macro to make it easier, for example that custom assertion initializer could also be written as
<FromGitter> <absolutejam_gitlab> Is there a good guide to struct vs classes?
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d62fabe3c1aba311bcecc53]
<FromGitter> <Blacksmoke16> and
<FromGitter> <absolutejam_gitlab> ah so they're not actually immutable
<FromGitter> <absolutejam_gitlab> but just due to how they're passed by value, they're usually used for immutability
<FromGitter> <Blacksmoke16> yea, and no i tested it, they have to be classes :/
<FromGitter> <Blacksmoke16> seems i need to add a spec for that behavior
<FromGitter> <Blacksmoke16> since the message template can change within the valid? method, it doesnt update the template correctly
<FromGitter> <Blacksmoke16> was thinking about, what if instead of returning a bool, it just returned Nil, but had some class be passed to everything
<FromGitter> <Blacksmoke16> like `builder.add_error("some message")`
<FromGitter> <Blacksmoke16> so assertions themselves could be structs, and use that vs including the message stuff within the assertion
<FromGitter> <Blacksmoke16> would that be better?
<FromGitter> <j8r> strange,why classes?
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d62feb2e403470ab6d7030e]
dingenskirchen has quit [Quit: dingenskirchen]
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d62febba080d70ab57e8819]
<FromGitter> <j8r> :/
<FromGitter> <Blacksmoke16> so that you can change the `message` from within the `valid?` method
<FromGitter> <Blacksmoke16> otherwise only gets set on the copy
<FromGitter> <Blacksmoke16> guess the question now is, is them being classes a big enough detriment to performance to change the implementation a bit?
<FromGitter> <j8r> don't know, are we supposed to use lots of assertions in lots of objects?
<FromGitter> <j8r> we can use it to validate JSON, or is it CrSerializer?
<FromGitter> <Blacksmoke16> that was the idea, you could make it runs validations after deserializing
<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
<FromGitter> <Blacksmoke16> i dont really see you having to validate an obj more than once or twice
<FromGitter> <j8r> If we use it and handle lots of requests with complex objects, the performance would be noticeable. Needs to be measured
<FromGitter> <Blacksmoke16> let me benchmark it real quick
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d6300fef2821072aa132f26]
<FromGitter> <Blacksmoke16> didnt expect that
<FromGitter> <Blacksmoke16> granted it was only 1 class with 1 assertion...
<FromGitter> <j8r> it consumes less memory
<FromGitter> <Blacksmoke16> how did you tell?
<FromGitter> <j8r> and also fastest, certainly due to the allocation.
<FromGitter> <Blacksmoke16> wait, am i missing something here? class has 8m which is more than struct's 5.5m?
<FromGitter> <j8r> You can use `Benchmark.memory`
<FromGitter> <j8r> in your results `struct` is better
<FromGitter> <Blacksmoke16> how? class has more iterations? and im assuming used less bytes per operation?
<FromGitter> <j8r> more throughput (B/op), and a total of less operations done
<FromGitter> <j8r> I think it's what `mean` means?
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d630434022dba538e5dfa49]
<FromGitter> <Blacksmoke16> i always assumed higher is better on iterations and B/op lower is better
<FromGitter> <j8r> yeah, that's the opposite
<FromGitter> <Blacksmoke16> 😕
<FromGitter> <j8r> lol
<FromGitter> <Blacksmoke16> that makes no sense to me
<FromGitter> <Blacksmoke16> then why is the one with more iterations marked as the fastest?
<FromGitter> <j8r> hum maybe you are right
<FromGitter> <j8r> let me check
<FromGitter> <Blacksmoke16> 😆
<FromGitter> <Blacksmoke16> oh boy
<FromGitter> <j8r> you are right yes sorry
<FromGitter> <j8r> haha
<FromGitter> <Blacksmoke16> all good
<FromGitter> <Blacksmoke16> so i guess based on that i wont worry about it for now
<FromGitter> <j8r> I confused myself
<FromGitter> <j8r> yes, such optimizations can wait
<FromGitter> <Blacksmoke16> indeed
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/Benchmark.html needs updated tho
<FromGitter> <Blacksmoke16> its example is missing the bytes per operation
<FromGitter> <j8r> the with real world applications, we will be able to see the real impact
<FromGitter> <Blacksmoke16> works for me
dingenskirchen has joined #crystal-lang
<FromGitter> <watzon> It would be really nice if documentation generation could work with external shards
<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.