ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.31.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
DeBot has quit [Quit: Crystal IRC]
jhass has quit [Quit: Bye]
asterite has quit [Quit: Bye]
DeBot has joined #crystal-lang
asterite has joined #crystal-lang
jhass has joined #crystal-lang
gangstacat has quit [Quit: Ĝis!]
_whitelogger has joined #crystal-lang
absolutejam2 has joined #crystal-lang
absolutejam2 has quit [Ping timeout: 246 seconds]
gangstacat has joined #crystal-lang
_whitelogger has joined #crystal-lang
duane has joined #crystal-lang
<FromGitter> <Daniel-Worrall> libz missing from https://github.com/crystal-lang/crystal/wiki/All-required-libraries ?
<FromGitter> <Daniel-Worrall> nvm, it's on the crystal install page
<FromGitter> <Blacksmoke16> think you only need it for the playground
<FromGitter> <Daniel-Worrall> eh, you'd think, but no
<FromGitter> <Daniel-Worrall> it's complaining I need it for running a websocket
<FromGitter> <Blacksmoke16> playground uses websockets so maybe thats it
<FromGitter> <Daniel-Worrall> oh, and I needed pkg-config :thinking:
<FromGitter> <Daniel-Worrall> new installs are weird when you don't pull from the package manager
<FromGitter> <ImAHopelessDev_gitlab> damnit just got hooked on the world series, back to coding!!
<FromGitter> <ImAHopelessDev_gitlab> there goes 2 hours, fack
duane has quit [Ping timeout: 265 seconds]
hightower3 has quit [Ping timeout: 264 seconds]
alex``` has quit [Ping timeout: 268 seconds]
teardown has joined #crystal-lang
<FromGitter> <christopherzimmerman> @ImAHopelessDev_gitlab what a disappointing game
<FromGitter> <Daniel-Worrall> Nested JSON is fked which slows down the progress on one of my apps :/
<FromGitter> <Daniel-Worrall> also, accidental Ctrl+Enter's suck. Submitted the issue without even formatting it properly :^)
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 240 seconds]
<FromGitter> <watzon> Really wishing Crystal had an async/await type situation
<FromGitter> <Daniel-Worrall> There are shards looking to assist in that
<FromGitter> <watzon> Yeah which is nice, but there's nothing like having it as an actual language feature
teardown has quit [Ping timeout: 265 seconds]
teardown has joined #crystal-lang
absolutejam2 has joined #crystal-lang
DTZUZO has quit [Ping timeout: 265 seconds]
ht_ has joined #crystal-lang
absolutejam2 has quit [Ping timeout: 264 seconds]
DTZUZU has quit [Ping timeout: 240 seconds]
ht_ has quit [Remote host closed the connection]
DTZUZU has joined #crystal-lang
absolutejam2 has joined #crystal-lang
dwdv has joined #crystal-lang
<FromGitter> <gdotdesign> I'm working on Crystal and Ruby projects simultaneously and right now on the Ruby one and was editing a file and I was thinking "Why is this nor formatting automatically? Is there an error somewhere?" πŸ˜‚
<FromGitter> <bararchy> I got you ^
<FromGitter> <bararchy> hahahah
<FromGitter> <bararchy> I'm also used to the formatter telling me if I broke something XD
<FromGitter> <gdotdesign> :D right?
dwdv_ has joined #crystal-lang
dwdv has quit [Ping timeout: 240 seconds]
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 265 seconds]
absolutejam2 has quit [Ping timeout: 268 seconds]
<FromGitter> <ImAHopelessDev_gitlab> @watzon similar to JS's await? Where you can basically call them one after another and they perform asynchronously?
<FromGitter> <ImAHopelessDev_gitlab> without having to do method chaining/callback hell?
<FromGitter> <watzon> Yeah JS, Rust, Python, Dart, and plenty of other languages have something like that built in
<FromGitter> <ImAHopelessDev_gitlab> there was a twitter thread discussing this on asterite's page. i remember seeing something about it a few weeks ago. can't find it atm though
FromGitter has quit [Read error: Connection reset by peer]
FromGitter has joined #crystal-lang
<FromGitter> <asterite> for those wanting async/await, a must read:
DTZUZO has joined #crystal-lang
FromGitter has quit [Read error: Connection reset by peer]
FromGitter has joined #crystal-lang
<FromGitter> <ilanpillemer> There is also as good talk by the Kotlin guy on this when he shows Kotlin's co routines.
alex``` has joined #crystal-lang
<FromGitter> <ilanpillemer> And Rob Pike's examples of patterns using channels and co routines also is pretty good, especially as so many of his examples include gophers burnjnf
<FromGitter> <ilanpillemer> Project Loom is also interesting
<FromGitter> <ilanpillemer> But the Kotlin's guy talk is great to did deep into the horrors of async await.
<FromGitter> <ImAHopelessDev_gitlab> i have no idea what's going on, but i'd like to watch gophers burn some c++ manuals
<FromGitter> <yxhuvud> Personally I'd much rather see a development towards structured concurrency than towards async/await. It perhaps forces slightly more thought on the user, but it also gives a lot more control. And the problem area in itself has nasty enough issues that perhaps that kind of thought is more helpful than not.
<FromGitter> <ImAHopelessDev_gitlab> i'd also like to see some JS books being burned as well. however, I don't think I'd be able to watch it. I use JS extensively for the front-end. I like JS, but the developer should always try to ascend.
<FromGitter> <ilanpillemer> Thougu Kotlin also has the colour problem.
<blassin> what's the "best" online index for browsing shards?
<FromGitter> <bararchy> shards.info
<FromGitter> <bararchy> http://shards.info/
<FromGitter> <bararchy> I like it
<FromGitter> <bararchy> @asterite great read! thanks for that
absolutejam2 has joined #crystal-lang
duane has joined #crystal-lang
alex``` has quit [Quit: The Lounge - https://thelounge.chat]
absolutejam2 has quit [Ping timeout: 264 seconds]
fifr has quit [Ping timeout: 276 seconds]
fifr has joined #crystal-lang
absolutejam2 has joined #crystal-lang
absolutejam2 has quit [Ping timeout: 240 seconds]
<FromGitter> <Blacksmoke16> https://github.com/veelenga/awesome-crystal is also good. Will be a pruning coming up to remove old/no longer maintained shards
<FromGitter> <Blacksmoke16> (so if you have a shard in there make sure its not on the naughty list) https://github.com/veelenga/awesome-crystal/issues/412#issuecomment-546724163
<FromGitter> <christopherzimmerman> That will be great. I kept looking through that but it seemed like almost everything was deprecated.
<FromGitter> <Blacksmoke16> yea, are quite a lot 😬
<FromGitter> <ImAHopelessDev_gitlab> http://shards.info/#recently
<FromGitter> <ImAHopelessDev_gitlab> why is there an Elm library there
<FromGitter> <tenebrousedge> Elm is the new Crystal!
<FromGitter> <vlazar> because there is a backend in Crystal https://github.com/JackFly26/Kahoot-Clone/blob/master/backend/shard.yml
<FromGitter> <vlazar> shards.info and others does not list shards exactly (like libraries you can use)
<FromGitter> <vlazar> it lists all repos with Crystal code I think
<FromGitter> <ImAHopelessDev_gitlab> i see, yah
<FromGitter> <vlazar> there is this list https://crystal.libhunt.com/categories which is more lib oriented
<FromGitter> <ImAHopelessDev_gitlab> i just "written in Elm" and was like O_o
<FromGitter> <bararchy> What's a better way to do this? -> ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5db6f243f26ea4729d0e9d9a]
<FromGitter> <Blacksmoke16> could do it at compile time
<FromGitter> <bararchy> how?
<FromGitter> <Blacksmoke16> something like
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5db6f362a03ae1584f2474a6]
<FromGitter> <bararchy> good idea :)
<FromGitter> <Blacksmoke16> but in this case wouldnt `0` work in . both cases?
<FromGitter> <tenebrousedge> I'd just do a hash block
<FromGitter> <tenebrousedge> well, if possible
duane has quit [Ping timeout: 240 seconds]
HumanG33k has joined #crystal-lang
duane has joined #crystal-lang
<FromGitter> <ImAHopelessDev_gitlab> good morning
<FromGitter> <ImAHopelessDev_gitlab> a phenomena is happening but i don't know what it's called
<FromGitter> <bararchy> Winter
<FromGitter> <bararchy> it's called Winter
<FromGitter> <ImAHopelessDev_gitlab> hehe
<FromGitter> <ImAHopelessDev_gitlab> for example, last few days i've been coding non-stop. then, today, when i take a look back at my code, i don't really understand what it's doing i have to "refresh" my brain after looking at it. but i just coded it like less than 48 hours ago...
<FromGitter> <ImAHopelessDev_gitlab> why is this happening and what is it called. most importantly, is it bad?
<FromGitter> <tenebrousedge> it's called, "working on a large program"
<FromGitter> <bararchy> it's normal
<FromGitter> <bararchy> it's called "context wsitching"
<FromGitter> <ImAHopelessDev_gitlab> @tenebrousedge you can relate, right?
<FromGitter> <bararchy> it's hard to keep "in memory" all the things you're doing for long, so you need to "reboot" the ata
<erdnaxeli> the blog post posted earlier today about async/await was really interesting, thanks asterite
<erdnaxeli> (the conclusion is: you don't want async/await :p)
<FromGitter> <ImAHopelessDev_gitlab> i just feel like something is wrong, because i code away and away, then move on to the next thing. then come back and my brain is like: O_O WTF
<FromGitter> <tenebrousedge> there's a limit to how much code you can keep in memory. Two days is a little short unless you're working with lots of different parts of a large codebase
<FromGitter> <tenebrousedge> but there's a related issue which you may have encountered, where you have a bug, and at the moment you get done solving it you no longer understand how it works
<FromGitter> <ImAHopelessDev_gitlab> so basically, my brain has some stack memory that overflows every few days?
<FromGitter> <tenebrousedge> "Yay, all the tests pass! Wait, what does this do, again?"
<FromGitter> <ImAHopelessDev_gitlab> ROFL!!!
<FromGitter> <ImAHopelessDev_gitlab> YES
<FromGitter> <tenebrousedge> the really embarrassing one is where you're working on a team, and you find some really stupid code, and you start swearing under your breath. "What moron wrote this?" `git blame` --> you.
<FromGitter> <ImAHopelessDev_gitlab> @tenebrousedge @bararchy well, i feel a lot better now, knowing at least it's a thing and other devs experience/ know about it. appreciate the support, kudos πŸ‘
duane has quit [Ping timeout: 240 seconds]
duane has joined #crystal-lang
<FromGitter> <gdotdesign> looking back at code that I wrote 2 or even 1 year ago is like "WTF is this?" πŸ˜‚
<FromGitter> <bararchy> Sometimes even a month ago is like "pfffff look what I learned now past me!"
absolutejam2 has joined #crystal-lang
<FromGitter> <repromancer_gitlab> @ImAHopelessDev_gitlab Even though I really don't enjoy his sense of humor or presentation style, I think Robert C. Martin's recommendations in Clean Code (the book or video course) go a long way toward avoiding those sort of code clarity problems.
<FromGitter> <naqvis> @Blacksmoke16 Thanks for putting together awesome-crystal naughty list, quick question on *CI but last build was more than 30 days ago*, build is triggered on commit, what if there is no change in code-base? so do you still believe such metric worth evaluating?
<FromGitter> <repromancer_gitlab> It's mostly a bunch of advice on naming and organizing things in a way that is "self-documenting", and I don't agree with everything he says, but I don't know a better book in that vein off the top of my head.
<FromGitter> <repromancer_gitlab> (I haven't read it yet, but I imagine Scott Wlaschin's free "F Sharp for Fun and Profit" blog/book covers a lot of the same ground)
<FromGitter> <absolutejam_gitlab> > i just feel like something is wrong, because i code away and away, then move on to the next thing. then go back to look at older code and my brain is like: O_o WTF ⏎ ⏎ It could be that you're hacking away and not thinking about the bigger picture too
<FromGitter> <absolutejam_gitlab> it's easy to go down a rabbit hole without actually planning out how your components will interact, what your API should look like, etc.
<FromGitter> <tenebrousedge> experience is what teaches you to recognize a mistake when you make it again
<FromGitter> <asterite> T.zero
ht__ has joined #crystal-lang
<FromGitter> <tenebrousedge> ?
<FromGitter> <asterite> for what bararchy needed before, 0 for Int32, 0.0 for Float64
<FromGitter> <tenebrousedge> example?
<FromGitter> <tenebrousedge> I saw that, yes
<FromGitter> <asterite> it would be great to have Slack for Crystal
<FromGitter> <bararchy> oh wow T.zero
<FromGitter> <asterite> imagine threaded conversations...
<FromGitter> <asterite> I don't know why most are against Slack
<FromGitter> <bararchy> because it needs invite
<FromGitter> <bararchy> and it means it's a closed ENV
<FromGitter> <tenebrousedge> ^
<FromGitter> <asterite> with a url you can autoinvite yourself
<FromGitter> <asterite> it's done in every Slack out there
<FromGitter> <asterite> I was able to join the Elm slack no problem, no human internvention
<FromGitter> <asterite> same for Crystal jp slack
<FromGitter> <naqvis> totally with you on slack usage, slack is becoming the norm, so believe moving to slack will be beneficial
<FromGitter> <naqvis> do we have slack chanel @asterite ?
<FromGitter> <alex-lairan> Maybe matermost ?
<FromGitter> <alex-lairan> Open System / Slack like
<FromGitter> <asterite> we don't have a slack channel :(
<FromGitter> <asterite> I'm not against irc or gitter
<FromGitter> <asterite> but threads, reactions, sharing inline code and much more is really lacking in irc
<FromGitter> <naqvis> true, but functionality offered by slack is superior
<FromGitter> <asterite> plus you can have channels in slack for different topics
<FromGitter> <naqvis> yeah true
<FromGitter> <naqvis> and threads for clean communication
<FromGitter> <alex-lairan> Dry-RB team moved to Zulip, I don't like it, but maybe it cool be a good alternative
<FromGitter> <ilanpillemer> Pony uses zulip. Go uses slack
<FromGitter> <j8r> Slack is bad, how to waste money
<FromGitter> <j8r> at least, Mattermost
<FromGitter> <j8r> cheaper and Open Source
<FromGitter> <j8r> But I prefer to have Matrix protocol compatibility
<FromGitter> <ilanpillemer> Slack is free if you don't care about infinite history.
<Yxhuvud> I'm against getting more slacks due to slack using so much resources :/
<Yxhuvud> interface is nice though..
<FromGitter> <j8r> Better to use an OSS product for an OSS project, IMO
<FromGitter> <Blacksmoke16> @naqvis the repo has a requirement that the shard has periodic builds
<FromGitter> <tenebrousedge> how easy is it to schedule a monthly build with GH?
<FromGitter> <Blacksmoke16> GH actions?
<FromGitter> <ilanpillemer> `at`?
<FromGitter> <tenebrousedge> yar
<FromGitter> <Blacksmoke16> im thinking once all those are removed/fixed that requirement would change to like `shard x hasn't passed in a month`
<FromGitter> <ilanpillemer> `cron`?
absolutejam2 has quit [Ping timeout: 268 seconds]
<FromGitter> <Blacksmoke16> its built into actions
<FromGitter> <tenebrousedge> `cron` will never die
<FromGitter> <Blacksmoke16> travis also supports daily/weekly/monthly builds so it shouldnt be a big issue
<FromGitter> <ilanpillemer> google calendar?
<FromGitter> <Blacksmoke16> should be automated period builds πŸ˜‰
duane has quit [Ping timeout: 268 seconds]
<FromGitter> <repromancer_gitlab> @asterite I hadn't heard of it till I checked out dry-rb, but I agree with their switch to Zulip for all the reasons listed here (https://zulipchat.com/why-zulip/) and here (https://zulipchat.com/for/open-source/)
<FromGitter> <repromancer_gitlab> Big pluses include actually-well-thought-out threading, full search history (standard plan is free for OSS projects), and actual Markdown support (vs. Slack's pseudo-markdown)
<FromGitter> <repromancer_gitlab> not to mention two-way Matrix support
<FromGitter> <asterite> nice
<FromGitter> <asterite> If someone wants to go for it, please open a discussion in the forums (I can πŸ‘ but I'm not in charge of infrastructure, though I'd love a more structured way to chat in real time related to Crystal)
<FromGitter> <kinxer> @repromancer_gitlab This looks fantastic.
<FromGitter> <repromancer_gitlab> @kinxer right?
<FromGitter> <kinxer> @ImAHopelessDev_gitlab What are the black lines?
<FromGitter> <ImAHopelessDev_gitlab> Potential ideas (abstract), then, once created they are linked with green lines
<FromGitter> <ImAHopelessDev_gitlab> If that makes sense lol
<FromGitter> <kinxer> Gotcha.
<FromGitter> <ImAHopelessDev_gitlab> I want to see others and how they visualize
<FromGitter> <ohenepee> Hello... Can someone pls help me with this... Newbie here
<FromGitter> <ohenepee> ``````
<FromGitter> <ohenepee> Oops.. What's with using gitter on mobile?
<FromGitter> <Blacksmoke16> its not great
<FromGitter> <kinxer> @ImAHopelessDev_gitlab That's probably pretty close to how I start. I'd have to think longer about how that (hopefully and usually) turns into something a little more neatly structured.
<FromGitter> <kinxer> @Blacksmoke16 Does carc.in work fine on mobile?
<FromGitter> <ImAHopelessDev_gitlab> @kinxer Is that when OOP comes in, or can it be done without it?
<FromGitter> <Blacksmoke16> it should
<FromGitter> <ohenepee> Say I have an array of Int32, and I'm iterating over it, how do I check if a number exists in it?
<FromGitter> <Blacksmoke16> `arr.includes? 17`?
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/0.31.1/Enumerable.html#includes?(obj)-instance-method
<FromGitter> <kinxer> @ohenepee If you're trying to show code that you have (and it's not too long), you could probably use https://carc.in/#/cr or https://play.crystal-lang.org/#/cr. (Though I don't think this question necessarily requires that.)
<FromGitter> <ImAHopelessDev_gitlab> @kinxer what's interesting is, I love objects. I view everything as an object. Same when I was coding in js (with nodejs)
<FromGitter> <ohenepee> @Blacksmoke16 yh I'm using that, but adding `&& array.index(item) < 5` gives me an undefined method error
<FromGitter> <ohenepee> The error is for fh
<FromGitter> <ohenepee> The
<FromGitter> <ohenepee> The error is for the < sign
<FromGitter> <kinxer> @ImAHopelessDev_gitlab I think there are, rarely, times when you don't need any classes (or structs or whatever), but generally my initial, messy though process does include objects. I think that may be a result of my education.
<FromGitter> <ImAHopelessDev_gitlab> I'm gonna make a topic about this, I think it's very interesting and want to see other developers` opinions/visualizations
<FromGitter> <kinxer> They're also not necessarily the *right* objects yet.
<FromGitter> <tenebrousedge> `array.first(5).includes? 17`
<FromGitter> <ohenepee> @tenebrousedge Won't that be a bottleneck for very large arrays?
<FromGitter> <Blacksmoke16> @ohenepee what are you trying to do?
<FromGitter> <Blacksmoke16> the error you're probably getting is `#index` will return `nil` if the item doesn't exist in the array
<FromGitter> <ohenepee> Yes true @Blacksmoke16
<FromGitter> <Blacksmoke16> so you would have to make sure the item exists, then see if its less than 5
<FromGitter> <ohenepee> @Blacksmoke16 Exactly
<FromGitter> <Blacksmoke16> like `&& (idx = array.index(item)) && idx < 5`
<FromGitter> <repromancer_gitlab> @ImAHopelessDev_gitlab @kinxer My personal projects usually go like this: I sketch out my program with high-level dummy classes/methods until I encounter the need for a bikeshed (http://bikeshed.com/). I then google around for pre-fabricated sheds, and decide they are too bloated for my needs. I then contemplate the Platonic ideal of the minimum necessary shed, and this becomes its own project. Then,
<FromGitter> ... it's Monday.
<FromGitter> <tenebrousedge> no
<FromGitter> <Blacksmoke16> but what is the higher level objective of what you're trying to do? as there might be a better way to go about it
<FromGitter> <tenebrousedge> do not take more than `n` elements of the array if you only care about the first `n` elements
<FromGitter> <tenebrousedge> `index` will scan the whole thing
<FromGitter> <Blacksmoke16> index stops when it finds the value
<FromGitter> <tenebrousedge> unless it doesn't
<FromGitter> <Blacksmoke16> right
<FromGitter> <ImAHopelessDev_gitlab> @repromancer_gitlab interesting haha
<FromGitter> <ohenepee> @Blacksmoke16 I am essentially trying to do exactly what you've described above, nothing different from that
<FromGitter> <Blacksmoke16> doing what @tenebrousedge suggested would be cleaner and prob a bit more performant
<FromGitter> <tenebrousedge> `array.first(n).index(n)` if you need the index
<FromGitter> <Blacksmoke16> @ohenepee right, but whats the reasoning for making sure a value isnt in the first 5 items of an array?
<FromGitter> <ohenepee> Bcoz I don't want it to be beyond that index... There are 10 items in each array
<FromGitter> <Blacksmoke16> like a static 10 items? or are the arrays built from dynamic values?
<FromGitter> <ohenepee> Sorry, I mean in *the* array, not in "each" array
<FromGitter> <ohenepee> Yeah, static 10 items
<FromGitter> <Blacksmoke16> and what does each item represent?
<FromGitter> <Blacksmoke16> if the values are static, a tuple might be better
<FromGitter> <ImAHopelessDev_gitlab> i love me some tuples
<FromGitter> <ohenepee> @Blacksmoke16 How do I check the index of the number I'm looking for in a tuple?
<FromGitter> <ohenepee> Cos I don't see index in the tuple doc
<FromGitter> <Blacksmoke16> tuple includes `Indexable` which defines it
<FromGitter> <Blacksmoke16> which is how it gets defined on array as well
<FromGitter> <ohenepee> Yep found it, thanks
<FromGitter> <ohenepee> But how exactly is this better than the array approach, in relation to making sure the item exists?
<FromGitter> <Blacksmoke16> was the array of values a constant, or just like `[1,2,3,4,...]`?
<FromGitter> <Blacksmoke16> a tuple would be faster than an array, assuming the array was not a const
<FromGitter> <ohenepee> Okay, I forgot to mention that I'm picking the array from a larger container array... Hence it'll be a lot of work to rewrite the whole file as tuples instead of arrays
<FromGitter> <Blacksmoke16> ah fair enough
<FromGitter> <ohenepee> Thanks for ur help @Blacksmoke16 @tenebrousedge
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5db72ffa14d55a378590db7d]
<FromGitter> <Blacksmoke16> `#first` prob returns a new array?
<FromGitter> <tenebrousedge> yes
<FromGitter> <Blacksmoke16> so is marginally slower in this case since the array is so small
<FromGitter> <tenebrousedge> having `ARR` declared outside the block also affects the speed
<FromGitter> <Blacksmoke16> trying to avoid the allocation of the array in the benchmark
<FromGitter> <Blacksmoke16> not what im trying to test
<FromGitter> <Blacksmoke16> they pretty much equal if the array is larger
<FromGitter> <Blacksmoke16> 1) 17k vs 1.14k
dannyAAM has quit [Quit: znc.saru.moe : ZNC 1.6.2 - http://znc.in]
<FromGitter> <ohenepee> @Blacksmoke16
dannyAAM has joined #crystal-lang
<FromGitter> <Blacksmoke16> yes?
<FromGitter> <ohenepee> Forgive me, but gitter sucks on mobile big time... Just wanted to say thanks for the benchmark
<FromGitter> <Blacksmoke16> np
<FromGitter> <kinxer> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5db732a7a03ae1584f263af6]
<FromGitter> <kinxer> I really expected the iterator to be faster...
<FromGitter> <kinxer> Also, I don't know if it's shuffling every time, but I wanted to compare the time without allocation.
<FromGitter> <kinxer> I goofed a little... I'll revise that code block in a sec.
<FromGitter> <kinxer> With more elements: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5db734da14d55a378590fb56]
<FromGitter> <ohenepee> Wow! That's a lot of insight for me... @kinxer
<FromGitter> <tenebrousedge> very interesting
alexherbo2 has joined #crystal-lang
<FromGitter> <kinxer> One more... ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5db7361f10bd4128a179c387]
<FromGitter> <kinxer> So it looks like (for this particular problem), using the iterator (which is returned by `Array#each()`) is always slower than creating a new array, but creating a new array does (of course) have a memory cost.
<FromGitter> <tenebrousedge> I would only choose `each.first` if I had profiled the entire codebase and identified that the use of `first` was a bottleneck and `each.first` fixed it
<FromGitter> <tenebrousedge> micro-benchmarks have little practical value
<FromGitter> <kinxer> I had just expected `each.first` to be faster because it wasn't copying array elements.
<FromGitter> <tenebrousedge> can you explain your thinking there in more detail?
<FromGitter> <kinxer> `Array#first(n)` creates a new array and copies the first `n` values (or references) from the original array into the new array. I'd have expected this memory operation to be slower than allocating an `Iterator` and then performing certain operations with it.
<FromGitter> <tenebrousedge> hmm. What if `n` is large?
<FromGitter> <ohenepee> `Hash(Int32, Hash(Int32, Hash(Int32, Hash(Int32, Array(String)))))` is the hash I'm to store complex data, the compiler claims it has an undefined method `each_key` for `Tuple(Int32, Hash(Int32, Hash(Int32, Hash(Int32, Array(String)))))`
<FromGitter> <kinxer> That's when I'd expect the `Iterator` to be faster, since I would expect the "check index, get value, check value" sequence in the `Iterator` to take less time than allocating a new array and then doing a "get next value, check value" loop.
<FromGitter> <ohenepee> Is there a problem or limit with deeply-nested hashes?
<FromGitter> <tenebrousedge> @ohenepee can you use some aliases there?
<FromGitter> <tenebrousedge> `alias MyContainer = Hash(Int32, Array(String))`
<FromGitter> <tenebrousedge> some semantically meaningful labels there are probably good for both bugfinding and legibility
<FromGitter> <kinxer> @ohenepee Is there a benefit to nested hashes instead of `Hash(Tuple(Int32, Int32, Int32, Int32), Array(String)`?
<FromGitter> <Blacksmoke16> hashes aren't super great for not simple things, might be better off using objects
<FromGitter> <kinxer> Also, that looks like you're trying to call `each_key` on a `Hash` entry rather than a `Hash`. Did you do something like `hash.each { |value| value.each_key}`?
<FromGitter> <ohenepee> @kinxer the nesting follows the idea or structure I'm building, so I prolly can't use ur option
<FromGitter> <ohenepee> @kinxer Yes I did
<FromGitter> <kinxer> Echoing what @Blacksmoke16 says, this looks like a job for some kind of tree.
<FromGitter> <kinxer> `Hash#each` yields a `(key, value)` to the block, so you want `hash.each { |(_, value)| value.each_key}`
<FromGitter> <kinxer> Using the parentheses in the block argument to unpack the tuple.
<FromGitter> <ohenepee> @kinxer Thanks, that fixed it... I'm actually rewriting something I wrote in NodeJS... Crystal is too sweet
<FromGitter> <tenebrousedge> @ohenepee `Hash#dig` might be useful for you
<FromGitter> <ohenepee> Checking it out
<FromGitter> <ohenepee> Yep... That's something I definitely need... Thanks @tenebrousedge
duane has joined #crystal-lang
absolutejam2 has joined #crystal-lang
sagax has joined #crystal-lang
<FromGitter> <hugopl> guys, I just wrote a stupid macro that could be useful for someone, https://github.com/hugopl/version.cr it just get the version number from the shard.yml and create a VERSION constant with it.
<FromGitter> <kinxer> @hugopl That looks useful. Thanks for sharing!
<FromGitter> <hugopl> thanks
teardown has quit [Ping timeout: 240 seconds]
<FromGitter> <ImAHopelessDev_gitlab> gosh i love crystal
ht__ has quit [Ping timeout: 246 seconds]
<FromGitter> <kinxer> @ImAHopelessDev_gitlab What's up?
ht__ has joined #crystal-lang
<FromGitter> <ImAHopelessDev_gitlab> Finishing up selling items to npc, next is trading which will be fun
<FromGitter> <ImAHopelessDev_gitlab> crystal makes it easy, though. so i should be fine, kinda been on a roll ever since i moved to notepad
teardown has joined #crystal-lang
<FromGitter> <kinxer> Trading between players?
<FromGitter> <ImAHopelessDev_gitlab> yeah
<FromGitter> <kinxer> Cool. Do you already have it implemented on the client-side in Godot?
<FromGitter> <kinxer> Or will you do that after you work out the server-side?
<FromGitter> <ImAHopelessDev_gitlab> yeah, implemented on the client with Godot, now just server-side
<FromGitter> <ImAHopelessDev_gitlab> which is the fun part tbh, i like crystal more than gdscript. however, both are really nice.
<FromGitter> <ImAHopelessDev_gitlab> that's how i created my passive tree. implemented it first on client (godot's ui system). then in crystal, secure it so a player can only allocate if they have dependent nodes, etc.
<FromGitter> <kinxer> Passive skills?
<FromGitter> <ImAHopelessDev_gitlab> yeah, like 5% increase health,e tc
<FromGitter> <kinxer> So you have totally different passive and active trees?
<FromGitter> <ImAHopelessDev_gitlab> yeah, active skills are gems where you slot into gear
<FromGitter> <ImAHopelessDev_gitlab> that's all done server-side as well in crystal, which is nice
<FromGitter> <kinxer> Oh, interesting. Do you have a class system of some kind, or is character customization just a combination of passives and gems?
<FromGitter> <ImAHopelessDev_gitlab> example, power slam skill, and increase area of effect gem. i extract them from the gear slots in crystal, then notify the client they have that skill now, with the supported gem
<FromGitter> <ImAHopelessDev_gitlab> just combination of passives and gems for now haha
<FromGitter> <kinxer> Cool. Sounds like you're making quite a lot of progress.
<FromGitter> <ImAHopelessDev_gitlab> yeah, i will need to stop at some point cause this is becoming too much. but honestly, the way i structured everything, it's pretty organized. i can get to whatever method i need instantly.
<FromGitter> <ImAHopelessDev_gitlab> however, that's prob just because i'm the only one working on this lol.
<FromGitter> <kinxer> Are you planning on releasing the game at some point?
<FromGitter> <kinxer> That is, as opposed to it just being a hobby project.
<FromGitter> <ImAHopelessDev_gitlab> yeah def planning on releasing it. i got a site ready. custom forum with a guild system, forum gold, ability to buy in-game microtransactions (working with paypal), and much more. just need to finish all this back end stuff (master and game server w/ crystal)
<FromGitter> <kinxer> Yeah, it sounds like you do really have everything set up. How are you planning on hosting servers?
<FromGitter> <ImAHopelessDev_gitlab> well, i've been thinking about a dedicated for the master server, and then VPSs for the game instance servers to horizontally scale. i've got this all setup have been testing it but only with VPSs, ⏎ ⏎ it works nice because I can add a Europe realm. Buy a vps or dedi located in Europe, run my installer script && upload server files and it auto connects to the master server (loop do), then
<FromGitter> ... once it authenticates itself, it's ready to create game instances. ⏎ ⏎ However, I'm only go to start with a few realms UsWest, UsEast, Brazil and see how it pans out. There would definitely have to be an alpha so I can test it at scale. I've only tested it with so many players (300 to 900) i think my last benchmark was. Th ... [https://gitter.im/crystal-lang/crystal?at=5db754b9a3f0b17849a69da8]
<FromGitter> <kinxer> Is your master server written in Crystal as well?
<FromGitter> <tenebrousedge> look into Traefik (https://traefik.io/) for routing
<FromGitter> <ImAHopelessDev_gitlab> Yeah!!
<FromGitter> <kinxer> So you actually have two (or three?) different Crystal servers that you've written?
<FromGitter> <ImAHopelessDev_gitlab> Master Server basically handles authentication (login), chat lobby, character listing, switching channels, browsing games, editing player profile, whispering, add/remove friends/block, create char, delete char, etc (all i can think of off the top of my head)
<FromGitter> <ImAHopelessDev_gitlab> @kinxer yeah two, master and game server. although, i was creating an auction house daemon thingi, but stopped because i don't know if i want to add an auction house yet lol
<FromGitter> <kinxer> Interesting.
<FromGitter> <kinxer> Honestly, you're a lot further than I thought you were. That's cool, though. You might end up having the first game in-production that's backed by Crystal.
<FromGitter> <ImAHopelessDev_gitlab> I really miss the old social aspect of games, that's why I really like the lobby. All the characters appear at the bottom with the player's gear (armor, boots, helmet, sword, and shield so far).
<FromGitter> <kinxer> Are game servers supposed to be long-lived (closer to an MMO instance) or short-lived (like a game of Gauntlet)? Or something in-between?
<FromGitter> <kinxer> The community aspect is also interesting. I've been reading a bit recently about how game features relate to the social experiences of players.
<FromGitter> <kinxer> @tenebrousedge That looks interesting. Thanks for sharing.
<FromGitter> <ImAHopelessDev_gitlab> probably something in-between. there is a limit of how many games a player can create per minute. however, the zones inside the game (levels), don't get populated with monsters, crates, entities, etc until a a player enters. the games will cease when the last player leaves. or, i might add a soft delete after 60 seconds of no players joining it. this way, players can transfer items to a new
<FromGitter> ... account. or, if they need to leave and come back with a different character.
<FromGitter> <ImAHopelessDev_gitlab> for example, items left on the floor will auto delete after 10 minutes
<FromGitter> <ImAHopelessDev_gitlab> i also had to add a limit on the amount of times that can be dropped in a zone.. cause a player coulddrop like so many, then another player joins and rip my bandwidth and cpu usage lmao
<FromGitter> <tenebrousedge> can you defer loading of those? Have "There are `x` items on the ground. Look at them?"
<FromGitter> <ImAHopelessDev_gitlab> I have a nice honey bucket flood system in place too, every game function has its own internal rate limiting. which helps a lot, especially for not spamming people with messages (although, they cna just block you). but not spamming lobby chat rooms, etc is nice.
<FromGitter> <ImAHopelessDev_gitlab> @tenebrousedge possibly, good idea
<FromGitter> <tenebrousedge> or if it's a mouse-driven game, you could display a generic bag of loot, and load the contents on hover
<FromGitter> <ImAHopelessDev_gitlab> actually pretty good idea, could be called bag of xxx or w/e, player can right click it to receive items or w/e
<FromGitter> <tenebrousedge> :plus1:
<FromGitter> <kinxer> Or you could even cause adverse conditions from having too much stuff on the ground (ground sucks up stuff or some creature(s) come to take it or something). Probably the treasure bag idea is better, though.
<FromGitter> <ImAHopelessDev_gitlab> > Honestly, you're a lot further than I thought you were. That's cool, though. ⏎ πŸ‘ :)
Flipez has quit [Read error: Connection reset by peer]
Flipez has joined #crystal-lang
ht__ has quit [Remote host closed the connection]
<FromGitter> <Daniel-Worrall> Does anyone foresee Crystal usable in the phone app market in the future?
<FromGitter> <Daniel-Worrall> maybe something like rubymotion
<FromGitter> <tenebrousedge> > FUTURE, *n*. That period of time in which our affairs prosper, our friends are true and our happiness is assured.
hightower2 has joined #crystal-lang
<hightower2> Hey a simple one, how can I do array[10] = "x" if index 10 is currently not yet valid/existing?
<FromGitter> <tenebrousedge> do indexes 0..9 exist?
<hightower2> no
<FromGitter> <tenebrousedge> then you probably need a hash and not an array
<hightower2> The function populates the array in non-sequential order
<hightower2> in the end all indices will exist
<hightower2> but the method which fills them doesn't fill them sequentially
<hightower2> (and the index is significant, it's not just about pushing elements to the array)
<FromGitter> <tenebrousedge> then create an array of empty strings (or whatever your data type is) that's the size you need and use `array#map`
<FromGitter> <tenebrousedge> mmm, or I guess if it's not sequential, then maybe use the array as the memo object in a `reduce` loop
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/0.31.1/Array.html#new(size:Int,value:T)-class-method then edit the values later
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/0.31.1/Array.html#new(size:Int,&block:Int32-%3ET)-class-method or this maybe?
<hightower2> great, just thought of that initializer based on tenebrousedge's comments
<hightower2> thanks
<FromGitter> <tenebrousedge> the block initializer populates the indices in order
<hightower2> actually, since this list is static, I'm gonna run this in ruby, then use the finished/populated result
<hightower2> as a one-time operation
<FromGitter> <tenebrousedge> huh
<FromGitter> <Blacksmoke16> that works too
<FromGitter> <tenebrousedge> I like pie
<FromGitter> <tenebrousedge> interesting
<FromGitter> <tenebrousedge> @Blacksmoke16 why should `insert` behave that way?
<FromGitter> <Blacksmoke16> idk, just as a way to handle that use case while not breaking the more use `[idx] = `
<FromGitter> <Blacksmoke16> just a thought i had
<FromGitter> <tenebrousedge> hmm. Kay
<FromGitter> <tenebrousedge> and `insert` mutates normally
<FromGitter> <Blacksmoke16> mainly it would kind of make sense
<FromGitter> <Blacksmoke16> if you insert and there is already a value it gets shifted
<FromGitter> <Blacksmoke16> if you insert and index is higher than size then just drop it at the end
<FromGitter> <Blacksmoke16> hightower2: use case would work as then as long as each key is inserted with the index it should be at, it would eventually be correct
<FromGitter> <Blacksmoke16> also made me think that it would be nice if some type restrictions were added to array
<FromGitter> <Blacksmoke16> like `self` if it mutates the current array, or `Array(T)` if it returns a new one
<FromGitter> <tenebrousedge> uhh, what?
<FromGitter> <tenebrousedge> shouldn't the type restrictions exist when the array is created/
<FromGitter> <Blacksmoke16> i mean if you do like `arr.push(17)` that method should be like `def push(val) : self`
<FromGitter> <Blacksmoke16> but `arr.shuffle` would be like `def shuffle : Array(T)`
<FromGitter> <Blacksmoke16> since it returns a new array
<FromGitter> <tenebrousedge> doesn't Crystal core omit those type restrictions?
<FromGitter> <Blacksmoke16> omit them how?
<FromGitter> <tenebrousedge> by not including them?
<FromGitter> <Blacksmoke16> right, they're not included atm
<FromGitter> <Blacksmoke16> but wouldn't hurt to have them?
<FromGitter> <tenebrousedge> so far, I prefer to avoid explicit typing to whatever degree possible
<FromGitter> <Blacksmoke16> im the opposite, don't omit return types if there is no need to
<FromGitter> <Blacksmoke16> makes docs better, makes catching bugs easier. if in the future you have to remove it thats fine, but until then why not include it
<FromGitter> <Blacksmoke16> kinda makes me wish you could specify the return type for docs without actually doing it
<FromGitter> <Blacksmoke16> `# RETURNS: Int32`
<FromGitter> <tenebrousedge> now that I'm okay with
<FromGitter> <tenebrousedge> but I'm coming from Ruby and JS, and I'm a lazy typist