<FromGitter>
<girng> tested it, yep works wonderfully !
<FromGitter>
<girng> Niceeee
Raimondi has quit [Ping timeout: 240 seconds]
<FromGitter>
<nrser> Hey everyone, I've been evaluating Crystal for the last day or two and been hitting a lot of "Error: you've found a bug in the Crystal compiler", macro expansion and other type-system errors that I've had mixed success fiddling my way out of... was wondering if anyone with more experience would be willing to help?
Raimondi has joined #crystal-lang
<FromGitter>
<nrser> Mostly stuff around splats and generics, where I'm not getting much useful out of the compiler
<FromGitter>
<sam0x17> If I use instances of a struct in a class (like as instance variables), are they heap allocated or stack allocated?
<FromGitter>
<sam0x17> @nrser definitely report those as issues on the github, it helps everyone ;)
<FromGitter>
<nrser> @sam0x17 yeah I'm trying to bookend it down a little bit between simple examples that I think preserve the fundamentals, but work, and the full use case that breaks
<FromGitter>
<nrser> Is this uncommon for most people? I've hit at 4-5 different ones in the last day
<oprypin>
yes it's uncommon
<oprypin>
and the most important thing when reporting is a complete code snippet causing it
<oprypin>
also when trying to get help.
<oprypin>
but i see you're already doing it so congratulations
<oprypin>
do you need help with any unresolved error at this time?
<FromGitter>
<nrser> What's up w all the "use a more specific type" errors?
<FromGitter>
<nrser> Think I've seen it with Object, Reference, Pointer, generics... what are you supposed to use for any type?
<FromGitter>
<nrser> Fine w unsafe btw just not sure how to do it
<oprypin>
oh, well there's no such thing as "any type"
<FromGitter>
<nrser> It's just for output & logging
<oprypin>
it's possible to implement probably but not implemented and no immediate plans
<FromGitter>
<nrser> What's object then?
<oprypin>
fake base class for everything
<FromGitter>
<nrser> Oh jeez
<oprypin>
what
<FromGitter>
<nrser> I
<FromGitter>
<nrser> It's a surprising limitation
<oprypin>
is it though? i don't know any compiled-to-native-code language that has anything close
<FromGitter>
<nrser> For something adopting Ruby's syntax to go from everything's an object to nothing can be
<FromGitter>
<nrser> Java?
<FromGitter>
<nrser> Don't they have Object?
<FromGitter>
<nrser> And, what's in C, like void*?
<FromGitter>
<nrser> Yeah prob like Haskell don't have it
<FromGitter>
<nrser> I feel like most langs have a way of saying "here's some pointers", even if it's boxing, unsafe, whatever
<oprypin>
well knock yourself out with Void* but then you need to restore the type info
<oprypin>
really though, wanting to do this is often a bad sign and there are almost always better solutions
<FromGitter>
<nrser> I'm just kicking the wheels, seeing what it can and can't do at this point
<oprypin>
primarily thinking of generics. and duck-typed methods are always there
<oprypin>
just shoot specific examples, always easier to work from there
<FromGitter>
<nrser> I managed to put together this thing that seems to hold and string-ify arbitrary Tuples and NamedTuples, but I haven't managed to store it them as instance variables... https://play.crystal-lang.org/#/r/61x9
<FromGitter>
<nrser> I keep getting compiler bugs or "use a more specific type" (not sure what more specific type would make any sense here thought)
<FromGitter>
<r00ster91> you get this for example here: `array = [] of Array`. Here Crystal is just not satisfied with the type you gave it. You need to say what the `Array` will contain. So this for example will compile: β `array = [] of Array(String)`
<FromGitter>
<r00ster91> You need to give more types
<FromGitter>
<nrser> huh?
<FromGitter>
<nrser> I'll look again but I don't think I have any arrays
<FromGitter>
<nrser> it's all Tuples / NamedTuples
<FromGitter>
<r00ster91> it was just an example
<FromGitter>
<nrser> Yeah the array and hash stuff is cake, but the Tuple / NamedTuple has been a bit trickier for me
<FromGitter>
<r00ster91> for example in the Tuple docs: https://crystal-lang.org/api/0.27.0/Tuple.html β you can see that it wants a type. This means whenever you write "Tuple", you need to write what type it holds. So e.g. Tuple(String)
<FromGitter>
<nrser> concrete types come out like `Reason(Tuple(String, String), NamedTuple(three: String))`
<FromGitter>
<nrser> for `Reason.new "one", "two", three: "four!"`
<FromGitter>
<nrser> so there's some further details, but `Reason` seems to work pretty well, but then I've run into trouble composing it
<oprypin>
this is just not a good way to store data
<oprypin>
should be Array, Hash
<FromGitter>
<nrser> ok, I'll switch them up
<oprypin>
the language's main author doesn't like namedtuples being used for storage so much that he wanted to remove them entirely
<FromGitter>
<nrser> I tended towards Tuple / NamedTuple since I thought compiler might be able to be a lot more clover w those 'cause immutable
<FromGitter>
<nrser> *clever
<FromGitter>
<nrser> And you have types at compile time, stack allocated... seemed like one of the nice parts, but, yeah, they didn't turn out to be too nice to work with like this
<oprypin>
maybe so, but the size of compiled code will be so ridiculously huge and it's just really inconvenient
<FromGitter>
<nrser> yeah that makes sense
<oprypin>
nrser, but then you're back to wanting an arbitrary value type in Hash, which won't work
<FromGitter>
<nrser> hmrm :/
<oprypin>
so *maybe* the approach needs to be rethought
<FromGitter>
<nrser> I mean if there's not a reasonable way to cart arbitrary data around then that's fine, these are the sort of things I'm doing this to find out
<oprypin>
surely you won't have any useful way to interact with this data, other than, say, string interpolation. maybe it's good to define the exact combinations of input types in a meaningful way
<oprypin>
say if this was for error reporting. there's no advantage in storing the data generically because there is no meaningful way of accessing the data in a structured way
<oprypin>
then why not just store the interpolated string...
<oprypin>
or you might want to have a class hierarchy with well-defined fields and interpolation
<FromGitter>
<nrser> The advantage is being able to pipeline the data to different destinations that want to handle it (display / store / whatever) differently
<FromGitter>
<nrser> With macros then you just leave the call sites (as macros) in the code and control where they actually get compiled in via compile time settings
<FromGitter>
<nrser> did this with custom Babel plugin in JS and it worked really nicely. Doesn't really work as well in Ruby w/o true macros / compiler access, but thought I would give a try here
<FromGitter>
<nrser> of course can move a string around, I guess I would just assume every lang can do that reasonably
<oprypin>
no matter how you spin this, the destinations won't have a way to usefully handle arbitrary data. it's either doing the same thing to every value or it has pre-defined patterns.
<oprypin>
for first one, how are you even gonna store this in a file or database? for 2nd one, why not then define exactly what those patterns are by using meaningful types?
<FromGitter>
<nrser> Like I said, I'm evaluating it... let's see what it can do, what it can't, what it makes pleasant, what it makes tiresome... I believe you the language can do specific things you ask it just fine :)
<oprypin>
yeah then the conclusion is, languages that compile to native code really don't want you to store arbitrary types
laaron has joined #crystal-lang
<FromGitter>
<nrser> Yeah, fair enough. Crystal seems primarily focused on performance, and don't want to be boxing and unboxing things all over the place.
<FromGitter>
<nrser> Are there particular use cases that the community feels like Crystal excels at?
<FromGitter>
<vladfaust> @nrser um, everywhere? It allows to write maintainable human-understandable (aka expressive) code just like Ruby, but it has speed of C and zero startup time (as of being compiled), making it perfect for all spheres of development
<FromGitter>
<vladfaust> @nrser um, everywhere? It allows to write maintainable human-readable code just like Ruby, but it's compiled into assembly code giving native speeds, thus making it a perfect tool for literally everything
ashirase has quit [Ping timeout: 246 seconds]
ashirase has joined #crystal-lang
<FromGitter>
<vladfaust> When we speak about class methods, we use dot (`.foo`), when about instance methods -- (`#foo`). Macros are described with dot as well (`.bar`), but they're different from class methods. Which symbol would you use for macros instead?
bazaar_ has quit [Quit: Reconnecting]
bazaar has joined #crystal-lang
_whitelogger has joined #crystal-lang
<FromGitter>
<r00ster91> @vladfaust I think `%foo` would fit well.
<FromGitter>
<vladfaust> Yeah, because `%` is used in macros. Smart
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
rohitpaulk has joined #crystal-lang
<FromGitter>
<proyb6> Who uses xxHash64 or other hashing shards in your projects? I'm unsure about SipHash in Crystal shards for general purpose, xxHash seems to hash faster on large data sample about 10KB size
<FromGitter>
<drum445> Does anyone have a sample project of Kemal and MySQL?
<FromGitter>
<proyb6> Yeah, I tried the C binding which someone suggested you earlier, the whole day I spent on reading about xxHash and Spooky on the web that both seem better as I havenβt tested if the SipHash has collision on words or filenames yet.
<FromGitter>
<vladfaust> SipHash is slower
<FromGitter>
<proyb6> Iβm curious how many bytes of sample you was testing?
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter>
<proyb6> Oh, forgot about the thread youβve posted. xxHash128 were discussed but the author have not have the time to work on it until the end of this year.
<oprypin>
note that there are no guarantees that it won't change with Crystal version. also, of course, you should be aware that same hash does not mean same value -- especially for this simplistic algorithm
<FromGitter>
<vladfaust> Thanks, @oprypin, I understand that
Raimondi has quit [Ping timeout: 240 seconds]
pabs has quit [Ping timeout: 246 seconds]
<FromGitter>
<vladfaust> They said everything in Crystal is Object, while a module is not
<FromGitter>
<vladfaust> `Foo.ancestors # => [] of ::NoReturn`
<FromGitter>
<vladfaust> ```code paste, see link``` β β If I have `Foo`, I can not anyhow get `Bar`. My best guess was `Object.all_subclasses.select{ |t| t <= Foo }`, but it doesn't work as of `Bar` being not a descendant of `Object` [https://gitter.im/crystal-lang/crystal?at=5c4497db746d4a677ae270ba]
<FromGitter>
<vladfaust> https://carc.in/#/r/620g is there a way to get `Bar, Baz` in the output? :thinking:
<FromGitter>
<mavu> evening, I have trouble finding a list of exceptions a http request can raise, could anyone point me in the right directions where I might find such a list?
<FromGitter>
<mavu> thanks :) β Coming from ruby (obviously :) ) I learned that you should not do a rescue *all* because You might catch things you did not expect and would want to handle in other places. β Should I just do a rescue all on http requests?
<FromGitter>
<girng> ya rescue ex : Exception
<FromGitter>
<girng> can do multiple it's nice
ua has quit [Read error: Connection reset by peer]
ua has joined #crystal-lang
<FromGitter>
<mavu> Ok, going with that. thanks.
rohitpaulk has quit [Remote host closed the connection]