<c-c>
I'm wondering how would a game state be saved in a crystal program
<c-c>
I guess yaml might be a possibility
<c-c>
or each object must implement their own serialization/de logic
<FromGitter>
<straight-shoota> depends on whether you want a text or binary format...
<c-c>
cannon looks convincing
<FromGitter>
<straight-shoota> yep
<FromGitter>
<straight-shoota> haven't used it yet, but it looks really great
<c-c>
I suppose my future game will have objects or structs with bunch numerical values (logic is in separate process), but theres a lot of them, so I suppose binary
lacour has quit [Read error: Connection reset by peer]
lacour has joined #crystal-lang
lacour has quit [Quit: Leaving]
gcds has joined #crystal-lang
latemus has quit [Ping timeout: 240 seconds]
latemus has joined #crystal-lang
latemus is now known as Guest18932
gcds has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
_whitelogger has joined #crystal-lang
<FromGitter>
<pnloyd> I take is `abstract @inst_var` is not a thing?
<FromGitter>
<pnloyd> I suppose since directly instances vars is bad practice it wouldn't much much sense.
<FromGitter>
<pnloyd> And other reasons.
gcds has joined #crystal-lang
<FromGitter>
<pnloyd> Is is possible to write code that instantiates an instance of a generic type parameter? (e.g to some "default" value, like 0 or "")
<FromGitter>
<pnloyd> I see there's `#zero` on num types I think that's what I wanted.
rohitpaulk has joined #crystal-lang
gcds has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter>
<ansarizafar> Does Crystal provide native handlers for unhandled exceptions and sigfaults?
<Groogy>
c-c wait you implementing concurrency using interprocess communication in Ruby?
<Groogy>
Holy shit that has to be a living nightmare
<Papierkorb_>
Groogy: Doing that right now. It's not really that bad.
<Papierkorb_>
It mainly sucks because you have to use forks
<Papierkorb_>
OTOH, hilariously enough, the benefits are that a crashing worker doesn't take your whole application down
<Groogy>
Problem I am seeing with syncing a game state over IPC is going to be nightmarish hellish
<Papierkorb_>
Groogy: IPC class based on pipe(2) and Marshal does wonders.
<Papierkorb_>
Ah for gaming it's not useful
<Papierkorb_>
of course
<Groogy>
and the overhead of serialization and deserilization compared to threads
<Papierkorb_>
But usually, such workers work for multiple seconds at a time, so it's not really an issue
<Groogy>
I mean unless he has a sort of game where the different processes are increadibly independent from each other
<Papierkorb_>
But then, you don't really write games in Ruby
flaviodesousa has joined #crystal-lang
<Papierkorb_>
Maybe small scripts (I think RPGMaker used Ruby?), but not "everything"
<Groogy>
Yeah but different use case
<Groogy>
my experience in ruby, every second it involved iteration it would slow down the application a lot
<Groogy>
eh don't know how to explain that better
<Papierkorb_>
Ruby isn't useful for real-time stuff, nuff said
<Groogy>
but my impression was whenever I added a Hash or Array it would have a cascading effect in my code to eventually mean everything is going to get slower
<Papierkorb_>
Where "oh that 1ms" really worsens the user experience
<Papierkorb_>
I'm really missing the fibers/channel from crystal in ruby though. would've made that ruby code here much easier
mark_66 has joined #crystal-lang
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter>
<pnloyd> I'm just getting my first fibers experience and I'm becoming hooked.
<FromGitter>
<pnloyd> So convenient.
<Groogy>
Hmmm even if they aren't concurrent maybe I should use them for processing entities just to have an architecture that's a bit future proof
claudiuinberlin has joined #crystal-lang
<Papierkorb_>
pnloyd, "Now how do I use select() .. No select .. how do I do this? ... It does it automatically?!"
claudiuinberlin has quit [Client Quit]
<FromGitter>
<pnloyd> To many questions?
<Papierkorb_>
pnloyd, Nah just basically how everyone starts out :)
<Papierkorb_>
(Me included)
<FromGitter>
<pnloyd> Ok because I have one and it's and like the other's it revolves around blocks
<FromGitter>
<pnloyd> Can I someone call reduce on items being yielded instead of using a block.. I think what I want is for `i_yield_things` to actually produce an iterator
<FromGitter>
<pnloyd> But I don't know how to do that.
<FromGitter>
<pnloyd> I want to reduce my yielded items.
<Papierkorb_>
You can't, or rather, there's nothing in the stdlib to turn a yielding method into an iterator
<Papierkorb_>
You can do that using channels and fibers, but the performance is quite bad. Nothing I'd generally advise
<Papierkorb_>
In that case, collect the yielded items into an array first, and then post-process that
<FromGitter>
<pnloyd> This is code in a simulation. :(
<FromGitter>
<pnloyd> I'm worried doing that a thousand times every simulation step will be a bad performance hit.
<Papierkorb_>
Two good-performance solutions: 1) provide an Iterator-returning version of your calculation, and then process that 2) Collect stuff into an Array first, process that later
<Papierkorb_>
Depending on your workload, the array might kill it, or might turn out to not be that bad after all
<FromGitter>
<Qwerp-Derp> What's the diff between `initialize` and `self.new`?
<Papierkorb_>
pnloyd, I'd say, try the array solution first, as that's really easy. If it turns out to be too slow you can still refactor
claudiuinberlin has joined #crystal-lang
<FromGitter>
<pnloyd> @Papierkorb Thanks I'll try building an array.
<Groogy>
@Qwerp-Derp, one allocates memory and calls initialize on that memory, one just initializes the memory
<Papierkorb_>
Qwerp-Derp, #initialize is what you generally provide. It sets up your instance. .new also allocates memory. Basically, `.new` calls `.allocate`, and then your `#initialize`
<Papierkorb_>
Qwerp-Derp, you should rarely need to override `.new`. Haven't needed it once
<FromGitter>
<Qwerp-Derp> Hmmm, it's just because I've seen it in the Crystal source code
<Groogy>
hmm actually curious, how do the default initializers work? Is there a method in allocate that makes sure the default initializers are performed or is there some magic happening around #initialize?
<Papierkorb_>
Groogy: #initialize is magic (@var checks), .new is auto-generated if you don't provide one.
<Papierkorb_>
Well only magic w.r.t. doing additional checks. it's a normal method otherwise
<Groogy>
yeah but I am just trying to grasp like
<Groogy>
I define my own #initialize
<Groogy>
where does the default initializer magic happen?
<Papierkorb_>
the compiler provides one if it makes sense
<Groogy>
in my #initializer method?
<Groogy>
initialize*
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<Papierkorb_>
If you don't have an #initialize, and your object can be default constructed, an empty #initialize is provided
Ven has joined #crystal-lang
Ven is now known as Guest84182
<Groogy>
I know but if I define one myself, where does it add the code to initialize the variables I don't in the initialize method but in the default initializer part
<Groogy>
i.e is it done in allocate? If I do Foo.allocate -> will variables be initialized?
<Groogy>
or does it inject the default initializers to every #initialize?
<Papierkorb_>
I'd expect that to happen in #initialize before your code
<Papierkorb_>
You could try, make the @var default value raise
<FromGitter>
<Qwerp-Derp> Is there any way to make this simpler?
<Papierkorb_>
... without the if
<FromGitter>
<Qwerp-Derp> Oh yeah
<Papierkorb_>
Please check up on `Object#try`
<FromGitter>
<mvlootman> which require statement would I need to instantiate the Compiler class (e.g. compiler = Compiler.new ) ? ⏎ I am looking at the Crystal::Playground module and I don't see any specific require statements. ⏎ However I get an undefined constant Compiler
<Papierkorb_>
iirc, "compiler/crystal"
<FromGitter>
<bew> And it's probably `Crystal::Compiler`
<FromGitter>
<mvlootman> the require "compiler/crystal" gives me Please use `make crystal` to build the compiler, or set the i_know_what_im_doing flag if you know what you're doing.
<FromGitter>
<mvlootman> that expands a few macros and gives me the error: undefined constant Program
<FromGitter>
<mvlootman> the Playground module Crystal::Playground is inside the Crystal module under compiler is that the reason that works there (calling Compiler.new etc.)?
<FromGitter>
<bew> Or require `compiler/crystal/program` too
<FromGitter>
<mvlootman> undefined constant LinkAttribute. ⏎ Should I be calling Compiler class directly?
sz0 has quit [Quit: Connection closed for inactivity]
<FromGitter>
<mvlootman> I want to compile some (generated) crystal code, ofcourse I could shell the crystal executable instead of instantiating the Compiler directly
<FromGitter>
<bew> Just require with * (see ex above)
<FromGitter>
<mvlootman> I tried compiler/crystal/* but that gave the undefined constant LinkAttribute
<FromGitter>
<bew> Ah x)
<FromGitter>
<bew> Weird
<FromGitter>
<mvlootman> also tried compiler/crystal/** that gave an error: /usr/bin/ld: /opt/crystal/embedded/lib/../lib/libgc.a(os_dep.o): undefined reference to symbol '_end' ⏎ //usr/lib/x86_64-linux-gnu/libffi.so.6: error adding symbols: DSO missing from command line ⏎ collect2: error: ld returned 1 exit status
<FromGitter>
<mvlootman> that is why I was wondering if this is a valid/good approach
<FromGitter>
<bew> I was about to suggest that (2 stars)
<FromGitter>
<bew> I don't know.. i think you can report an issue on GitHub, it looks like a bug, but no idea why
<FromGitter>
<mvlootman> I am not sure if its a bug or that I am doing it wrong 😄
<FromGitter>
<bew> Does compiling the compiler works or do you get this error too?
gcds has joined #crystal-lang
<FromGitter>
<mvlootman> I would need to try that, haven't done that before
<FromGitter>
<mvlootman> perhaps there lies the problem
<FromGitter>
<bew> I'd say, make sure your os is up-to-date too
<FromGitter>
<bew> Your libs etc
<Papierkorb_>
iirc, crystal itself also uses **, I don't see much wrong with doing it like that
<FromGitter>
<mvlootman> i am running Crystal 0.23.1 [e2a1389] (2017-07-13) LLVM 3.8.1 not build from sources
<FromGitter>
<mvlootman> i will build it from the master branch and see if that works
<FromGitter>
<mvlootman> I get similar error running make
<FromGitter>
<mvlootman> when installing the required libraries there are some errors
<FromGitter>
<mvlootman> E: Unable to locate package libevent-core-2.0-5 and package libevent-extra-2.0-5 and libevent-pthreads-2.0-5
<Papierkorb_>
sounds like your package index is outdated. `apt update`
<FromGitter>
<mvlootman> apt update said no updates. I just upgraded to Ubuntu 17.10
<FromGitter>
<yxhuvud> perhaps you removed third party srouces when upgrading? It is really irritating that it removes all the ppa's every time with no easy way to reenable thm .
<FromGitter>
<mvlootman> apt-get install shows libevent-core-1.4-2 libevent-core-2.1-6 for libevent-core so that is newer than 2.0-5
<FromGitter>
<mvlootman> @yxhuvud could very well be
<FromGitter>
<mvlootman> ok make seems to work now (i missed installing bdwgc )
<FromGitter>
<mvlootman> make ran without errors, it compiled crystal in the bin folder. however running it gave error : error while loading shared libraries: libgc.so.2: cannot open shared object file: No such file or directory. I think my lib versions are messed up
<Papierkorb_>
make clean, make again
<FromGitter>
<bew> Papierkorb, `make again` is not a valid target :P
<FromGitter>
<mvlootman> make clean ⏎ make ⏎ when running ./build/crystal: ⏎ ./crystal: error while loading shared libraries: libgc.so.2: cannot open shared object file: No such file or directory [https://gitter.im/crystal-lang/crystal?at=59f1ad31e44c43700a7d27cc]
<Papierkorb_>
Yup, you just wrecked your installation. Is your crystal binary built for a previous version of Ubuntu?
<FromGitter>
<mvlootman> how can I tell?
<Papierkorb_>
Maybe dpkg-query can tell you. I don't use Ubuntu though
<FromGitter>
<mvlootman> running ldconfig solved the issue
flaviodesousa has quit [Ping timeout: 240 seconds]
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<Papierkorb_>
Why though? Was there someone who was fed up with Go so much they implemented basically-ruby?
<Papierkorb_>
I mean getting to that point is no small feat, but what's the intended use-case?
claudiuinberlin has joined #crystal-lang
<Groogy>
according to the github page
<Groogy>
to write concurrent microservices
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
rohitpaulk has joined #crystal-lang
<crystal-gh>
[crystal] asterite closed pull request #5057: Add time formatters for days with ordinal suffix. Includes specs and docs. (master...add_ordinal_date_formatters) https://git.io/vd3kG
Ven has joined #crystal-lang
Ven has quit [Client Quit]
claudiuinberlin has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 258 seconds]
<crystal-gh>
[crystal] asterite pushed 2 new commits to master: https://git.io/vFJnD
<FromGitter>
<r3bo0t> as @crisward mentioned above as well
<FromGitter>
<r3bo0t> go through that thread, it will really help you to understand the problem.
Ven has joined #crystal-lang
<FromGitter>
<r3bo0t> Even I am very new to Crystal, so not countable for wrong assumption :P
Ven is now known as Guest20545
<FromGitter>
<r3bo0t> @crisward @sdogruyol how to manage connection_pool for (crystal-db + crystal-mysql) from kemal application. ⏎ I keep getting `Exception: (DB::PoolTimeout)` after sometimes on my Kemal application ⏎ seems like I keep exhausting my connection pool :|
<FromGitter>
<r3bo0t> @asterite how should be release db connection with `scalar` and `exec` commands in crystal-db?
Ven_ has joined #crystal-lang
<FromGitter>
<r3bo0t> I can’t seems to find it anywhere
<linuksz>
@asterite, doesn't seem do it would be the problem.
<linuksz>
my laptop has 2GiB RAM, and a Core2Duo 1,8GHz cpu
<linuksz>
how much time would it be to compile the compiler?
<FromGitter>
<crisward> @r3bo0t I don't think you have to
<FromGitter>
<asterite> You don't need to compile the compiler, just download the repo and set CRYSTAL_PATH to the `src` directory
<FromGitter>
<r3bo0t> @crisward but I keep getting (DB::PoolTimeout) after using server for sometime
<FromGitter>
<crisward> @r3bo0t Are you just using scalar and exec ? not query?
<FromGitter>
<r3bo0t> and once I restart the server, it works like charm
<FromGitter>
<r3bo0t> using query as well
<FromGitter>
<crisward> query can hold onto connections, until you manually release them, depending on if you're using a block or not
claudiuinberlin has joined #crystal-lang
<linuksz>
@asterite, it doesn't work with CRYSTAL_PATH set
<linuksz>
0.23.1 is installed on my system, and master has too much difference
<FromGitter>
<r3bo0t> with query I am mostly using blocks only cc: @crisward
<linuksz>
i have to compile the compiler
<FromGitter>
<crisward> All your deps up to date?
<linuksz>
how much time would it take?
<FromGitter>
<r3bo0t> Yes, just update few hours back
<FromGitter>
<crisward> Also mysql, postgres or sqlite?
<FromGitter>
<r3bo0t> mysql (crystal-mysql)
<FromGitter>
<asterite> linuksz you can report a bug, maybe someone can help you (I didn't see it happen on mac osx and that's all I have)
<FromGitter>
<asterite> someone else reported the same issue some days ago, not sure it was you though
<linuksz>
@asterite: the server code snippet works fully with --release flag?
<FromGitter>
<crisward> I had an issue, when I had an sql error with the wrong fields would leak connections. I did a pull request which I think got merged.
<FromGitter>
<r3bo0t> @asterite most of the Macs now a days run with 8GB of RAM and SSD (so even swap is very fast). In small VPC sometimes swap is actually not present.
<FromGitter>
<r3bo0t> @crisward let me look into the same a bit more once. Thanks.
<FromGitter>
<crisward> If you have any sample code, I don't mind taking a look
<FromGitter>
<crisward> When do you open your connection pool, when the server launches ?
<FromGitter>
<ondreian> been a couple months since I've been able to work with Crystal, but did something change with the way `Macro#run` works? ⏎ I get a fairly uninformative error of: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=59f239cbb20c642429504445]
<linuksz>
is it possible to use connectionless UNIX sockets?
<FromGitter>
<r3bo0t> linuksz: if you compile the same code on linux machine with more RAM (say 4 or 8 GB) with good SWAP memory, it will work there too.
<FromGitter>
<r3bo0t> I had the same issue on smaller EC2 instance, I tried the same on larger EC2 machine and it worked fine for me.
<Papierkorb>
So, what are the use cases? 1) QDebug() was great: You do << and then after the statement ends, it gets output with on a new line. Great. But we have string interpolation, which is much easier to use 2) MutexLocker is great: Leave the method and it gets unlocked. Fantastic. But we have blocks, you could do e.g. `mutex.lock{ do something while locked }; not_locked_anymore_here`
<Papierkorb>
RAII is a good concept in a language like C++, but we have many other language patterns which make other paradigms more useful overall
<FromGitter>
<unreadable> `mutex.lock { ..code.. }` seems to clean comparing to go wow
<Papierkorb>
That pattern is already used all over crystal outside mutexes :)
<Papierkorb>
E.g., for database transactions.
<Papierkorb>
`db.transaction{ do; something; in; the; transaction }` <- ROLLBACK if any exception was thrown, COMMIT otherwise. Can't do much wrong with that
<FromGitter>
<unreadable> I'm starting to love the ruby syntax more and more
<Papierkorb>
unreadable, well my two use-cases above are simply those I still remember from my time with C++/Qt - If you know of others, lemme know
<FromGitter>
<unreadable> or i'd better say crystal's syntax
<Papierkorb>
Yah well those parts are really Rubys invention .. or maybe they copied it from somewhere else too ;)
<FromGitter>
<unreadable> Perl hehe
<FromGitter>
<unreadable> there a funny twitter psot
<FromGitter>
<unreadable> can't find it now
<FromGitter>
<unreadable> *post
<Papierkorb>
And boy did it suck that you had to overload operator<< all the time to dump your structures into a log.
<Papierkorb>
in C++ that is
<FromGitter>
<unreadable> well, that's right. Never coded c++ in production, but I'm thinking of getting a part time job on embedded devices with c
jackivan88 has joined #crystal-lang
_whitelogger has joined #crystal-lang
Disrecollection has joined #crystal-lang
<crystal-gh>
[crystal] luislavena opened pull request #5188: Relocate and document Time::DayOfWeek (master...refactor-day-of-the-week) https://git.io/vFU2J
<bmcginty>
Is there any reason crystal would be closing file descriptors in a sub-sub-process, after a dobule fork? I've done .reopen on my std* objects to point to /dev/null, and they stay around for a while, then they're just closed. very odd.
FromGitter has quit [Remote host closed the connection]