<FromGitter>
<andrewhamon> So I was wondering if any former rubyists have had similar concerns, and how you worked around it/what other patterns you used instead
<FromGitter>
<andrewhamon> I've seen the idea of a `respond_to?` type constraint, which would alleviate basically all of my concerns. Something that looks like `@publisher : respond_to?(:publish)`and would restrict `@publisher` to any object with a `publish` method.
<FromGitter>
<andrewhamon> The problem, though, is that I'm pretty sure that in order for that to work at compile time, the compiler would basically have to do all the same work that it would have to do to infer the type of `@publisher`
Raimondi has quit [Quit: WeeChat 1.6-dev]
Raimondi has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Ping timeout: 264 seconds]
z64 has quit [Ping timeout: 250 seconds]
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
Raimondi has quit [Ping timeout: 244 seconds]
z64 has joined #crystal-lang
ponga has quit []
<FromGitter>
<andrewhamon> So it seems I can use generic classes, with a type parameter for each dependency I want to inject. And then I can instantiate like `Publisher(typeof(hub), typeof(redis)).new(hub, redis)` and everything seems to work fine!
snsei has joined #crystal-lang
Raimondi has joined #crystal-lang
<FromGitter>
<andrewhamon> And the friction isn't that bad since DI tends to get used in longer lived objects that I don't instantiate super often
bjz has joined #crystal-lang
<FromGitter>
<cjgajard> you can also use inference from arguments of `initialize`, example: https://carc.in/#/r/1fvs
<FromGitter>
<andrewhamon> @cjgajard I was literally about to say "But I feel like the compiler should be able to just do what I'm doing"
<FromGitter>
<andrewhamon> I'll give that a try, it seems like exactly what I need!
Philpax__ has joined #crystal-lang
Philpax_ has quit [Ping timeout: 258 seconds]
soveran has joined #crystal-lang
soveran has quit [Ping timeout: 252 seconds]
<FromGitter>
<andrewhamon> Converted all my code, working like a charm!
<FromGitter>
<cjgajard> :clap: Is it open source?
<FromGitter>
<andrewhamon> Haven't put it on github yet :p But I'm making what's basically a clone of Pusher (https://pusher.com)
<FromGitter>
<andrewhamon> I started off with Ruby, but was really put off by EventMachine since it essentially dictates how I do all IO (and its basically required since all the web socket libraries in ruby use event machine in some form)
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
sp4rrow has joined #crystal-lang
matp has quit [Remote host closed the connection]
matp has joined #crystal-lang
sp4rrow has quit [Quit: The Internet needs a break and I need a cookie]
mgarciaisaia has joined #crystal-lang
mgarciaisaia has quit [Client Quit]
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
snsei has quit [Remote host closed the connection]
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 244 seconds]
Raimondii is now known as Raimondi
soveran has joined #crystal-lang
soveran has quit [Ping timeout: 264 seconds]
Philpax__ has quit [Ping timeout: 248 seconds]
<FromGitter>
<sdogruyol> @andrewhamon that's great to hear
<FromGitter>
<sdogruyol> when do you plan to release it?
Philpax has joined #crystal-lang
vivus-ignis has joined #crystal-lang
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Remote host closed the connection]
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
_whitelogger has joined #crystal-lang
bjz has joined #crystal-lang
fedruantine_ has joined #crystal-lang
fedruantine has quit [Quit: client exited: Ex-Chat]
dhk has joined #crystal-lang
triangles has joined #crystal-lang
bjz_ has joined #crystal-lang
bjz has quit [Ping timeout: 245 seconds]
rolha has joined #crystal-lang
<rolha>
hello everyone
<rolha>
can I have an initialize method in an abstract class?
<FromGitter>
<sdogruyol> @rolha hello
<FromGitter>
<sdogruyol> i guess you can
<rolha>
hi sdogruyol
<rolha>
ah, ok. It's just that I have a abstract class Foo with a initialize
<rolha>
and a class Bar < Foo
<rolha>
when I call Bar.new ... the compiler complains Bar has no initialize with that signature
<rolha>
might be a mistake of mine then, thanks
<FromGitter>
<sdogruyol> @rolha since Bar inherits from the abstract Foo it has to have that method :)
<rolha>
sdogruyol, thanks. it must be definitely an error in my code then.
<FromGitter>
<cjgajard> mine = atom + `crystal` package, the linter works great
<FromGitter>
<sdogruyol> atom is a cpu killer
<rolha>
I used to use atom but this ^^^
<rolha>
a text editor shouldn't need 4Gb RAM :-P
<FromGitter>
<sdogruyol> indeed
<FromGitter>
<sdogruyol> i uninstalled atom when it cant even open a file over 1MB
soveran has quit [Remote host closed the connection]
<FromGitter>
<cjgajard> rolha, the code you pasted on my workaround is the same code that fails :sweat_smile:
<rolha>
duh. copy pasta malfunction, sry
<rolha>
fixed
<FromGitter>
<sdogruyol> @rolha i like you scientific blog posts
<FromGitter>
<sdogruyol> keep up the great work :)
<rolha>
sdogruyol, ahah thanks.
<FromGitter>
<sdogruyol> yeah it definitely has different perspective for me
<rolha>
sdogruyol, crystal has a lot of potential in that area
<FromGitter>
<sdogruyol> it seems like so but i dont get much about math stuff :P
<rolha>
python has taken a lot of ground in this area and i think crystal has everything to be better
<rolha>
it just needs the mind share
<FromGitter>
<cjgajard> rolha, yes, great work on that blog! (but if you allows me to comment something I don't like that all functions arguments have type declarations :( crystal strong point is not having to declare them... IMHO, arguments types should be only for overloading)
<FromGitter>
<sdogruyol> probably so but why no Go or Rust?
<rolha>
they have potential too of course. it's all down to libraries, community, IMO
<rolha>
the typing system is a plus a my opinion
<rolha>
one of the problems, again in my opinion, with python
<rolha>
is that dynamic typing makes it difficult to make big projects
<FromGitter>
<sdogruyol> @rolha dynamic needs a lot of test coverage for big stuff
<FromGitter>
<sdogruyol> no compiler to cover your back
<rolha>
yes. crystal's compiler saved my bacon many times.
<FromGitter>
<sdogruyol> same here
<FromGitter>
<sdogruyol> I've seen that we're spoiled by Ruby and most of the time we're doing careless stuff leading to runtime erros with a lot of nils
<rolha>
and the error messages... :) really cool. "do you mean resampled instead of resample?"
<FromGitter>
<sdogruyol> Ruby is great does a lot of stuff but sometimes we have to do our part :P
<rolha>
yep, but it's good to offload some work on the compiler :)
<FromGitter>
<sdogruyol> indeed, IMHO it's a win / win
<rolha>
i never programmed in ruby before
<rolha>
that's why i so many silly questions :-P
<FromGitter>
<sdogruyol> @rolha yo should definitely share your experience
<rolha>
*have
<FromGitter>
<sdogruyol> nope, you ask good questions
<rolha>
i will! lunch time, sry. see you all
rolha has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
<unshadow>
Papierkorb: Dont you think passing in a Hash is easier ? and more clear
<Papierkorb>
unshadow: It's not easier, and how is it clearer? The caller can just use the arguments via names
<Papierkorb>
Now I'd have to either hope you document it, then figure out how you meant the docs, OR I read the code itself and just hope it's not behind garbled if conditions of sorts in there or somewhere else
<Papierkorb>
Or, I just use named arguments and it's crystal clear.
<Papierkorb>
unshadow: Even Ruby understood it, as there've been named arguments now for quite some time.
<Papierkorb>
In crystal, they're named (or unnamed), you can force the caller of the method to use named ones though if you insist
Raimondii has joined #crystal-lang
<unshadow>
Papierkorb: Done :) It does looks nicer now
Raimondi has quit [Ping timeout: 244 seconds]
Raimondii is now known as Raimondi
<Papierkorb>
unshadow: Happy to help. It was done like this by many in Ruby, and there it created exactly the same issues docs-wise, that's why I really don't like it
soveran has joined #crystal-lang
<FromGitter>
<fridgerator> Anyone else using `crystal-pg` with connection pooling (`pool` shard) right now? It seems `crystal-pg` v0.12.0 was released recently which added `crystal-pg` support. I'm having some issues after the update.
<Papierkorb>
"Finally one can build shit thats fast"
<RX14>
hmm, i'm not sure why having too many requests per second would stop a spawn{}
<crystalmq>
@RX14 It seems as though it might be IO bound - because the spawn outputs to a socket
<crystalmq>
But my (limited) understanding is that the fibers should yield when they are IO bound
<unshadow>
crystalmq: sent you a PR :)
<RX14>
yes
<RX14>
fibers will yields when read/write blocks
<RX14>
then a callback gets added to libevent
<RX14>
the scheduler has a queue of fibers to be run
<crystalmq>
@unshadow recevied thanks! I'll take a look now
<RX14>
and spawn and the like schedule it on the end
<crystalmq>
@RX14 Right..
<RX14>
every yield pops the top fiber
<RX14>
if there's nothing to run it runs the event loop
<RX14>
so every fiber should be scheduled
<RX14>
if anything was to get starved it would be the event loop
<crystalmq>
@RX14 That makes sense
<crystalmq>
so the symptoms I'm seeing are this:
<crystalmq>
at around 100k requests per second (input on one TCP socket, output on another TCP socket), i can see equal inputs and outputs
<crystalmq>
When we read the 180k requests per second mark, i can see the inputs are stable at around 180k, but no outputs (the consumer is showing 0 messages received and no data coming from TCP Socket)
<crystalmq>
Eventually, after about 30 seconds the OOM killer kills the app
<crystalmq>
so this leads me to believe the inputs are being buffered (as evidenced by the memory balloning)
<crystalmq>
But for some reason, the fiber with the 'output' isn't getting scheduled time
<RX14>
unshadow, that doesn't look like the same symptioms
<crystalmq>
@unshadow, doesn't look the same to me unfortunately
<crystalmq>
@RX14 the basic premise is that data is received on an input socket, and then is output to N number of clients on their already connected sockets (stored in an array of sockets)
<crystalmq>
Does that make sense? It's 1am here and I'm not sure if that makes sense to anyone but me
<FromGitter>
<sdogruyol> @fridgerator pg is now working with crystal-db
<unshadow>
@sdogruyol how can I get Gitter invite ?
<Papierkorb>
?
<FromGitter>
<sdogruyol> just login with your github acc
<FromGitter>
<sdogruyol> how's the crystal version compared to go?
<RX14>
yeah I got it now
<crystalmq>
@sdogruyol looks like the crystal version is faster
hako has joined #crystal-lang
<RX14>
well
<RX14>
this isn't optimized at all
<crystalmq>
@RX14 Totally agree with you there!
<crystalmq>
(The worst part is the spawn/loop/spawn/loop)
<RX14>
i'm really not sure what the problem is with crystal
<RX14>
when it locks up you should run perf on it
<crystalmq>
@RX14 - what perf tools would you recommend?
<RX14>
you want to build --debug --release
<crystalmq>
Ive literally been using crystal about a week :)
<crystalmq>
thanks for that.
<crystalmq>
I'll give that a go and let you know.
<RX14>
then after that
<RX14>
you want to use perf record -p pid
<RX14>
maybe adjust the sampling frequency with -F
<RX14>
that'll produce a perf file
<RX14>
which you can then use perf report on
<crystalmq>
@RX14 I'll take a look, thanks for all your help everyone.
<RX14>
no problem
cococoder_ has quit [Quit: Page closed]
<FromGitter>
<bcardiff> @sdogruyol @fridgerator be aware that `#query_all` allocates an array for all the result. Better use `#query` so you can stream one row at a time.
<FromGitter>
<sdogruyol> @bcardiff does query also accept the type with as: like queary_all ?
<FromGitter>
<bcardiff> `#query` returns a ResultSet. `ResultSet#read` takes *types as argument. So yes.
<FromGitter>
<sdogruyol> cool
<FromGitter>
<bcardiff> query_all is built on top of query
bmcginty has quit [Ping timeout: 258 seconds]
<FromGitter>
<bcardiff> In the following days we will probably focus on docs/guide for DB now that will/crystal-pg has join the party
<FromGitter>
<sdogruyol> yeah guess it's pretty much complete for a beta
<FromGitter>
<sdogruyol> and there's the pool already built in
bmcginty has joined #crystal-lang
<FromGitter>
<bcardiff> yeap. with many options that can be tweaked from the querystring of the connection string
<FromGitter>
<sdogruyol> i realized that after taking a look at the source
<FromGitter>
<sdogruyol> will there be a more intuitive way for configuration?
<FromGitter>
<sdogruyol> like a config object or something
<RX14>
I need transactions before switching though
<RX14>
I built my own transaction wrapper for the old crystal-pg
soveran has quit [Remote host closed the connection]
<RX14>
then named my savepoints using random numbers
<RX14>
although I probably could have used the counter
crystalmq has quit [Quit: Page closed]
<FromGitter>
<bcardiff> I see. Why random instead of incremental?
<RX14>
the savepoint syntax might be pg-specific though
<RX14>
because it was just easier at the time
<RX14>
random numbers are cheap anyway
<FromGitter>
<bcardiff> ok. Something you lack there is a state check. like what happens if the parent tx is rollback/commit and the inner transaction want's to continue doing something?
<RX14>
i'm not sure thats even possible
<RX14>
because it's savepoints you rollback to a specific place in the transaction
<FromGitter>
<bcardiff> if you always use nested block for transaction no, but if you keep object around you might reach that state.
<RX14>
they're not true nested transactions
<RX14>
well
<FromGitter>
<bcardiff> Yes, but you might end in an invalid state from the programmers perspective. Not the main story for sure.
<RX14>
actually i don't think it's so much of an issue if you keep the API simple
<RX14>
like you begin the transaction and subtransactions the same way
<FromGitter>
<bcardiff> But I will see if I can do nested transaction during the week. I didn't though someone was using them already.
<RX14>
well I said the code was a hack
<FromGitter>
<bcardiff> Yes, that would be the api idea.
<RX14>
but it works
<RX14>
like you can only push and pop transactions from a stack
<RX14>
and then you can't really get to an invalid state
<FromGitter>
<bcardiff> only ongoing transactions should be able to exec queries. upon commit/rollback tx the child transaction need to be marked as not-ongoing / closed . Not a big deal I want to provide better exception if possible.
<RX14>
well I wouldn't have multiple transaction objects, just keep the transaction state in the connection
<RX14>
then you don't have to worry about the bookkeeping
<RX14>
you just have 2 operations on connection: begin trasnaction and commit trasnaction
<RX14>
and all the bookkeeping is internal without transaction objects flying around
<RX14>
oh and rollback transaction obviously
<FromGitter>
<bcardiff> I don't want commit/rollback in connections. But let me think about the design for nested transaction. I just avoided until now.
<FromGitter>
<bcardiff> i've to go now. thanks for the intereset.
<RX14>
byte
<RX14>
bye*
<RX14>
heh
snsei has joined #crystal-lang
sp4rrow has joined #crystal-lang
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
soveran has quit [Ping timeout: 268 seconds]
pawnbox has joined #crystal-lang
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
vivus-ignis has quit [Ping timeout: 265 seconds]
soveran has quit [Remote host closed the connection]
<FromGitter>
<sdogruyol> @fridgerator are you going to switch to crystal-db for crecto?
<FromGitter>
<bararchy> What is the current "go to" web framework in Crystal ? I know Amethyst is kinda dead
<FromGitter>
<sdogruyol> i guess it's kemal @bararchy
<FromGitter>
<bararchy> (y)
<FromGitter>
<bararchy> cool , thanks :)
<FromGitter>
<bararchy> :+1:
<FromGitter>
<sdogruyol> :D
<FromGitter>
<bararchy> @sdogruyol What do you think about using #3672 for cryload ?
<FromGitter>
<sdogruyol> @bararchy havent thought of that :P
<FromGitter>
<bararchy> it could exec the cryload bin for each CPU core, I think maybe this way you can gain higher loads
<FromGitter>
<bararchy> It could also show us if the Libevent loop is the issue or sockets
<FromGitter>
<bararchy> as in Concurrent Connections
pawnbox has quit [Remote host closed the connection]
soveran has joined #crystal-lang
soveran has quit [Remote host closed the connection]
soveran has joined #crystal-lang
soveran has quit [Remote host closed the connection]
<FromGitter>
<fridgerator> @sdogruyol yes, thats my plan
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
<FromGitter>
<sdogruyol> @fridgerator great
soveran has quit [Remote host closed the connection]
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
soveran has joined #crystal-lang
snsei has quit [Remote host closed the connection]
bjz has joined #crystal-lang
<crystal-gh>
[crystal] dylandrop opened pull request #3673: Fixes #3547; as call with implicit receiver when invoked as a parameter to a method call (master...fix-3547) https://git.io/v1obU
soveran has quit [Remote host closed the connection]
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
ssvb has quit [Ping timeout: 265 seconds]
mgarciaisaia has joined #crystal-lang
<FromGitter>
<jots_twitter> How to do $x number of `HTTP::Client.get` requests concurrently and return when all have completed? https://play.crystal-lang.org/#/r/1fxu
<FromGitter>
<jots_twitter> thanks. I will have to read up on futures. first stab didn't work, program exits without printing any data: https://play.crystal-lang.org/#/r/1fy2
<BlaXpirit>
firejox, I only now noticed your suggestion "Maybe we can use Pointer.null to get type id". unfortunately, that doesn't work
<BlaXpirit>
I suspect that .crystal_type_id just reads the value at the pointer, but that's exactly the problem - we need to set the value ourselves
<BlaXpirit>
that gave me a different idea, and this workaround actually works https://carc.in/#/r/1fy8
<BlaXpirit>
or realloc could be a different workaround
<BlaXpirit>
if that's a thing
<BlaXpirit>
seriously though, when you think about it, overriding `allocate` is useless to userspace program, you literally have no way to correctly implement it
<BlaXpirit>
(other than silly workarounds)
<BlaXpirit>
sigh, even this doesn't save me though, because instance_sizeof(self) doesnt work
<FromGitter>
<fridgerator> @bcardiff , I'm working to change the adapter in Crecto to use crystal-db. I'm running into issues using `Time?` as a type in `DB.mapping` (`Nil assertion failed (Exception)`). I see in the roadmap in the readme `Time` is not yet supported, but I was curious if there was any workaround.
<Papierkorb>
fridgerator, um do Gitter users get highlighted this way or do I need the @?
<FromGitter>
<jots_twitter> thanks @Papierkorb! had the hash thing so that data is cached between requests. I will give this one a try.
<FromGitter>
<fridgerator> @Papierkorb I see my name as highlighted