-3

Now that swift has been released by Apple I have have been thinking the posibility of using gobject as a runtime for existing languages such as rust or even swift.

My main concern is that while vala does this, it compiles to c before and needs language bindings even if the library that you are trying to use already uses gobject and even then somehow vala cant use features that c doesn't support such as function overloading, while objective-c doesn't support it, but swift does and can still be used with it.

On the good side both runtime systems have many similarities, such as using reference counting, having signals and being more dynamic than the average

Alex Brown
  • 41,819
  • 10
  • 94
  • 108
  • 1
    This is not a question. – Alex Brown Feb 03 '15 at 22:50
  • this was my first question in stack overflow , i am sorry if i missunderstood any of the rules of this website , could someone sugest a more aceptabe question , or another website . – Diego Antonio Rosario Palomino Feb 04 '15 at 02:58
  • Excellent! - *welcome* to stack overflow. Please take the free tour! http://stackoverflow.com/tour. I'm sure you'll get into the swing of things real soon and I and thousands of other enthusiasts will be happy to answer your questions. You'll love it. – Alex Brown Feb 04 '15 at 05:13
  • After you have read the tour, and understood the sort of questions that really work well here, you need to think about your statement above, and identify the specific problem you have encountered, that admits a real solution (not an opinion or an op-ed). Now I don't know anything about gobject or vala, but I would imagine a very broad and answerable question would be "Can I run swift on gobject"?. Now that's a neat question, but you already know the answer is NO, so where are you going with this? Have you tried some stuff and found tantalising possibilities? – Alex Brown Feb 04 '15 at 05:17
  • You'll have noticed I edited your title and question. That happens a lot here on stack overflow - I fixed your spelling mistakes, and fixed formatting. Not because I'm smarter than you, but because poor spelling tends to turn people away, and I wanted you to have a fair shake of the stick. (people edit my posts, too!) – Alex Brown Feb 04 '15 at 05:19

1 Answers1

3

You can view GObject (and in extension GLib and the ecosystem of GLib based libraries) as a common language runtime for several languages:

  • Vala / Genie
  • Gjs (then GNOME version of ECMAScript / JavaScript)
  • C
  • C++
  • Python (through PyGObject)
  • Probably others, really any language that can talk to the C API

Actually it really is an extension to the C runtime (which is the core common language runtime of most Operating Systems) that adds OOP support.

There are other such technologies like the Java JVM the .NET CLR and as you describe Apple is using the Objective C runtime now for multiple languages as well.

There is (in principle) nothing that prevents someone to write a Rust or Swift compiler that does something similar to Vala (emits C code and uses GObject as it's object system).

About your concern:

Vala could as well emit object code directly (without the intermediate "compile to C" step).

There are some advantages to the concept the valac is written at the moment though:

  • You can take the emitted C files and use them in a C program without the need to have valac installed
  • It's much easier for Vala to consume C files and
  • The foreign function interface (called VAPI in Vala) was designed to make it easy to consume C libraries and abstract from common C idioms (like zero terminated strings, passing array with a length parameter, etc.)
  • The generated C code can be optimized by the C compiler
  • Standard C tools can be used to inspect the generated C code
  • You can actually read the C code to see what Vala does internally (big plus for people that already know C)

Vala uses C as a higher level "assembly" language.

Jens Mühlenhoff
  • 14,565
  • 6
  • 56
  • 113
  • thanks Jens , but i still have a few of questions that i already kind of figured out but i am not sure: 1- vapi files are like the bridging mechanism betweven objetive c and swift (adf.ly/ywXS3 ) and if another languje were to use gobject i could use the same vapi files 2- method overloading is not used because of naming conventions ,but it could be 3- cocoa could be used directly from c like gobject adf.ly/yx9sH – Diego Antonio Rosario Palomino 12 mins ago – Diego Antonio Rosario Palomino Feb 05 '15 at 14:21
  • On stackoverflow you should only ever ask one question at once, this is not a discussion forum, but a Q&A site. This means that you ask one specific question and others will try to provide an answer that is as precise as possible. – Jens Mühlenhoff Feb 05 '15 at 16:58
  • If you are interested in a discussion I would advice you to go to either the mailing list or the IRC channel, see the contact section on this page: https://wiki.gnome.org/Projects/Vala – Jens Mühlenhoff Feb 05 '15 at 17:01
  • Of course feel free to ask more questions here on stackoverflow with the vala tag, but like a said you should only ask **one** question at a time. – Jens Mühlenhoff Feb 05 '15 at 17:03