ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.24.2 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
<FromGitter> <eliasjpr> @straight-shoota can you point me to the PRs I am interested in learning more
<FromGitter> <eliasjpr> Mode the HTTP improvements
<FromGitter> <eliasjpr> I personally would like to see improvements on the crystal database drivers
qard has joined #crystal-lang
<FromGitter> <eliasjpr> Nvm just found the Pr
qard has quit [Quit: qard]
qard has joined #crystal-lang
qard has quit [Ping timeout: 256 seconds]
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
Yxhuvud has quit [Client Quit]
Yxhuvud has joined #crystal-lang
qard has joined #crystal-lang
<FromGitter> <girng> https://play.crystal-lang.org/#/r/3w7g/edit is it possible to add this NamedTuple to the array, even if it doesn't have the `equipped` key?
<FromGitter> <girng> reason i ask is because some characters don't have any items equipped, and i don't want to send the equipped key with the namedtuple over the network
<FromGitter> <bew> Don't use NamedTuple that way, use a struct (it's roughly the same thing memory and performance wise, and it's more flexible
<FromGitter> <bew> Or even a class, I don't you should try to over optimize things that way
<FromGitter> <bew> Don't *think
<FromGitter> <girng> ok. i'll just send over the key "equipped", i worry about bandwidth/optimize things l8er
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
<FromGitter> <girng> how can i create my own type
<FromGitter> <girng> i am getting really annoying writing Hash(String, Int32) all over the place
<FromGitter> <bew> Alias?
<FromGitter> <girng> ty
<FromGitter> <bew> And what do you mean by "all over the place"?
<FromGitter> <girng> for example, equipped has to have Hash(String, Int32) here: https://i.gyazo.com/a0fcea7bbfb884851af6c865c548dc0d.png ⏎ ⏎ but i already defined it here: https://i.gyazo.com/7964f9511a3efa9cdea1bfb199603743.png ⏎ ⏎ and i already freaking set it here: https://i.gyazo.com/e0e4cc52c6fb9f88cf561d2a917d9e40.png [https://gitter.im/crystal-lang/crystal?at=5ad6a8056bbe1d2739f9affb]
<FromGitter> <girng> i will create alias of "EQ_TYPE"
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
DTZUZO has quit [Ping timeout: 240 seconds]
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
illy_ has joined #crystal-lang
Yxhuvud has joined #crystal-lang
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
DTZUZO has joined #crystal-lang
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
That_Guy_Anon has joined #crystal-lang
<FromGitter> <bararchy> @girng alias MyType = Hash....
<FromGitter> <bararchy> It helps for long type name
<FromGitter> <girng> im going to make a headers.cr file (similar to headers.h) in c++
<FromGitter> <girng> put ALL MY types n stuff in there
<FromGitter> <girng> aliases, etc
<FromGitter> <schoening> Just so I am sure I understood this once and for all: ⏎ if @a.is_a?(String) cannot be guranteed because it is a getter and I could have some weird getter that returns a string on first call and then only numbers. Thats the idea right? And if (a = @a).is_a?(String) is, as a value ok since it no longer is a getter. Correct?
That_Guy_Anon has quit [Ping timeout: 240 seconds]
<FromGitter> <bararchy> Basically `@a` is an instance var, which means it can be changes anywhere in the class
qard has quit [Ping timeout: 256 seconds]
<FromGitter> <bew> @schoening note: `@a` is not a method call (a getter), but the logic is the same as what you explained
<oprypin> schoening, no, this is not a getter, just an instance variable. this is a precaution against a different execution thread possibly changing the value in the background
<oprypin> local variables don't get shared between threads
rohitpaulk has joined #crystal-lang
That_Guy_Anon has joined #crystal-lang
alex`` has joined #crystal-lang
alex`` has quit [Ping timeout: 246 seconds]
<FromGitter> <bararchy> @girng looking at the code you posted, I would create a Account or User class with all relevant data in it, it seems too complex to be a Tuple (in the sense it's hard to manage this way, and hard to scale up if needed)
That_Guy_Anon has quit [Ping timeout: 276 seconds]
That_Guy_Anon has joined #crystal-lang
That_Guy_Anon has quit [Client Quit]
<FromGitter> <bararchy> not sure why but working in Crystal make you susceptible to Hash\Tuple abuse, I've seen many people do this instead of using Class\Struct (even me)
thews has quit [Ping timeout: 264 seconds]
<FromGitter> <codem4ster> Hi folks, I have a question ⏎ why this must give compile time nil error ⏎ ⏎ ```some_string : String? ⏎ ⏎ # codes here ⏎ ⏎ some_string.split if some_string``` [https://gitter.im/crystal-lang/crystal?at=5ad6f4e85d7286b43a3eb0ec]
<FromGitter> <codem4ster> couldn't the compiler understand that some_string cannot be able to be nil
thews has joined #crystal-lang
thews has quit [Changing host]
thews has joined #crystal-lang
<FromGitter> <bararchy> @codem4ster is this the real code example? could some_string be actually `@some_string` in your actual code?
<FromGitter> <epergo> @codem4ster it should work, https://carc.in/#/r/3w9j
<FromGitter> <codem4ster> sorry, I mean this ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ad6f72527c509a77423aa98]
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter> <codem4ster> and another thing; if this is a rule, why the local variables behave different than instance variables? This is very confusing.
<FromGitter> <epergo> I think it doesn't work because the compiler doesn't really know if between the check and the actual split has been another method call or whatever that changed the instance variable some_string to nil
<FromGitter> <epergo> if you extract the value to an auxiliary variable and do the condition on it, works
<FromGitter> <bararchy> @codem4ster If you look 4-5 lines above your original question you would see the answer to your question :) ⏎ for the sake of pushing the nail even further ⏎ ⏎ `@var` means an instance variable ⏎ ... [https://gitter.im/crystal-lang/crystal?at=5ad6f94c109bb04332d42264]
<FromGitter> <bararchy> so @codem4ster you can do ⏎ ⏎ ```def test ⏎ if (some_string = @some_string) ⏎ some_string.split ⏎ end ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5ad6f99b15c9b031140b7e94]
<FromGitter> <codem4ster> This is easier I think; ⏎ ⏎ ```@some_string.as(String).split if @some_string``` ⏎ ⏎ But that is not the case. Crystal has concurrency not parallelism, it has Fibers not Threads, it uses a scheduler. So this 'if' line is a blocking operation and there is no way to go through split and if even it was threaded. [https://gitter.im/crystal-lang/crystal?at=5ad6fab96d7e07082b07cde6]
<FromGitter> <codem4ster> So there is no way to change the value of the @some_string between if and split.
<FromGitter> <straight-shoota> Crystal doesn't actually support parallelism yet, but it is designed for it.
<FromGitter> <straight-shoota> So yes, it probably won't be a problem with the current state of concurrency. But it wouldn't be such a great idea if the language needed to be changed once parallelism arrives, would it?
<FromGitter> <ezrast> Even without parallelism, the type of `@some_string` would still only be guaranteed up until the first method call inside the conditional body.
<FromGitter> <codem4ster> ok I understand
rohitpaulk has joined #crystal-lang
<FromGitter> <codem4ster> but in this example local variable is shared and in local variables compiler works as expected. Am I missing something ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ad6fd327c3a01610df416da]
<FromGitter> <straight-shoota> yes, your variable doesn't change it's type
<FromGitter> <codem4ster> so?
<FromGitter> <straight-shoota> it can never be nil or a different type than Int32
<FromGitter> <straight-shoota> just replace `i -= 1` with `i = nil` and you'll se the compiler taking care
<FromGitter> <codem4ster> yes I'm already saying that. Compiler can take care local variables even if they're shared between fibers.
<FromGitter> <straight-shoota> exactly
<FromGitter> <codem4ster> then why it cannot take care of instance variables in the same situation?
<FromGitter> <straight-shoota> because it can't track them
<FromGitter> <codem4ster> why it can't track them?
<FromGitter> <codem4ster> :)
<FromGitter> <codem4ster> because shared? local variables are shared also. But it can track them.
<FromGitter> <bararchy> @codem4ster local vars arent shared between threads
<FromGitter> <bararchy> when there will be threads
<livcd> many of you came from Ruby. What made you to try Crystal and why did you "abandon" ruby ?
<FromGitter> <bararchy> it's the assumption of the compiler that he would be able to take care of it
<FromGitter> <codem4ster> oh now I got it
<FromGitter> <codem4ster> they're shared on fibers not threads
<FromGitter> <codem4ster> although crystal not support threads this design is choosen for the future
<FromGitter> <bararchy> exactly ^
<FromGitter> <straight-shoota> even without threads, instance variables belong to objects and they could be modified by different code the Compiler might not even know about (like C bindings)
<FromGitter> <bararchy> livcd basiclly speed, and after starting it became 'safety' and then speed
<FromGitter> <codem4ster> thanks @bararchy, @straight-shoota
<FromGitter> <straight-shoota> local variables are limited to the local scope and the compiler knows exactly when and how they could be modified
<livcd> bararchy: interesting. Do you still use ruby or is everything in Crystal already ?
<FromGitter> <bararchy> I have the option to use Crystal 100% :) but small stuff I will do in pry
<FromGitter> <codem4ster> @livcd my reason is only speed. I don't like static typing :) My mindset is resistant to static typing. :)
<FromGitter> <bararchy> @codem4ster give it time, it was the same for me too, after a few months I started doing this in Ruby ⏎ ⏎ ```a = get_from_client ⏎ if a.is_a?(String) ⏎ .... ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5ad7030515c9b031140badf7]
<FromGitter> <bararchy> which is a very anti-pattern for Ruby
<FromGitter> <bararchy> Ruby pushes you to forget about types and handle everything with Exceptions
<FromGitter> <bararchy> I actually saw code people made that instead of `if-else` they totally used Exception handeling to control program flow
<livcd> I am curious how many of you will go back to Ruby when GraalVM+TruffleRuby is ready
<FromGitter> <straight-shoota> no way
<FromGitter> <straight-shoota> Crystal as a language is so much superior to ruby
<FromGitter> <straight-shoota> static typing with global inference is really nice, union types are awesome, the concurrency model etc.
<FromGitter> <straight-shoota> there are soo many bugs you can't even have in Crystal because the language and compiler prevents them
<FromGitter> <yxhuvud> aye. I came for the performance but stayed for the language
<FromGitter> <yxhuvud> and that if statement could read `if a` without checking type if the point is only to remove the nil type, which very much matches how ruby would do it.
<FromGitter> <girng> @bararchy thanks for suggestion. i like my inline namedtuples, makes it feel more like javascript object literals (from what i'm so used to)
<FromGitter> <girng> but im sure if it gets too advanced i will need re-organize
<FromGitter> <girng> @livcd im not sure, unless there are performance advantages, and if there is a crystal converter, then i'll try it but if not, im not going to
<FromGitter> <girng> im not going to convert all my codebase over, seems waste of time. but those truffle people are nice people i posted on their github and received help in an issue thread. they are good people
<FromGitter> <girng> is there a table printing console method/functionality built in crystal?
<FromGitter> <girng> for example, something like this: https://www.npmjs.com/package/cli-table but more simpler
<FromGitter> <epergo> amber framework use this shard
<FromGitter> <girng> sweeet! @epergo starred thank you!
<FromGitter> <epergo> you're welcome 😄
<FromGitter> <girng> @epergo wow, that is a gosh damn nice table formatting in console
<FromGitter> <girng> gonna show a before/after 1 sec
<FromGitter> <girng> Much easier to read now :D :D :D
<FromGitter> <epergo> yeah! it's a nice little shard
<FromGitter> <girng> is it possible to just update the table instead of submitting a new "puts" each time?
<FromGitter> <bararchy> @girng you can try `print table\r`
<FromGitter> <bararchy> which should rewrite over the same line
<FromGitter> <bararchy> but it might not work if the table uses `\n`
<FromGitter> <bararchy> which I guess it does
<FromGitter> <bararchy> so..no. ⏎ or use ncurses etc..
<FromGitter> <girng> ic
<FromGitter> <girng> for my game server manager, i was thinking maybe i could execute a .exe each time i restart my crystal server (for dev purposes), which would open up the .exe server manager written in godot, then i could just send these values over a stream to it and have it update in the godot engine
<FromGitter> <girng> when i say "restart my crystal server" i mean re-running `crystal src/App.cr`
<FromGitter> <girng> so, through code i could get it to launch a file automatically, and terminate that process when the app restarts. would be really cool
<FromGitter> <bararchy> interesting to see if Crystal can get even fater using this: https://www.phoronix.com/scan.php?page=news_item&px=GraalVM-1.0-Released
<FromGitter> <bararchy> though I would argue if anything good can come from oracle :\
<FromGitter> <girng> whats difference between ⏎ "Checks that the underlying value is Int, and returns its value as an Int32." `as_i` ⏎ ⏎ and `to_i32`? ⏎ ... [https://gitter.im/crystal-lang/crystal?at=5ad71f80109bb04332d4d9ed]
<FromGitter> <bararchy> as means cast, .to_i32 means convert ⏎ ⏎ "1".as Int32 will never work, those are different types that canoot be casted ⏎ "1".to_i32 uses a convertion table to replace the var from `1:String` to `1:Int32` [https://gitter.im/crystal-lang/crystal?at=5ad72000270d7d3708dcb2b3]
alex`` has joined #crystal-lang
<FromGitter> <girng> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ad7203f27c509a7742479a3]
<FromGitter> <girng> so if it's a JSON::Any, i just need to cast it?
<FromGitter> <girng> that means as_i, since no conversion wil take place (since it's already a JSON::Any)?
<FromGitter> <bararchy> JSON::Any is a union type of all posibble types a json can handle. ⏎ you can `{"foo": 1}.to_i32` right? but JSON::Any mioght be exactly that
<FromGitter> <bararchy> can=can't
<FromGitter> <girng> okay, so thinking of UNION Types think as_i
<FromGitter> <bararchy> I think JSON::Any has some way to "know?" or something thous it support `.to_h` or `.to_a` etc.. ⏎ but now I'm just gueeing
<FromGitter> <bararchy> you should look at the source for that
<FromGitter> <girng> "union type of all possible types" = as_i, makes sense now
<FromGitter> <girng> ty Bar
<FromGitter> <bararchy> np :)
<FromGitter> <girng> i ask kinda weird questions. but it's bcz i hate just putting it into my code and thinking "oh, okay this works". but i like to understand "why it works"
<FromGitter> <girng> i do a lot of trial and error lol
<FromGitter> <bararchy> @girng only way to learn :)
<FromGitter> <girng> slow and steady :D
<FromGitter> <girng> when you are in a case when clause statement. and if a method "returns" something, is there a way to detect that?
<FromGitter> <girng> i guess i could just use `raise`
Jenz has joined #crystal-lang
<Jenz> Good day people, how is Crystal doing?
<FromGitter> <girng> goo morning!
<Jenz> Im in a superb mood, I installed arch so I could run gdb on crystal programs (even though barely anything works)
<Jenz> That was not the only reason though, lol
<FromGitter> <girng> nice, im on WSL
<FromGitter> <girng> although i tried crystal on lubuntu it's very nice
<Jenz> I was on macOS before, yikes, glad I left it
<Jenz> Do not get me wron though, macOS is nice, just not for me I guess
<Jenz> *wrong
<FromGitter> <girng> @jenz i'd crystal is doing very well i joined two weeks and beeen asking questions in this chat 24/7
<FromGitter> <girng> and i always receive help, and on the crystal subeddit
<FromGitter> <girng> subreddit*
<Jenz> Yeah, the crystal community is great :D, Ive been here for maybe two months or something (I have no control of time, might be twice as much), it quickly became my favorite lang
<FromGitter> <girng> =]
<FromGitter> <sdogruyol> welcome to Arch @Jenz
<FromGitter> <sdogruyol> I've also dropped OS X and switched back to Linux
<Jenz> Thanks! Are you on a macbook?
<Jenz> And congratulations on getting into the core team, Kemal is awesome
<Jenz> Loads of awesome people here ^^
alex`` has quit [Ping timeout: 240 seconds]
<FromGitter> <sdogruyol> thank you Jenz
<FromGitter> <sdogruyol> nope, I'm not on a Macbook
<FromGitter> <pfefferminz132> proc = Process.new("/usr/bin/less", input: Process::Redirect::Pipe, output: Process::Redirect::Inherit) ⏎ ⏎ string = `seq 1 200` ⏎ ⏎ #proc.input.flush_on_newline = true ... [https://gitter.im/crystal-lang/crystal?at=5ad731fc1130fe3d36ed57ce]
<FromGitter> <pfefferminz132> took me some time to find out but this way pipes with less work
<FromGitter> <bararchy> @pfefferminz132 use code block for code please
<wuehlmaus> damned, i did not want to send the source so i used gitter, my fault, sorry!
_axx has quit [Quit: I Must Go, My Planet Needs Me]
<wuehlmaus> [and i obviously don't know how to use gitter :)]
<FromGitter> <bararchy> lol all good :)
<FromGitter> <girng> gn be back in 5-6 hours need sleep
<FromGitter> <j8r> hum there are still issues with llvm6 :/
alex`` has joined #crystal-lang
<FromGitter> <sdogruyol> @fridgerator how about crecto :) https://twitter.com/
<FromGitter> <fridgerator> 👍
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter> <fridgerator> I need to get a logo fort he crecto org, instead of my ugly face 😆
rohitpaulk has joined #crystal-lang
<Jenz> @j8r Is there an issue that tracks these llvm6 issues?
<FromGitter> <sdogruyol> @fridgerator this might be useful https://egoist.moe/slogan/
<FromGitter> <fridgerator> thanks
rohitpaulk has quit [Ping timeout: 256 seconds]
rohitpaulk has joined #crystal-lang
<FromGitter> <alex-lairan> ```NoMethodError: undefined method `capitalize' for nil:NilClass``` ⏎ ⏎ I want to code in crystal in my actual job :'( [https://gitter.im/crystal-lang/crystal?at=5ad742bc5d7286b43a404d71]
<Jenz> Sounds awesome
<Jenz> But you gotta learn how to handle nils first :D
<FromGitter> <alex-lairan> Not my code
<FromGitter> <alex-lairan> x)
<Jenz> Oh ok, cool, was just about to post a link to the docs on how to handle nil
<Jenz> *-s
bmcginty_ has quit [Ping timeout: 265 seconds]
bmcginty has joined #crystal-lang
duane has joined #crystal-lang
duane has quit [Ping timeout: 264 seconds]
Jenz has quit [Ping timeout: 246 seconds]
That_Guy_Anon has joined #crystal-lang
duane has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
Jenz has joined #crystal-lang
<crystal-gh> [crystal] RX14 closed pull request #5959: Add HTTP::Server#bind_unix (master...jm/feature/http-server-unix) https://git.io/vpTnX
<travis-ci> crystal-lang/crystal#aa596d3 (master - Add HTTP::Server#bind_unix (#5959)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/368174312
<DeBot> https://github.com/crystal-lang/crystal/pull/5959 (Add HTTP::Server#bind_unix)
Jenz has quit [Remote host closed the connection]
<wuehlmaus> carc.in is quite usus, i just thought that it was in critter automatically :)
<wuehlmaus> thanks for the links
<oprypin> uh what
<wuehlmaus> ah, gitter, sorry for confusing, i meant gitter.im
Jenz has joined #crystal-lang
<FromGitter> <sam0x17> well friends I have successfully got the crystal *compiler* to build stuff in a google cloud function by including pre-compiled versions of pcre and libevent. working on a shard that automatically "bootstraps" a crystal app/library by uploading it to a cloud function that does the compilation and then deploys the compiled binary to its own cloud function. This is instead of the existing approach I use whereby I
<FromGitter> ... simply upload a --static compiled binary from my machine.
<FromGitter> <sam0x17> WIP repo: https://github.com/sam0x17/gcf.cr
<Jenz> There is no documentation on how to use --static, is there? I have never understood how to use it
<FromGitter> <sam0x17> my understanding is, if you provide --static, your binary won't crash if libevent and pcre are missing
<FromGitter> <straight-shoota> Jenz, no it's experimental
<FromGitter> <sdogruyol> Can we get an upvote for https://news.ycombinator.com/item?id=16868126
<FromGitter> <straight-shoota> well, `--static` tells the linker to use static libraries if available.
<FromGitter> <straight-shoota> so you don't need to have the libraries installed on the target system as they're included in the binary
<FromGitter> <sam0x17> i.e. more portable, but bigger binary
* Jenz gets it
<FromGitter> <sam0x17> but yeah, when it's done my shard will create a zip of the current crystal app, upload it to the compile-crystal cloud function, which downloads the specified version of the crystal compiler (or default to the latest release) , compiles the app, and then deploys it as its own cloud function with the specified options and name
<FromGitter> <sam0x17> second part is fully working, just stubbing the uploading of the zip right now
rohitpaulk has joined #crystal-lang
Jenz has quit [Quit: Lost terminal]
Jenz has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 264 seconds]
<FromGitter> <girng> back, good morning
<FromGitter> <girng> @sdogruyol upvoted
baweaver is now known as baweaver_away
baweaver_away is now known as baweaver
Jenz has quit [Remote host closed the connection]
Jenz has joined #crystal-lang
Jenz has quit [Disconnected by services]
<FromGitter> <j8r> @Jenz not sure if it's my distribution or missing libraries, so i prefer to use Alpine
<FromGitter> <j8r> @Jenz You can take a look at https://store.docker.com/community/images/jrei/crystal-alpine if you want to use static linking
<FromGitter> <sdogruyol> @j8r how do you deploy that to other distros?
<FromGitter> <girng> is there a method that checks if a hash has all the keys specified?
<FromGitter> <straight-shoota> @sdogruyol If you make a static build on Alpine it should run on any linux
<FromGitter> <straight-shoota> @girng what are "all the keys"?
<FromGitter> <girng> ["bio", "location", "gender"]
<FromGitter> <girng> i see, we can use .keys on a hash
<FromGitter> <girng> i need to check an incoming hash, that has bio, location, and gender as a key. if not, return false
<FromGitter> <fridgerator> something like `(["bio", "location", "gender"] - other_hash.keys).empty?`
<FromGitter> <girng> we can use subtract operator on arrays?
<FromGitter> <girng> wow, that is neat
<FromGitter> <fridgerator> https://crystal-lang.org/api/0.24.2/Array.html#-%28other%3AArray%28U%29%29forallU-instance-method
<FromGitter> <girng> ```code paste, see link``` ⏎ ⏎ @fridgerator cool, looks like it works =] [https://gitter.im/crystal-lang/crystal?at=5ad78b3827c509a77426ce32]
<oprypin> that is actually pretty terrible
<FromGitter> <fridgerator> ^
<FromGitter> <fridgerator> knew this guy would chiem in
<FromGitter> <girng> :D
<FromGitter> <girng> what i do lol
<oprypin> just `-` operator on arrays is terrible
<oprypin> well first of all you should leave validation to JSON.mapping
<oprypin> `{"bio", "location", "gender"}.all? { |k| incoming_message.has_key? k }` this would be the much more efficient way to do that
<oprypin> also clearer intent
<FromGitter> <girng> ohhh, i see now. .all? can be used cause the tuple is an enumerable
<FromGitter> <girng> just like array
<FromGitter> <girng> but faster?
<FromGitter> <girng> differnce between .each and .all?
<FromGitter> <girng> https://crystal-lang.org/api/0.20.3/Enumerable.html#all%3F-instance-method
<oprypin> https://crystal-lang.org/api/0.24.2/Enumerable.html#all%3F%28%26block%29-instance-method
<FromGitter> <girng> ok so im doing it inside a method
<FromGitter> <girng> i need to write return in front of it?
<FromGitter> <fridgerator> no crystal returns the last evaulated statement from methods
<FromGitter> <girng> because i want the method to return true, if there any missing hash keys
<FromGitter> <girng> well, i need to do more stuff below it
<FromGitter> <fridgerator> stick a `!` in front of it?
<FromGitter> <j8r> @sdogruyol Alpine Linux is for now the only reliable platform for static linking
<FromGitter> <girng> oh
<FromGitter> <girng> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ad78f886bbe1d2739fe146a]
<FromGitter> <girng> there got it working :)
<FromGitter> <girng> nice!
<FromGitter> <kalicki> hey guys
<FromGitter> <kalicki> do you know if you have any similar codeclimate tool that supports Crystal?
<FromGitter> <kalicki> for code review/Test coverage and quality
<FromGitter> <hugoabonizio> @kalicki for code quality there's ameba https://github.com/veelenga/ameba
Jenz has joined #crystal-lang
WA9ACE has joined #crystal-lang
Jenz has quit [Remote host closed the connection]
<FromGitter> <girng> so if i do as_h from my json text, it's now creating all these types for it `(Array(JSON::Type) | Bool | Float64 | Hash(String, JSON::Type) | Int64 | String | Nil)`
<FromGitter> <girng> that doesn't seem efficient.. what am i doing wrong
<FromGitter> <girng> why so many 64 bit gosh damn i just want a string
<oprypin> see JSON.mapping
<oprypin> also note that all this .as_h code breaks in the next version of Crystal
<FromGitter> <girng> .....
<FromGitter> <j8r> @oprypin as_h will broke?!
<oprypin> i thought it was already released so didnt think much of it
<FromGitter> <girng> but how do you do JSON.mapping on data that you don't KNOW
<oprypin> .as_h itsellf will work but it will give a result that needs to be dealt with differently
<FromGitter> <girng> what the types/keys are going to be sent...
<FromGitter> <girng> from the client...
<oprypin> girng, you just said {"bio", "location", "gender"} - so you know
<FromGitter> <girng> hacker could easily use wireshark and modify and send diff keys though
<FromGitter> <girng> and try to crash server
<oprypin> catch exception
<FromGitter> <j8r> exactly
<FromGitter> <girng> yes my methods are in a begin raise
<oprypin> https://crystal-lang.org/api/0.24.2/JSON/Any.html#as_h%3AHash%28String%2CType%29-instance-method -> https://crystal-lang.org/api/master/JSON/Any.html#as_h%3AHash%28String%2CAny%29-instance-method
<FromGitter> <girng> but i don't understand how to use json mapping inline
<FromGitter> <girng> compared to just as_h
<FromGitter> <j8r> One of the few use case to not use mapping is dealing with dynamic APIs
<oprypin> dont use it inline, define a struct
<FromGitter> <girng> im reading data from server like this: (Godot send a JSON STRING in TCP). `handle_connection`: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ad796e5102fac7b7b277bb9]
<FromGitter> <girng> now, msg becomes JSON::Any
<FromGitter> <girng> so i am confused
<oprypin> just also send the message type
<FromGitter> <girng> is JSON::Any bad??
<FromGitter> <j8r> slow and hard to work with
<FromGitter> <girng> message type is a string
<FromGitter> <girng> always will be a json string from godot
<FromGitter> <j8r> if you now what to expect, pls use a mapping
<FromGitter> <girng> for example, from the client i send: ` {"cmd":"LOGIN","message":{"password":"mike","username":"Test"}}`
<FromGitter> <girng> it's always gonna be a string over tcp
<FromGitter> <girng> now, if a user saves a profile, i send ` {"cmd":"SAVEPROFILE","message":{"bio":"test","gender":"","location":""}}`
<oprypin> cool cool
<FromGitter> <girng> so iuno how to put all this data in a "struct" or use json mapping for it. it's just 1 string that gets parsed
<FromGitter> <girng> think of nodejs's JSON.parse(), is how i'm viewing it
<FromGitter> <girng> is my perspective on how it's working (cause i'm so used to it)
<oprypin> cant vouch for performance of this with a large number of commands, but https://carc.in/#/r/3wbm
<oprypin> probably not such a good idea
<FromGitter> <girng> ohh i see
<FromGitter> <girng> so i can define all those in my headers.cr file?
<FromGitter> <girng> that will make it much more static
<oprypin> i guess
<FromGitter> <girng> bcz i have a lot of code i need a separate file for the structs then, which is fine
greengriminal has joined #crystal-lang
<FromGitter> <girng> but that is surely better than json::any right?
<oprypin> surely
<FromGitter> <girng> json::any is a TRAP
<FromGitter> <girng> thank you oprypin, this helps a lot
<FromGitter> <girng> this feels more like i'm using a statically typed language now, of which i like
<FromGitter> <girng> the more stuff i define, better i feel about my code
<FromGitter> <girng> explicitly define*
greengriminal has quit [Quit: Leaving]
<FromGitter> <girng> @oprypin i have currently 32 commands. using the | operator will be ok with that many times?
<oprypin> nah, hold on
<FromGitter> <schoening> Are macros one of those things that once you "get" them you love them? At a glance I am reminded of what people say about lisp programmers only being able to use their own code coz they all created their own dsl :p
<oprypin> girng, https://carc.in/#/r/3wbq
Nik736 has joined #crystal-lang
Nik736 has quit [Client Quit]
<oprypin> schoening, macros are not the solution, they're just a way to make an existing solution less repetitive
<oprypin> "hmm, i sure have copypasted this line many times, how about i make a macro"
<oprypin> funnily enough, the example i just posted begs for a macro with enough of those cases
<oprypin> but it's not where the thought process should start
<FromGitter> <girng> @oprypin so now, i can continue to just add more commands to the enum list, and add another `when` to handle it
<oprypin> yes
<FromGitter> <girng> very cool, this is what i had before: https://i.gyazo.com/0ed139e92dfdf77727a60bceb1b346d2.png
<z64> ary's talk on macros is excellent, i definitely recommend watching it (can't grab a link myself right now..)
<oprypin> girng, you can do that as well, it's just MUCH more efficient to select on a number than it is to go through all strings
<oprypin> normally i wouldn't tell you to bother with this but this code for selection of command will be run the most by far, so it's worth optimizing
<FromGitter> <girng> yeah, your enum / struct way is better, in fact it's probably way better
<oprypin> macros > https://vimeo.com/190927958
<FromGitter> <girng> thats nice of you,i appreciate the example.... a lot =]
<FromGitter> <girng> now i can get rid of my damn `as_h`'s all over the place now :D
<FromGitter> <girng> @oprypin but wait, how do i send the receiver_integer over tcp? i just put the command in a json key
<oprypin> girng, like, send an integer, like you've already shown
<oprypin> same as payload_size
<FromGitter> <girng> i c, so basically read_bytes(1), as the integer will be 1 byte?
<FromGitter> <girng> send that before the message
<FromGitter> <girng> in godot
<FromGitter> <girng> so i'm doing ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ but now i get payload size error wtf lol [https://gitter.im/crystal-lang/crystal?at=5ad7a4a27c3a01610df79c75]
<FromGitter> <girng> `Payload Size is too large. 2063597568` LOL
<oprypin> you probably sent 4 bytes in godot and for whatever reason said to receive 1 byte in crystal
<FromGitter> <girng> i will need to re-compile from source maybe to send just the 1 byte
<FromGitter> <girng> of the receiver_id iuno
<oprypin> girng, did you send any id in godot? you're supposed to send an id
<FromGitter> <girng> oops let me try
<oprypin> ... put_u8 presumably
<FromGitter> <girng> YES
<FromGitter> <girng> WORKS
<FromGitter> <girng> in godot: ⏎ ⏎ ```masterclient.put_8(2) ⏎ masterclient.put_utf8_string(to_json(MSG_BUFFER))``` [https://gitter.im/crystal-lang/crystal?at=5ad7a61527c509a77427558d]
<FromGitter> <girng> there we go... awesome oprypin, epic =]
<FromGitter> <kornel_gora_twitter> Hi i would like to learn crystal. Can i make with this language cloud computing stuff or not ??
<FromGitter> <fridgerator> "cloud" just means a server running somewhere
<FromGitter> <fridgerator> so yes
<FromGitter> <girng> why does p escape "'s and puts doesn't
<FromGitter> <girng> that scared me, thought godot was sending extra weird data
<FromGitter> <girng> i am not using `p` ever again
<oprypin> girng, `p` is a debugging tool
<oprypin> prints a string as if it was a piece of code
<oprypin> >> p "\nhi\""
<DeBot> oprypin: "\nhi\"" - more at https://carc.in/#/r/3wc0
<FromGitter> <girng> well, p is showing all my json like this `"{\"cmd\":\"PING\",\"message\":{\"c\":\"PING\"}}"`
<FromGitter> <girng> but when i do puts, it's `{"cmd":"PING","message":{"c":"PING"}}`
<FromGitter> <girng> but godot is sending `{"cmd":"PING","message":{"c":"PING"}}` as a string. so why does `p` escape all the quotes
<oprypin> >> p "{\"cmd\":\"PING\",\"message\":{\"c\":\"PING\"}}"
<DeBot> oprypin: "{\"cmd\":\"PING\",\"message\":{\"c\":\"PING\"}}" - more at https://carc.in/#/r/3wc1
<oprypin> >> puts "{\"cmd\":\"PING\",\"message\":{\"c\":\"PING\"}}"
<DeBot> oprypin: {"cmd":"PING","message":{"c":"PING"}} - more at https://carc.in/#/r/3wc2
<FromGitter> <girng> see
<FromGitter> <girng> puts much nicer
<oprypin> you still dont get it
<FromGitter> <girng> well you said debug, but why do i need escaped "'s to help me debug the string lol
<oprypin> what if someone sends you just a hundred newlines as part of the string and you print it. what will be easier to understand -- a blank screen or "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
<FromGitter> <girng> well, in that case yeah
<FromGitter> <fridgerator> @girng have you ever used unity 3d? just curious on your thoughts of godot vs unity
<FromGitter> <girng> but why is crystal escape the quotes in any event, is that part of read_string(bytesize)?
<FromGitter> <girng> replacing new lines with \n is useful for debugging, but escaping quotes i don't understand how that is useful, because godot isn't sending that
<FromGitter> <girng> in your example, godot is sending new lines...
<FromGitter> <girng> that would be useful to see the \n's then
<FromGitter> <girng> @fridgerator well, i'll keep it short and sweet: Godot for 2d, Unity for 3d
<FromGitter> <girng> @fridgerator however, for app development, Godot is much better than your html crap packaged w/ electron. Godot's UI tools are insane and underrated because no one thinks you can create ui stuff because it's a "game engine" however they are wrong
<oprypin> girng, do you not see that i literally put the string in the middle of my program and it works?
<FromGitter> <girng> @oprypin i don't understand that code tbh too advanced of a macro for me :P
<oprypin> dont look at the link
That_Guy_Anon has quit [Read error: Connection reset by peer]
<FromGitter> <girng> @oprypin ok, on sec let me show u something
That_Guy_Anon has joined #crystal-lang
<oprypin> girng, pls https://carc.in/#/r/3wc9
<oprypin> it produces a string literal that you can immediately paste in source code
<oprypin> it lets you know the boundaries of the string unambiguously
<FromGitter> <girng> well, i don't want those escapes to be send over the server
<FromGitter> <girng> or to be read
<oprypin> oh my god
<FromGitter> <girng> i was under the assumption i am sending just the regular text as shown in my godot s/s
<FromGitter> <girng> is there a diff method besides read_string w/ no escape?
<FromGitter> <fridgerator> @girng is there any charting libraries for godot?
<oprypin> girng, would you write a piece of code like this: https://carc.in/#/r/3wch
<oprypin> or perhaps you'd write like this https://carc.in/#/r/3wci and it actually works?
<FromGitter> <drum445> Hello team, could somebody please let me know whether this is something I need to worry about on my API: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ It happens when a client connects and disconnects quickly, such as multiple page refreshes [https://gitter.im/crystal-lang/crystal?at=5ad7b0746d7e07082b0ba1ca]
<oprypin> you need escaping to produce strings in source code
<FromGitter> <girng> o
<oprypin> there is no such escaping happens in the actual string, it's just a way to represent it in source code
<FromGitter> <girng> ohhhh i see
<oprypin> and `p` just happens to produce the escaped output because it's convenient. the actual string is not like that
<FromGitter> <girng> that's for all languages mostly?
<FromGitter> <girng> or just crystal specific
<oprypin> the actual string is what you see when you use `puts` but it's not always convenient to use `puts`
<oprypin> all languages have it
<FromGitter> <girng> well, your \n example is actually good because i do need to check for new lines and if i use p i can see them
<oprypin> not all but most
<FromGitter> <girng> so basically, source code (internally) needs to escape them. so actually, raw_message is literally the raw_message, if i do `p raw_message`
<FromGitter> <girng> raw source code message
<FromGitter> <j8r> there is also `pp`, usefull to debug async/long tasks
<oprypin> girng, no, it is not internally stored like that
<FromGitter> <girng> WTF
<oprypin> when you put an escaped string in source code, the compiler reads it once and stores it as a proper string
<oprypin> and `p` converts a normal string to a source-like representation just for you to see it that way
<oprypin> drum445, seems normal
<oprypin> it's good that it doesnt let the error go undetected, isnt it?
<FromGitter> <drum445> There are a fair amount of them that stack up over time, nothing I need to concern myself with you reckon? It doesn't seem to affect performance or even stop the response
<oprypin> drum445, you shouldn't leave unhandled exceptions
<oprypin> i always argue that these should crash the entire program
<FromGitter> <drum445> I don't know how to catch those though matey :(
<FromGitter> <drum445> I would appreciate some advice
swav has joined #crystal-lang
<FromGitter> <girng> "when you put an escaped string in source code" .................... i give up. I NEVER did this, godot is sending it from the client w/o escapes. yes, i understand p converts it to display, but i never "put an escaped string in the source code" willfully. ⏎ ⏎ so you're telling me it gets converted/escaped automatically regardless if i send something that is escaped or not? then, the `p` re-converts it so i
<FromGitter> ... can see it as it was when it first got entered into the source code?
<FromGitter> <drum445> I get that, but thanks mate. I'm not sure where in my code to put the catch
<FromGitter> <girng> converted into source code*
<FromGitter> <drum445> Mind if I send you a sample?
<oprypin> girng, imagine you were doing a test, where you don't want to care about what godot does
<oprypin> like the test I was sending you before
<oprypin> here's what you'd have https://carc.in/#/r/3wcj
<oprypin> you can plop that string right into source code
<oprypin> in my previous example I used a way of producing a string that happens to be nicer in this scenario https://carc.in/#/r/3wbq
<oprypin> but both lead to the exact same result
<FromGitter> <girng> ok
<FromGitter> <girng> didn't know source code has to have em escaped
<FromGitter> <girng> makes sense
<FromGitter> <drum445> here is my main file, could you please let me know where I should add the exception handler? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ad7b2ca270d7d3708dfbbb4]
<oprypin> girng, well of course it does, otherwise it's nonsense https://carc.in/#/r/3wck
<oprypin> drum445, oh it's kemal ouch
<FromGitter> <girng> i mean internally
<FromGitter> <girng> not syntaxically
<FromGitter> <drum445> do you know where it would go in that file matey?
<oprypin> girng, no, internally they're just your normal text
<FromGitter> <drum445> not even sure how to write it tbh 😢
<oprypin> drum445, no, there's nowhere in that file that you could put it. it's on kemal
<FromGitter> <drum445> you don't like Kemal?
<oprypin> i've seen a few worrying things about it, yeah. but i dont have enough experience to recommend either it or anything else
<oprypin> i mean i have general experience but never cared abotu web frameworks
<FromGitter> <drum445> fair enough, I'm quite a fan of it atm. Either way any ideas how to catch the error?
<oprypin> drum445, just ignore it, it's ok. if it ever becomes a problem in future versions of the language, kemal can be changed to handle it
<oprypin> drum445, i sure prefer kemal over amber :p
<FromGitter> <drum445> Ha yeah same mate, I'll ignore it for now. Thanks a lot for your help bud
<FromGitter> <girng> "source-like representation just for you to see it that way" = this implies that the source code has to escape it? if it's "source-like" ⏎ ⏎ but now you said "internally they're just your normal text". then what is the reason for a source-like representation if internally they are normal text.
<oprypin> > otherwise it's nonsense https://carc.in/#/r/3wck
davic has quit [Quit: ZNC - http://znc.in]
<FromGitter> <girng> only use-case i can see is the \n issue, which is good to see. but escaped strings is silly makes no sense to escape them because it doesn't help the debugging process at all. in fact, it makes it harder because i just spent 10 minutes wondering why the hell godot was sending escapes strings. then i realized i was using p instead of puts
<FromGitter> <girng> whatever im done im sorry
<oprypin> >> puts 5
<DeBot> oprypin: 5 - more at https://carc.in/#/r/3wcl
<oprypin> >> puts "5"
<DeBot> oprypin: 5 - more at https://carc.in/#/r/3wcm
<oprypin> >> p "5"
<DeBot> oprypin: "5" - more at https://carc.in/#/r/3wcn
<oprypin> pretty useful if you ask me
<oprypin> if you cant tell a number from a string
<FromGitter> <girng> well that value should be explicitly typed anyway, why i'm using json.mapping now
<oprypin> thats nice
alex`` has quit [Ping timeout: 256 seconds]
<FromGitter> <girng> when you do STRUCTNAMEHERE.from_json is this allocated on the stack or heap?
<FromGitter> <girng> @oprypin if on stack, if a lot of commands are being done at once, will there be a possible chance of a stack overflow error?
duane has quit [Ping timeout: 256 seconds]
<FromGitter> <ezrast> @girng you're worried about stack vs heap for performance reasons, right?
<FromGitter> <girng> kinda. i just don't want commands to be sent too much that might give stack overflow error
<FromGitter> <girng> if allocated on stack but im not sure
<FromGitter> <ezrast> You basically don't need to worry about that outside of recursive code
<FromGitter> <ezrast> and if you're still worried for some reason just use a class
<FromGitter> <girng> ok, thx
<FromGitter> <bew> I just added an example to #5954 to make it easier to understand what the fix is exactly :)
<DeBot> https://github.com/crystal-lang/crystal/pull/5954 (Fix enum flags assigned values when a member has value 0)
<FromGitter> <straight-shoota> 👍
<crystal-gh> [crystal] Sija opened pull request #5962: Expand Regex to allow querying for metacharacters (master...regex-special-char) https://git.io/vpIjw
<crystal-gh> [crystal] Sija opened pull request #5963: Use Char instead of String in split/join calls whenever possible (master...followup-to-pr-5882) https://git.io/vpLvn
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang