ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.33.0 | 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> <bew> @stronny not sure if you got tge answer after all, but iirc you can do `"a=".split "=", remove_empty: true` to only get `["a"]` (note: i'm writing from memory on my phone, so i might be wrong on the exact argument)
<FromGitter> <stronny> yes, I've read why how and what. and Ary even said that personally once again
<FromGitter> <bew> Nevermind, you got the answer already
return0e has quit [Ping timeout: 240 seconds]
return0e has joined #crystal-lang
dwdv has left #crystal-lang ["leave"]
postmodern has joined #crystal-lang
_whitelogger has joined #crystal-lang
ur5us has quit [Ping timeout: 240 seconds]
ur5us has joined #crystal-lang
ur5us has quit [Ping timeout: 256 seconds]
_ht has joined #crystal-lang
_ht has quit [Quit: _ht]
FromGitter has quit [Remote host closed the connection]
FromGitter has joined #crystal-lang
<FromGitter> <oren> is there a way to exist a function? not the entire program?
<FromGitter> <oren> i guess 'return' does that.
alexherbo2 has joined #crystal-lang
<FromGitter> <Daniel-Worrall> breaking flow keywords you should know are `next`, `break`, `return`, `raise`
<FromGitter> <Daniel-Worrall> I feel like I missed one
<FromGitter> <nothratal> Hello
<FromGitter> <nothratal> can someone explain to me why the compiler enforces a space after an argument in methods? There is probably a good reason for it, I just didn't find it yet
<FromGitter> <j8r> @Daniel-Worrall `exit`
<FromGitter> <j8r> I will break the whole program :)
<FromGitter> <stronny> @nothratal I guess that has something to do with named tuples?
gangstacat has quit [Ping timeout: 272 seconds]
<FromGitter> <j8r> Optimization question: I would like to make path parsing as fast as possible, with as fewer allocations as possible. ⏎ Transform `aa/bb/cc` into `"aa"` `"bb"` and `"cc"`
<FromGitter> <stronny> do you need parts as separate variables?
<FromGitter> <j8r> Obviously there is `String#split`, but I was also digging in the unsafe land
<FromGitter> <stronny> hey, you know what
<FromGitter> <stronny> you can have Slices pointing to a first byte of a part
<FromGitter> <j8r> I tried with Slices, but I didn't see any meaningful gain
<FromGitter> <j8r> In fact, it would be like consuming the string - if possible
<FromGitter> <stronny> the problem here is UTF8
<FromGitter> <stronny> I think you can have a single loop iterating over string's characters and making slices upon encountering "/"
<FromGitter> <j8r> It won't be a problem, since URL path are ASCII only
<FromGitter> <stronny> then it should be as fast as it can be
<FromGitter> <j8r> I did try it by keeping an `offset`, and using `Slice#index`
<FromGitter> <j8r> I have to try it again and do a proper benchmark
<FromGitter> <stronny> what do you mean consuming the string?
<FromGitter> <j8r> Like an Array of chars, shift
<FromGitter> <stronny> still don't understand
<FromGitter> <j8r> I would like to avoid allocations
<FromGitter> <stronny> you already have a string allocated
<FromGitter> <j8r> Using `#split` or `#partition` will use `malloc`
<FromGitter> <stronny> slices don't allocate
<FromGitter> <j8r> But I need each time to create a new one, not sure it would be more efficient?
<FromGitter> <stronny> each time create a new String?
<FromGitter> <stronny> where does it come from?
<FromGitter> <j8r> `String#split` will create a new string on each iteration
<FromGitter> <stronny> worse, it will create Array(String)
<FromGitter> <j8r> `Slice# (start : Int, count : Int) ` is what I used to create new slices
<FromGitter> <j8r> @stronny I meant `String#split(&)`
<FromGitter> <stronny> I would go with smth like this
<FromGitter> <j8r> Or, maybe the perf was negligible because the bottleneck was elsewhere...
<FromGitter> <j8r> Ok thanks, I will try again with slices then
gangstacat has joined #crystal-lang
<FromGitter> <stronny> @j8r https://play.crystal-lang.org/#/r/8p7m
<FromGitter> <stronny> the hard part is doing something useful without allocating Bytes back to a String though
postmodern has quit [Read error: Connection reset by peer]
postmodern has joined #crystal-lang
<Welog> Hello there :) I got disconnection (Timeout) with this code : https://github.com/maxpowa/ircbot.cr/blob/master/src/ircbot/irc.cr every 19 days. Do you have any tips to provide regarding TCP socket keepalive ? (line 25-28) I'm using 0.33.0 version
ua has quit [Read error: Connection reset by peer]
ua has joined #crystal-lang
<FromGitter> <stronny> my tip would be moving from socket layer keepalives to application layer. idk whether icp proto has any pings/nops etc, but if it does, I'd go that way
alexherbo2 has quit [Remote host closed the connection]
<Welog> Yes IRC has ping / pong mechanism and it is implemented in the code. And it works well a few days (19-20 days) but after that it seems the connection is timeout (IRC server tell "lost connection" and socket rescue after 5 minutes ERROR Errno: connect: Connection timed out)
<FromGitter> <stronny> well maybe there's something wrong with the connection at the network level
travis-ci has joined #crystal-lang
<travis-ci> crystal-lang/crystal#2d91f14 (master - Show warnings on docs command (#8880)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/660133567
<DeBot> https://github.com/crystal-lang/crystal/pull/8880 (Show warnings on docs command)
travis-ci has left #crystal-lang [#crystal-lang]
<Welog> ok thanks for your tips
travis-ci has joined #crystal-lang
<travis-ci> crystal-lang/crystal#c65610a (master - Add flush to many builders (#8876)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/660135852
travis-ci has left #crystal-lang [#crystal-lang]
<DeBot> https://github.com/crystal-lang/crystal/pull/8876 (Add flush to many builders)
travis-ci has joined #crystal-lang
<travis-ci> crystal-lang/crystal#fd96648 (master - Move Adler32 and CRC32 to Digest namespace (#8881)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/660136447
<DeBot> https://github.com/crystal-lang/crystal/pull/8881 (Move Adler32 and CRC32 to Digest)
travis-ci has left #crystal-lang [#crystal-lang]
postmodern has quit [Quit: Leaving]
alexherbo2 has joined #crystal-lang
alexherbo2 has quit [Remote host closed the connection]
yxhuvud has joined #crystal-lang
<FromGitter> <j8r> How do you call an object that deal with `/some/path/*`, in a web framework? ⏎ For now I called it `PathGlob`
<FromGitter> <Blacksmoke16> either that or maybe variadic?
<FromGitter> <Blacksmoke16> id go with glob personally, not sure what the use case would be for it tho?
<FromGitter> <j8r> The object is `Parameters::PathGlob`, it is an abstract
<FromGitter> <j8r> I would like to catch everything after a given path, like the amber router parameter glob
<FromGitter> <j8r> *glob parameter
<FromGitter> <Blacksmoke16> 👍 yea seems fine
<FromGitter> <j8r> I don't know `PathGlob` or `GlobPath` 😅
<FromGitter> <Blacksmoke16> `Glob`?
<FromGitter> <Blacksmoke16> whats the other path param called?
<FromGitter> <j8r> ho, yeah I need to create one to glob all query params too...
<FromGitter> <j8r> so `QueryGlob` and `PathGlob`, sounds good
<FromGitter> <Blacksmoke16> 👍 sure
<FromGitter> <j8r> I already have `RequiredQuery` and `OptionalQuery`
<FromGitter> <Blacksmoke16> hmm
<FromGitter> <Blacksmoke16> part of me says to make the order consistent, `GlobQuery`
<FromGitter> <j8r> Yeah sorry
<FromGitter> <j8r> `PathGlob` and `QueryGlob`, I messed up
<FromGitter> <Blacksmoke16> gotcha
<FromGitter> <j8r> Athena isn't that fast https://github.com/the-benchmarker/web-frameworks :(
<FromGitter> <Blacksmoke16> i know, sacrificing speed for QoL/features
<FromGitter> <Blacksmoke16> still plenty fast
<FromGitter> <Blacksmoke16> about on par with Amber, rest are mainly just routers so ofc they going to be faster
<FromGitter> <Blacksmoke16> iirc lucky needs updated to better support multi processes like the others are using
<FromGitter> <Blacksmoke16> which is why its so low
<FromGitter> <Blacksmoke16> oh wait, PR was merged, results just need ran again
<FromGitter> <kinxer> Is there a good way of getting the classes in a module?
<FromGitter> <stronny> hm?
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/8p8q
<FromGitter> <Blacksmoke16> this would also include normal constants tho
<FromGitter> <kinxer> Thanks, @Blacksmoke16.
<FromGitter> <kinxer> I don't suppose there's a good way of inspecting what kind of constants those are (beside assuming that pascal-case means classes)?
<FromGitter> <Blacksmoke16> @j8r right, but those changes were made 3 days ago
<FromGitter> <Blacksmoke16> results on master dont include it, hence why i thought it wasnt updated yet
<FromGitter> <j8r> Sure, I really need to run the project to see how fast my router/framework is :D
<FromGitter> <stronny> @kinxer https://crystal-lang.org/api/0.33.0/Crystal/Macros/TypeNode.html#constant(name:StringLiteral%7CSymbolLiteral%7CMacroId):ASTNode-instance-method
<FromGitter> <Blacksmoke16> that would have the same issue
<FromGitter> <Blacksmoke16> @j8r good luck 😉
<FromGitter> <kinxer> @stronny Thanks! https://carc.in/#/r/8p90
<FromGitter> <kinxer> I'm just contemplating how difficult it would be to create a dependency sandboxing shard in Crystal. I'm assuming it'll be very difficult, but it may not be feasible at all...
<FromGitter> <Blacksmoke16> oh interesting
<FromGitter> <stronny> plz explain?
<FromGitter> <Blacksmoke16> dependency sandboxing? like a service container?
<FromGitter> <kinxer> Based on https://webassembly.org/docs/security/
<FromGitter> <stronny> ah, you mean permissions
<FromGitter> <kinxer> I guess so, yes.
<FromGitter> <kinxer> It would be nice not to have to trust shard X not to read my filesystem and send that off somewhere. Containerization helps with that issue, but it doesn't really solve the base problem (and has its own difficulties).
<FromGitter> <stronny> I don't think that's possible and/or practical or even a good idea
<FromGitter> <kinxer> Why not a good idea?
<FromGitter> <stronny> permissions are hard
_ht has joined #crystal-lang
<FromGitter> <kinxer> That's not a compelling argument. That's just why we need a good reason to do it, which we have.
<FromGitter> <stronny> this is not a new problem, how was it solved before?
<FromGitter> <kinxer> At the OS level?
<FromGitter> <kinxer> I admit I don't have much experience with this topic. I know that browsers use sandboxing as a way of running untrusted code (e.g. plugins); I'd guess that experience with that is why WASM comes with solutions to this built-in.
<FromGitter> <kinxer> Also, how old is this problem, really? Wide software dependency ecosystems have only been around for what, 15 years at most? Software has been around for much longer, but industrial software dependencies have a point of contact (a company) who you can sue if they bake in malicious code. Open source software seems to rely really heavily on having a large number of eyes on the code, which usually works (since it's
<FromGitter> ... unlikely that they would all benefit from malicious code). But in many software ecosystems (such as our Crystal shard ecosystem), lots of packages that are useful have a single developer. I tend to trust those people, but I shouldn't *have to* trust those people not to insert malicious code. It's only been a year and a ha ... [https://gitter.im/crystal-lang/crystal?at=5e667ecfd17593652b721897]
<FromGitter> <stronny> C libs were around since forever
<FromGitter> <kinxer> And was there a technical solution to this problem in C or its ecosystem? Or was it a sociological solution?
<FromGitter> <j8r> ... they use postgres, omg...
<FromGitter> <stronny> I don't think a technical solution is possible
<FromGitter> <kinxer> In Crystal or at all?
<FromGitter> <stronny> at all
<FromGitter> <kinxer> Why is that?
<FromGitter> <stronny> I can't see a way to solve the problem is all
<FromGitter> <Blacksmoke16> @j8r yea :/ used to be sqlite
<FromGitter> <Blacksmoke16> i added a docker-compose file that should make things easier tho
<FromGitter> <stronny> a philosophical solution would be revisiting our current ethos around development
<FromGitter> <kinxer> Ah... In WASM, the way they're solving it is by building module separation into the language. Obviously, most language ecosystems can't do that. However, I'd expect that you should be able to enforce certain constraints in compiled languages at compile-time.
<FromGitter> <kinxer> I'm curious what you mean by that.
<FromGitter> <stronny> I don't consider wasm approach to be a *solution*
<FromGitter> <kinxer> Why is that?
<FromGitter> <stronny> it doesn't solve the problem?
<FromGitter> <kinxer> Could you explain why you think that?
<FromGitter> <stronny> first let's define the problem then
<FromGitter> <stronny> you know what: maybe a way forward would be in FP pure functions
<FromGitter> <kinxer> Those are just deterministic functions?
<FromGitter> <kinxer> (A legitimate question)
<FromGitter> <stronny> no side-effects, no access to grobal state
<FromGitter> <kinxer> Right. How do you do I/O in that scheme?
<FromGitter> <stronny> you don't
<FromGitter> <stronny> you use FP for the *libraries*
<FromGitter> <stronny> you do i/o in a *program*
<FromGitter> <stronny> that's hard though
<FromGitter> <kinxer> Yeah, it sounds difficult.
<FromGitter> <kinxer> Though, again, that's not inherently a reason not to do it.
<FromGitter> <stronny> there was this talk by detroyallsoftware I think
<FromGitter> <kinxer> @naqvis A static analysis tool is a good first step; thanks for the link.
<FromGitter> <stronny> maybe this one https://www.destroyallsoftware.com/talks/boundaries
<FromGitter> <kinxer> Thanks. I'll have to watch that later.
travis-ci has joined #crystal-lang
<travis-ci> crystal-lang/crystal#40d57a9 (master - Move Iconv to Crystal namespace (#8890)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/660264610
travis-ci has left #crystal-lang [#crystal-lang]
<DeBot> https://github.com/crystal-lang/crystal/pull/8890 (Move Iconv to Crystal namespace)
ur5us has joined #crystal-lang
<FromGitter> <j8r> @Blacksmoke16 have you in athena an handler that runs at the very first of a request processing?
<FromGitter> <Blacksmoke16> an event gets emitted really early yea
<FromGitter> <j8r> I had one, but I don't sereany need now there is a GlobPath
<FromGitter> <j8r> What is the main use case? Static file serving was one, but now there is GlobPath
<FromGitter> <Blacksmoke16> CORs is the main one that comes to mind
<FromGitter> <Blacksmoke16> its also used within the framework itself, as the route gets resolved within it
<FromGitter> <Blacksmoke16> is what they say about it
_ht has quit [Remote host closed the connection]
<FromGitter> <j8r> Note I already have a Route hanlder, which executes after the route is found
<FromGitter> <Blacksmoke16> i been thinking about one that gets emitted after the arguments to the route action are resolved
<FromGitter> <Blacksmoke16> but i cant think of a real good use case for it so meh
<FromGitter> <j8r> Me too, I'll remove it
<FromGitter> <j8r> So I only have final and a route handlers
<FromGitter> <Blacksmoke16> well to be clear, i mean after the route and its arguments have been resolved, but before it actually executes
<FromGitter> <Blacksmoke16> it *would* allow you to alter the arguments that the action would receive
<FromGitter> <j8r> Yep, that's what route hanlder does
<FromGitter> <Blacksmoke16> gotcha
<FromGitter> <Blacksmoke16> having more events makes things more flexible, but they can always be easily added in future if a use case comes up
<FromGitter> <j8r> before there was a response/result handler, but now that's the return object that handles it
<FromGitter> <j8r> of the route action
<FromGitter> <Blacksmoke16> where does this happen in the code?
<FromGitter> <Blacksmoke16> nvm
<FromGitter> <j8r> it is a `Response` module, which has a `add_response(response : HTTP::Server::Context)`
<FromGitter> <j8r> the http status and content type will be set automatically after, then the response sent
<FromGitter> <Blacksmoke16> gotcha