sferik has quit [Read error: Connection reset by peer]
sferik_ has joined #crystal-lang
asterite has quit [Quit: asterite]
asterite has joined #crystal-lang
<asterite>
kostya: out of curiosity, what did you say in github in russian? Google translate is not very good :(
<kostya>
he ask me to help with crystal, i say i am not crystal dev
<asterite>
but you still help a lot :)
sferik_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
sferik has joined #crystal-lang
bcardiff has quit [Quit: Leaving.]
bcardiff has joined #crystal-lang
sferik has quit [Read error: Connection reset by peer]
xiy has quit [Ping timeout: 258 seconds]
sferik has joined #crystal-lang
<Cassyblanca>
asterite: Thanks, it's nice to see them updated. Luckily, the lib/ and samples/ directories pretty much answered all of my questions that the docs missed.
<asterite>
:)
<asterite>
Are you writing bindings to something?
<Cassyblanca>
Quite a few things, actually. I'm writing a small experimental game to determine how I feel about the language. So far I've been writing bindings for SDL 2, OpenGL 3, and LuaJIT for the project, and plan to tackle at least OpenAL in addition.
<asterite>
WOW! That’s a lot!
<Cassyblanca>
Assuming I don't get any contractual restrictions at my new job, I'm hoping to make them long-term generalized bindings
<Cassyblanca>
So far I've only been binding things as I come to need them.
<asterite>
Yes, that would be good. Some others started some bindings, mostly as a proof of concept (I think), so it would be great to have one good API for each of these libraries
<Cassyblanca>
Documentation issues aside, I'm really pleased with Crystal. Not sure how performance will stand up against other native languages at the moment, but overall it's been a positive experience.
<Cassyblanca>
And writing an FFI binding is a dream in comparison to other languages I've used.
<asterite>
That’s always good to hear :)
<asterite>
The only thing I “fear” when it comes to performance is the GC, which in many other languages is… well, kind of feared, or hated, rejected, etc.
<asterite>
What other languages have you used?
<Cassyblanca>
Primarily C, Objective-C and C++, but I've used and experimented with a lot of others.
<Cassyblanca>
I do have two questions, though. First, is there currently a GitHub repository or something for contributing to docs? I'd be happy to help fill in some of those gaps.
<jhass>
it's in the gh-pages branch
<Cassyblanca>
Second, is there a way to create prototypes of classes/etc in other module files? Because right now the crystal compiler seems entirely based on the order files are passed into the command line - just need to determine if I'm going to structure my source tree to avoid having to nitpick certain pieces, or if I'm missing something.
<asterite>
The way to do things is to require the definition of something before using it
<asterite>
And you usually pass just one file to the command line
<asterite>
Maybe with some code I can understand better the problem
<Cassyblanca>
require as in a require() method a la Ruby/etc, or as in "sort your source files going to crystal build"?
<jhass>
the former
<asterite>
Like in Ruby
<Cassyblanca>
Ah, alright. Hadn't seen that in any of the docs/sample code. I'm assuming require is intelligent (as opposed to a C #include) and won't give issues regarding circular dependency?
<asterite>
About the docs, I started writing something and then stopped, because things were changing and it was sometimes a waste of time to synchronize everything, but recently the language has been gaining some attention, and also getting stable, so it would be good to expand and improve the docs
<asterite>
Yes, once you require something the compiler remembers the absolute path and never “loads” it again
sferik has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<Cassyblanca>
I definitely understand that writing docs for a new language can be a pain. Not my first time playing with a brand new language (Swift, Rust, and a few others before them). :p
kostya has quit [Remote host closed the connection]
<asterite>
Just to let you know, there’s this repo https://github.com/ggiraldez/crystal-gl but it’s mostly a proof of concept (I think)… at least there’s a 3D cube and you can walk around it, which means it should be possible to do more complex things
<Cassyblanca>
"The SDL version is broken since SDL 1.2 only creates OpenGL 2 contexts and there's no way to request a 3.0 context. Migrating to SDL2 is planned for the future." <- Then I've already passed them. :P
<asterite>
:D
<Cassyblanca>
As I said though, assuming I don't get anything more strict than I've already received re: ownership of my code, I'd be happy to help out with the docs here and there.
sferik has joined #crystal-lang
asterite has quit [Ping timeout: 244 seconds]
<Cassyblanca>
Is there any documentation on require()? Because requiring the file seems to be working, but it can't seem to find a class I've defined in that module.
<jhass>
can you show code yet/a minimal reproducing example?
<asterite>
Circular dependencies are less of a trouble in this language :)
<Cassyblanca>
:P
<asterite>
Mmm...
<Cassyblanca>
Since you were pinged out at the time: <Cassyblanca> Is there any documentation on require()? Because requiring the file seems to be working, but it can't seem to find a class I've defined in that module.
<Cassyblanca>
Error in /Users/cassy/Desktop/fileA.cr:13: undefined constant MyOtherClass
<Cassyblanca>
v = MyOtherClass.new
<asterite>
Basically, line 3 of fileB.cr is never typed unless you create a MyOtherClass instance
<asterite>
so MyOtherClass doesn’t need ot know about MyClass (but it will need to know about it when you instantiate it)
<asterite>
Let me check
<Cassyblanca>
I imagined that, but like I said - it was just a short experiment to force compiler-time circular dependency. I could build up a more complex example for testing it if need be. :p
<asterite>
Doing `crystal fileA.cr` works for me, does it give you an error?
<Cassyblanca>
Yep. Alright, so that changes how I'm doing my build command, then - if I can just require necessary modules through the main file, there's no need to **/*.cr
<asterite>
Yes. In almost all projects you have a single point of entry to your library, mainly a file named “your_lib.cr”, which requires everything else needed
<asterite>
You could require specific components
<asterite>
but in Crystal this is not very needed, as types and methods are only checked when used, and the parser is pretty fast
<asterite>
so requiring extra code is not a problem, as long as you don’t overwrite other people’s code by reopening stuff (which you can do, but you wouldn’t normally do)
<Cassyblanca>
What's the search pattern for requiring files, and is there a way to add paths (via command-line) for that?
<jhass>
CRYSTAL_PATH, the default is src:libs:/compiler_location/src:/compiler_location/libs
<jhass>
you can set that as env var to override it/add paths
<jhass>
we probably should add an -I to the build command
<Cassyblanca>
Oh, nice, a local libs path is already on the search path. Hah, I was using that without even knowing. :p
<asterite>
Yes, adding something like `-l` would probably be useful, but I’d like to avoid having to specify a load path
<asterite>
We are slowly building a dependency management tool, right now it puts dependencies in yhe “libs” directory, and since that’s on the path it’ll work
<asterite>
Then you put your app’s code in src, and that’s it, no need to fiddle with CRYSTAL_PATH
<asterite>
But… it can be useful at times, so we’ll eventually add that feature
<Cassyblanca>
(Technically it's creating a C API, which LuaJIT can bind to with FFI)
<Cassyblanca>
But anyway, seems everything's working out fine.
<Cassyblanca>
I'm moving to Cupertino tomorrow, so I've got to get some things ready. o/
<asterite>
Take care!
<Cassyblanca>
Oh, before I disappear. Is there a cleaner way of dereferencing pointer types than using the index operator?
<asterite>
You can do: pointer.value
<asterite>
same as [0
<asterite>
]
<asterite>
Mmm… cleaner how?
<Cassyblanca>
Explicit intent - using the index/subscript/whatever you like operator implies it's an array. :p
<Cassyblanca>
.value works fine though, assuming there isn't too much overhead (as in, say, Lua when searching a table)
<Cassyblanca>
(as opposed to the index operator)
<Cassyblanca>
Anyway, I'll be around. o/
<asterite>
The [], []= is actually just a method, so you can make it do whatever you want. However, for a Pointer I think it makes sense. Get me the n-th element of this typed pointer, or set it
<asterite>
That maps directly to a load from memory with a base address and an offset
<asterite>
so there’s absolutely no overload, even though it looks nice :-P
<asterite>
(or even though you might think it’s an array access)
<Cassyblanca>
Oh, I perfectly understand it (I've done more with memory management in C/C++ than I care to remember), but in instances where something is specifically a single-element pointer (such as in my Lua binding, above), I think it expresses the intent more clearly. Part of the intention with this small game project is so that others can look at and learn from it.
<asterite>
Great. So in Crystal you’d use pointer.value, because all you have are types and methods. Well, there’s also pointerof, typeof and some other things, but this could be done with a method… In C/C++ that’s *var, right?
<jhass>
+1 to porting them to methods, even if they become "pseudo methods"
<jhass>
less keywords = more win :)
<asterite>
jhass: are you talking about pointerof and typeof?
<jhass>
yeah
<asterite>
I think in the beginning it was a “ptr” method, but for some reason we changed it to the other way… I think mainly because they aren’t really methods that operate on the value of types, but rather on the types themselves
<asterite>
like, the type of variables at compile time...
<jhass>
well, you could say a Pointer is an object describing a reference to an object, the method would ask the object to give an object describing a reference to it, a pointer. does that make sense?
<jhass>
sort of like foo.method(:bar) asks foo to give an object (Method) to describe a method on its class, in ruby
<asterite>
Yes, I think it makes sense. But it would be a magical method, the parser would recognize it and create a special construct
<asterite>
And you wouldn’t be able to define a method with that name
<asterite>
Would that be problematic?
<asterite>
(the same way .is_a?(…) works, kind of)
<jhass>
I think a bit more about it, but I'd say reducing the keywords is still better
<jhass>
we already got "non-overridable" methods, so expanding on that I wouldn't mind
<asterite>
What would you name that method?
<jhass>
final methods? I think that's the right term
<jhass>
could actually be a language feature, final methods
<jhass>
then it would integrate even better
<asterite>
Final methods are hard(er) because when you include a module you’d have to check you are not defining a method
<jhass>
since the class is Pointer, .pointer
<asterite>
My worry is that if someone wants to define a method “pointer”, they wouldn’t be able to do that
<jhass>
keywords tend to steal names for locals
<jhass>
and I'd rather like to be restricted on a few method names than on the locals
<waj>
the problem is… pointerof is not really a method, it can only be applied to variables
<jhass>
is there an actual technical limitation to support foo[0].pointer ?
<jhass>
mh, you don't know what type you get I guess
<waj>
we know the type, but we don't know where the value is stored
<asterite>
Ah, I forgot about that limitation
<waj>
because you can override the [] method in any class
<jhass>
what about Pointer.of foo ?
<waj>
what's wrong with pointerof? :)
<jhass>
I dislike keywords ;)
<jhass>
they restrict me on the names for locals I can use
<asterite>
But pointerof is not a name I would normally use for locals
<asterite>
that’s why it’s named in such a weird name
sferik has quit [Read error: Connection reset by peer]
<waj>
I understand, but crystal doesn't have too many keywords anyway
<jhass>
I think we're approaching twice as many as ruby already
sferik has joined #crystal-lang
<waj>
BTW… I'm still looking for a good replacement of "previous_def" :)
<jhass>
lib, struct, class, all gone
<jhass>
In ruby?
<asterite>
jhass: there’s a more interesting thing to solve, is that right now when you do “include Type”, include is a keyword. So we can’t do “[1,2, 3].should include(1)” :(
<asterite>
Maybe “i_dont_need_to_use_alias_method” instead of “previous_def"?
<asterite>
Ah, but that keyword still has underscores, ugh
<jhass>
ruby actually solved the alias method problem, but nobody realized
<jhass>
Module#prepend
<asterite>
and then you call super? I can’t remember well how it was
<jhass>
yes
<asterite>
But you call super in the prepended module, right?
<jhass>
yes
<asterite>
And you first start the lookup in the prepended modules?
<asterite>
(I’m trying to remember, maybe it’s a good pattern to have also here)
<jhass>
Foo.prepend Bar changes Foo.ancestors from [Foo, Kernel, Object, BasicObject] to [Bar, Foo, Kernel, Object, BasicObject]
<jhass>
while include does [Foo, Bar, Kernel, Object, BasicObject]
<asterite>
I see
<jhass>
oh, Kernel actually comes after Object, of course
<jhass>
you can do funny things with Module#prepend in Ruby, like defining an included hook that enumerates all methods of the class you're prepended to and then define methods in the module that for example decorate those, without any .method(x).call or alias_method hacks, simply calling super
<jhass>
it's basically the same mechanism that singleton classes use btw
<jhass>
just on the class rather than on the per object level