You are not logged in.

#1 2013-05-20 20:06:57

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

[SOLVED] Why Vala?

Hello,

Since so many Gnome applications (and elementary, too) are now being written in Vala, I wanted to look into the language a bit. I just found out that Vala's compiler "compiles" the Vala code into general C, which is then compiled by, say, gcc.

I wonder what advantage Vala has over plain old C, in that case? I tried some Googling but didn't get an exact answer to this question. Wikipedia states the following:

For memory management, the GObject system provides reference counting. In C, a programmer must manually manage adding and removing references, but in Vala, managing such reference counts is automated if a programmer uses the language's built-in reference types rather than plain pointers.

But is that really all there is to prefer Vala over C?

Do you use Vala, and if so, why do you prefer it over C? I'm not trying to get a flamewar going about which language is better - I'm honestly wondering about why someone would use Vala when all it does (AFAIK) is generate regular C code.

Cheers!

Last edited by Unia (2013-05-20 23:56:15)


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#2 2013-05-20 21:30:47

jakobcreutzfeldt
Member
Registered: 2011-05-12
Posts: 1,041

Re: [SOLVED] Why Vala?

I don't use it personally but I've learned it in the past (and have since forgotten it). I think the other selling points are that its syntax is more similar to higher-level languages, so it should be easier/more productive in a sense; the garbage collection thing; and a syntax that is more object-oriented-friendly.

Offline

#3 2013-05-20 21:52:35

lucke
Member
From: Poland
Registered: 2004-11-30
Posts: 4,018

Re: [SOLVED] Why Vala?

I presume developing in C# can be easier/quicker than using C. That's why some apps in the gnome universe were being written in Mono. And introducing Vala, to my mind, was done in part to replace Mono. C#-like syntax, compiling with gcc, no Microsoft. Win-win-win without dows?

Last edited by lucke (2013-05-20 21:53:10)

Offline

#4 2013-05-20 22:09:12

Stebalien
Member
Registered: 2010-04-27
Posts: 1,237
Website

Re: [SOLVED] Why Vala?

Vala also provides really nice DBus Integration, closures, and asynchronous functions.


Steven [ web : git ]
GPG:  327B 20CE 21EA 68CF A7748675 7C92 3221 5899 410C
Do not email: honeypot@stebalien.com

Offline

#5 2013-05-20 22:49:12

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: [SOLVED] Why Vala?

So, basically it is to make programming "easier" or, to user different words, make C more "reach-able" for those who do not fully understand it yet and also to get rid of Mono?

But when one already knows C and is already capable of programming a GTK application in it, using Vala has no advantages despite that it might be quicker?


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#6 2013-05-20 23:15:52

portix
Member
Registered: 2009-01-13
Posts: 757

Re: [SOLVED] Why Vala?

Vala was first invented for glib2's GObject system, i think one reason was that using the GObject type system in C involves a lot of boilerplate code, for example if you look at http://trac.webkit.org/browser/trunk/So … ttings.cpp nearly the whole class is boilerplate.

Offline

#7 2013-05-20 23:35:06

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,524
Website

Re: [SOLVED] Why Vala?

Gcc compiles C into "plain old assembly", so why would you want to program in C?  Cut out the middle man, and write in assembly.

Assembly is assembled into plain old binary machine code, so why would you want to program in assembly?

Binary machine code is translated at runtime by the processor into high and low voltage states on a series of registers and output lines.  Why would you want to write binary code when you can pull out the processor and just have a few probes wired to the cmos power supply ... and very quick and precise hands.

</sarcasm>

Point being, the fact that one language compiles into another isn't really relevant.  All the other pros and cons can be relevant, but to me the only thing important is what I'm comfortable with and what I'm good at.  I 'get' C.  So any claims that I could program faster in other languages is just bogus.  I've tried.  I've learned a good bit of python, and a small bit of many other python-level languages, but I'd never be as fast in python as I am in C.  Sure, there may be fewer lines that need to be written (thats often not even true though) but lines of C code flow out of me much easier than lines of pyton.  C is just how I think, so barring other requirements, if two languages are equally fit for a job and if C is one of them, that's what I use.

But if someone else "thinks in Vala", then for them there's vala.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#8 2013-05-20 23:55:18

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: [SOLVED] Why Vala?

Trilby wrote:

Gcc compiles C into "plain old assembly", so why would you want to program in C?  Cut out the middle man, and write in assembly.

Assembly is assembled into plain old binary machine code, so why would you want to program in assembly?

Binary machine code is translated at runtime by the processor into high and low voltage states on a series of registers and output lines.  Why would you want to write binary code when you can pull out the processor and just have a few probes wired to the cmos power supply ... and very quick and precise hands.

</sarcasm>

That I did not know. I guess that ultimately answers my question, I thought Vala was just some sort of "wrapper" over C.

Cheers everyone!


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#9 2013-05-21 02:52:38

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: [SOLVED] Why Vala?

There's another way I like to think about it.

There are so many high level languages that were designed to be easy: Python, Ruby, Java, C#. But none of them compile to native machine code (I think...). There's a space for a high level language that's easy to use and compiles to native machine code. C++ has many problems that causes people to not like it (too complex, compare it to Python!). D is too obscure and possibly to "C" like to be considered easy. That leaves pretty much nothing (maybe a functional language that I don't know about?).

Even though I've never used it, I think Vala is an amazing idea. Imagine writing something like Python code and then "compiling" it into a C file that could be compiled by any standard C compiler.

I wish there were more "language wrappers" like Vala. hmm

Offline

#10 2013-05-21 03:04:46

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,785

Re: [SOLVED] Why Vala?

drcouzelis wrote:

...There's a space for a high level language that's easy to use and compiles to native machine code. C++ has many problems that causes people to not like it
...
Even though I've never used it, I think Vala is an amazing idea. Imagine writing something like Python code and then "compiling" it into a C file that could be compiled by any standard C compiler.

I wish there were more "language wrappers" like Vala. hmm

Like C++?  Many C++ implementations are just that.  Especially the early ones.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#11 2013-05-21 08:18:05

jakobcreutzfeldt
Member
Registered: 2011-05-12
Posts: 1,041

Re: [SOLVED] Why Vala?

Trilby wrote:

Point being, the fact that one language compiles into another isn't really relevant.  All the other pros and cons can be relevant, but to me the only thing important is what I'm comfortable with and what I'm good at.  I 'get' C.  So any claims that I could program faster in other languages is just bogus.  I've tried.  I've learned a good bit of python, and a small bit of many other python-level languages, but I'd never be as fast in python as I am in C.  Sure, there may be fewer lines that need to be written (thats often not even true though) but lines of C code flow out of me much easier than lines of pyton.  C is just how I think, so barring other requirements, if two languages are equally fit for a job and if C is one of them, that's what I use.

But if someone else "thinks in Vala", then for them there's vala.

That's just an argument about fluency. It's like saying "well, I learned the basics of writing in shorthand, but long-form English still flows out of me faster, ergo long-form writing is more efficient for me." Whereas if you became fluent in shorthand, it would flow out of you at the same rate as long-form but, given the design of the language, you would have to write much less so overall you would be more efficient with it. If you're saying that C flows out of you faster than Python ever did, it's because you never became fluent in Python. If you were fluent, you wouldn't have to think about how to write each line; it would flow out of you just like C does. And given that, as you acknowledge, the same thing can often be accomplished in Python with fewer lines of code, you could ultimately be more efficient in writing Python than C. That's not to say that knowing C is a waste. Obviously there are places where the raw speed and programmer control of C win out over Python, but then languages like Vala seek to remove that advantage by just compiling to C.

BTW, slightly unrelated, interestingly the vala compiler supports two languages: Vala and Genie. Vala's syntax is more similar to C# while Genie's syntax is more similar to Python, Boo and others. Both are compiled down to C code.

Last edited by jakobcreutzfeldt (2013-05-21 08:18:38)

Offline

#12 2013-05-21 11:12:43

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,524
Website

Re: [SOLVED] Why Vala?

Yes, but I was able to acheive this feeling of fluency in C much faster than I could acheive fluency in python.  My lack of fluency in java, ruby, perl, and others is because I've never spent much time using them.  But I've spent at least as much time with python as I had to spend with C to feel fluent, yet I don't feel fluent in python.  It is just not intuitive to me.

Different people think in different ways, and so for each there are different languages, and even different toolkits and libraries.  For years I wanted to learn at least some basic gui programming.  I tried Qt with a variety of recommended IDEs or just an editor, I tried wx, I spent a good bit of time "learning" gtk, but they never took.  I had basically conceeded that I'd never wrap my brain around all the weirdness of gui programming in C.  Then I read the code for dwm ... and a lightbulb went on.  I could see what was happening, I could follow the flow of control through the code, and it made sense.  With the toolkits there was always a man behind the curtain envoked with something like "gtk_magic_main(argc,argv);".  Despite spending *much* more time with each of the toolkits, they never took.  But once I saw how to write X11 event handlers, it just made sense, and I went on to churn out of a few gui programs.

So I do agree with your point on fluency.  But fluency is not a function of simply how much time one has spent trying to learn something.  It is also a function of how well that 'something' integrates with how their brain works.  For some people the abstractions of higher level languages make it easier for them to see the big picture and keep moving; others need to see the inner workings to feel like they can have any control over the language.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#13 2013-05-21 12:58:07

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: [SOLVED] Why Vala?

ewaller wrote:
drcouzelis wrote:

...There's a space for a high level language that's easy to use and compiles to native machine code. C++ has many problems that causes people to not like it
...
Even though I've never used it, I think Vala is an amazing idea. Imagine writing something like Python code and then "compiling" it into a C file that could be compiled by any standard C compiler.

I wish there were more "language wrappers" like Vala. hmm

Like C++?  Many C++ implementations are just that.  Especially the early ones.

I don't consider C++ a high level language that was designed to be easy to use. I'm sorry, I don't think I have any substantial reason for that opinion, just the opinion that C++ was designed to be able to do absolutely everything and none of it very well. hmm

Is there a modern compiler that will transform a C++ file into C source code?

Oh, I forgot to mention Objective-C. I used to heavily promote Objective-C. I finally gave that up when I found out it's been heavily... wierdified in Linux / GCC. It can't be used without GNUStep, and I couldn't even get anything Objective-C to compile in FreeBSD 9. sad

You know, the more I talk about programming languages, the more I feel like I have no idea what I'm talking about. tongue

Offline

#14 2013-05-22 15:31:40

Odaer
Member
Registered: 2010-08-14
Posts: 87

Re: [SOLVED] Why Vala?

Why is modern c++ not a easy high level language? I don't understand why it is so much harder than python.
It's way easier for gui programming than pure c.

Offline

#15 2013-05-22 16:59:54

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: [SOLVED] Why Vala?

Odaer wrote:

Why is modern c++ not a easy high level language? I don't understand why it is so much harder than python.

According to the Wikipedia, C++ is "an intermediate-level language, as it comprises both high-level and low-level language features".

What is and isn't a high-level language is subjective. In my opinion, C++ is a low-level language because it continually requires to me think about what the language needs and how the computer is going to handle it.

For example, in C++, when I create a string, I need to consider "Do I need to call the deconstructor somewhere?", "Should I create and use it as a pointer or a reference?", "Will I be using this in a way that warrants using a smart pointer?", "Am I using C strings, C++ strings, or strings from some other library?", "Does the string need to be declared somewhere in a header file?", and so on. Alternatively, in Python, I just create a string and start using it.

In summary, I spend all my time in C++ thinking about C++. In Python, I spend all my time thinking about the program I'm writing.

Have you programmed in both C++ and Python? In your opinion, is programming in C++ as easy as programming in Python?

Offline

#16 2013-05-22 17:59:45

SquidGuy
Member
From: the depths of the sea
Registered: 2013-05-07
Posts: 47

Re: [SOLVED] Why Vala?

drcouzelis wrote:

Have you programmed in both C++ and Python? In your opinion, is programming in C++ as easy as programming in Python?

Python is "baby-mode easy" programming compared to c++, IMHO.  If my intention is to sit down and hack out a workable program in 30 minutes, I'll generally use Python if I only have a rough idea because when you're done it reads like a novel.  c++ is mildly more complex in actuality.  C, even more-so.  On the other hand, if it's about performance in execution, then obviously C is the better choice.

I do agree, though, that they aren't equal in accessibility.

Offline

#17 2013-05-23 18:05:58

Old user, new ID
Member
Registered: 2012-09-18
Posts: 13

Re: [SOLVED] Why Vala?

I agree with almost everything Trilby said.

A lot of people seem to mix two properties of languages, level and size.

C might be a low-level(ish) language in todays standards. But one of its strengths is that it's small. Or as The Bible puts it:

C is not a big language, and it is not well served by a big book. --The Bible

Even the good high-level languages of today are not exactly small. So, it's quite understandable -even expected- to find people with good programming background and at least basic understanding of hardware to prefer C.

Offline

Board footer

Powered by FluxBB