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
alex`` has quit [Ping timeout: 245 seconds]
lvmbdv has quit [Ping timeout: 244 seconds]
lvmbdv has joined #crystal-lang
<FromGitter> <watzon> Anyone played around with https://github.com/icy-arctic-fox/spectator yet? I just found it and it's awesome.
<FromGitter> <watzon> Pretty close to rspec
<FromGitter> <Blacksmoke16> i dont see the big benefit of it
<FromGitter> <Blacksmoke16> just makes it harder for those not familiar with it to figure out whats going on, and another dep that could end up breaking/stop being maintained
<FromGitter> <watzon> For me the built in spec library is too minimalistic for some of my projects. It's missing the ability to create variables local to a context mainly, which is a huge pain in the butt for me.
<FromGitter> <Blacksmoke16> cant you make a method do that?
<FromGitter> <Blacksmoke16> or a macro?
<FromGitter> <watzon> The idea is that you shouldn't have to
<FromGitter> <watzon> That also adds complexity, but generally specs are undocumented
<FromGitter> <watzon> Because they're specs
<FromGitter> <wontruefree> does anyone run crystal on 32 bit
<FromGitter> <watzon> And by "create variables local to a context" I mean what rspec's `let` method does
<FromGitter> <wontruefree> it is a massive pain
<FromGitter> <watzon> @wontruefree it should
<FromGitter> <wontruefree> I cant imagine it is used much on 32 bit
<FromGitter> <watzon> Probably not
<FromGitter> <watzon> Not many things run 32 bit anymore
<FromGitter> <wontruefree> haha
<FromGitter> <wontruefree> very true
<FromGitter> <wontruefree> I am having trouble even getting master to build
<FromGitter> <watzon> Damn `send` would be really helpful right about now
<FromGitter> <watzon> Hard to test private methods without it
<FromGitter> <wontruefree> hahaha
<FromGitter> <Blacksmoke16> test private methods?
<FromGitter> <watzon> Yeth
<FromGitter> <Blacksmoke16> should just test them indirectly
<FromGitter> <Blacksmoke16> is the point of them being private
<FromGitter> <wontruefree> you could probably make a macro to expose a private method
<FromGitter> <watzon> Well you can for sure, but in some cases it's nice to be able to access them directly
<FromGitter> <Blacksmoke16> then dont make it private
<FromGitter> <wontruefree> I would mostly agree with @Blacksmoke16 but sometime you need to test private stuff
<FromGitter> <wontruefree> sometimes they shouldnt be public
<FromGitter> <wontruefree> but they are sensitive enough you want to test them
<FromGitter> <Blacksmoke16> protected and wrap your spec in that type
<FromGitter> <watzon> I'll just go the indirect route. Don't want to make things unnecessarily complex. It would just be nice to have `send`
<FromGitter> <Blacksmoke16> that would be the way to go, private methods are usually used to share logic within a class, but should be tested via the public API they are used in
<FromGitter> <Blacksmoke16> as the details in the private method dont matter as long as the public api is well tested and passes
<FromGitter> <wontruefree> I personally dont like rspec style but specter seems really well put together
<FromGitter> <watzon> I agree for the most part, but sometimes when you're using multiple private methods in one of your public methods it can be hard to determine where something is broken if it's in one of the private ones. Being able to test each method separately helps to guarantee that they're all doing exactly what they're supposed to.
<FromGitter> <Blacksmoke16> it just seems like its adding more complexity to something that doesnt need it
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d64905d35f914538d90d2e6]
<FromGitter> <Blacksmoke16> @watzon just reopen the type and make the method public in your spec
<FromGitter> <Blacksmoke16> assuming its not a huge method
<FromGitter> <watzon> I guess that is a possibility
<FromGitter> <Blacksmoke16> less than ideal as it'll be in two places and tests wouldnt reflect changes you make in real code tho
<FromGitter> <Blacksmoke16> er no
<FromGitter> <Blacksmoke16> do like
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d6490e19b381b084ffe8fb4]
<FromGitter> <watzon> That was what I thought you were talking about
<FromGitter> <Blacksmoke16> prob be the way to go if you really want to do it
<FromGitter> <watzon> We'll see how I feel about it after I finish everything else
<FromGitter> <wontruefree> what do you think of this ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d649150a498b67237a0cff0]
<FromGitter> <Blacksmoke16> is it a class or instance method?
<FromGitter> <watzon> That's pretty simple actually, but I'd probably do something more like ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d6491c007d1ff39f88cf81b]
<FromGitter> <watzon> Instance method
<FromGitter> <watzon> It also needs some help if the method has arguments
<FromGitter> <Blacksmoke16> one thing i noticed in ruby/crystal that i didnt realize before
<FromGitter> <watzon> Which it does in this case
<FromGitter> <Blacksmoke16> subclasses inherit private methods
<FromGitter> <Blacksmoke16> naw you can just do
<FromGitter> <watzon> > subclasses inherit private methods ⏎ ⏎ Yup :)
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d649220dbf5ae2d42cf043c]
<FromGitter> <Blacksmoke16> something like that
<FromGitter> <watzon> Yeah that could work
<FromGitter> <watzon> Of course you'd need `*args` and `**kwargs`
<FromGitter> <wontruefree> haha
<FromGitter> <wontruefree> that works
<FromGitter> <Blacksmoke16> you guys use travis for your projects?
<FromGitter> <watzon> Yup
<FromGitter> <Blacksmoke16> which settings do you use? build on PR or pushed branch or both?
<FromGitter> <Blacksmoke16> annoys me it runs twice but doesnt work too good without both
<FromGitter> <Blacksmoke16> as you could make a PR and they wont run since the branch is never pushed, or it never runs since its not a PR to update the docs
<FromGitter> <watzon> I do both
<FromGitter> <wontruefree> what does `GC Warning: getcontext failed: using another register retrieval method...` mean
<FromGitter> <Blacksmoke16> fair enough
<FromGitter> <watzon> I think this is my favorite part about Spectator: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d6496d4be3a8a311af2e63b]
<FromGitter> <watzon> Built in profiling
<FromGitter> <Blacksmoke16> `491 microseconds` :S
<FromGitter> <watzon> That number will shoot up a ways once I start profiling the training worker haha
<FromGitter> <Blacksmoke16> you know about the other spec formats?
<FromGitter> <Blacksmoke16> like `crystal spec -v` or `crystal spec --tap`
<FromGitter> <watzon> Nope. I mean I know about the `-v` option, but what's `--tap`?
<FromGitter> <Blacksmoke16> https://testanything.org/
<FromGitter> <watzon> Ahh interesting
<FromGitter> <Blacksmoke16> can also output junit
lvmbdv has quit [Remote host closed the connection]
lvmbdv has joined #crystal-lang
lvmbdv has quit [Ping timeout: 248 seconds]
lvmbdv has joined #crystal-lang
chemist69 has quit [Ping timeout: 276 seconds]
chemist69 has joined #crystal-lang
lvmbdv has quit [Ping timeout: 248 seconds]
lvmbdv has joined #crystal-lang
<FromGitter> <galvertez> can anybody spot what i'm doing wrong here? ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ i keep getting compile type is `Link | Nil`, which is true, it is nilable, but i thought the `if @link` would be good enough... i feel like i've done it this way before and it's never had any trouble... i.e. the compile time type for `@link` in *that location* can never be `Nil` [h
<FromGitter> ... ttps://gitter.im/crystal-lang/crystal?at=5d64b7d9022dba538e699003]
<FromGitter> <galvertez> bonus points to anyone who figures out what i'm creating here, but only a few bonus points 'cause i think there's basically only one reason you'd write code like that lol
<FromGitter> <galvertez> maybe i was doing that w/ local variables and not instance variables
<FromGitter> <galvertez> yea i must have been lol it actually worked... that is kind of annoying, but i guess it's a convenient way of saying "dear compiler, trust me, it's not nil"
<FromGitter> <watzon> @galvertez so instance variables can't be used in guard statements like that, the easiest way around that is to assign to a local variable inside of the if ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d64be399b381b084fffae88]
<FromGitter> <watzon> The second guard clause can also be converted to a `try` statement ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d64be7907d1ff39f88e2532]
<FromGitter> <galvertez> yeap
<FromGitter> <galvertez> rofl, i didn't check here for a while and i did exactly that :)
<FromGitter> <galvertez> i'm not sure i understand why they shouldn't be usable in guard statements? something to do w/ concurrency?
<FromGitter> <watzon> > something to do w/ concurrency? ⏎ ⏎ Pretty sure this is it. Since the instance var is accessible elsewhere it might change while whatever is happening inside the guard clause is happening.
<FromGitter> <galvertez> yea
<FromGitter> <galvertez> oh god i'm imagining the first time that was a bug
<FromGitter> <galvertez> and how hard that must have been to figure out
<FromGitter> <watzon> no kidding haha
<FromGitter> <galvertez> @watzon any guess what i'm building?
<FromGitter> <galvertez> i *think* that's enough context to extrapolate the rest
<FromGitter> <watzon> @galvertez only thing I can think of is some kind of HTML parser
<FromGitter> <galvertez> rofl a linked list but now that i'm re-reading it i can see how you'd get that
<FromGitter> <watzon> Ahh that also makes sense
<FromGitter> <watzon> Well cool
<FromGitter> <watzon> Good project
<FromGitter> <galvertez> eh idk if it's a project i'm kind of just screwing around
<FromGitter> <watzon> Well a linked list is a good learning project
<FromGitter> <galvertez> i think it will be useful for my raft shard tho 'cause i'm gonna need easy detachment/reattachment of elements so i think using array would mean *huge* arrays and lots of pointer shuffling etc.
<FromGitter> <galvertez> if not, then i take away some lessons anyway
<FromGitter> <galvertez> i was surprised not to find any linked lists in crystalshards.xyz though
<FromGitter> <galvertez> oh there's one in awesome-crystal. shoulda looked there first
return0e_ has joined #crystal-lang
return0e has quit [Ping timeout: 272 seconds]
<FromGitter> <mavu> Morning, I'm trying to find a method to check if a IO (serial port /dev/ttyUSB0 in this case) has data available to read, without blocking or waiting when there is nothing to read. ⏎ What would I use? ⏎ Gets seems to block/wait for data. so does read_line
<FromGitter> <j8r> check each second for example?
<FromGitter> <mavu> @j8r how would I do that if the read_line blocks?
<FromGitter> <mavu> hmm ⏎ at least I think it blocks. need to ckech that, it might just loop a lot.
<FromGitter> <j8r> you can have something like ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d64ebd3a498b67237a32bcb]
<FromGitter> <mavu> I don't think that works, because it will just stop at the line "if !(content = io.gets_to_end).empty?" until a ^D is received on the line.
<FromGitter> <mavu> (I just tried a gets_to_end in a loop, and it loops once when it receives a EOF then waits again.
<FromGitter> <mavu> I need something that returns when it cant read anything (or throws would be fine too I guess)
<FromGitter> <mavu> Just found this random comment : "Crystal handles non-blocking for you, just write blocking code in separate fibers and communicate using channels and crystal will use non-blocking code and select() calls behind-the-scenes." ⏎ Maybe I have to try that approach. not sure if that mapps really well to sending commands on a serial connection and waiting for a reply (of which I don't know how long/many lines it will
<FromGitter> ... be)
<FromGitter> <watzon> Yeah Crystal has async similar to that of nodejs which uses a single call stack on a single thread. Soon we will have multithreading support as well.
alex`` has joined #crystal-lang
<FromGitter> <asterite> mavu: there's no way to do that, but maybe there should. Many have already requested it. Though I'm not sure if what you want to do can be done in a different way
absolutejam has joined #crystal-lang
DTZUZO has joined #crystal-lang
return0e_ has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
<FromGitter> <naqvis> @mavu I would suggest to go with `read_byte` or `read` with small number of bytes along with usage of `IO::Timeout`. The reason i'm suggesting such is that `gets_to_end` waits till it drains the IO and thus give you sense of blocking.
<FromGitter> <yxhuvud> I would expcet it to be possible to read what is available, but also to `select` over a bunch of those
<FromGitter> <yxhuvud> but maybe ports are not availab le as file handes?
<FromGitter> <asterite> you probably need to do what you need to do in Go: https://stackoverflow.com/questions/27209697/how-to-read-input-from-console-in-a-non-blocking-way-with-go
gangstacat has quit [Quit: Ĝis!]
gangstacat has joined #crystal-lang
alex`` has quit [Ping timeout: 246 seconds]
<FromGitter> <ArtLinkov> Another pgsql question, is there any way to return all the log messages that a query raises in the database while it executes? ⏎ Example (something like this): ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d6543aa4b1189084e73703f]
<FromGitter> <ArtLinkov> Same for db.query
<FromGitter> <Blacksmoke16> didnt know that was a thing ^.^
<FromGitter> <absolutejam_gitlab> Me either but
absolutejam has quit [Ping timeout: 246 seconds]
<FromGitter> <ArtLinkov> I assume something like this is possible because it does return the build-in errors when I do something wrong within the query
<FromGitter> <watzon> Oh hello @ArtLinkov. How is SQL hell?
<FromGitter> <ArtLinkov> Hi @watzon :) ⏎ It's moving along slowly, but despite all my suffering. It's still better than python XD
<FromGitter> <watzon> Heck yes it is 😂
<FromGitter> <ArtLinkov> I've moved on to some decent complexity functions in the database
<FromGitter> <ArtLinkov> With errors and validations and such
<FromGitter> <watzon> That's awesome
alex`` has joined #crystal-lang
ht_ has joined #crystal-lang
<FromGitter> <jwoertink> `YAML.parse({% read_file("config.yml") %})` I have this, but I get `no overload matches 'YAML.parse' with type Nil`. I thought `read_file` returns a `StringLiteral`, so shouldn't that never be `nil`?
<FromGitter> <Blacksmoke16> hmm
<FromGitter> <jwoertink> 😂 I said the same
<FromGitter> <Blacksmoke16> i think the issue lies somewhere else
<FromGitter> <Blacksmoke16> ah
<FromGitter> <Blacksmoke16> make it `YAML.parse({{ read_file("shard.yml") }})`
<FromGitter> <Blacksmoke16> `{% %}` syntax is mostly for "control" structure, while `{{}}` is for pasting the value
<FromGitter> <jwoertink> ah. I thought `{{ }}` was only used in side of actual macro defs
<FromGitter> <jwoertink> yeah, the error went away
<FromGitter> <jwoertink> thanks!
<FromGitter> <Blacksmoke16> np
<FromGitter> <bew> @jwoertink you need to use `{{ }}` !!
<FromGitter> <jwoertink> 😄 thanks
<FromGitter> <bew> Aargh gitter android...
<FromGitter> <Blacksmoke16> :S
<FromGitter> <jwoertink> lol
<FromGitter> <watzon> Lol yeah the gitter app leaves much to be desired
<FromGitter> <watzon> No editing
<FromGitter> <watzon> smh
<FromGitter> <Blacksmoke16> i think its done (enough for initial release that is)
<FromGitter> <watzon> That's pretty sweet
<FromGitter> <Blacksmoke16> let me know if i missed something, or have some feedback
<FromGitter> <Blacksmoke16> thanks :)
<FromGitter> <Blacksmoke16> will do a blog post about it in coming week, also maybe a short one on some implementation patterns i used, \cc @absolutejam_gitlab
dannyAAM has quit [Quit: znc.saru.moe : ZNC 1.6.2 - http://znc.in]
dannyAAM has joined #crystal-lang
<FromGitter> <bew> Test
<FromGitter> <bew> @watzon it's pretty obscure, but double tap on you msg let's you edit it
<FromGitter> <bew> your*
<FromGitter> <watzon> Lol well that's good to know
<FromGitter> <bew> @Blacksmoke16 nice to see your assertion doc is up :) I'd suggest renaming your generics P and C to something a bit more explanatory, like ChoicesT for C (not sure what's P, PredicateT maybe?)
<FromGitter> <Blacksmoke16> Property
<FromGitter> <Blacksmoke16> i guess `PropertyType` would be better?
<FromGitter> <bew> Yeah definitely
<FromGitter> <Blacksmoke16> I could go with that
<FromGitter> <Blacksmoke16> @bew https://github.com/Blacksmoke16/assert/pull/3
<FromGitter> <Blacksmoke16> API docs will be updated in a few min when CI is done
<FromGitter> <shdown> Is there a way to get a Python/Go-style slice of an array? I understand that `Slice` is just a pointer and a size and slicing an array into it would be unsafe, but why can’t we have a `struct ArraySlice(T)` with `Array(T)` reference, offset and size?
<FromGitter> <Blacksmoke16> not super familiar with this stuff, but pretty sure you can turn an array into a slice
<FromGitter> <Blacksmoke16> something like `Slice.new(arr.to_unsafe, sizeof(arr))` i think
<FromGitter> <Blacksmoke16> might just be `arr.size`
<FromGitter> <shdown> Yes, but that would be unsafe: the array may change its pointer on reallocation.
<FromGitter> <shdown> While Python and Go provide safe slices.
<FromGitter> <Blacksmoke16> slices are safe
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/0.30.1/Slice.html#new(size:Int,value:T,*,read_only=false)-class-method
<FromGitter> <Blacksmoke16> `While a pointer is unsafe because no bound checks are performed when reading from and writing to it, reading from and writing to a slice involve bound checks. In this way, a slice is a safe alternative to Pointer.`
<FromGitter> <shdown> Really? :) https://play.crystal-lang.org/#/r/7gno
<FromGitter> <Blacksmoke16> ah i see what you mean now
<FromGitter> <watzon> Yeah don't trust slices haha
<FromGitter> <watzon> @shdown what exactly are you wanting to do?
<FromGitter> <Blacksmoke16> why not just use an array in that example
<FromGitter> <shdown> Because it would copy it?
<FromGitter> <watzon> So you want a slice of an array that still references the original array?
<FromGitter> <shdown> Yes
<FromGitter> <watzon> Well there's nothing built in that I know of, but it shouldn't be too hard to roll your own. Tbh I've never liked the use of the word Slice for what it's used for in Crystal.
<FromGitter> <shdown> AFAIK this is how it is implemented is Python. I just wondered why it’s not in built-in, this is like super useful.
<FromGitter> <watzon> Agreed. I feel like the current slice implementation would be better off if it was Bytes, and then what you're looking for would be Slice. But it's doubtful that will change.
<FromGitter> <watzon> You could always create an issue though, maybe the maintainers will have something to say about it
mps has left #crystal-lang [#crystal-lang]
ht_ has quit [Remote host closed the connection]
absolutejam has joined #crystal-lang
<FromGitter> <absolutejam_gitlab> Does Python have slices?
<FromGitter> <absolutejam_gitlab> I know Go does but I thought Python just had mutable Arrays
<FromGitter> <absolutejam_gitlab> Do you mean like a first-class object or like slice literals, eg. `foo[0:1]`?
<FromGitter> <absolutejam_gitlab> @Blacksmoke16 https://blacksmoke16.github.io/assert/Assert/Assertions/Assertion.html
<FromGitter> <absolutejam_gitlab> That's a mouthful haha
<FromGitter> <Blacksmoke16> :S
<FromGitter> <Blacksmoke16> assuming you mean the class name?
<FromGitter> <absolutejam_gitlab> yeah
<FromGitter> <Blacksmoke16> eh, not like you have to type it a lot
<FromGitter> <Blacksmoke16> could be worse :P
<FromGitter> <absolutejam_gitlab> you thought about using a DLS for assertions?
<FromGitter> <Blacksmoke16> like what?
<FromGitter> <absolutejam_gitlab> like `assertion "Foo" do ... end`
<FromGitter> <absolutejam_gitlab> if you're heading down that route
<FromGitter> <Blacksmoke16> got a more complete example? not sure i follow
<FromGitter> <absolutejam_gitlab> Just a way to abstract away from `class MyCustom(PropertyType) < Assert::Assertions::Assertion`
<FromGitter> <Blacksmoke16> not really
<FromGitter> <absolutejam_gitlab> I mean, I'm all for classes and the in-built syntax, but you look like you're heading down that route
<FromGitter> <Blacksmoke16> would it even be worth it? its not like you have to interact with the class you define often
<FromGitter> <Blacksmoke16> but i guess it would be doable like
coderobe has quit [Read error: Connection reset by peer]
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d6599794b1189084e75cd76]
<FromGitter> <Blacksmoke16> but for how often you'd prob use it, doubt it would be worth it
<FromGitter> <Blacksmoke16> much less flexible
<FromGitter> <absolutejam_gitlab> @mavu you could use a loop and `break` or a channel
<FromGitter> <absolutejam_gitlab> Yeah, not something I'm a huge fan of @Blacksmoke16 unless you are writing a full DSL
<FromGitter> <absolutejam_gitlab> but it looked like you were already deep in the macro matrix
<FromGitter> <Blacksmoke16> not something i was planning on
<FromGitter> <Blacksmoke16> not really, the whole implementation is pretty simple tbh
<FromGitter> <Blacksmoke16> like 2 macro loops and one helper for the initializer
<FromGitter> <absolutejam_gitlab> @mavu I did something similar with fibers and a channel, essentially pattern matching to close the channel and exit the fiber
<FromGitter> <absolutejam_gitlab> IIRC
<FromGitter> <absolutejam_gitlab> I found a much easier way soon after and scrapped it but it worked
<FromGitter> <absolutejam_gitlab> Fair enough
<FromGitter> <absolutejam_gitlab> Why the `initializer` macro?
<FromGitter> <Blacksmoke16> less typing
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d659ac7a080d70ab5907cd7]
<FromGitter> <Blacksmoke16> plus makes it harder to forget a required field or call super
<FromGitter> <absolutejam_gitlab> oh, do you *need* the `super`?
<FromGitter> <Blacksmoke16> yes
<FromGitter> <absolutejam_gitlab> I kinda wish there was an in-built `post-initialize` or something
<FromGitter> <absolutejam_gitlab> Or a forced super
<FromGitter> <absolutejam_gitlab> Some way to provide an initialize for children but also perform inherited stuff in the iniitalize
<FromGitter> <Blacksmoke16> not that i know of, but yea. it's required as thats what sets the property name, and the message/groups if none were given in the annotation
<FromGitter> <Blacksmoke16> thats what super is for :P
<FromGitter> <absolutejam_gitlab> I'd be against the macro if it was just replacing `initialize`
<FromGitter> <absolutejam_gitlab> just new syntax for a language feature
<FromGitter> <Blacksmoke16> yea mainly was just to help keep things a bit more DRY
<FromGitter> <Blacksmoke16> esp if an assertion only has like 1 ivar
lvmbdv has quit [Ping timeout: 244 seconds]
lvmbdv has joined #crystal-lang
lvmbdv has quit [Ping timeout: 244 seconds]
coderobe has joined #crystal-lang
absolutejam has quit [Ping timeout: 268 seconds]
lvmbdv has joined #crystal-lang
olbat[m] has quit [Ping timeout: 252 seconds]
olbat[m] has joined #crystal-lang