ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 260 seconds]
f1reflyylmao is now known as f1refly
andremedeiros has quit [Read error: Connection reset by peer]
andremedeiros has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
_ht has joined #crystal-lang
hendursaga has joined #crystal-lang
hendursa1 has quit [Ping timeout: 240 seconds]
andremed- has joined #crystal-lang
andremedeiros has quit [Ping timeout: 268 seconds]
andremed- is now known as andremedeiros
ua has quit [Ping timeout: 260 seconds]
<FromGitter> <spTorin> How can I make a PUT method in the HTTP::Client with "Content-Type: application / json" and JSON string?
<FromGitter> <spTorin> Analog of this: ⏎ ⏎ ```curl -X PUT http://localhost -H 'Content-Type: application/json' -d '{ "key" : "value" }'``` [https://gitter.im/crystal-lang/crystal?at=606ed78d55d78266a6307812]
<FromGitter> <MrSorcus> @spTorin https://gist.github.com/MrSorcus/6fdbabe4c3240101b0feff7888c97afa - maybe this?
Vexatos has quit [Quit: ZNC Quit]
sorcus has quit [Quit: WeeChat 3.1]
Vexatos has joined #crystal-lang
sorcus has joined #crystal-lang
<FromGitter> <spTorin> @MrSorcus it's worked! tnx!
andremedeiros has quit [Read error: Connection reset by peer]
andremedeiros has joined #crystal-lang
ua has joined #crystal-lang
<FromGitter> <lodenos> Hey Guy’s I’ve a wierd question to ask why `Slice#.new(pointer : Pointer(T), size : Int, *, read_only = false)` size is a Int not a UInt ?
<straight-shoota> The method allows to pass any int type, but it gets automatically casted to the internal type
<straight-shoota> internal size is still Int32 btw.
<FromGitter> <lodenos> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=606ef9b91f84d71853a4c38b]
<FromGitter> <lodenos> Yes but UInt it’s more logical
<FromGitter> <lodenos> That mean the maximum size of Slice(Int8) = 2_147_483_648 Bytes
<straight-shoota> stdlib APIs try to avoid unsigned integers to prevent you from shooting yourself in the foot.
<straight-shoota> It's just to easy to use slice.size in algebra operations and you get a real mess when subtraction raises an overflow, just because you go below 0
<straight-shoota> and UInt32 wouldn't be a real solution either, because you still couldn't have slices bigger than 4_294_967_295 bytes while 64-bit architectures allow much more
<straight-shoota> So the idea is to increase the size to Int64 instead (the difference between Int64 and UInt64 is negligible)
<straight-shoota> there's already a PR for that, but the exact migration procedure is not yet finalized
<FromGitter> <lodenos> I see I understant why this choise, My question seem weird but just for understand the choice behind
<straight-shoota> the question is perfectly reasonable
<straight-shoota> :D
* FromGitter * tenebrousedge lurks
<FromGitter> <resuni:matrix.org> How do you deal with a situation where a function could return a number of given types? Simple example: https://play.crystal-lang.org/#/r/at75
<FromGitter> <Blacksmoke16> do type checking to ensure its what you want/expect
<FromGitter> <Blacksmoke16> or just dont do that
<FromGitter> <tenebrousedge> `case` works to sort out types
<FromGitter> <tenebrousedge> but you might want to have some mixin class there
<FromGitter> <Blacksmoke16> whats the end goal here? the error there is because `@object` can be nil, when its defined that it cant
<FromGitter> <Blacksmoke16> then if you fix that `CallingClass` doesnt have `.var1` method so that wouldnt work either
<FromGitter> <Blacksmoke16> are a few ways to solve this, but it would help to know the end goal first
<FromGitter> <tenebrousedge> avoiding initializing properties as nil is pretty good too
<FromGitter> <tenebrousedge> letting anything be `nil` that doesn't have to be is just obnoxious
<FromGitter> <resuni:matrix.org> I'm in a situation where I have to instantiate from a different class depending on what I'm parsing.
<FromGitter> <Blacksmoke16> maybe setup some sort of interface base class, then have implementations for each "type" of thing?
<FromGitter> <Blacksmoke16> versus having 1 type with a big union of everything, you could just type it as the base type
<FromGitter> <resuni:matrix.org> When I use if statements or case statements, the compiler still sees the possibility that the conditions aren't met and complains about nil.
<FromGitter> <tenebrousedge> yee
<FromGitter> <Blacksmoke16> got an example of that @resuni:matrix.org?
<FromGitter> <Blacksmoke16> prob just arent using them correctly or something
<FromGitter> <resuni:matrix.org> Well, I haven't tried using a case statement that actually looks at the type. Should I use #is_a? to do that? https://crystal-lang.org/api/1.0.0/Object.html#is_a?(type:Class):Bool-instance-method
<FromGitter> <tenebrousedge> nah just use `case Foo`
<FromGitter> <tenebrousedge> or rather `when Foo`
<FromGitter> <Blacksmoke16> ^
<FromGitter> <resuni:matrix.org> ohhhhh
<FromGitter> <Blacksmoke16> ofc can also just use 1 type
<FromGitter> <resuni:matrix.org> I didn't know you could do that.
<FromGitter> <Blacksmoke16> which will raise a compiler error if there is a type unhandled by the case
<FromGitter> <resuni:matrix.org> That makes sense, I'm going to try to use `in`
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <tenebrousedge> I'm just glad that the syntax of that was finalized
<FromGitter> <resuni:matrix.org> I've updated my example: https://play.crystal-lang.org/#/r/at7m
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=606f333097cf5067464d886f]
<FromGitter> <Blacksmoke16> using `test.object` in both cases defeats the purpose
<FromGitter> <Blacksmoke16> same idea as that
<FromGitter> <Blacksmoke16> so would want to assign it to a local var first
<FromGitter> <Blacksmoke16> or more ideally do something like this:
<FromGitter> <tenebrousedge> short initializers good: ⏎ https://play.crystal-lang.org/#/r/at7t
<FromGitter> <tenebrousedge> passing a block argument for more complicated tasks is also good
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/at7u
<FromGitter> <tenebrousedge> `getter foo { Foobar.new(1) }`
<FromGitter> <resuni:matrix.org> I don't think class inheriting like that is an option in my case, but I'll think on it.
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <tenebrousedge> could you use a module?
<FromGitter> <tenebrousedge> Goddess I've missed thinking about code
<FromGitter> <resuni:matrix.org> I have to go in a few minutes, but one question about the case statement: Why does that work with a local variable but not the getter inside the object?
<FromGitter> <resuni:matrix.org> > procs and methods aren't guaranteed to return the same more-specific type on two successive calls
<FromGitter> <resuni:matrix.org> Why does assigning a local variable change this?
<FromGitter> <Blacksmoke16> because it makes things based on the return value of the first call
<FromGitter> <Blacksmoke16> i.e. its not going to change
<FromGitter> <Blacksmoke16> as its not another method call you know?
<FromGitter> <tenebrousedge> that does make sense
<FromGitter> <resuni:matrix.org> ok, I think I understand.
<FromGitter> <resuni:matrix.org> I'll probably be back later with more questions about that lol
<FromGitter> <Blacksmoke16> 👍
hendursaga has quit [Ping timeout: 240 seconds]
DTZUZU has joined #crystal-lang
<FromGitter> <resuni:matrix.org> I made a mistake in my first example. The case statement is actually in a second function in CallingClass: https://play.crystal-lang.org/#/r/at87
<FromGitter> <resuni:matrix.org> In which case reassigning to a local variable doesn't make sense.
<FromGitter> <Blacksmoke16> why wouldnt it?
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/at8b
<FromGitter> <resuni:matrix.org> Because it's an instance variable in the same class. I'm not making a method call in that case, am I?
<FromGitter> <resuni:matrix.org> I didn't use o
<FromGitter> <resuni:matrix.org> Oh, duh.
<FromGitter> <resuni:matrix.org> > The value of these kinds of variables could potentially be affected by another fiber after the condition was checked
<FromGitter> <resuni:matrix.org> What is a fiber?
<FromGitter> <resuni:matrix.org> Is it like a thread?
<FromGitter> <tenebrousedge> yeah, like a thread
<FromGitter> <resuni:matrix.org> I think that clears up my confusion about why assigning to a local variable works then. I wasn't thinking about concurrency.
<FromGitter> <tenebrousedge> I mean you could also just have a method that returns "1" or "2" on alternate calls
<FromGitter> <tenebrousedge> the result of two subsequent calls doesn't have to be remotely similar
hendursaga has joined #crystal-lang
Welog has quit [Remote host closed the connection]
_ht has quit [Remote host closed the connection]
shalokshalom has joined #crystal-lang
postmodern_ has joined #crystal-lang
hendursaga has quit [Ping timeout: 240 seconds]
hendursaga has joined #crystal-lang
chachasmooth has quit [Ping timeout: 240 seconds]
chachasmooth has joined #crystal-lang
postmodern_ has quit [Quit: Leaving]
shalokshalom has quit [Ping timeout: 248 seconds]