<FromGitter>
<Blacksmoke16> kinda a misleading error message :p
alexherbo2007 has joined #crystal-lang
alexherbo200 has quit [Ping timeout: 268 seconds]
waheedi has quit [Quit: waheedi]
<FromGitter>
<j8r> Path is kinda useless :(
<FromGitter>
<j8r> instead of `File.basename(File.dirname("a/b/c"))`, we can now do `Path[Path["a/b/c"].dirname].basename`... yeah
<FromGitter>
<j8r> `Path#dirname` will better return a `Path`, not `String`
<FromGitter>
<j8r> `Path` helps mainly for documentation for now, and that's a good start
laaron- has joined #crystal-lang
laaron has quit [Remote host closed the connection]
<FromGitter>
<j8r> What's also annoying is to `.to_s` everywhere :(
<FromGitter>
<mwlang> oh, nice find today. Attempting to check if a JSON::Any (which is a parsed response from API endpoint) has a particular key. I'm fumbling around trying has_key?, failing that, attempting to convert Hash and try has_key? etc...and then....I notice it....#[]? in the docs. Such a tiny thing, my eyes kept skipping over it, and I thought, no way! but sure enough, data["lastUpdateId"]? instead of
<FromGitter>
... data.has_key?("lastUpdatedId") works! And so much nicer than Ruby's.
<FromGitter>
<mwlang> I'll take a 28x performance boost with a sprinkling of .to_s any day!
<FromGitter>
<j8r> If you just want to know if the key exists, has_key is better
<FromGitter>
<mwlang> well, I put it to work, too.
<FromGitter>
<mwlang> so those are the three possible responses I get from the server.
<FromGitter>
<Blacksmoke16> interesting
<FromGitter>
<Blacksmoke16> hows that work if the same endpoint returns diff objs?
<FromGitter>
<Blacksmoke16> or are they diff endpoints, that would make more sense
<FromGitter>
<mwlang> actually, I'm slightly wrong...it's a two step process. The first call is made RESTfully. That gets me the first one described. The subsequent calls are the Websocket with only diffs streamed.
<FromGitter>
<mwlang> that's the bottom one.
<FromGitter>
<mwlang> both websocket and rest endpoints can alternatively return the code and message in case of an error.
<FromGitter>
<Blacksmoke16> gotcha, should work the same assuming both are just strings
<FromGitter>
<mwlang> yeah, I'm reading...it's an interesting approach you suggested. I wasn't aware that Serializable stuff existed.
<FromGitter>
<Blacksmoke16> i can make an example if you need
<FromGitter>
<mwlang> if there's a big performance improvement to refactor this, then yeah, it's worth refactoring.
<FromGitter>
<mwlang> but if it's "about the same" I'll probably roll with this as it's not *ugly*
<FromGitter>
<mwlang> I've got more to go, like tracking if the order books have expired and forcing a refresh RESTfully and restarting the websocket
<FromGitter>
<j8r> the main point is to validate the schema early
<FromGitter>
<mwlang> now that's a valid point, too.
<FromGitter>
<mwlang> ok, that's actually a very good point and worth the refactor.
<FromGitter>
<Blacksmoke16> it wouldnt be much change
<FromGitter>
<r00ster91> Is it good practice to use a named tuple when the keys will never change but the keys? (I can update using `merge`)
<FromGitter>
<j8r> use a record?
<FromGitter>
<j8r> depends of the use case
<FromGitter>
<j8r> not a record, a custom struct with properties
<FromGitter>
<r00ster91> you are right! I could just fine use a struct. thank you
<FromGitter>
<Blacksmoke16> @mwlang would also allow you to add like psudo getters for those values in the 2d array
<FromGitter>
<Blacksmoke16> since you dealing with objects now
<FromGitter>
<Blacksmoke16> would have to add some annotations to some properties to make them read the correct keys, since they are diff
<FromGitter>
<mwlang> I think the way I'd handle the REST and WS endpoints is with two different structs
<FromGitter>
<mwlang> I probably needlessly combined things since I wasn't thinking in terms of schema validation as part of the processing up front.
<FromGitter>
<Blacksmoke16> well yea
<FromGitter>
<Blacksmoke16> each obj would have to be its own
<FromGitter>
<Blacksmoke16> otherwise it would get messy
<FromGitter>
<mwlang> can you mock one up for me -- I'm trying to go through the docs and figure it out, but admittedly scratching my head w/o concrete example.
<FromGitter>
<mwlang> ok, great. but how does that handle the case when a code and message is returned instead of the expected structure?
<FromGitter>
<Blacksmoke16> id assume that gets returned when there is a server error?
<FromGitter>
<Blacksmoke16> ie. non 200
<FromGitter>
<mwlang> good question! I hadn't thought to check status code returned, but you're probably right.
<FromGitter>
<Blacksmoke16> 👍
<FromGitter>
<mwlang> so we can just skip the handoff if status != 200
<FromGitter>
<Blacksmoke16> yea or serialize it into some `Error` struct
<FromGitter>
<Blacksmoke16> if you need to do stuff with it
<FromGitter>
<mwlang> ok, I got this. thanks for your help.
<FromGitter>
<Blacksmoke16> np
<FromGitter>
<MrSorcus> `passing Void return value of lib fun call has no effect` ⏎ What must i do with this error? Replace `Void` with `Void*`?
ua_ has quit [Excess Flood]
ua_ has joined #crystal-lang
<FromGitter>
<Blacksmoke16> whats the code?
ua_ has quit [Excess Flood]
waheedi has joined #crystal-lang
<FromGitter>
<mwlang> @Blacksmoke16 in this line: ```getter bids : Array(Array(String))``` how would I expand that second array to be what it ultimately is, two floating point numbers? In this case, it should resolve to price and quantity
<FromGitter>
<Blacksmoke16> but they come back from the api as strings/
<FromGitter>
<mwlang> I thought to set up another json serializeable struct, but these two values (which are strings, yes), aren't keyed with a name.
<FromGitter>
<Blacksmoke16> sec
<FromGitter>
<mwlang> they'll just always be [ [1,2], [2,3], [3,4] ]
<FromGitter>
<Blacksmoke16> is the length static? or could it change?
<FromGitter>
<Blacksmoke16> im assuming the latter
<FromGitter>
<Blacksmoke16> im not super good with arrays and json pull parser, but basic would have a converter that converts the strings to floats and returns the array
<FromGitter>
<tenebrousedge> so if I have this: https://play.crystal-lang.org/#/r/6vqs ⏎ Is it possible to define the `isosceles?`, `equilateral?`, and `scalene?` methods based on a `Hash`?
<FromGitter>
<Blacksmoke16> and what would you expect the response to be? true assuming `@matching_sides === 3`?
<FromGitter>
<tenebrousedge> yes
<FromGitter>
<Blacksmoke16> what benefit would that bring?
<FromGitter>
<tenebrousedge> this is exercise code; I just want to know if this is possible. Ideally I would like to write https://play.crystal-lang.org/#/r/6vra
<FromGitter>
<Blacksmoke16> oh ok
<FromGitter>
<tenebrousedge> that doesn't work among other reasons because the `rule` is inserted as a string
<FromGitter>
<tenebrousedge> I think it also complains about the lack of type hinting
<FromGitter>
<tenebrousedge> hmm. That's a step further, but in this exercise equilateral triangles are also considered isosceles, so the test needs to be `>= 2`
<FromGitter>
<r00ster91> here it's as expected but why not for an `if`? https://carc.in/#/r/6vse
<FromGitter>
<tenebrousedge> I wouldn't really expect logical constructs to change scope
<FromGitter>
<tenebrousedge> blocks, yes
<FromGitter>
<asterite> only blocks and proc literals change scope
<FromGitter>
<asterite> (and, well, methods)
<FromGitter>
<tenebrousedge> @asterite and it's relatively accurate to say that a variable will be considered to be defined if it's ever on the left side of `=` inside the current scope?
devil_tux has quit [Ping timeout: 246 seconds]
devil_tux has joined #crystal-lang
devil_tux has quit [Ping timeout: 245 seconds]
<FromGitter>
<tenebrousedge> do macros only support using `for` for iteration?
<FromGitter>
<Blacksmoke16> yes
<FromGitter>
<Blacksmoke16> and you cant do like `next` or `break`
<FromGitter>
<tenebrousedge> is there an issue related to that which might offer some context?
<FromGitter>
<tenebrousedge> @z64 thanks, that's very informative
<z64>
yw
<FromGitter>
<tenebrousedge> I don't think that not having e.g. `map` in metaprogramming is very consequential; the point is not really to create new values, so the return value of any metaprogramming iterator should not be important. Using `each` or `each_with_index` is more supportable, but those have obvious workarounds. I think I might add a note to the documentation, though