jhass changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Crystal 0.35.1 | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
oddp has quit [Ping timeout: 256 seconds]
f1refly has quit [Ping timeout: 244 seconds]
f1refly has joined #crystal-lang
sagax has joined #crystal-lang
rocx has quit [Ping timeout: 260 seconds]
<FromGitter> <galvertez> do you guys think it's bad style to have something like ⏎ ⏎ ```require "custom-lib" ⏎ # your code here ⏎ require "custom-lib/finalize"``` ⏎ ⏎ i am writing something that would be much more efficient if there were some things that would only be considered *after* the user of my lib's code has been read and parsed, but i can't think of any other way to guarantee that
<FromGitter> <galvertez> and for what i'm writing, i'd prefer if this library got the heck out of the way of the rest of the user's code and let it do its thing, so i want to to be as tight as possible
go|dfish has quit [Ping timeout: 256 seconds]
<FromGitter> <naqvis> afaik, everything will be merged inside single file and then proceed with compilation, so don't think placement of `require` going to make any difference, other than scope.
<raz> it can make a difference for macros tho
<raz> more than once i've wished for a "require_after". once i even needed an {% after_compile %} (which doesn't exist, so had to do it outside of crystal :D)
<raz> my use-case for the "require_after" usually is: user may inherit some of my classes and i need to patch them up in some way after that happened.
<FromGitter> <naqvis> raz your usecase isn't already solved via `inherited` ?
<FromGitter> <naqvis> but yeah, that's black world of *macrosssssss*
<raz> nope, in some cases that's not enough. they are rare tho and i may not have described it well. the times i bump into it usually a 3rd party shard is involved that i don't want (or can't) patch up. e.g. "require ORM" -> create classes using that ORM -> then i want to add more to these classes or reflect on them
<raz> in that specific case the classes may depend on one another, so asking the user to add an "include" to each is neither nice, nor really practical
<raz> anyway, i'll admit a use-cases are fairly exotic, so haven't bothered nagging for such to be added to crystal (yet :p)
<raz> these*
<FromGitter> <Austaras> Is vscode extension currently broken?
<FromGitter> <naqvis> raz, sounds like you are after RTTI
<FromGitter> <naqvis> @Austaras how should we understand the `broken`?
<FromGitter> <Austaras> It just keeps emitting can't find file 'prelude' while I can still compile from terminal
<FromGitter> <naqvis> that's actually ameba-extension
<FromGitter> <naqvis> if you turn off `crystal-ameba` extension, that shouldn't be the case
<raz> yep, runtime reflection would _also_ be nice, but prob much harder to add. whereas a "require_after" should be very easy i think (basically just prepend to a file that then gets required last)
<FromGitter> <naqvis> try to change settings and change prblems settings to build `"crystal-lang.problems": "build"`
<FromGitter> <naqvis> see if it still give you that issue?
<FromGitter> <naqvis> my understanding was that, it was caused by `ameba extension`, seems I might be wrong in my understanding :P
<FromGitter> <Austaras> It's currently set to build. After I change it to syntax error goes away
<FromGitter> <Austaras> But that's quite useless
<raz> i haven't had much luck with the crystal vscode extensions. i only use the auto-formatting (alt+shift+f) and ignore the rest
<raz> (been a while since i last tried tho, and tbh also don't really have a need for any more than that)
<FromGitter> <naqvis> yeah true, I like `crystal-ameba` extension, as that shows the small squiggles and give you some better hints
<FromGitter> <naqvis> other than that, things aren't that good from language-plugin level
<raz> yup i think i wouldn't mind the squiggles either, but last i tried it would only cause vscode to freeze up randomly and i didn't bother looking further into it
<raz> i just use entr to amea & auto-compile on change, which works fine for me
<raz> ameba*
<raz> vscode handily lets me click the file/line in the error message to jump to it, that helps too :)
<FromGitter> <naqvis> huh, never tried that functionality of jump to line :)
<FromGitter> <naqvis> did you had to do some customized setup of tasks/runner for that output parsing?
<FromGitter> <naqvis> or that works out of the box? raz?
<raz> just out of the box in the vscode terminal
<raz> you have to apple-click tho
<raz> (not sure how it is on other OS'es)
<FromGitter> <naqvis> gotcha
<FromGitter> <naqvis> i'm on mac as well
<raz> yup, it just looks for $filename:$line_no i think
<FromGitter> <naqvis> look like that way
<FromGitter> <naqvis> but definitely good enough
<FromGitter> <naqvis> as so far when running ameba on external terminal, i had to manually find the lines in source code
<FromGitter> <naqvis> will try vscode terminal
<raz> yea, it's pretty good. can just be a bit annoying to find a spot for it where it doesn't take up too much screen space ;)
<FromGitter> <naqvis> true
<FromGitter> <evvo> Hello!
<FromGitter> <evvo> Does anyone had any problem with bigger responses with Kemal ?
<FromGitter> <evvo> From what I see, the response is chunked when is bigger than certain amount and that is when it brakes for some reason. ⏎ Using Chrome, Firefox and Insomnia, the request is simply in "pending" state. I was able to get the response from VS Code's HTTP client, but it might be missing some parts
<FromGitter> <scriptmaster> Kemal is buggy, it is returning 500 error after stress testing with 200k+ requests. crystal http server ran fine and still running. but that is just crystal. I am new to crystal - only a few days. I am looking into luckyframework - seems robust
<FromGitter> <evvo> What about Grip ?
<FromGitter> <evvo> Actually - https://github.com/kemalcr/kemal/issues/575
<FromGitter> <scriptmaster> I haven't tested grip. I could spin an instance and have it run for 1-2 days and see its stability. Seeing that it is a fork of kemal, it may have its caveat. Again, I am new to crystal, so my evaluation is specific to kemal and crystal versions.
<FromGitter> <scriptmaster> I have had problems with latest version of crystal and kemal too. especially >= 0.35.0
<FromGitter> <scriptmaster> My version Crystal 0.34.0 [4401e90f0] (2020-04-06)
<FromGitter> <scriptmaster> bcardiff patch might work for you: https://github.com/kemalcr/kemal/issues/575#issuecomment-650387005
<FromGitter> <evvo> Yes - I was just testing that
<FromGitter> <evvo> Thanks
<FromGitter> <galvertez> that is exactly what i'm dealing with :D
<FromGitter> <galvertez> i.e. it's the difference between looking something up as a member of a hash during runtime, or having a macro write a bunch of if/else statements that i can't know about beforehand because the 3rd party is defining the classes
<FromGitter> <galvertez> i think most usecases are handled with `inherited`, but constants are defined after that macro runs, so it doesn't work for what i'm working on (i am all but certain that a constant is the correct thing to use for this)
<FromGitter> <galvertez> and before you suggest `finished` - i tried that too lol. constants get concretely defined after all class hooks, but i have a need to define a method for a parent class based on the definition of its children, using a macro
<FromGitter> <galvertez> well, not a *need*, but it would certainly make this easier and faster
<raz> yup in the cases where i've needed it, i've just resorted to "require before; do stuff; require after"
<raz> it's not super terrible, but wouldn't like to ask users to do that in a public shard
<FromGitter> <naqvis> yeah, but personally I will suggest against such implementations, as things become *magic* where the magic happening on some derived classes.
<FromGitter> <naqvis> I would have gone with different contract for different purposes, thus making things very clear and easy to reason about
<FromGitter> <naqvis> but yeah, this is just my own way of working :P
<raz> yea when that's possible, it's clearly a better choice. in some cases it just isn't feasible. (e.g. it can be the difference between 30 lines of magic or a highly intricated >300 line patch on a 3rd party shard that has to be maintained etc.)
<raz> i love crystal for enabling that kind of white magic. unlike e.g. Golang, where any type of reflection is a nightmare. but yea, with great power comes great responsibility. :D
<FromGitter> <naqvis> true, monkey patching is good but can be abused as well. So agree "with great power comes great responsibility" :P
oddp has joined #crystal-lang
<FromGitter> <scriptmaster> the great responsibility is with the merger of this pull request https://github.com/kemalcr/kemal/pull/576 :P
<FromGitter> <lodenos> Hi, I have a question about the macro
<FromGitter> <lodenos> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5eff072dc223cc536a4f74d3]
<FromGitter> <lodenos> I would like generate my *it* with the macro
<FromGitter> <lodenos> But actually I have this error with *it* `Error: can't declare def dynamically`
postmodern has quit [Read error: Connection reset by peer]
postmodern has joined #crystal-lang
go|dfish has joined #crystal-lang
_whitelogger has joined #crystal-lang
<FromGitter> <naqvis> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5eff0d9c405be935cdda7607]
<FromGitter> <naqvis> in specs you don't need `def`, but use `it`
<FromGitter> <naqvis> but curious to know why you want to generate multiple duplicate code-base for specs?
<FromGitter> <naqvis> what's your use-case?
<FromGitter> <lodenos> @naqvis Thx it's work, I'm just completly crazy ^^
<FromGitter> <s0kil> You could use a fork temporarily, https://github.com/mint-lang/kemal
flaviodesousa has joined #crystal-lang
flaviodesousa has quit [Remote host closed the connection]
<FromGitter> <s0kil> > It just keeps emitting can't find file 'prelude' while I can still compile from terminal ⏎ ⏎ Related to https://github.com/crystal-lang-tools/scry/issues/173
<FromGitter> <s0kil> You could clone https://github.com/crystal-lang-tools/scry locally, merge this PR https://github.com/crystal-lang-tools/scry/pull/174 and build, that solved the issue for me.
<FromGitter> <s0kil> Would also need to set the absolute path to scry in vscode settings.
postmodern has quit [Quit: Leaving]
rocx has joined #crystal-lang
Welog has joined #crystal-lang
<FromGitter> <Blacksmoke16> @scriptmaster should check out Athena 😉
MasterdonX has quit [Ping timeout: 240 seconds]
MasterdonX has joined #crystal-lang
<raz> my money is on grip, but yes athena is definitely also worth a look (i think it's mostly a matter-of-taste decision between the two)
<FromGitter> <rishavs> personally, I love sticking to the std lib even for webdev. I think crystal by default has everything I need, without me having to get a framework into the picture. Crystal is almost like go in that respect
deavmi has quit [Ping timeout: 240 seconds]
<FromGitter> <Blacksmoke16> if what you're doing is simple, otherwise you end up just making your own framework
deavmi has joined #crystal-lang
<FromGitter> <Blacksmoke16> main area of the http server is missing is routing
<FromGitter> <rishavs> yeah, not gonna deny that.
<FromGitter> <Blacksmoke16> not using one for sake of not using one might just cost you in the long run
<FromGitter> <Blacksmoke16> in productivity and maintainability
<FromGitter> <rishavs> routing is easy, when you need to do it naively. but, boy o boy, it gets complex when you really want to optimize it
<FromGitter> <Blacksmoke16> mhm
<FromGitter> <j8r> @Blacksmoke16 @wyhaines JS has so much improved this last years :D
<FromGitter> <j8r> hum, that's already in ecma 262
<FromGitter> <j8r> so, simpler as I thought.
<FromGitter> <j8r> one sensitive thing is to estimate the number of bytes the slice must take, otherwise it raises at runtime with an index error
<FromGitter> <Blacksmoke16> nice one!
<FromGitter> <j8r> On thing to note is the precision is not really good, but does not matter for a game
<FromGitter> <j8r> and the float become a JS Float, with a length of 64bit
<FromGitter> <j8r> How can I append bytes with https://crystal-lang.org/api/master/IO/ByteFormat.html , instead of overwritting?
<FromGitter> <j8r> I would like to have like `uninitialized UInt8[5]`: first byte is a UInt8, and the 4 others a Float32.
<FromGitter> <phykos> while bootstapping the compiler, I got this: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5eff5957c223cc536a506f80]
<FromGitter> <phykos> how to fix this?
<FromGitter> <j8r> enable_global_isel... interesting
<FromGitter> <j8r> are you on aarch64?
<FromGitter> <j8r> then, try updated master
<FromGitter> <phykos> yep
<FromGitter> <phykos> did
<FromGitter> <j8r> don't know then :/
<FromGitter> <j8r> have you `make clean` before?
<FromGitter> <j8r> maybe you tried before the fix, and the old `.o` is stil lthere
<FromGitter> <j8r> Got this: https://carc.in/#/r/9dg5
<FromGitter> <phykos> k
<FromGitter> <phykos> fuck I deleted the compiler
<FromGitter> <phykos> just oof
<FromGitter> <Blacksmoke16> @phykos what llvm version are you on?
<FromGitter> <phykos> 10
<FromGitter> <wyhaines> @j8r A Slice is just a bucket of bytes, and you can slice it up yourself into smaller buckets. ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ You can use each of those smaller slices of your main buffer with ByteFormat, and you will get a 5 byte buffer with the first being UInt8, and then next 4 being your Float32. [https://gitter.im/crystal-lang/crystal?at=5eff6648d65a3b0292c746c5]
<FromGitter> <j8r> right
<FromGitter> <j8r> Not sure why they use uninitialized StaticArray instead of slice: https://crystal-lang.org/api/master/IO/ByteFormat.html#encode-to-bytes
<FromGitter> <j8r> may avoid a maloc
<FromGitter> <j8r> I confirm that. However, it is potentially dangerous
<FromGitter> <j8r> JS suck a bit: we cannot use `byteOffset` not multiple of 4... I found a workaround though
<jhass> phykos: sounds like outdated llvm_ext.o
<FromGitter> <j8r> there is something good in JS but not in Crystal, the byte length of a typedArray
<jhass> Slice#bytesize
<FromGitter> <j8r> No
<FromGitter> <j8r> I mean, Float32 take 4 bytes
<FromGitter> <j8r> needed by IO::ByteFormat
<jhass> 😕
<FromGitter> <j8r> > The TypedArray.BYTES_PER_ELEMENT property represents the size in bytes of each element in an typed array.
<FromGitter> <j8r> I think it can be a good addition to the language
<FromGitter> <j8r> I have a logic to parse bytes by only giving the bytes offset
<jhass> sizeof?
<FromGitter> <j8r> it does that :o
<jhass> >> sizeof(Float32)
<DeBot> jhass: # => 4 - https://carc.in/#/r/9dgz
<FromGitter> <j8r> seems to, thanks
<FromGitter> <j8r> I submit a PR to add that to https://crystal-lang.org/api/master/IO/ByteFormat.html#encode-to-bytes, it is very valuable
<jhass> well
<jhass> you would only ever use it for implementing to_io for a new type
<jhass> that cannot be just composed from calling to_io on other types
<jhass> doesn't seem super important
<FromGitter> <j8r> I need it to initialized a slice
<FromGitter> <j8r> to send over a socket, then read it in JS to a Float
<FromGitter> <j8r> anyone using `IO::ByteFormat` will probably need `sizeof()`
<jhass> nobody should use IO::ByteFormat directly outside the scenario I described above
<FromGitter> <j8r> why?
<FromGitter> <j8r> Then, how can I send a Float32 with websocket?
<jhass> Just put it into a slice?
<FromGitter> <j8r> yes, how?
<FromGitter> <j8r> I'm all for if there is another way than `IO::ByteFormat` :)
<jhass> ah, we still didn't solve the slice literals :/
<jhass> hrm, I expected a Slice#to_io at least :/
<FromGitter> <j8r> There is definitely room for improvement around `IO::ByteFormat`
<FromGitter> <j8r> BTW I can't use IOs, because I use `WebSocket.send(Bytes)`
<jhass> wait, Websocket doesn't expose IO?
<jhass> who designed that :/
<jhass> well I guess you could .stream
<jhass> https://carc.in/#/r/9dhk something like this I guess, not pretty but better than using IO::ByteFormat directly
<FromGitter> <j8r> the stream has to be closed to send the stuff?
<FromGitter> <j8r> I try
<FromGitter> <j8r> I am afraid this will add overhead :/
postmodern has joined #crystal-lang
<FromGitter> <j8r> also, to optimize this, I need anyway to know the buffer size
<FromGitter> <j8r> Thanks btw, I didn't know it was possible to do this way :)
<jhass> the stream is just a thin IO wrapper, it writes the header and then forwards any calls to the underlying socket
<jhass> the socket.close in the example is just to flush the stuff before the hexdump
<FromGitter> <j8r> ha ok
<jhass> not sure what you're talking about with optimize this and buffer size
<FromGitter> <j8r> I will have to use macros to know the size of the buffer, `sizeof()` is not very dynamic-friendly
<jhass> it's buffered IO anyhow
<jhass> socket is buffered IO
<jhass> YAGNI
<jhass> just call .write_bytes many times
<jhass> no need for your own buffer and thus sizeof
<FromGitter> <j8r> not really
<FromGitter> <j8r> Before I only have 5 bytes sent, now I have a blob of 1019 bytes
<FromGitter> <j8r> I have to set correctly `frame_size` of stream
<FromGitter> <j8r> Not sure if this is what I want, this not really streaming
<jhass> are you sure you need to match the frame size exactly? Are you sure you need to send only a single frame?
<FromGitter> <j8r> I need to send a lot
<FromGitter> <j8r> of rather small packets (entities position in a game)
<jhass> so pick a smaller frame size slightly larger than your theoretical maxium payload?
<FromGitter> <j8r> this method does not behave as we think
<jhass> I'd test first whether the simple stupid thing works before spending so much time and energy on a complex solution
<FromGitter> <j8r> yeah
<FromGitter> <j8r> but that's kind of obvious here, I cannot send 1024 packet 100 times per second :/
<jhass> so see above
<FromGitter> <j8r> yeah, that's an option
<FromGitter> <j8r> the thing is there will have also bigger packets, for chunk data (16*16 tiles).
<FromGitter> <j8r> Anyway, I can compare both - this will be the best
<FromGitter> <j8r> I save both approach somewhere
go|dfish has quit [Ping timeout: 256 seconds]
<FromGitter> <j8r> ha hum look: https://carc.in/#/r/9dhs
<FromGitter> <j8r> more obvious here: https://carc.in/#/r/9dhv
<FromGitter> <j8r> the data is overridden
go|dfish has joined #crystal-lang
<sorcus> Hi :-)
<jhass> You mean how to implement MyConverter?
<jhass> or how to read a field twice?
<FromGitter> <Blacksmoke16> prob would be easier to do like
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/9dio
<sorcus> jhass: Yeah, how to read twice.
<jhass> yeah, I'd suggest what Blacksmoke16 says too
<sorcus> Blacksmoke16: Hmm... Looks good.
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <Blacksmoke16> might even be better to abstract the setting to a private method that you could call in `after_initialize` and within `foo_raw=`
<sorcus> Blacksmoke16: Sorry, i don't fully understand. What does you mean? X-)
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/9dip
<FromGitter> <Blacksmoke16> assuming the object is actually mutable like that
<sorcus> Blacksmoke16: Ah, now i understand. Thank you for explanation :-)
<FromGitter> <Blacksmoke16> 👍
<sorcus> Blacksmoke16: What does `getter!` mean?
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/Object.html#getter!(*names)-macro
<sorcus> Blacksmoke16: Ah, exactly. :-D
<FromGitter> <s0kil> Anyone else having an issue with Kemal WS server? ⏎ Client responds with ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5effac56613d3b3394256c31]