<FromGitter>
<gettalong> So, I'm currently trying to do a proof of concept port of my Ruby PDF library HexaPDF to Crystal. While fleshing out the tokenizer class, I came across the fact that Crystal doesn't allow dynamic Symbol objects as Ruby does.PDF supports (binary) strings
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
<FromGitter>
<gettalong> PDF supports (binary) strings which I will probably represent as (String | Bytes) and so called "name" objects which work exactly like Symbol in Ruby (which is rather nice). In Crystal I'm currently a custom class that uses a StringPool, ie. `def initialize(str); @value = @@pool.get(str); end`, since it is not possible to subclass String. Has anyone done something similar to get "dynamic symbols" in Crystal? Is there a better
<FromGitter>
... way?
<FromGitter>
<domgetter> @gettalong What do you mean by "dynamic symbol"?
<FromGitter>
<fridgerator> like `"test".to_sym` ?
snsei has joined #crystal-lang
<FromGitter>
<gettalong> Yes, exactly.
snsei has quit [Remote host closed the connection]
<FromGitter>
<gettalong> In PDF hashes can only have PDF names as keys. This translates nicely to Ruby, i.e. `{key: "value"}`. However, in Crystal I currently need to write something like `{HexaPDF::Name["key"] => "value"}`.
<FromGitter>
<fridgerator> are the keys known at compile time?
<FromGitter>
<fridgerator> or is user input?
<FromGitter>
<gettalong> They come from the PDF file itself. Most keys are the same for all PDFs but there are also some PDF file specific ones.
<FromGitter>
<gettalong> The simplest thing would be using Symbol but that would only work if they could be created dynamically. So that won't work. Strings would have been my next choice but since PDF also has the notion of strings, there would be the problem of differentiating between strings and PDF names. That left me with the custom class as described before.
<FromGitter>
<fridgerator> hrmm
<FromGitter>
<fridgerator> good question man, i'm not sure
<FromGitter>
<gettalong> Me neither but I've only been working with Crystal for a short time
<FromGitter>
<gettalong> I think I will go with the current solution for the time being and see how it goes when more of the code is ported
Ven` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
vikaton has quit [Quit: Connection closed for inactivity]
fenicks has left #crystal-lang [#crystal-lang]
<FromGitter>
<domgetter> Is there a way to define a new type like this: Tweet = NamedTuple(username: String, content: String)
<FromGitter>
<domgetter> So that in procs, I don't have to put the NamedTuple type all over the place?
<foobarfighter>
hey all... considering crystal. anybody here using it in production?
<foobarfighter>
in early stages of exploration
<FromGitter>
<bew> There are a few, yes, but as the language is still not 1.0 yet, not much currently
<FromGitter>
<bew> I've heard that it works well and is stable enough
<FromGitter>
<bew> But as the language evolve, you may need to rewrite some parts of your application
<foobarfighter>
thanks bew
<foobarfighter>
looks very promising
<foobarfighter>
really like the ruby-ish syntax
<FromGitter>
<bew> Yeah :) soo clean
<foobarfighter>
ive worked on some very big ruby projects... rails based. switched over to python for the last couple of years. one of the issues that i had with ruby/rails back then was the loader
<foobarfighter>
is the compiler for crystal fast? or is this going to be the new autoloader
<foobarfighter>
?
<FromGitter>
<bew> It is quite fast, the current biggest known project is the compiler itself, and it takes less than 30s to compile (in debug mode)
<FromGitter>
<bew> However it takes forever to compile to release mode (with full optimization): around 20min..
<FromGitter>
<bew> Before 1.
<FromGitter>
<bew> Oops
<foobarfighter>
whats the most prominent crystal lang deployment right now?
<FromGitter>
<bew> Before 1.0 we aim to allow incremental compilation, so we don't have to recompile everything everytime but it's a hard task
<vegai>
those are not Crystal projects, just wanted to point out that the creators of the language are involved in real projects
<foobarfighter>
gotcha
<vegai>
sounds like a cool company, really :P
<foobarfighter>
yeah it really does
<vegai>
if I'd want to move to Brazil, I'd certainly consider them as an employer or partner :)
<Yxhuvud>
.. I thought they were from Argentina
<foobarfighter>
watched a talk on crystal earlier. the ideas are really great.
<vegai>
Yxhuvud: oops, sorry! My bad
<vegai>
yes, Argentina
<vegai>
Buenos Aires
<vegai>
I was thinking of Rio de Janeiro for some reason
<foobarfighter>
argentina is a hotbed of great tech talent. brazil too probably. i am very new to this whole community but i would not criticize anybody looking in that area.
<vegai>
<politics>With the US slowly imploding, I bet south america will have great opportunities in the future</politics>
<foobarfighter>
i agree. in the us :)
<vegai>
heh. Well. I don't know
<foobarfighter>
really wish somebody big had deployed already on crystal. would make this decision a lot easier.
<vegai>
what are you trying to decide?
<FromGitter>
<domgetter> foobarfighter: Do you have a link to that talk?
<foobarfighter>
for context... i've recently left my job. going out on my own and researching the possibility of a new stack.
<foobarfighter>
i was actually a rails contributor at one point... really like ruby but ive been away from it
<vegai>
you'll probably be better off starting with Crystal right now than you would be if you waited to make a perfect choice
<foobarfighter>
lolz... thanks vegai
<vegai>
even if it would fail and you'd have to rewrite later
<FromGitter>
<domgetter> Yes, don't think about it, just switch over :)
<vegai>
rewrites are way easier than analysis paralysis, imho
<foobarfighter>
its a little more nuanced than that but sure... i agree with ur general premise which i assume to be... just pick something and stop fucking around
<vegai>
yea :)
<vegai>
although.... don't pick PHP
<vegai>
:P
<foobarfighter>
omg php
<foobarfighter>
the scars
<vegai>
yeah, me too
<foobarfighter>
if you had to compare the maturity around crystal against the maturity of nodejs for example. where would you place it?
<foobarfighter>
are we still in the ryan dahl stages>
<foobarfighter>
?
<foobarfighter>
and thats not a knock on ryan... just that when he was running things it was still very early
<foobarfighter>
there were a few experimenters and a lot of hype... but it wasnt production-ready IMO
<foobarfighter>
and at this point nodejs is production ready
<vegai>
well... 0.21
<foobarfighter>
so basically no
<vegai>
I wish I could answer that better, but so far I cannot
<foobarfighter>
understood
<vegai>
the manastech people are sleeping now, hopefully
<vegai>
you should probably ask them too
<foobarfighter>
basically you would test it but you wouldnt bet the farm on it yet
<vegai>
I think I would make a bet on it myself
<foobarfighter>
ok good to know
<vegai>
as another data point, which might be interesting
<vegai>
the compiler has about 130k LOC. There are about 93k LOC of specs
<vegai>
which seems to me like a fine ratio
<foobarfighter>
test coverage is important
<foobarfighter>
whatever language im using better work tho... kind of the price of entry for this sort of thing wouldnt u agree?
<vegai>
huh, never looked at Argentina before seriously. It looks like a fine place to live
<foobarfighter>
lol
<vegai>
sure
<foobarfighter>
im sure it is
<foobarfighter>
are u US based?
<vegai>
Finland
<foobarfighter>
oh cool
Raimondii has joined #crystal-lang
olek_poz has joined #crystal-lang
<foobarfighter>
thanks vegai... bed time for me :)
Raimondi has quit [Ping timeout: 268 seconds]
Raimondii is now known as Raimondi
<vegai>
nightie night :)
foobarfighter has quit []
Qchmqs has joined #crystal-lang
blufor has quit [Ping timeout: 256 seconds]
<FromGitter>
<sdogruyol> @foobarfighter there are already production users and some are doing serious stuff like we do payment process
<FromGitter>
<sdogruyol> And Crystal is much more mature than node back in the Ryan days
<FromGitter>
<sdogruyol> Actually Crystal is just awesome waiting for prime time :) No hypes, just awesomeness here
<FromGitter>
<KCreate> Hey is it somehow possble to check methods@that are never called for semantic errors?
<FromGitter>
<KCreate> ups, didn't mean the "@"
<FromGitter>
<bew> @KCreate maybe by redefining the method to raise on call? (that's not a good solution imho)
<RX14>
@KCreate how do you mean?
<RX14>
If a method is never called, it can't be error checked
<RX14>
you can call it in a typeof() which means it won't be run
<RX14>
but you still have to call it with some arguments
<FromGitter>
<KCreate> The main use case would be to check for undefined methods
<RX14>
well,
<RX14>
well, as I said, you can always use the typeof trick
<FromGitter>
<KCreate> But that would require knowing which methods are never called
<FromGitter>
<KCreate> I'm currently working on this (https://github.com/crystal-lang/crystal/issues/4223) and thought that there are maybe other methods in the stdlib that are never called and have errors in them
<FromGitter>
<KCreate> (from the spec i mean)
<FromGitter>
<bew> See #3801, in the last comment, @bcardiff links to a project that does what you want i think
<kodo[m]>
> When a database is opened with crystal-db there is already a connection pool working. DB.open returns a DB::Database object which manages the whole connection pool and not just a single connection.
<kodo[m]>
Interesting
<jhass>
yup, so just do CONNECTION = DB.open "..." and you're good
qchmqs_ has quit [Client Quit]
Qchmqs has joined #crystal-lang
<kodo[m]>
ah do you make connection as global ok, I was doing that at one point but wasn't sure that was the right paradigm. thanks
<kodo[m]>
What happend if I do it that way and don't close connection before program exits?
<jhass>
worst case the kernel will close out any left open FDs of the program
<jhass>
if no finalizer/at_exit hook catches it
<kodo[m]>
So why even say to close it?
<kodo[m]>
Like what are the programs that people are worried about?
<kodo[m]>
problems
<jhass>
say you write a program that connects to lots of DBs for a short or medium amount of time, in some kind of loop maybe so you'd even reconnect to the same one but forgot bout it
<jhass>
you'd run out of FDs for your process soon enough
<jhass>
it's also just a general way of being clean, if you dispose of stuff as soon as you don't need it you won't forget to do it and will have more resources for other stuff directly afterwards
<jhass>
but if the program needds one (pool) of connections to something for its entire lifetime, I wouldn't bother
<jhass>
when it comes to files its different, I think not all kernels guarantee to flush when they close it for you
<kodo[m]>
K. thanks
Ven_ has quit [Ping timeout: 260 seconds]
Ven has joined #crystal-lang
Ven is now known as Guest20500
Guest20500 has quit [Ping timeout: 260 seconds]
Ven_ has joined #crystal-lang
<kodo[m]>
Is there a way to check if a variable exists?
<Papierkorb>
no, that doesn't make much sense in Crystal
<jhass>
how can you be uncertain?
Ven_ has quit [Ping timeout: 260 seconds]
<kodo[m]>
I have a shared template, some variables in one place and not others, maybe I just use an instance var since it gets initialzed as nil
<kodo[m]>
can't use instance variables at top level, heh nevermind
Ven_ has joined #crystal-lang
<jhass>
just make a class for the template then, better anyway ;)
<kodo[m]>
better as in I just be making templates as classes anyway?
<kodo[m]>
should be*
<jhass>
yeah that's how it's intended to be used
<jhass>
so you just say Foo.new(data, data, data).to_s
<kodo[m]>
ok
<kodo[m]>
Good to know
Ven_ has quit [Ping timeout: 260 seconds]
Ven_ has joined #crystal-lang
Ven_ has quit [Read error: Connection reset by peer]
Ven_ has joined #crystal-lang
<kodo[m]>
weird. in my template if I do <% if @some_var %> and then in the conditional if i do @some_var[:thing] it complains because type as defined as union Nil
<kodo[m]>
you would think the compiler would figure out it was non nil since I explictly checked
<kodo[m]>
is defined as*
<jhass>
kodo[m]: no you have to assign it to a local first
<jhass>
instance variables don't reduce their type in ifs since in theory they can be concurrently modified between threads
<kodo[m]>
what's the best way to do that in a template? <% foo = @foo.as(Hash) %> ?
<jhass>
another way (which bypasses the compiler check) is to do getter! some_var and then if some_var?; some_va[:thing]
<jhass>
you can even do it in the if
<jhass>
<% if some_var = @some_var %>
olek_poz has quit [Ping timeout: 260 seconds]
<kodo[m]>
Doesn't work for this case though `<% current_user = @current_user.as(User) %>`
<kodo[m]>
doh wrong paste
<kodo[m]>
`<% if @current_user && current_post = @current_post %>`
<jhass>
just skip the first part
<jhass>
nil is falsy
<jhass>
the value of an assignment is the RHS
<kodo[m]>
ah so current_post = @current_user && @current_post
zaiste has joined #crystal-lang
<kodo[m]>
although I want to set current_user as local also
<jhass>
why do you want to && something so badly ;)
<kodo[m]>
i want to make sure current user and current post are set
<FromGitter>
<domgetter> RX14: So after digging through the crystal-pg source in my lib folder, I got it to spit out the message from postgres, which is "message: password authentication failed for user "postgres""
<RX14>
well
<RX14>
looks like you're running the biunary from a different user account than the postgres CLI
<RX14>
the postgres CLI can skip password auth if you're the correct user account
<FromGitter>
<domgetter> RX14: Got it. I set the postgres config to "trust" for auth.
<RX14>
why not just provide a password?
<FromGitter>
<domgetter> The docs don't say how to do that.
bjz has quit [Read error: Connection reset by peer]
bjz has joined #crystal-lang
<FromGitter>
<jwoertink> I'm having an issue with an instance variable saying that it wasn't not initialized in all of the initialize methods, but the only place I reference it is in an initialize method
<FromGitter>
<jwoertink> I can't re-create the issue outside of my project, so I'm obvisouly doing something weird, I just don't know what
<FromGitter>
<jwoertink> any ideas of what I could look for?
<FromGitter>
<drosehn> If it's an instance variable which is referenced only in a single `initialize` method, then why not have it a variable which is local to that method?
<FromGitter>
<jwoertink> I need to be able to access it in other methods
<FromGitter>
<jwoertink> I can add other instance variables with primitive types in to that initialize, and they're fine. If I do a super simple example outside of this project it's fine. Just seems to be this setup specifically that doesn't work
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
Guest53848 has joined #crystal-lang
<FromGitter>
<jwoertink> ok, so if I define it as `@current_screen : TitleScreen` and then just call `not_nil!` before every method, then it works...
Guest53848 has quit [Quit: ZNC 1.6.4 - http://znc.in]
<FromGitter>
<jwoertink> oh, I know what's going on. The error message is deceiving because the stack mentions this, but it has nothing to do with any of this code
<FromGitter>
<jwoertink> Alright, so now for a new question
<FromGitter>
<jwoertink> I have this method `Window.new.show`. In the show method I create a new instance of this one object. I need this object to exist before I can instantiate my `TitleScreen` object.
<FromGitter>
<jwoertink> What's the best way to create a new instance of something later on in a program, but not instantiate it in initialize?
<FromGitter>
<jwoertink> or do I just make it nilable and do `@thing = nil` in initialize, but set it after?