jhass changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.18.7 | Fund Crystals development: http://is.gd/X7PRtI | Paste > 3 lines of text to https://gist.github.com | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Logs: http://irclog.whitequark.org/crystal-lang
Oliphaunte has quit []
mkl0501 has quit [Quit: http://www.kiwiirc.com/ - A hand crafted IRC client]
mkl0501 has joined #crystal-lang
mkl0501 has quit [Client Quit]
Philpax has joined #crystal-lang
Philpax has quit [Ping timeout: 240 seconds]
Dreamer3 has quit [Quit: Leaving...]
jwaldrip has quit [Quit: Connection closed for inactivity]
pawnbox has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
onethirtyfive has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
Kkkk has joined #crystal-lang
Kkkk has quit [Client Quit]
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
tomchapi_ has joined #crystal-lang
tomchapi_ has quit [Client Quit]
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 240 seconds]
Raimondii is now known as Raimondi
<FromGitter> <sdogruyol> morning all
am_ has joined #crystal-lang
<FromGitter> <alex-lairan> morning @sdogruyol :)
pawnbox has quit [Ping timeout: 250 seconds]
toydestroyer has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
toydestroyer has joined #crystal-lang
am_ has quit [Ping timeout: 250 seconds]
am__ has joined #crystal-lang
pawnbox has quit [Ping timeout: 250 seconds]
mkl0501 has joined #crystal-lang
alanwillms has joined #crystal-lang
mkl0501 has quit [Quit: http://www.kiwiirc.com/ - A hand crafted IRC client]
alanwillms has quit [Quit: Saindo]
mkl0501 has joined #crystal-lang
ponga has joined #crystal-lang
mkl0501 has quit [Quit: http://www.kiwiirc.com/ - A hand crafted IRC client]
pawnbox has joined #crystal-lang
Philpax has joined #crystal-lang
Philpax_ has joined #crystal-lang
Philpax has quit [Ping timeout: 258 seconds]
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
<FromGitter> <sdogruyol> i'm curious if it's the best practice to specify the types of all method arguments
<FromGitter> <alex-lairan> imo, when I can specify, I specify
<FromGitter> <alex-lairan> ^.^ It's more secure for data
<RX14> i rarely specify unless i need overloads, or instance vars
<RX14> duck typing is good
<FromGitter> <sdogruyol> hmm i see
<FromGitter> <sdogruyol> i tried specifying types on everything at Kemal
<FromGitter> <sdogruyol> and the specs are failing, not sure if it's bug
<FromGitter> <sdogruyol> lol
<FromGitter> <alex-lairan> But, how to be sure to have a string on input?
<FromGitter> <alex-lairan> (example)
<FromGitter> <alex-lairan> or, you have created a node object, you want an array of node
<FromGitter> <sdogruyol> sorry, but i dont get what you mean
<RX14> just trust the caller really
<RX14> if it conforms to the method signature
<FromGitter> <sdogruyol> haha
<FromGitter> <sdogruyol> yeah makes sense
<RX14> i mean if they stick the wrong type in it will usually not compile
<RX14> if they know what they are doing they can stick in a type that looks like a string but isnt
<RX14> which is one of the great things about duck typing
<RX14> mocking is super duper easy
<FromGitter> <sdogruyol> yeah that's why Ruby is great
<FromGitter> <alex-lairan> I never trust users of my class :p
<FromGitter> <sdogruyol> trust the compiler then :P
<FromGitter> <alex-lairan> If I can protect it to have a specific comportment, I do it :)
<FromGitter> <alex-lairan> Yea, Crystal a bit different of Ruby thank his compiler :)
<RX14> specifying type signatures is something i only really do if I need to
<RX14> i don't see the point if the compiler can do the work for me
<FromGitter> <alex-lairan> (I'm C++ dev, and philosophy is, never trust others developers) ^.^
<FromGitter> <sdogruyol> yeah i can understand that coming from cpp
<FromGitter> <sdogruyol> more safety oriented
<RX14> more like users have to do the safety instead of the cmpiler
<RX14> anyway, i would suggest trusting your users more
<RX14> type signatures are more effort for little, if any gain
<FromGitter> <alex-lairan> yes, I try on Ruby and Crystal :)
<RX14> of course you need them on ivars and overloads
<FromGitter> <alex-lairan> guy's, I have a problem with yaml::any type :/
<FromGitter> <alex-lairan> I have my yaml file like that: ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=57af3d460fd99f7041381e2f]
<FromGitter> <alex-lairan> as you can see, emails doesn't have `collection_actions` and `resource_actions`
<FromGitter> <alex-lairan> And `YAML::any` type don't have `has_key?` method :/
DeBot has joined #crystal-lang
<RX14> you'll want to assert that each member of collections is a hash, then use has_key there
<FromGitter> <alex-lairan> How I can loop on `collections` elements with verify presence or not of `collection_actions` and `resource_actions`
<RX14> do a collecctions.each then use as_h on the members
Raimondii has joined #crystal-lang
<RX14> then you've got a hash that you ca use has_key? on
<FromGitter> <alex-lairan> Ok thank I try this :)
<FromGitter> <alex-lairan> I've panic because YAML::any don't have `to_h` or `to_hash` ^.^
<FromGitter> <alex-lairan> Thank it's work good now :)
<RX14> yes it's as_h on yaml::any
<RX14> because it performs an assertion
<RX14> whereas to_h implies it'll always work
<FromGitter> <alex-lairan> Ok ;)
Raimondi has quit [Ping timeout: 250 seconds]
Raimondii is now known as Raimondi
pawnbox has joined #crystal-lang
<FromGitter> <alex-lairan> On Crystal code, I see many methods specify types :) https://github.com/crystal-lang/crystal/blob/68783f1ebdd5b9bbefc8892ddbc200fe1f13bbea/src/yaml/any.cr#L159
<FromGitter> <alex-lairan> An return types too :D
<jhass> yes, for more readable standard library docs
<jhass> that's the main reason
<FromGitter> <alex-lairan> Auto generated docs :)
Philpax_ has quit [Ping timeout: 250 seconds]
<FromGitter> <alex-lairan> What is your tool ?
<jhass> crystal doc
<FromGitter> <alex-lairan> OMFG Awesome
<RX14> yeah specifying return types is something i do quite a lot
<RX14> although i wish crystal doc did basic type inference to tell return types if possible
steenuil has quit [Ping timeout: 250 seconds]
steenuil has joined #crystal-lang
<crystal-gh> [crystal] TheLonelyGhost opened pull request #3150: Checks if cookies is empty before adding to header (master...empty-cookies-should-not-set-cookie-header) https://git.io/v6u1o
am__ has quit [Ping timeout: 276 seconds]
snsei has joined #crystal-lang
steenuil has quit [Ping timeout: 276 seconds]
steenuil has joined #crystal-lang
snsei has quit [Remote host closed the connection]
libman has joined #crystal-lang
onethirtyfive has quit [Remote host closed the connection]
pawnbox has quit [Remote host closed the connection]
<FromGitter> <sdogruyol> ha
Philpax_ has joined #crystal-lang
libman has quit [Quit: Leaving.]
ponga has quit [Quit: Connection closed for inactivity]
Philpax has joined #crystal-lang
Philpax_ has quit [Ping timeout: 250 seconds]
<FromGitter> <crisward> Anyone have experience with crytsal-db / mysql?
<FromGitter> <crisward> Trying to get data from a text field and it's returning a `Slice(UInt8)`
<FromGitter> <crisward> not sure what that is or how to convert to text
<BlaXpirit> crisward, are you sure it's a text field? is it unicode?
<tilpner> crisward - Returning? Doesn't crystal-db allow you to choose the type via rs.read(Type)?
<tilpner> (I've only used the sqlite3 version, perhaps there are differences)
<FromGitter> <crisward> yes it's unicode
<BlaXpirit> well worst case you can use String.new(bytes : Slice(UInt8), encoding : String)
<FromGitter> <crisward> I'm using DB.mapping(), I set the type to string and it throws
<FromGitter> <crisward> I'll try an implement your suggestion
<BlaXpirit> crisward, i implied that it is suboptimal
<BlaXpirit> havent worked with DBs in crystal, dont know a proper solution
<FromGitter> <crisward> Ah, ok. Can't help thinking the driver should do this and I'm using it wrong.
<FromGitter> <crisward> String.new works, no need to set encoding for UTF8 it would seem
<BlaXpirit> hold up... when json contains an integer and I do .as_f, it doesn't let me???
<BlaXpirit> what am i supposed to do
jeromegn has quit [Ping timeout: 276 seconds]
jeromegn has joined #crystal-lang
<BlaXpirit> this is quite ugly, looking for tips to improve https://carc.in/#/r/171q
<FromGitter> <crisward> can you not use json mapping? (btw I'm no expert)
<BlaXpirit> this json has all possible reasons why it can't work with mapping xD
<FromGitter> <crisward> if it's just neatness wouldn't a switch statement, with a separate toNumber method look a bit cleaner?
<BlaXpirit> switch statement?
<BlaXpirit> i get that you mean case but i don't think it applies
<FromGitter> <crisward> sorry, case, not a ruby programmer, more js/coffee
<BlaXpirit> sigh, can't cast Hash(String, JSON::Type) to Hash(String, Float64 | Int32)
<BlaXpirit> got it - https://carc.in/#/r/171r - actually a good idea with case statement, thanks
<BlaXpirit> this gives me an idea - `value.as Number` should be equivalent to `value = value.as Number`
<FromGitter> <crisward> looks much better