ChanServ changed the topic of #crystal-lang to: The Crystal programming language | | Crystal 0.21.1 | Fund Crystal's development: | Paste > 3 lines of text to | GH: | Docs: | API: | Logs:
Guest36204 is now known as Ven`
<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?
<FromGitter> <domgetter> oh, that just works
<FromGitter> <fridgerator> lol :thumbsup:
olek_poz has joined #crystal-lang
olek_poz has quit [Ping timeout: 258 seconds]
madgoat has joined #crystal-lang
madgoat has left #crystal-lang [#crystal-lang]
leex has quit [Ping timeout: 260 seconds]
leex has joined #crystal-lang
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
unshadow has joined #crystal-lang
foobarfighter has joined #crystal-lang
<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
<foobarfighter> bew are you a core dev on crystal?
foobarfi_ has joined #crystal-lang
foobarfi_ is now known as foobarfighter_
<foobarfighter> lol...swtiching from web based to native. oh irc :)
foobarfighter has quit [Quit: Page closed]
foobarfighter_ is now known as foobarfighter
<foobarfighter> vegai: so nobody using this for a production app?
<vegai> I don't know of any
<foobarfighter> good data point.... thanks vegai
<foobarfighter> im not against trying something new... would just like to know how many times im going to hit growing pains
<vegai> yes
<foobarfighter> is that a frequent occurrence?
<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
<foobarfighter> @domgetter... one sec
<vegai> be wary of foobarfighter :)
<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 ( 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
<DeBot> (Dead code in crystal sources)
<FromGitter> <bew> Oh no miss understood again...
<FromGitter> <bew> You want undefined methods or uncalled methods?
<FromGitter> <bew> @KCreate
<FromGitter> <KCreate> Undefined methods was what I originally thought about, but having a list of uncalled methods might help
_whitelogger has joined #crystal-lang
Ven has joined #crystal-lang
Ven is now known as Guest92517
danielpclark has joined #crystal-lang
<crystal-gh> [crystal] KCreate opened pull request #4229: Fix #4223: Fixed undefined method Math.gamma (master...fix-missing-methods-libm)
splitty_ has quit [Ping timeout: 240 seconds]
Guest92517 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
danielpclark has quit [Quit: Leaving]
unshadow has quit [Ping timeout: 240 seconds]
unshadow has joined #crystal-lang
Ven has joined #crystal-lang
Ven is now known as Guest99962
unshadow has quit [Ping timeout: 240 seconds]
unshadow has joined #crystal-lang
splitty_ has joined #crystal-lang
unshadow has quit [Client Quit]
Guest99962 has quit [Ping timeout: 240 seconds]
Ven_ has joined #crystal-lang
Ven_ has quit [Ping timeout: 268 seconds]
Ven_ has joined #crystal-lang
zaiste has joined #crystal-lang
Ven_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Ven has joined #crystal-lang
Ven is now known as Guest83349
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
zaiste has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Guest83349 has quit [Ping timeout: 256 seconds]
Ven_ has joined #crystal-lang
<kodo[m]> Am I supposed to do ` ENV["DATABASE_URL"] do |db|` for each time I query database?
<kodo[m]> or should I only be using one connection and sharing it using some paradigm
<FromGitter> <sdogruyol> no you can use a pool
<kodo[m]> I don't see an actual query in pool spec... at least not that I can tell
qchmqs_ has joined #crystal-lang
Qchmqs has quit [Ping timeout: 268 seconds]
<kodo[m]> > When a database is opened with crystal-db there is already a connection pool working. 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 = "..." 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, 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 = %> ?
<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 = %>`
<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
<jhass> oh, I wasn't reading properly, sorry
<jhass> this seems to work
<kodo[m]> Nice that works, thanks
<kodo[m]> when in doubt just add more parens
Qchmqs has quit [Ping timeout: 258 seconds]
<FromGitter> <sdogruyol> @domgetter ah ok i just seen this
Ven_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<crystal-gh> [crystal] ysbaddaden opened pull request #4230: Std fix openssl 110 (master...std-fix-openssl-110)
<FromGitter> <sdogruyol> hey @jhass long time no see, how are you doing?
<jhass> fine fine :)
<FromGitter> <sdogruyol> so you got a full time job?
<RX14> jhass, i'm glad you seem to have a bit more time these days
<FromGitter> <sdogruyol> same here
<jhass> yuo
<jhass> *yup
<FromGitter> <sdogruyol> it's great to have great people around :P
<FromGitter> <domgetter> @sdogruyol oh awesome, I didn't know people would've seen it by now
zaiste has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<RX14> hmm
<RX14> would be interesting to get an email of all new github repositories which were mainly crystal
<Yxhuvud> someone is clearly watching them as someone in here noticed when I created some very much not done stuff for sharing with myself :P
<FromGitter> <bew> does someone tried to compile a crystal program for AVR architecture ?
<FromGitter> <sdogruyol> guess there are some people watching
<kodo[m]> why does twitter api have to be so kafkaesque
<kodo[m]> TIL OAuth built into stdlib
<kodo[m]> How do people get id of last inserted record?
<kodo[m]> n/m
<FromGitter> <domgetter> Are there any tutorials for connecting to a postgresql database with Crystal?
<RX14> the README and the crystal-db README should eb enough
<FromGitter> <domgetter> RX14: You wouldn't happen to know why I'm getting DB::ConnectionRefused, would you?
<RX14> there's no password?
<kodo[m]> The death star is operational
<FromGitter> <domgetter> RX14: according to you don't put in a password for postgres?
<FromGitter> <domgetter> "Other connection uris are `postgres://server:port/database`"
<RX14> depends if you have a password or not...
<RX14> if you put in a password in the commandline
<RX14> you add one to the UR:
<RX14> you add one to the URL
<FromGitter> <domgetter> I didn't put in a password when I ran the `psql` command I showed in the gist
<RX14> ok
<RX14> well it should work then
<RX14> try taking the port off?
<RX14> i can't see any ohter reason
<FromGitter> <domgetter> Still saying connection refused
<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.
<FromGitter> <domgetter> That is, this one:
<RX14> it's just standard url syntax...
<RX14> protocol://user:password@hostname:port/path?query
<FromGitter> <domgetter> And I don't know the standard
<RX14> except the protocol is postgres
<FromGitter> <domgetter> It would be nice if the docs were clear on that for people who don't know
<RX14> it's in the postgres docs too
<RX14> might be worth linking to that
<FromGitter> <sdogruyol> @kodo[m] why dark crystal
fenicks has joined #crystal-lang
olek_poz has joined #crystal-lang
<kodo[m]> sdogruyol: i dunno because crystal's colour scheme is black and white and I like
<kodo[m]> I was gonna call it Crystal Status, but Dark Crystal sounded cooler
olek_poz has quit [Read error: Connection reset by peer]
<RX14> i like dark crystal
endou has joined #crystal-lang
<FromGitter> <KCreate> what about crystalwatch?
endou has quit [Read error: Connection reset by peer]
bjz has joined #crystal-lang
<kodo[m]> CrystalWatch is cool too
<kodo[m]> Created a ticket for a new name
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 -]
<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 ``. 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?
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 268 seconds]
Raimondii is now known as Raimondi
danielpclark has joined #crystal-lang