RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.27.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
faitswulff has quit []
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
ashirase has quit [Ping timeout: 272 seconds]
ashirase has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
f1refly has quit [Ping timeout: 268 seconds]
f1refly has joined #crystal-lang
chemist69 has quit [Ping timeout: 250 seconds]
moei has quit [Ping timeout: 250 seconds]
chemist69 has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
Jenz has joined #crystal-lang
<Jenz> Moin o/
<Jenz> DIM = {100, 60}
<Jenz> Why do I get an error: "invalid constant value" for that?
<Jenz> Very weird
Jenz has quit [Quit: leaving]
<FromGitter> <bew> Where/how do you use it?
crystal-lang564 has joined #crystal-lang
ashirase has quit [Ping timeout: 246 seconds]
ashirase has joined #crystal-lang
DTZUZU has quit [Ping timeout: 268 seconds]
DTZUZO has quit [Ping timeout: 268 seconds]
return0e_ has joined #crystal-lang
return0e has quit [Ping timeout: 246 seconds]
DTZUZU has joined #crystal-lang
DTZUZO has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
crystal-lang564 has quit [Ping timeout: 258 seconds]
<FromGitter> <apahl> Hi, I am working through "Programming Crystal" by Ivo Balbaert and Simon St. Laurent and I have a question about including modules vs. subclassing. Please keep in mind that I do not come from a Ruby background... ⏎ What is the advantage of implementing `Comparable` as a module in the stdlib and including it in a class where I want to use it vs. implementing it as a class and then subclassing it?
<FromGitter> <j8r> you're telling essentially composition vs inheritance?
<FromGitter> <apahl> Yes, probably. For the example of `Comparable` what is the advantage of implementing it via composition?
<FromGitter> <j8r> yes: you can include it to a struct, a class or another module
<FromGitter> <j8r> and, you can include multiple module. With inheritance, you can only inherit once and that's it
<FromGitter> <apahl> Ok, so it can be more versatilly applied that way?
<FromGitter> <apahl> Thanks for the explanation!
<FromGitter> <j8r> Yes, it's more flexible
<FromGitter> <j8r> behind this choice there is also a logic behind: it wouldn't make sense to have a `Comparable` class that can be used as-is. It's a set of methods that can be included ans used in other structs/classes
<FromGitter> <apahl> Ok, I understand. Thanks again for the explanation, that helped a lot.
<FromGitter> <j8r> you're welcome :)
crystal-lang564 has joined #crystal-lang
laaron has quit [Remote host closed the connection]
<FromGitter> <codenoid> how do i json.parse with a structs ?
laaron has joined #crystal-lang
ternarysolo has joined #crystal-lang
<FromGitter> <vladfaust> `Struct.from_json("{}")`
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
Vexatos has quit [Quit: ZNC Quit]
Vexatos has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
duane has joined #crystal-lang
laaron has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<FromGitter> <jwoertink> Anyone know of a good way to sort of "reset" an instance when you do this sort of pattern? ....
<FromGitter> <jwoertink> ```class Thing ⏎ INSTANCE = new ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5c8fd0dc2fb6800d803ee97a]
<FromGitter> <jwoertink> Mainly for running a spec where the first spec sets up some variables on the instance, then the second spec already knows of these variables
<FromGitter> <j8r> You want to change a constant?
<FromGitter> <j8r> you can use `class_property instance`
<FromGitter> <jwoertink> Yeah, sort of .... I just want to reset the values of `INSTANCE` between specs
<FromGitter> <jwoertink> but the pattern works fine in the code
<FromGitter> <j8r> you can instantiate a new class Thing for each
<FromGitter> <j8r> each spec should be independent of each other, they can be ran separately
<FromGitter> <jwoertink> I'm not sure I follow, but let me make a quick example
<FromGitter> <j8r> you should be able to run each `it "should be ... " do ... end` independently, with `crystal spec spec/myfile.cr:12`
<FromGitter> <j8r> don't use a constant if it's not really a constant
<FromGitter> <aemadrid> I’ve seen the singleton usecase a lot on Crystal that way though
<FromGitter> <j8r> @jwoertink https://play.crystal-lang.org/#/r/6ivt
<FromGitter> <j8r> yeah that's bad
<FromGitter> <jwoertink> ok, so let's say it has to be a constant because it's a part of a library that won't be changing that...
<FromGitter> <j8r> This is a global mutable state
<FromGitter> <aemadrid> you might want to make that class resettable - meaning you can say `Xyz::INSTANCE.reset(…)`
<FromGitter> <j8r> @jwoertink anyway https://play.crystal-lang.org/#/r/6ivv
<FromGitter> <jwoertink> that's what I was thinking of doing. I was curious of other's solutions
<FromGitter> <j8r> I'm afraid not :(
moei has joined #crystal-lang
DTZUZO has quit [Ping timeout: 245 seconds]
crystal-lang564 has quit [Ping timeout: 258 seconds]
<FromGitter> <kinxer> @jwoertink Soon I'm going to refactor the code I have that uses a singleton, but to reset it in specs I reopen it in the spec_helper, kind of like so: https://play.crystal-lang.org/#/r/6iwa
<FromGitter> <jwoertink> Yeah, that makes sense. Thanks @kinxer
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
crystal-lang564 has joined #crystal-lang
<FromGitter> <jwoertink> When using `Spec.before_each`, is there a way to scope it to just the describe block you're in?
<FromGitter> <vladfaust> Nope
<FromGitter> <jwoertink> fair enough. Thanks!
<FromGitter> <kinxer> I don't think so. I think you have to redefine it to an empty method at the end of the block.
ternarysolo has quit [Ping timeout: 246 seconds]
<FromGitter> <vladfaust> It literally runs before each spec in you compiled specs
<FromGitter> <vladfaust> However, if you split the specs...
<FromGitter> <vladfaust> And run each in separate call...
<FromGitter> <kinxer> That's a sad state of affairs.
<FromGitter> <vladfaust> Absolutely
<FromGitter> <jwoertink> Yeah. I put it in one file that I wanted it to run, then ran `crystal spec/` and expected it to only work on that file I added it in
<FromGitter> <kinxer> Speaking of things that (probably) don't exist, is there a way to use macros in comments?
<FromGitter> <jwoertink> Yeah, you can just do `{% %}` in a comment
ternarysolo has joined #crystal-lang
<FromGitter> <kinxer> Oh, cool.
<FromGitter> <jwoertink> there's an example of where it's being done
<FromGitter> <jwoertink> well, already being in a macro for, but I'm pretty sure that works
crystal-lang564 has quit [Quit: Konversation terminated!]
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
ternarysolo has quit [Ping timeout: 250 seconds]
f1refly has quit [Quit: WeeChat 1.6]
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c9000d78126720abc04abfe]
<FromGitter> <Blacksmoke16> never realized how big the perf diff is between them for `["one", "two", "three"].includes? "three"`
<FromGitter> <kinxer> Oh, wow.
<FromGitter> <Blacksmoke16> ```count = 3 ⏎ ⏎ pp StaticArray(Int32, count).new(42)``` [https://gitter.im/crystal-lang/crystal?at=5c9002bdf3dbbd230c7a1fe4]
<FromGitter> <Blacksmoke16> there goes my idea :P
<FromGitter> <Blacksmoke16> makes me think that routers would benefit from StaticArray assuming they know number of routes at compile time
ternarysolo has joined #crystal-lang
<FromGitter> <straight-shoota> @Blacksmoke16 The costly part is allocating an array on the heap. That's typically a one-time cost for a router.
<FromGitter> <Blacksmoke16> i.e. once all routes are registered?
<FromGitter> <straight-shoota> Your benchmark should only compare the call to `#includes?` not instantiating the collection
<FromGitter> <Blacksmoke16> sec
<FromGitter> <straight-shoota> yes
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c9004f18aa66959b630ef92]
<FromGitter> <Blacksmoke16> darn
<FromGitter> <Blacksmoke16> good call
duane has quit [Ping timeout: 246 seconds]
ternarysolo has quit [Ping timeout: 255 seconds]
<FromGitter> <kinxer> Where would I find the code for the `crystal docs` command?
<FromGitter> <kinxer> Thank you.
<FromGitter> <r00ster91> you're welcome. good luck if you want to implement something
<FromGitter> <Blacksmoke16> one thing i noticed that was missing is default values on Ivars
<FromGitter> <Blacksmoke16> when used w/o initialize
lucasb has joined #crystal-lang
<FromGitter> <Blacksmoke16> would have to be a new section on the docs id imagine
<FromGitter> <Blacksmoke16> skipping private and non `getter/property` ones
<FromGitter> <j8r> That's strange that the `Set` perf is as bad
<FromGitter> <j8r> What's your code?
<FromGitter> <j8r> Or maybe that's the `Set#includes?` that isn't optimized
<FromGitter> <j8r> It performs a `Hash#has_key?`
<FromGitter> <Blacksmoke16> i dont have it on this computer but was like
<FromGitter> <Blacksmoke16> ```SET = Set{"one", "two", "three"} ⏎ ⏎ benchmark.ips do |b| ⏎ SET.includes? "three" ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5c90221352c7a91455b8bfc5]
<FromGitter> <Blacksmoke16> something like that
<FromGitter> <j8r> I wonder if the list is longer...
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter> <Blacksmoke16> :shrug:
<FromGitter> <Blacksmoke16> prob would have some impact id imagine
<FromGitter> <dscottboggs_gitlab> Is `crystal tool expand` broken?
laaron has quit [Remote host closed the connection]
<FromGitter> <dscottboggs_gitlab> no, I think my macro is broken...
<FromGitter> <dscottboggs_gitlab> does `{% debug %}` work on like `macro(args)...end` type macros or just literals?
<FromGitter> <dscottboggs_gitlab> ok I think I get it now... `{% debug %}` only works when you put it *after* what you want output
laaron has joined #crystal-lang