ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | 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
lanodan has quit [Quit: WeeChat 3.5]
lanodan has joined #crystal-lang
ur5us has quit [Ping timeout: 255 seconds]
gordea has quit [Quit: gordea]
Sankalp has quit [Ping timeout: 260 seconds]
Sankalp has joined #crystal-lang
ur5us has joined #crystal-lang
ur5us has quit [Ping timeout: 260 seconds]
alexherbo2 has joined #crystal-lang
jmdaemon has quit [Ping timeout: 252 seconds]
<FromGitter> <azurelmao> structs are supposed to be faster to allocate than classes since they are on the stack, right?
<FromGitter> <azurelmao> then what happens when a class has a struct instance var
<FromGitter> <azurelmao> does the struct get allocated on the heap, since it's in a class?
<FromGitter> <oprypin:matrix.org> @azurelmao: https://pryp.in/blog/24/abandoned-post-modern-memory-management-what-are-structs-in-crystal.html ⏎ mostly the last part after the horizontal line 😬
<FromGitter> <azurelmao> Okay, so it doesn't matter whether I have a struct or class if it's in a class
<FromGitter> <azurelmao> I'm asking this because I encountered a very weird behavior recently
<FromGitter> <Blacksmoke16> Oh?
<FromGitter> <azurelmao> I have a World class and a Chunk class akin to minecraft's
<FromGitter> <azurelmao> the Chunk just has a static array and some methods to work on it
<FromGitter> <azurelmao> while the World has an array of Chunks
<FromGitter> <azurelmao> So, I remembered that structs are supposed to be better for performance, and I changed the Chunk from a class to a struct
<FromGitter> <azurelmao> and when I ran my program it just kept running indefinitely
<FromGitter> <azurelmao> idk if it was copying lots of memory which made it slower or what
<FromGitter> <Blacksmoke16> like running until you ctrl+c it?
<FromGitter> <azurelmao> the World class has a method which initializes it like so
<FromGitter> <azurelmao> ```4.times do |x| ⏎ 4.times do |z| ⏎ @chunks << Chunk.new ⏎ end ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=63875cfa2cb65702404f0277]
<FromGitter> <Blacksmoke16> and it works just fine if you dont change anything else and only make `Chunk` a class again?
<FromGitter> <azurelmao> yes
<FromGitter> <azurelmao> https://carc.in/#/r/e5uq
<FromGitter> <azurelmao> "Execution timed out"
<FromGitter> <azurelmao> change Chunk to a class and it will work fine
<FromGitter> <Blacksmoke16> pretty sure this is more so related to using a static array with a size of 32k+
<FromGitter> <Blacksmoke16> change it to an array of Int32 and `@blocks.insert i, 1`
<FromGitter> <Blacksmoke16> changing it to a class must cause LLVM to do something diff that is more performant :shrug:
Flipez has quit [Read error: Connection reset by peer]
Flipez has joined #crystal-lang
alexherbo2 has quit [Remote host closed the connection]
alexherbo2 has joined #crystal-lang
Flipez has quit [Changing host]
Flipez has joined #crystal-lang
yxhuvud has quit [Read error: Connection reset by peer]
yxhuvud has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 260 seconds]
alexherbo2 has joined #crystal-lang
alexherbo2 has quit [Remote host closed the connection]
alexherbo2 has joined #crystal-lang
<FromGitter> <djberg96> How do I get at some of the underlying stat info from `File.info`? Specifically I want to get at the blksize.
<FromGitter> <Blacksmoke16> isnt the block size a file system thing and not a specific file?
<FromGitter> <djberg96> I can see the `@st_blksize` inside what looks like a `LibC::Stat`
<FromGitter> <djberg96> but am not sure how to get at it
<FromGitter> <Blacksmoke16> oh
<FromGitter> <Blacksmoke16> in that case looks like its not exposed in the public api of `File::Info` so would have to monkey patch in a getter for it i guess
<FromGitter> <djberg96> how do I get at it?
<FromGitter> <Blacksmoke16> try like
<FromGitter> <Blacksmoke16> ```struct File::Info ⏎ def block_size ⏎ @stat.st_blksize ⏎ end ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=63877d05a34b51121154e791]
<FromGitter> <djberg96> thanks!
<FromGitter> <djberg96> time to submit a PR
<FromGitter> <Blacksmoke16> main catch is its not really portable
<FromGitter> <Blacksmoke16> so could bump that if you have a use case, but im not sure if a PR would be accepted
alexherbo2 has quit [Remote host closed the connection]
alexherbo2 has joined #crystal-lang
<FromGitter> <moe:busyloop.net> hmm. i'm starting to wonder if braces should be mandatory in conditionals 🤔
<FromGitter> <moe:busyloop.net> `if foo.includes? "bar" || foo.includes? "batz"` is such a naughty trap
<FromGitter> <Blacksmoke16> `if foo.in? {"bar", "batz}` 😉
<FromGitter> <Blacksmoke16> er `{"bar", "batz"}.in? foo`
<FromGitter> <Blacksmoke16> i deff ran into that a few times. wonder if its something ameba could catch?
<FromGitter> <moe:busyloop.net> yup, and then the next dev comes around and adds a `&&` or `||` at the end
<FromGitter> <moe:busyloop.net> ameba should def flag it (dunno if it already does, don't have it on this codebase)
<FromGitter> <moe:busyloop.net> but i feel like the compiler should probably, too. ⏎ at least when it says there's a `&&` or `||` involved.
<FromGitter> <Blacksmoke16> ```code paste, see link``` ⏎ ⏎ nope [https://gitter.im/crystal-lang/crystal?at=6387823a25ca105c88dda781]
<FromGitter> <moe:busyloop.net> nasty!
<FromGitter> <moe:busyloop.net> i even had tests on it but it slipped through those, too
<FromGitter> <Blacksmoke16> oof, id create an ameba issue for it if there isnt already one
<FromGitter> <Blacksmoke16> deff get a 👍 from me
<FromGitter> <moe:busyloop.net> yea nah, that's one for the compiler
<FromGitter> <moe:busyloop.net> "this most likely doesn't mean what you think it means - thank me later, kthxbye"
<FromGitter> <Blacksmoke16> most likely goes into ameba territory imo. compiler doesnt really do any of that kind of stuff atm
<FromGitter> <Blacksmoke16> given its valid syntax
<FromGitter> <moe:busyloop.net> it should, i think i've seen such errors (or at least warnings) in other languages
<FromGitter> <moe:busyloop.net> and most people probably don't use ameba
<FromGitter> <Blacksmoke16> somewhat related: https://github.com/crystal-lang/crystal/issues/12365
<FromGitter> <moe:busyloop.net> hm yup
<FromGitter> <Blacksmoke16> ameba is more likely to be implemented sooner as well. if the compiler ends up getting user warnings like this eventually great, but better to have something at least
<FromGitter> <moe:busyloop.net> true
<FromGitter> <moe:busyloop.net> i'll try to remember to write a ticket later (gotta push my fix first 😬)
<FromGitter> <Blacksmoke16> was also talk of setting up ameba CI on crystal repo, so would help that too
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <moe:busyloop.net> yea, i wouldn't be surprised to see that bug on many repos once ameba starts flagging it
<FromGitter> <Blacksmoke16> 🎉
alexherbo2 has left #crystal-lang [#crystal-lang]
jmdaemon has joined #crystal-lang
jhass[m] has quit [Quit: Bridge terminating on SIGTERM]
jhass[m] has joined #crystal-lang
walez has joined #crystal-lang
<FromGitter> <azurelmao> > change it to an array of Int32 and `@blocks.insert i, 1` ⏎ ⏎ Can I make the capacity of the array constant? So as not to accidentally increase the size somehow
<FromGitter> <azurelmao> @Blacksmoke16
<FromGitter> <Blacksmoke16> you can give it an initial size, but that doesnt prevent it from getting bigger
<FromGitter> <azurelmao> yhm I see
<riza> if you plan ahead, you can!
<FromGitter> <azurelmao> @Blacksmoke16 hey, remember how I asked you some time ago how to have a class var of the instance of that class?
<FromGitter> <azurelmao> it was something like {new}
<FromGitter> <azurelmao> what was it exactly?
<FromGitter> <Blacksmoke16> `class_getter instance : self { new }`?
<FromGitter> <azurelmao> ah yes that
<FromGitter> <azurelmao> thank you
taupiqueur has quit [Quit: WeeChat 3.7.1]
walez has quit [Quit: Leaving]
alexherbo2 has joined #crystal-lang
<FromGitter> <azurelmao> It seems to work, yet not at the same time :/ ⏎ https://carc.in/#/r/e5vz
taupiqueur has joined #crystal-lang
<FromGitter> <Blacksmoke16> you're never `+= 1` the instance one. only the one you explicitly new up via `Foo.new`
<FromGitter> <Blacksmoke16> `Foo.instance` would return the same instance. if you want to prevent someone from doing `Foo.new` would have to also define a private initializer
alexherbo2 has quit [Remote host closed the connection]
taupiqueur has quit [Quit: WeeChat 3.7.1]
renich has joined #crystal-lang
_ht has joined #crystal-lang
alexherbo2 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 260 seconds]
ur5us has joined #crystal-lang
<FromGitter> <azurelmao> Ohh
<FromGitter> <azurelmao> I thought what the {new} thing did was set it to an instance whenver .new was called
<FromGitter> <Blacksmoke16> no, its the same as like `class_getter instance : self = new` but lazy. i.e. doesnt actually initialize the instance until you call `.instnace`
walez has joined #crystal-lang
walez has quit [Client Quit]
_ht has quit [Quit: _ht]
oprypin_ has quit [Quit: Bye]
oprypin has joined #crystal-lang