<FromGitter>
<bararchy> all good @girng , and you? β I'm still waiting to get a beta access to your game ;)
<FromGitter>
<fusillicode_twitter> everything ok @girng :)
<FromGitter>
<fusillicode_twitter> guys is there a way to tell the compiler that at some point in my code a variable isn't `nil`?
<FromGitter>
<fusillicode_twitter> I have an explicit check with an `unless` but unfortunately it seems that the compiler can't figure out that the var is `nil`
<FromGitter>
<fusillicode_twitter> btw the var is actually a record extracted from the db π€
<FromGitter>
<girng> glad to hear! you guys are awesome
<FromGitter>
<fusillicode_twitter> this is part of an iteration block
<FromGitter>
<fusillicode_twitter> inside the iteration I do some validations by also querying a db and if something is broken I store the errors, log them and then skip to the next iteration
<FromGitter>
<fusillicode_twitter> but if everything is ok I go on but unfortunately the compiler complains about nilable refs :(
<FromGitter>
<fusillicode_twitter> in the over mentioned case the `record` that I need to use to perform some other stuff
<FromGitter>
<fusillicode_twitter> P.S: in particular I need some of the `record` properties and I would really like to avoid a whole bunch of `.try(&.record_property)` :(
<FromGitter>
<HarrisonB> Do you have the full stack trace?
<FromGitter>
<fusillicode_twitter> ok without the `--error-trace`
<FromGitter>
<fusillicode_twitter> I get the error where I try to use the `record`, i.e. `record.name`
<FromGitter>
<fusillicode_twitter> `undefined method 'name' for Nil (compile-time type is (Db::Company | Nil))`
<FromGitter>
<fusillicode_twitter> but with the `--error-trace` I end up in `Crecto` π
<FromGitter>
<bew> Can you show the code around record.name?
<FromGitter>
<fusillicode_twitter> I tried to extract only the meaningful pieces @bew, I hope that it gives an idea about what I'm doing (i.e. an incredible mess XD)
<FromGitter>
<fusillicode_twitter> btw this `Db::RecordsRepo.by_email(email)` is this: β β ```Repo.get_by(MODEL, email: email)``` β β MODEL is just a constant referencing the a Crecto model :) [https://gitter.im/crystal-lang/crystal?at=5bbeeb06c7bf7c3662ef5c8c]
<FromGitter>
<bew> The unless only protects the `task_errors...`
<FromGitter>
<fusillicode_twitter> mmm
<FromGitter>
<fusillicode_twitter> so...I need to...let me see...
<FromGitter>
<bew> I suggest you a `if record` with your stuff, then an `else` with the error (for example)
<FromGitter>
<fusillicode_twitter> I also thought about it but I have a few of these checks and the `if record` `else` would clutter the code
<FromGitter>
<fusillicode_twitter> :(
<FromGitter>
<fusillicode_twitter> just to know, there's no way to make an "unsafe" not nilable cast? π€
<FromGitter>
<Blacksmoke16> `.not_nil!`
<FromGitter>
<bararchy> Yeha, but be careful about using the not_nil! Call , I hate seeing it in the code, usually the compiler logic on nilabillty is better then the devs XD
<FromGitter>
<fusillicode_twitter> @bararchy I totally agree with you but I really don't know what to do in my case :(
<FromGitter>
<fusillicode_twitter> unfortunately I only need to store the error because I have other things that I want to check beside the record presence
<FromGitter>
<fusillicode_twitter> after all the checks however I would rely on the errors to decide to skip to the next record (I'm actually inside an iteration) or tho procede further
<FromGitter>
<Blacksmoke16> maybe wrap that logic into a method that gets called if record.nil?
<FromGitter>
<fusillicode_twitter> yep let me see
<FromGitter>
<fusillicode_twitter> btw thanks a lot for the support π
<FromGitter>
<fusillicode_twitter> you guys are indeed awesome :D
DTZUZO_ has quit [Ping timeout: 244 seconds]
rohitpaulk has quit [Ping timeout: 252 seconds]
<FromGitter>
<fusillicode_twitter> unfortunately I think that even the method doesn't solve my problem :(
lvmbdv has joined #crystal-lang
<FromGitter>
<ljuti> @jokke Found your OpenAPI spec library. If Iβd add support for OAS version 2, how should I go about it?
<FromGitter>
<ljuti> Oh, sorry. It was written by another Joakim (Reinert). :)
<jokke>
ljuti: cool :) Hmm good point... I think we should provide namespaces then.
<FromGitter>
<ljuti> @jokke OK, so itβs just Gitter then showing someone elseβs profile :)
<jokke>
well. i'm connected over irc
<FromGitter>
<ljuti> Yeah, I just realized that
<jokke>
but probably also over gitter
<jokke>
no, apparently not
<FromGitter>
<ljuti> Well, youβll think about it and then tell me what to do :)
<jokke>
ljuti: i assume many things are reusable. Maybe just providing the namespaces V2 and V3 or so and then moving only conflicting things into those namespaces would suffice. The version has to be set to some constant over a macro though, otherwise we can't branch out to differing versions from deeper levels..
rohitpaulk has joined #crystal-lang
<jokke>
are HTTP::Cookies secure?
<jokke>
as in signed?
<FromGitter>
<bararchy> "Sigend"?
<FromGitter>
<bararchy> what do you mean by a sigend cookie?
<jokke>
HMAC
<jokke>
as in i can be sure i was the one issuing it
<FromGitter>
<proyb6> It wonβt be secure if Monster Cookie is around, joking
<FromGitter>
<aboeglin> If someone can clarify something for me
<FromGitter>
<drum445> @jokke if you are using kemal-sessions then yes they use HMAC and append it to the cookie
rohitpaulk has quit [Ping timeout: 252 seconds]
<FromGitter>
<aboeglin> @vladfaust I do spend quite some time reading it. But I find it hard to google that kind of things, if you don't know the term behind a syntax it's very hard to know what it refers to. Also, I don't really find that syntax on the docs. I still have no clue how one would use that class though.
<FromGitter>
<j8r> @aboeglin I would advice to directly code a project to learn the language - you'll learn better how it works. Then, you can dig around to use more advanced features to improve you code
<FromGitter>
<j8r> @aboeglin TLDR: liek any language (even spoken one), learn what you need to bootstrap, then worry to learn more advanced vocabulary π
<FromGitter>
<aboeglin> @j8r I actually do, I'm currently rewriting a service with kemal
<FromGitter>
<aboeglin> but sometimes when reading docs I come across some syntax I do not understand
<FromGitter>
<j8r> In that case, for me, I search this syntax in the compiler
<FromGitter>
<j8r> `grep -rn '&block'` for example, this returns me were the syntax is used
<FromGitter>
<j8r> this gives me examples :)
<FromGitter>
<j8r> @aboeglin you are new, yeah? No worry to start slowly.
<FromGitter>
<aboeglin> but here it's not only about blocks, I use blocks with kemal and HTTP::Client already
<FromGitter>
<aboeglin> yes I am, the command gives me `grep: crystal: No such file or directory` though.
<FromGitter>
<j8r> and then you have the repo in local to contrib to, feel free
rohitpaulk has joined #crystal-lang
<FromGitter>
<j8r> hooo, I remind I need to send a PR to better explain `struct` vs `class`...
DTZUZO_ has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 252 seconds]
<FromGitter>
<aboeglin> Great, you can hit me when it's live !
<FromGitter>
<aboeglin> And can you confirm that my sample use of the Formatter class is correct ?
<FromGitter>
<fusillicode_twitter> > hooo, I remind I need to send a PR to better explain `struct` vs `class`... β β I actually need to contribute too to a great shard ;)
<FromGitter>
<j8r> It looks good
<FromGitter>
<fusillicode_twitter> and I also think I've found a bug in the compiler XD
<FromGitter>
<aboeglin> The docs don't say that though, when we want to capture a block, we just need not to yield anything inside it ?
<FromGitter>
<bararchy> @drujensen you're here?
<FromGitter>
<aboeglin> Capturing a block is something that happens in the implemented method, or in the user of it ? I don't really grasp where it happens from the docs. I read the page on capturing blocks twice now.
<FromGitter>
<aboeglin> > To capture a block you must specify it as a method's block argument, give it a name and specify the input and output types. For example:
<FromGitter>
<aboeglin> I don't understand what this means, as I do the same thing with the double method
<FromGitter>
<aboeglin> I just don't find it clear
<FromGitter>
<j8r> or create `def initialize` that defines `@email`
<FromGitter>
<fusillicode_twitter> right right
<FromGitter>
<fusillicode_twitter> let me see if I can achieve what I want
<FromGitter>
<j8r> you can even use generics, like `include C(Int32)` :D
<FromGitter>
<ljuti> Geez, macros are too powerful and confusing for me yet
<FromGitter>
<fusillicode_twitter> > Geez, macros are too powerful and confusing for me yet β β we're on the same boat XD
<FromGitter>
<j8r> π― @ljuti
<FromGitter>
<fusillicode_twitter> but they're definitely more readable than the ones that you can find in a language like...I don't know...Scala XD
<FromGitter>
<proyb6> True, Scala is way complex
<FromGitter>
<proyb6> I get Crystal clear in a day
<FromGitter>
<fusillicode_twitter> +1
<FromGitter>
<proyb6> Just like the Capture block in the last few message
<FromGitter>
<proyb6> &block refer to {...}
<FromGitter>
<fusillicode_twitter> I didn't had the time to follow that but I think that I got the main point :)
<FromGitter>
<fusillicode_twitter> btw @j8r what do you think of using a `forward_missing` and a wrapper approach rather than sharing a behavior with mixins? π€
return0e has quit [Remote host closed the connection]
<FromGitter>
<fusillicode_twitter> sorry for the bothering but I'm really interested in what other people thinks about these kind of stuff XD
<FromGitter>
<proyb6> Now it got me thinking, how Node.js, Ruby and PHP are still popular among the community. Newbies could find interpreter language are less complicated and ability move quickly without worry about one compile time error will halt the whole project or spending too long to learn before you do something useful. β β If we keep saying Crystal is better for performance, isnβt going to attract much when Kotlin and
<FromGitter>
... Swift does well in their ecosystem and Go and Rust does well in system programming. Lua is great for gaming industry, python for data and academic. β β What do you intend to use Crystal for? [https://gitter.im/crystal-lang/crystal?at=5bbf6bde435c2a518e8c4541]
<FromGitter>
<j8r> @fusillicode_twitter you can, but if you can use just `include`s that's the best
<FromGitter>
<ljuti> The macro generates method definitions out of OBJECT_TYPES, right?
<FromGitter>
<fusillicode_twitter> @j8r got it but I think that in my case the wrapper approach would be more appropriate, i.e. I have two structs that are identical but for one field that in one is a string and the other a float
<FromGitter>
<ljuti> Now, I want to control which types it should define in a module with conditions
<FromGitter>
<fusillicode_twitter> and I'm going from the string one to the float one by trying to convert the a string to a float
<FromGitter>
<bajro17> how to use ?HTTP::Server::Response.status_code
<FromGitter>
<fusillicode_twitter> @proyb6 whenever I talk about Crystal (pretty often right now) the first thing that I mention is not how much performant it is but how fast it makes you
<FromGitter>
<j8r> @fusillicode_twitter use generics
<FromGitter>
<ljuti> I tried putting specific structs and classes into a separate SCOPED_OBJECT_TYPES array, didnβt fully work
<FromGitter>
<fusillicode_twitter> @j8r oh gosh...I'm scared by them XD
<FromGitter>
<aboeglin> @proyb6 so if you understand captured blocks well, you define that when implementing the method right ? It's basically a function that takes a block and makes it a proc to be called later, otherwise a callback.
<FromGitter>
<bajro17> in terminal it show me status 200
<FromGitter>
<bajro17> but I dont see anything
DTZUZO_ has joined #crystal-lang
<FromGitter>
<Blacksmoke16> you never print anything
<FromGitter>
<bajro17> @Blacksmoke16 can you help me please
<FromGitter>
<Blacksmoke16> nvm, main reason is im not sure the http server works in the playground? Its exiting with error code 1 so thats prob not good
<FromGitter>
<bajro17> I dont understand good this
<FromGitter>
<rickychilcott> I've tried splats, by the don't seem to work well in a method definition.
<FromGitter>
<rickychilcott> Said another way, without macro part of the example to provide more complexity, is it possible to use a Tuple in a method definition to act as arguments β β ```def test_method({name, age}) β #code β end``` [https://gitter.im/crystal-lang/crystal?at=5bbf7302c7bf7c3662f37f86]
return0xe has quit [Read error: Connection reset by peer]
<FromGitter>
<bajro17> @vladfaust thank you I will try it now <3
return0e has joined #crystal-lang
DTZUZO has joined #crystal-lang
DTZUZO_ has quit [Ping timeout: 268 seconds]
<FromGitter>
<vladfaust> πͺ
<FromGitter>
<aboeglin> @bajro17 well, that's what I tried to understand above, so from what I understand, with that method you can use it like this : β β ```get "/some-route" { |context| handle_request }``` β β And it would just add it to the routes property. [https://gitter.im/crystal-lang/crystal?at=5bbf75f4384492366120de79]
<FromGitter>
<bajro17> @aboeglin if I do like this I get Error in redis.cr:46: wrong number of block arguments (given 1, expected 0) β β app.get "/some" { |context| handle_request }
<FromGitter>
<bajro17> I cant pass with that any argument
<FromGitter>
<proyb6> @aboeglin You are correct, further more, I read Crystal programming from Pragmatic Books is very clear if you like to get a book
<FromGitter>
<aboeglin> @bajro17 well, I don't really understand the type of the block though, that may be part of your issue
<FromGitter>
<aboeglin> what is (-> String) supposed to be ?
<FromGitter>
<rickychilcott> It's a type annotation to say that block needs to be a Proc which returns a String, right?
<FromGitter>
<rickychilcott> you need to make sure your Proc returns a string, likely not what `context` is
<FromGitter>
<aboeglin> but takes no argument right ?
<FromGitter>
<vladfaust> Or change Proc to return `Nil` or `Void`, which is more common in this case
<FromGitter>
<vladfaust> `Void` is the best here, because AFAIK it ignores any output from the proc
<FromGitter>
<aboeglin> should it rather be something like ( HTTP::Context -> Void ) ?
<FromGitter>
<vladfaust> +
<FromGitter>
<aboeglin> not sure about the type of context
<FromGitter>
<vladfaust> If not sure, dive into API
<FromGitter>
<aboeglin> but get is probably a bad name for it, I'd rather call that method add_route
<FromGitter>
<j8r> This isn't idiomatic to use Void
<FromGitter>
<j8r> use `Nil`. `Void` is typically when you do bindings
<FromGitter>
<aboeglin> @vladfaust seems to say something different above
<FromGitter>
<j8r> `grep -r Void crystal` an you'll see
<FromGitter>
<j8r> yeah but @vladfaust is @vladfaust :P
<FromGitter>
<vladfaust> Nothing I say makes sense!
<FromGitter>
<j8r> Hahaha
<FromGitter>
<vladfaust> Just sharing experience
<FromGitter>
<vladfaust> Works good for me!
<FromGitter>
<vladfaust> Wouldn't compiler say "no" if a `-> Nil` Proc returns a non-nil value?
<FromGitter>
<j8r> in the end both do more or less the same, but greping in the stdlib shows that Void is used on paths like openssl, yaml and socket with `Void*` for example.
<FromGitter>
<j8r> You can use also `-> _`
<FromGitter>
<vladfaust> Can't do `-> _` if variable!
<FromGitter>
<j8r> ?
<FromGitter>
<j8r> this syntax is quite used on the stdlib, and also referenced in the docs
<FromGitter>
<j8r> `Void` is never used outside C related stuff
<FromGitter>
<jwoertink> if I'm making a `HEAD` request to a server, and I have access to `HTTP::Server::Response`, is there anything I can use from that to tell that it was in fact a HEAD request?
<FromGitter>
<vladfaust> `# A proc accepting no arguments and returning Void` I thinks that makes sense
<FromGitter>
<jwoertink> also, does crystal http server skip writing to the body when it's a HEAD request?
<FromGitter>
<bararchy> We can now test Windows builds on CI :)
<FromGitter>
<bcardiff> Ohhhhhhhhh
<FromGitter>
<fridgerator> π
<jokke>
you can do this with gitlab ci too :P
<jokke>
you would need a windows server though :P
<FromGitter>
<bcardiff> I hope CircleCI joins the party
<FromGitter>
<bararchy> Reading the post let me feel like we might be needed to wait for 3-6 month for proper tooling support, unless a spec can run with what they have now (visual 2017)
<FromGitter>
<straight-shoota> nice
<FromGitter>
<straight-shoota> jokke, it runs on GCE
<FromGitter>
<bajro17> is it possible this app.run method to run inside initialize
<FromGitter>
<bajro17> when I try nothing happen in program but I dont get any error
<FromGitter>
<aboeglin> anyone has experience with using databases in crystal ?
Heaven31415 has joined #crystal-lang
<FromGitter>
<bew> @bajro17 if should work i guess (can't try right now), but I don't see why you'd want to do that: you should use the `initialize` method only to *initialize* your object, not do fancy stuff, either do the fancy stuff explicitely, or make a wrapper around the constructor that does some other things after initializing the object
johndescs has quit [Ping timeout: 245 seconds]
johndescs has joined #crystal-lang
<FromGitter>
<aboeglin> Code style question, let's say I just want to print the body of a request
<FromGitter>
<j8r> @wontruefree the problem was here before GitHub was acquired Microsoft - dependence to a private company. Nothing change. Look at China repo removals, DMCA take downs etc. And if Google or whatever evil buys Gitlab, you'll migrate again? The only answer is decentralization.
<FromGitter>
<bajro17> @j8r yes we can focus mostly on blockchain to whole web be decentralized