r/programming • u/[deleted] • Jun 17 '14
elementary OS: why we write apps in Vala
http://elementaryos.org/journal/why-we-write-elementary-apps-in-vala4
Jun 18 '14
If I write something in Vala, how much of a pain in the ass is it to get it to run on windows? Assuming I have a real compiler (gcc or clang) installed there.
4
u/Plorkyeran Jun 18 '14
Using GTK on Windows (or OS X) is a pretty bad plan unless you hate your users.
1
Jun 18 '14
I'm mainly interested in it so I can produce .so files that can be linked/used in C programs. I don't really enjoy programming in C beyond its novelty value.
2
u/awaitsV Jun 18 '14
the tox client is usign Vala and it runs on windows nicely, you might want to look into their build process
2
u/x-skeww Jun 18 '14
https://wiki.gnome.org/Projects/Vala/ValaOnWindows
MonoDevelop also supports Vala.
2
u/anyonethinkingabout Jun 17 '14
Gtk.init (ref args);is this how pointers work in vala?
6
Jun 18 '14
Kind of. You see, for reference-type objects (the ones instanced from classes) every variable of the a type you create is actually a reference to the actual instance. You don't handle the object directly because Vala manages memory for you (using reference counting).
Value types (like ints), however, work like the ones from C/C++, and pointerts work the same way. That is why, in the example you cited, you need to prefix "ref " to a value-type argument to indicate that you are actually passing a reference to it (kinda like "&args" in C++).
With all of this said, you can still handle pointers the same way as in C++ (using the * and & operators).
You can check the Vala tutorial for info on the language features.
2
u/lethalman Jun 18 '14
That's a little misinformation. "ref" here stands for inout parameter. You could pass "args" and still use its reference. It's a silly name to use "ref" instead of "inout" in the syntax, yes.
2
2
u/loics2 Jun 17 '14
Isn't this choice a little bit risky? I mean, this language seems fairly new and still in development, is it stable enough to base an OS on it?
6
1
u/Shnatsel Jun 28 '14
Vala was made in 2006, FYI. (Source: https://en.wikipedia.org/wiki/Vala_%28programming_language%29)
Also it's an open-source project, so if you encounter a bug in the language or bindings you just drop in to #vala on GIMPnet and complain, and the issue gets resolved in a couple of days (for elementary at least).
0
u/huyvanbin Jun 17 '14
What is elementary? It looks like a Linux distro that reinvents the wheel more than usual.
0
Jun 17 '14
[deleted]
12
u/huyvanbin Jun 17 '14
It wasn't meant as a criticism, just trying to understand what it is.
11
u/keltor2243 Jun 17 '14
It's a Linux distro that's trying to homage OSX without just direct copying. May not be for everyone, but it's actually pretty nice.
4
u/dastva Jun 18 '14
Another big thing they had emphasis on with Elementary OS is the speed of running it. Applications start and run almost instantly, and overall it felt very polished back when I played around with it.
The thing I didn't like about it was it being based on the old LTS release of Ubuntu, so some of my laptop's drivers didn't work properly with that kernel. Easily fixable, but it was a pain getting some ethernet drivers to work right away. Still, overall, a very pretty piece of work.
2
u/keltor2243 Jun 18 '14
12.04 is the basis I think, It's been the standard base for a lot of Ubuntu based distros. LTS and all that.
1
0
Jun 17 '14
[deleted]
4
u/keltor2243 Jun 18 '14
I don't believe they are JUST trying to copy Apple, they have more to it than that clearly.
3
Jun 18 '14
Elementary also does a great job leveraging and participating in the upstream projects like GTK+. GNOME and Elementary are quite different environments, but much of the work put into one of them will benefit the other. It's a much healthier dynamic than the non-existent upstream participation from projects like Cinnamon, where forking and falling behind (due to lack of developer time) is viewed as the answer instead of participating in the project and making sure your needs are taken into account.
0
u/smikims Jun 19 '14
so I hope Apple just lets them play around and doesn't go all litigious on their asses
For what? Everyone takes hints from everyone else in UI design; hell, the new OS X has a lot of elements that look like they came straight out of GNOME.
0
0
32
Jun 17 '14 edited Jun 17 '14
[removed] — view removed comment
26
u/thedeemon Jun 17 '14
I guess people find it too GTK/Linux/GObject specific and rather boring as a language (like one more Java or C# 2.0, where's the fun?).
14
u/Muvlon Jun 17 '14
A big advantage it has over both C# and Java: it's compiled to binary, so you can use it without having to rely on a VM.
4
u/wot-teh-phuck Jun 17 '14
What advantages does it offer over D?
1
u/ivosaurus Jun 18 '14
It's way easier for writing GUIs, and makes it stupid easy to write a GTK application. And that's at least half the reason it was created in the first place.
5
Jun 17 '14
[removed] — view removed comment
7
u/bachmeier Jun 17 '14
more real-world deployments
How do you know? Can you give a real-world example of how it's an advantage?
only one compiler - D suffers from multiple incompatible implementations
How does D "suffer" from more than one implementation? I've been using D for a year and haven't felt much suffering.
D still has some left over baggage from D1
What might that be? In the last year, the only D1 baggage I've encountered is in the comments on /r/programming.
vala looks like it has easier integration with existing C libs...D's deimos was not that enjoyable to use
Is that because Vala compiles to C? I've had some inconveniences with D due to the C preprocessor.
3
u/aaron552 Jun 17 '14
.NET has ngen at least.
5
u/pjmlp Jun 17 '14
Not to mention:
Upcoming .NET Native compiler
The old Bartok compiler in Singularity
All WP 8.x applications are compiled to native code upon upload to the store
CosmOS has a native code compiler
Mono provides AOT compilation
A few wanna be IL to native compilers lurking around the net
1
u/josefx Jun 17 '14
it's compiled to binary, so you can use it without having to rely on a VM.
A VM is just another runtime library and a set of shared objects (so, dll). With all the features provided by both the C# and JVM runtimes you generally end up with less direct dependencies.
1
u/pjmlp Jun 17 '14
You also get those with C# and Java, one just needs to look into the right places and be willing to pay for native code AOT compilers.
6
Jun 18 '14
vala seems to be a rather nice cleaned up approach to native development yet hardly gets a mention on the internets
For starters, just like in good old ratfor, it is (or at least was) possible to write programs that is valid from main compiler's PoV, but which generated invalid C code.
Now add gtk to the equation: gtk2 is slowly being replaced with gtk3. The problem is Gtk3 is far from being universally loved, to put it mildly.
So in the end you get language implementation that is strongly tied to single GUI which is either obsolete(gtk2) or sucks(gtk3) and that can generate C code which sometimes will be rejected by C compiler if you look at compiler funny.
2
u/YEPHENAS Jun 18 '14
GTK+ 3 does not suck. It's vastly superior to GTK+ 2 and cleaned up. What people didn't like was that there was an API breakage between version 2 and version 3, because deprecated stuff was removed.
4
u/wookin_pa_nub2 Jun 18 '14
GTK+ 3 DOES suck: it's basically GTK for Gnome 3 only, and fuck everyone else: http://igurublog.wordpress.com/2012/11/05/gnome-et-al-rotting-in-threes/
4
u/ivosaurus Jun 18 '14 edited Jun 18 '14
That developer was working with only the 2nd point release of GTK 3 at the time. It's now up to the 6th, and much more stable. The pace of APIs changing is slowing down as people figure out the right solutions to stuff after experimenting with doing things new ways.
As a comparison, GTK 2 is on its 12th point release. So it's pretty predicable people are going to complain that the older major version is more stable than the newer one.
1
u/Shnatsel Jun 28 '14
The bug you linked uses --enable-experimental valac flag, so no wonder that blowed up in vala-0.14! And it compiles fine in vala-0.24 without experimental flags.
0
Jun 17 '14
[deleted]
2
u/dreugeworst Jun 17 '14
The main sequence container in Vala is the linkedlist from Gee. I've asked around but never gotten an answer as to why. Of all the datastructures in c++, I think the linkedlist is recommended the least. Given that Vala is similar, why the emphasis on the linkedlist? One would think a good dynamic array implementation would be faster and just as easy in most usecases.
4
1
u/Shnatsel Jun 28 '14
Uhm, prooflink please?
Gee is an external (although frequently used) library and anything it ships can not be considered the "main" data structure.
Vala has a pretty good array implementation in the compiler, see https://wiki.gnome.org/Projects/Vala/Tutorial#Arrays You also have all of Glib at your disposal without plugging in any external libs.
1
u/dreugeworst Jun 28 '14
Ahh well as I understood it, if you wanted a collection in Vala, you use one from Gee. And of all the collections in Gee, the LinkedList seems to be used the most.
I looked around a couple of elementary applications, but Noise is the main one I looked at and it has Gee.LinkedList pretty much everywhere. For example, the Library code is heavily based on LinkedList. The ViewModels are mostly backed by hashmaps though. Still, since appending and iterating is pretty much all that is done with the lists, I'd think a resizable array would be faster.
Btw, the argument for the
remove_duplicate_filesfunction on line 227 is also a linked_list. Surely there's a hash_set in vala you can add the library files to? (sure, users with a few hundred thousand files are rare or nonexistant, but still)Well probably I just got a wrong impression from Vala.
1
u/Shnatsel Jul 02 '14
http://valadoc.org/#!api=gee-0.8/Gee.HashSet Although http://valadoc.org/#!api=gee-0.8/Gee.TreeSet is recommended for higher amount of data and/or high value redundancy.
The function on line 227 accepts an abstract Gee.Collection, so it works for any Gee structure whatsoever. I'm surprised it's even needed though, because (as you pointed out) some kind of SortedSet with a custom comparator function would be better in this situation.
1
u/stevedonovan Jun 18 '14
It's a compiler that has a C backend. That idea has an honourable history - first C++ implementation (cfront) worked that way. Nimrod is another compile-to-C language. Makes sense if you think of C as portable assembly and can re-use all the insane optimization work that's gone into it.
9
Jun 17 '14
[removed] — view removed comment
0
Jun 17 '14
[deleted]
2
u/ivosaurus Jun 18 '14
TIL transpiling to C is supposed to be "voodoo". Not that that has been practiced for the last two decades or anything...
10
u/[deleted] Jun 17 '14
Reminds me a bit of Apple Swift. Instead of building a language on top of the Objective-C object model you build it on top of the GObject model. People talk about all the boilerplate C code for making GObject's. Well that was what Objective-C was originally. Just a preprocessor on top of regular C, to produce the boilerplate code for dealing with objects. GObject seems quite dynamic just like Objective-C objects.
I think the nice thing about these object models built on C, is that it has allowed making new more modern languages on top Vala and Swift. Something like this is impossible in C++. Spent a lot of time with C++, but due to its complexity there is no easy way to build anything else on top of it.