The Crystal Programming Language Forum

A few concerns about crystal

It’s been quite a while since I last use Crystal, I’m glad you guys are progressing and are coming near to 1.0, I’m considering using crystal again for my side project, here’s my few concerns:

  1. It seems crystal is really in lack of sync primitive as std only provide Mutex, it’s not surprising since crystal only got parallelism lately but is there any plan for it? I think at least RWLock is needed, and maybe some concurrent containers?
  2. Since crystal is an OOP language, and there seems to be some infrastructure for LTO, any ideas about devirtualization?
  3. A minor one, why everytime instantiate a proc from a function a generic parameter is needed?
def foo(a : Int32)
  foo
end

a = ->foo(Int32)
  1. Probably after 1. 0 because it’s not a breaking change
  2. What do you mean by LTO and devirtualizarion? I’m not familiar with those things
  3. Because in the general case methods don’t require type annotations. The least ambiguous way to know this is by putting the type in the proc. That said, I never needed to make a proc out of a method in my life, so maybe you could show what to you are using this for?
  1. I’d really like to use it and I believe its vital in the parallel world, guess I need to write one myself, there seems also a naive RWLock in std.
  2. LTO = link time optimization, devituralize is that in when you call a method on a object, you will often go through a vtable, but sometimes that’s not needed so performance is better, e.g
    1. when this class has no subclass
    2. when this method is never overridden
    3. when we can believe this object is of its concrete type
      some of those analysis can only be done when whole program is known, aka link time
  3. I want to put them in a hashmap, so I can call them later. What do you mean the least ambiguous way?
  1. there are no vtables in Crystal. The optimizations you ask already exist

  2. How do you want to capture the proc? If it’s ->foo then what happens if someone adds an overload without arguments? It becomes ambiguous

That’s cool, I googled crystal vtable and that leads to your post in 2014. And yeah I’m for ->foo if there is only one instance of foo, if there are multi than I agree a parameter is needed