ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.31.1 | 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
chachasmooth has quit [Ping timeout: 246 seconds]
chachasmooth_ has joined #crystal-lang
<FromGitter> <watzon> Whoops lol
return0e has quit []
<FromGitter> <sam0x17> @Daniel-Worrall there are a bunch of people using duktape for game scripting, and they have some benchmarks on their website
<FromGitter> <sam0x17> I haven't benchmarked this in particular, though because I cache the context, it's quite efficient
<FromGitter> <sam0x17> the tricky thing is it's just ES5, so you have to play around with babel to transpile things into running on it (did for this)
<FromGitter> <sam0x17> *didnt' need to for this
return0e has joined #crystal-lang
<FromGitter> <watzon> Oh Duktape doesn't have ES6 support?
<FromGitter> <Daniel-Worrall> unfortunately
<FromGitter> <watzon> We need good V8 bindings
<FromGitter> <watzon> I'm gonna look into that
devil_tux has joined #crystal-lang
<devil_tux> can I skip overriding annotations when creating new class, see: https://play.crystal-lang.org/#/r/7y5e
<devil_tux> ie. I want to use predefined annotation values
<FromGitter> <Blacksmoke16> well that ann is applied to the class, not the def
<FromGitter> <Blacksmoke16> so it doesnt exit
<FromGitter> <Blacksmoke16> exist*
<FromGitter> <watzon> devil_tux https://play.crystal-lang.org/#/r/7y5f
<FromGitter> <watzon> You need `@type` not `@def`
<devil_tux> watzon: ah dumby me
<devil_tux> Blacksmoke16: yea i can see it now
<devil_tux> ty guys
<FromGitter> <Blacksmoke16> np
f1refly has joined #crystal-lang
f1reflyylmao has quit [Ping timeout: 246 seconds]
<FromGitter> <jaydorsey> good evening. was wondering if someone could help me understand what might have changed recently with File.real_path?
<FromGitter> <jaydorsey> I used to be able to do `File.real_path(“bin”)` for example, and it would read that path. Now, it seems to die on every folder with an error message ```Unhandled exception: Error resolving real path of 'foo': No such file or directory (Errno) ⏎ from /Users/jay/.asdf/installs/crystal/0.31.1/src/crystal/system/unix/file.cr:92:5 in 'real_path' ⏎ from /Users/jay/
<FromGitter> ... .asdf/installs/crystal/0.31.1/src/file.cr:554:5 in 'real_path' ⏎ from test.cr:1:1 in '__crystal_main' ⏎ from /Users/jay/.asdf/installs/crystal/0.31.1/src/crystal/main.cr:97:5 in 'main_user_code' ... [https://gitter.im/crystal-lang/crystal?at=5dbf9f252f8a034357304609]
<FromGitter> <jaydorsey> I just remembered I recently upgraded to macOS catalina on both my work and home computers, so i wonder if that might be related
<FromGitter> <jaydorsey> I tried giving the app I built full disk access via System Prefs and the error still occurs
<FromGitter> <jaydorsey> I’m actually going to open a bug report here. This is really problematic for the little toy app I’m reading, but I’m pretty certain this is a bug/behavior w/ macOS catalina only
return0e_ has joined #crystal-lang
return0e has quit [Ping timeout: 240 seconds]
<FromGitter> <Daniel-Worrall> Is `Fiber.yield` not working properly? my program is exiting without passing to the fibers
<FromGitter> <watzon> @Daniel-Worrall have a working code sample?
<FromGitter> <Daniel-Worrall> It works completely fine with sleep
<FromGitter> <Daniel-Worrall> sec
<FromGitter> <Daniel-Worrall> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5dbfb74814d55a3785cee6d3]
<FromGitter> <Daniel-Worrall> clearly something to do with the http client
ht_ has joined #crystal-lang
<FromGitter> <Daniel-Worrall> Is it possible to add missing nested folders when writing a file?
<FromGitter> <watzon> `FileUtils.mkdir_p`
<FromGitter> <watzon> So weird, I tested your code and I feel like it should be working, but it's definitely now
<FromGitter> <Daniel-Worrall> hm, but no one-liner
<FromGitter> <Daniel-Worrall> Yeah, it's not the first time I've come across it
<FromGitter> <Daniel-Worrall> Fiber.yield doesn't play nice in all cases
<FromGitter> <watzon> Seemingly not
<FromGitter> <watzon> Here's a doc link to mkdir_p https://crystal-lang.org/api/0.30.1/FileUtils.html#mkdir_p(paths:Enumerable(String),mode=511):Nil-instance-method
<FromGitter> <Daniel-Worrall> I got doc links up but ty
<FromGitter> <Daniel-Worrall> I'll go issue this yield
<FromGitter> <watzon> Yeah it seems like an issue
<FromGitter> <Daniel-Worrall> Hm why don't any of the Dir methods accept a `Path` object
<FromGitter> <watzon> Good question
ht_ has quit [Remote host closed the connection]
<devil_tux> :q
devil_tux has quit [Quit: leaving]
<FromGitter> <watzon> Weird
<FromGitter> <watzon> `"/" == '/'` is false
<FromGitter> <watzon> I would've thought that it would be true
<FromGitter> <yxhuvud> One is a string, one is a char.
<FromGitter> <watzon> Well yeah, but they should be equal. For instance `1.0 == 1` is true, even though one is a `Int32` and the other is a `Float64`
<FromGitter> <watzon> I could swear `Char`s and `String`s use to be able to be tested for equality
return0e has joined #crystal-lang
return0e_ has quit [Ping timeout: 268 seconds]
DTZUZO has quit [Ping timeout: 268 seconds]
<FromGitter> <absolutejam_gitlab> @Daniel-Worrall I asked this on the forums and it's because the `Path` module is relatively new
<FromGitter> <absolutejam_gitlab> Makes sense to move to that direction though
<oprypin> @Daniel-Worrall: i think the main direction is to have methods on the Path object instead. not that it can always work out well...
<FromGitter> <lbarasti> @Daniel-Worrall @watzon, that's the expected behaviour for `Fiber.yield`. In the example above ⏎ ⏎ 1) The main fiber suspends and the scheduler puts it in the queue. ⏎ 2) The other fiber starts, issues the HTTP call and suspends, waiting for a response ⏎ 3) The scheduler picks the main fiber, as no other fibers are ready to run, and the program terminates [https:
<FromGitter> ... //gitter.im/crystal-lang/crystal?at=5dbfebf6e886fb5aa24f7461]
<FromGitter> <lbarasti> if you add a print statement before the get request, you'll see that gets printed
<FromGitter> <watzon> Ahh that makes sense
return0e has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
<repo> hey
<repo> what was the syntax for multi line values in named tuples again?
<repo> i remember the comma being somewhere in a weird place
<repo> hmm weird
<repo> my macro expands to this: https://p.jokke.space/Fqxhc/
<repo> which looks fine to me
<repo> but i get an error nonetheless: https://p.jokke.space/eyRh2i/
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 268 seconds]
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 265 seconds]
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 264 seconds]
dwdv_ has joined #crystal-lang
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 265 seconds]
<repo> unrelated question: i tried to run the following query with will/crystal-pg: `db.query_all("SELECT * FROM log_messages WHERE ts_message @@ to_tsquery(?)", args: ["foo"])` but got a syntax error at or near ")"
<repo> the query (with expanded args) `SELECT * FROM log_messages WHERE ts_message @@ to_tsquery('foo');`­works­fine
<repo> (in psql shell that is)
DTZUZO has joined #crystal-lang
duane has joined #crystal-lang
DTZUZO has quit [Ping timeout: 268 seconds]
HumanG33k has quit [Ping timeout: 245 seconds]
HumanG33k has joined #crystal-lang
<FromGitter> <Daniel-Worrall> ah, I thought Fiber.yield made guarantees about finishing execution. Guess I'll need to make a channel and receive x amount of times
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
<FromGitter> <asterite> repo: use `$1` instead of `?`
<jhass> we should rename Fiber.yield to Fiber.yield_dont_use_me_use_a_channel_instead :D
HumanG33k has quit [Ping timeout: 265 seconds]
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
duane has quit [Ping timeout: 246 seconds]
<FromGitter> <yxhuvud> No.
duane has joined #crystal-lang
<FromGitter> <yxhuvud> also the same issue exist with threads, in about every language I've seen that doesn't do structured concurrency with cancellation
DTZUZO has joined #crystal-lang
ht_ has joined #crystal-lang
<FromGitter> <sam0x17> XD
<FromGitter> <sam0x17> fibers + channels is pretty badass. I did a 500 file S3 upload concurrently the other day with a spawn block and it didn't crash and did complete and was quick
<FromGitter> <sam0x17> also didn't use crazy amount of ram
<FromGitter> <sam0x17> (as in 1 fiber per file)
<FromGitter> <Blacksmoke16> what did that look like? ⏎ ⏎ ```files.each do |file| ⏎ spawn do ⏎ client.update file ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5dc0517fa03ae1584f684709]
<FromGitter> <Blacksmoke16> what did that look like? ⏎ ⏎ ```files.each do |file| ⏎ spawn do ⏎ client.update file ⏎ end ⏎ end``` ⏎ ⏎ ? [https://gitter.im/crystal-lang/crystal?at=5dc0518c14d55a3785d37f41]
<FromGitter> <Blacksmoke16> then like ⏎ ⏎ ```files.size.times do ⏎ channel.receive ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5dc051adef84ab3786f5daff]
<FromGitter> <sam0x17> yup
<FromGitter> <sam0x17> exactly like that
<FromGitter> <Blacksmoke16> easy enough
<FromGitter> <sam0x17> all the small files (about 150) finished in the first 2 seconds, and then the large files all finished around the same time a minute later
<FromGitter> <sam0x17> so it really was doing tons of uploads at the same time
<FromGitter> <sam0x17> mind you this is on a gigabit connection
hightower2 has joined #crystal-lang
<hightower2> Hey folks, see this example:
<hightower2> Why my calling the function with explicitly wanting to set value for arg2, sets it for arg1?
<FromGitter> <Blacksmoke16> im pretty sure the syntax is `arg2: "mystring"1
<FromGitter> <Blacksmoke16> `:` not `=`
<FromGitter> <Blacksmoke16> surprised that doesnt cause an error
<hightower2> mm, ok, maybe I got confused by both syntax in python and in ruby (in ruby both work, with different behavior)
<hightower2> but it's kinda weird, yeah
<hightower2> ah, so in this case it obviously assigns value to arg2, then passes arg2 as value for first positional arg
<FromGitter> <Blacksmoke16> makes sense yea
<hightower2> ok, cool, thanks for discussion
<FromGitter> <asterite> I'd like `arg1=...` inside a method call to be a semantic error
<FromGitter> <kinxer> Agreed.
<FromGitter> <j8r> There is no real use case, or allow it inside parenthesis
<repo> asterite: ah
<repo> asterite: silly me :D
<repo> quick question: is there something like go templates for crystal?
<repo> as in runtime-evaluated templates
<FromGitter> <asterite> maybe https://github.com/straight-shoota/crinja
<repo> hm yeah
<repo> but maybe this is already enough for my usecase: "sum: %{one} + %{two} = %{three}" % {one: 1, two: 2, three: 1 + 2}
<FromGitter> <ImAHopelessDev_gitlab> hello
dannyAAM has quit [Quit: znc.saru.moe : ZNC 1.6.2 - http://znc.in]
dannyAAM has joined #crystal-lang
<FromGitter> <tenebrousedge> o hai
<hightower3> howdy
<FromGitter> <wontruefree> here is a shameful plug of Chicago Crystal meetup. Ill have a shameless one later http://chicagocrystal.org/events/bbhsjryzpbkb/
<hightower3> Hm what exact syntax can I use to create a hash from something like this: hash = hash2.map {|k,v| k => process(v) }
<hightower3> if I don't put {} around k=> I get syntax error. If I do, I get array of hashes in 'hash', rather than key=values directly
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/Enumerable.html#each_with_object(obj,&)-instance-method
<FromGitter> <Blacksmoke16> prob want that
<hightower3> very probably, almost certainly :) thanks
<FromGitter> <Blacksmoke16> n
<FromGitter> <Blacksmoke16> np
<hightower3> Although that requires me to specify type which I hoped to avoid, but well...
<FromGitter> <Blacksmoke16> got an example of your previous version?
<hightower3> Previous code which I didn't realize immediately that it gave me array of hashes, was: methods = hash.map do |k,v| {k=>process(v)} end
<FromGitter> <Blacksmoke16> sorry, i mean a runnable example, like a playground link?
<hightower2> this results in array of hashes, whereas I hoped for a hash directly, without explicit mention of types if possible
<FromGitter> <Blacksmoke16> and whats the output you want?
<hightower2> {"k1" => "1", "k2" => "2"}
<FromGitter> <Blacksmoke16> but your hash is already like that?
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/7yba like this but a singular hash vs an array?
<hightower2> yes, yes, I used a silly example with function being #downcase. I'd call some other/custom function there which is gonna return a Proc
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/Hash.html#transform_values!(&block:V-%3EV)-instance-method
<FromGitter> <Blacksmoke16> what about that?
<hightower2> brilliant
<hightower2> that'll do it++
<FromGitter> <Blacksmoke16> 👍
duane has quit [Ping timeout: 268 seconds]
<hightower3> ahm, again not quite there yet because I need to be aware of both key and value. transform_* functions seem to only give key or value, not both
<hightower3> ok n/m, will rethink the approach
<FromGitter> <Blacksmoke16> each_with_obj might be the better approach
<FromGitter> <Blacksmoke16> could prob do like
<FromGitter> <Blacksmoke16> prob should just make a new hash then use .each to set values on that new hash
<hightower3> yes, most probably. Once I resort to specifying the type manually all options are open. Thanks.
<hightower3> mm.. I also thought of using Hash[...] which is supported in ruby and sometimes support really interesting ways of constructing the object, but I see [] isn't supported here.
<FromGitter> <tenebrousedge> there's `Hash{ }` syntax
<hemite> Am I missing something in the crystal vscode plugin? It seems it seems that "go to definition" does not work
<FromGitter> <tenebrousedge> no idea. I quit using vscode for Crystal because it didn't seem like much use. Spacevim has a reasonable level of support
<hemite> completion, goto definition, and proper debug support ( stack traces )?
<FromGitter> <asterite> hightower3: maybe to_h with block?
<FromGitter> <tenebrousedge> hightower3 you may also be able to find some interesting uses for the default block hash syntax
<hemite> tenebrousedge ^^
<FromGitter> <asterite> hemite: I don't think any crystal IDE out there has good support for completion, go to definition, etc.
<FromGitter> <tenebrousedge> and Crystal in general doesn't have great debug support
<hemite> Ah ok, thanks guys
<hemite> and also 😞
teardown has quit [Ping timeout: 276 seconds]
<hightower3> mm asterite, intesting. Speaking of which, why isn't to_h with the block variant listed in methods on https://crystal-lang.org/api/master/Hash.html ? (It only shows up in popup if I hover the mouse over Enumerable's methods
<FromGitter> <Blacksmoke16> prob because its inherited from Enumerable and not directly defined on Hash
<FromGitter> <asterite> yes, that ^
<hightower3> yes, yes, I meant, it seems like extra step needed from the reader to click there and check... but, if you didn't receive similar reports then probably I'm just not used to it.
<hightower3> asterite but yeah, to_h seems very nice, thanks
<FromGitter> <asterite> cool! :-)
<FromGitter> <asterite> I think it might be overkill to inline list all inherited methods. In Java and other OOP languages it's the same: parent methods are listed separately, just a short mention to them
teardown has joined #crystal-lang
<FromGitter> <christopherzimmerman> Is there a way to access the results of two iterators in a block if I know the size of them in advance? ⏎ ⏎ Something like ⏎ ⏎ ``` a = (1...6).each ⏎ b = (3...8).each ⏎ ⏎ Pointer.malloc(5) { |i| a.next + b.next }``` [https://gitter.im/crystal-lang/crystal?at=5dc08af69c39821509e2c4c2]
<FromGitter> <tenebrousedge> You can `zip` them
<hightower3> tenebrousedge yep found it, but it seemed too far away from elegance I wanted
<FromGitter> <tenebrousedge> hightower3 do you have a code example?
<hightower3> I thought I have it with to_h, but I got compiler exception which I can't reproduce on play. Playing around with it now.
<FromGitter> <christopherzimmerman> I don't think zipping them solves the problem of accessing them inside that block, unless I am missing something
<hightower3> christopherzimmerman yes, yes, the zip option would entail something like zip( hsh.keys, hsh.map{|k,v| transform(k,v)} )
<FromGitter> <tenebrousedge> `zip` lets you access them in *a* block
<FromGitter> <tenebrousedge> you could probably use `with_object` or `reduce` if you needed to
<hightower3> and with a block, yes (again one documented in Enumerable :)
duane has joined #crystal-lang
dwdv_ has left #crystal-lang ["leave"]
twistedpixels has joined #crystal-lang
<FromGitter> <ImAHopelessDev_gitlab> @wontruefree nice, I hope it gets recorded
<FromGitter> <Daniel-Worrall> Published a binding to JS-Beautify. Thanks to @sam0x17 for the inspiration. https://github.com/Daniel-Worrall/js-beautify.cr
<FromGitter> <Daniel-Worrall> I've done some duktape.cr testing before but hadn't thought to bake the lib inside the shard and makes things a lot easier
<FromGitter> <sam0x17> @Daniel-Worrall nice that's fantastic!
<FromGitter> <sam0x17> I've also published bindings for clean-css (github.com/sam0x17/css-minifier) and uglifyjs (github.com/js-minifier) however still cleaning those up
<FromGitter> <sam0x17> my goal is to get amber and lucky etc to drop any npm/node dependencies , but need to offer a fully viable pipeline first
<FromGitter> <sam0x17> it's horrifying that state of the art minification relies on npm these days
<FromGitter> <sam0x17> 1) https://github.com/sam0x17/html-minifier (done)
<FromGitter> <sam0x17> main thing I want to clean up is I wasn't aware of the `read_file` macro, so I was relying on `baked_filesystem` in palces where I didn't need to
<FromGitter> <sam0x17> that and docs
<FromGitter> <sam0x17> and making sure options work
<FromGitter> <ilanpillemer> how do you create a second reference to the same class?
<FromGitter> <sam0x17> @Daniel-Worrall one comment I have, you might want to only initialize the duktape context on the first use rather than at startup
<FromGitter> <Daniel-Worrall> I believe it is doing that already
<FromGitter> <sam0x17> ah ok
<FromGitter> <Daniel-Worrall> There are 3 different ones for each
<FromGitter> <sam0x17> yeah I saw, nothing wrong with that
<FromGitter> <Daniel-Worrall> That's just defining the initializer
<FromGitter> <Daniel-Worrall> It's not calling it
<FromGitter> <sam0x17> oh ok right right
<FromGitter> <sam0x17> I gotta get better at reading other people's crystal xD
<FromGitter> <Daniel-Worrall> Macro magic
<FromGitter> <sam0x17> yup
<FromGitter> <sam0x17> I took a crack at embedding lessjs but couldn't get it working
<FromGitter> <Daniel-Worrall> It's understandable though that web based minification is all written on web langs
<FromGitter> <sam0x17> NO ITS A TRAVESTY!!!! ⏎ I mean yeah it makes sense xD
<FromGitter> <Daniel-Worrall> You may want to use the runtime or a method call api method btw so you don't have to rely on interpolation fucker
<FromGitter> <Daniel-Worrall> Fuckery*
<FromGitter> <sam0x17> imo should have been in c/c++ land for the last 20 years and we should just be linking to it
* FromGitter * tenebrousedge twitches
<FromGitter> <sam0x17> basically node and npm ruined all of web dev
<FromGitter> <Daniel-Worrall> In my case I had to initialize the global variable since I was using sandbox and not context
<FromGitter> <sam0x17> yeah I forget which I used
<FromGitter> <sam0x17> I played with both
<FromGitter> <sam0x17> but yeah the interpolation fuckery -- in my case I made it work consistently but you are right
<FromGitter> <Daniel-Worrall> I tried it your way and still got parsing errors
<FromGitter> <sam0x17> I did specs for code with newlines and single and double quotes, but yeah was tricky
<FromGitter> <sam0x17> hardest part is just crystal being a double quote only language, so a lot of like `"\\\""` type stuff
<FromGitter> <Daniel-Worrall> Exactly why I recommend against the interpolation
<FromGitter> <sam0x17> so what's the fancy alternative? I'll check it out later
<hightower3> yeah the ' being char, yet so rarely used, is a big inconvenience
<FromGitter> <Daniel-Worrall> Runtime has the methods baked in but is a little bit of an overhead
<FromGitter> <tenebrousedge> double quote only? There's percent syntax
<hightower3> yeah I mean something that is one keypress, without modifiers or extra keys
<FromGitter> <Daniel-Worrall> Or you can put things on the stack and use duk_call yourself
<FromGitter> <Daniel-Worrall> I'd do it the second way but there's a convenience method so whatever
<FromGitter> <sam0x17> that percent stuff (if you're talking about what I think you're talking about) is one of my hated ruby things
<FromGitter> <sam0x17> I see it and it looks like greek
<FromGitter> <tenebrousedge> since every character can appear in a string, there's not going to be a single-character string syntax that won't be obnoxious for some strings
<FromGitter> <Daniel-Worrall> See duktape.org/api.html#duk_call
<FromGitter> <sam0x17> thx
<FromGitter> <sam0x17> ahhh, so you can just give it a string directly
<FromGitter> <sam0x17> yeah, that solves that
<FromGitter> <Daniel-Worrall> Or see duktape.cr reader Runtime example
<FromGitter> <tenebrousedge> the percent-syntax allows you to choose your delimiters; that's as good as you can get
<FromGitter> <Daniel-Worrall> Readme*
ht_ has quit [Quit: ht_]
<FromGitter> <sam0x17> @tenebrousedge yeah it's very good design wise, I just dont like how it looks visually
<FromGitter> <sam0x17> for me crystal and ruby is all about asthetics
<FromGitter> <sam0x17> or largely
<FromGitter> <tenebrousedge> I would say they're about flexibility, Ruby in particular
<FromGitter> <sam0x17> and you'd be right
<FromGitter> <sam0x17> I'm just stubborn
<FromGitter> <tenebrousedge> the flexibility allows you to choose an aesthetically pleasing form
<FromGitter> <tenebrousedge> usually
<FromGitter> <sam0x17> but yeah on that note, I would happily sacrifice character literals for single quoted strings in crystal
<FromGitter> <tenebrousedge> what do you think about Ruby's `?` char literals?
<FromGitter> <sam0x17> maybe do some type magic where a string of length 1 *is* a char
<FromGitter> <tenebrousedge> `?A` => `'A'`
<FromGitter> <Daniel-Worrall> I like the flexibility given by being able to define chars easier
<FromGitter> <sam0x17> oh I love that
<FromGitter> <sam0x17> @tenebrousedge
<FromGitter> <tenebrousedge> I mean, what exactly is the semantic difference between a single-char string and a char?
<FromGitter> <sam0x17> I was just brainstorming in my head and had come up with basically that
<FromGitter> <sam0x17> didnt realize ruby had that
<FromGitter> <sam0x17> also my question
<FromGitter> <tenebrousedge> I think people hate it and rubocop tells you it's bad, but it's there
<FromGitter> <sam0x17> I bet it has to do with memory layout
<FromGitter> <sam0x17> rubocop will tell you whatever you tell it's cops to tell you
<FromGitter> <tenebrousedge> yeah, I read through all the cops and wrote my own .rubocop.yml
<FromGitter> <sam0x17> yup same
<FromGitter> <sam0x17> I used to work somewhere where more than 10 line function was a rubocop no-no
<FromGitter> <sam0x17> NEVER AGAIN
<FromGitter> <tenebrousedge> I'm forcing myself to write comments for every method :( I hate me
<FromGitter> <sam0x17> there is such a thing as a self-documenting method name ;)
<FromGitter> <tenebrousedge> Probably :/ but it's still probably good to document the expected input and return types, and suchlike
<FromGitter> <watzon> It would be nice if there was a way to do `a, b, c = string.split(' ')` where the assignment will just be `nil` if there aren't enough items in the array
<FromGitter> <Blacksmoke16> what happens now? out of bounds?
<FromGitter> <watzon> Yep https://carc.in/#/r/7ydm
<FromGitter> <tenebrousedge> what's your use case?
<FromGitter> <watzon> Maybe utilizing `||=` for that would be nice
<FromGitter> <Val> ```code paste, see link``` ⏎ ⏎ Is it a bug? [https://gitter.im/crystal-lang/crystal?at=5dc09fffa03ae1584f6a973d]
<FromGitter> <watzon> @tenebrousedge I've needed it several times. The only alternative is to do a split and then use `arr[0]?`.
<FromGitter> <Blacksmoke16> what happens if you use an actual binary
<FromGitter> <watzon> Right now the carc.in link I gave is my use case
<FromGitter> <tenebrousedge> @watzon what about `scan` with an optional named capture group?
<FromGitter> <Blacksmoke16> @Val see https://github.com/crystal-lang/crystal/issues/8340
teardown has quit [Ping timeout: 265 seconds]
<FromGitter> <Val> @Blacksmoke16 thanks !
<FromGitter> <watzon> Good idea, `scan` could probably work
<FromGitter> <watzon> It would be nice if it wasn't necessary though
<FromGitter> <tenebrousedge> I like avoiding `scan`. On the other hand, I tend to see `split` as being hacky
<FromGitter> <Daniel-Worrall> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5dc0a198e886fb5aa254c819]
<FromGitter> <Daniel-Worrall> that's the best hacky PoS I could come up with
<FromGitter> <Daniel-Worrall> and that `|| nil` isn't even needed
<FromGitter> <watzon> That's not bad actually
<FromGitter> <Daniel-Worrall> Eh, there's surely a better way to do it
<FromGitter> <tenebrousedge> shorter: ⏎ ⏎ ```arr = "a bc".split ⏎ a, b, c = Array(String?).new(3, &->arr.[]?(Int32))``` [https://gitter.im/crystal-lang/crystal?at=5dc0a241e1c5e9150833c8b0]
<FromGitter> <tenebrousedge> I don't think I like that :/
<FromGitter> <Daniel-Worrall> It'd be String, but ye
<FromGitter> <tenebrousedge> ??
<FromGitter> <Daniel-Worrall> Oh, I'm misunderstanding the Int32 bit
<FromGitter> <Daniel-Worrall> yeah, I got it.
<FromGitter> <Daniel-Worrall> Shame it returns String? for the not_nils
<FromGitter> <watzon> Yeah shorter isn't always better, that's for sure
<FromGitter> <watzon> I ended up with this ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5dc0a41b7477946bad2c41f6]
teardown has joined #crystal-lang
<FromGitter> <Blacksmoke16> is it worth creating a whole new array just to do that tho?
<FromGitter> <Blacksmoke16> vs
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5dc0a51afb4dab784a651703]
<FromGitter> <watzon> Yeah probably not. Hence my desire to be able to destructure an array without getting the out of bounds error
<FromGitter> <watzon> It would make things so much simpler
<FromGitter> <Blacksmoke16> make an issue about it?
<FromGitter> <watzon> Yeah I probably will
<FromGitter> <watzon> #8436
<DeBot> https://github.com/crystal-lang/crystal/issues/8436 (Allow array destructuring to produce nil values)
<FromGitter> <tenebrousedge> for a time can't you new up a `Time` object?
<FromGitter> <tenebrousedge> or `Time::Span` ?
<FromGitter> <watzon> This is a special case. I'm taking in an input in the form of `days/hours/minutes` and getting a future time that
<FromGitter> <watzon> So basically `Time.utc + days.days + hours.hours + seconds.seconds`
duane has quit [Ping timeout: 268 seconds]
<hightower3> What am I missing here.. I define function taking arg `data : IO | IO::FileDescriptor`. Inside function, I call data.size, and this gives compile error: undefined method size for IO::ARGF (compile-time type is (IO | IO::FileDescriptor))
<hightower3> Why is it mentioning IO::ARGF when I've limited the types
<hightower3> or IO didn't limit it?
<hightower3> fg
<FromGitter> <tenebrousedge> ARGF is presumably an `IO`
<FromGitter> <tenebrousedge> to narrow types though, you want to use `as`
<FromGitter> <watzon> There's no real reason for the union as far as I can tell
<FromGitter> <watzon> `IO | IO::FileDescriptor` will always match `IO`
<FromGitter> <watzon> May as well just have `data : IO`
<hightower3> yeah I wanted some more specific type
<hightower3> didn't realize IO will catch IO::*
<hightower3> stupidest things end up the hardest
Human_G33k has joined #crystal-lang
HumanG33k has quit [Ping timeout: 240 seconds]