Vala: Gotchas, Tips and Tricks
Asked Answered
G

9

46

As a programmer who is new to Vala, what is your number one piece of advice to someone who is new to the language?

Grow answered 30/1, 2010 at 9:22 Comment(4)
Honestly I think its a little early for this question. Vala is a brand new language. Tips and Tricks are only learned through experience which would be hard for anyone to have at this point.Hello
+1 I agree with Lucas, and I don't see you getting 550 reputation worth of answers (although I would love to be proven wrong!) so here's a vote for your genuine and keen interest in your chosen topic :)Yogini
It was too early two years ago... how about now?Coccyx
It may still have been too early two years ago... how about now?Demonic
M
38

It largely depends on what background you are coming from. If you're coming from C/C++/Java, the best bit of advice is to learn functional programming. Vala supports true closures, and so you should learn (deeply) how to use lambda expressions. The best resource for this is Structure and Interpretation of Computer Programs by Abelson and Sussman. It was the introductory textbook for CS at MIT for many years. It is available free on-line at http://mitpress.mit.edu/sicp/full-text/book/book.html, but the paper version is more readable. Video lectures are available at http://groups.csail.mit.edu/mac/classes/6.001/abelson-sussman-lectures/. Problem sets are available free at http://icampustutor.csail.mit.edu/6.001-public/.

Aside from that, I'd generally just try to learn the C# programming style well. It is similar to Vala, but there are many books on that topic.

Catches:

  • Be aware Vala doesn't have garbage collection. It does reference counting.
  • Be aware that Vala is still being developed. It is a rather new language, and it has not reached 1.0. Code you write now may break in the future.
  • If choosing to learn Vala, be aware that it is slightly obsolete, as far as programming language concepts go. It does not do anything to help with multicore programming. It does not do anything to help with memory management (code performance is based largely on cache coherency -- good garbage collected languages can reorganize memory to help here). It is a wrapper around C, and comes with many of C's limitations (although it does add closures).

Also, one of the posters recommended tinycc. This is a reasonable choice for development, but you should use an optimized compiler like gcc (or if supported, Intel's compiler) for deployment.

Mauriciomaurie answered 16/2, 2010 at 3:49 Comment(3)
@user274045: I don't see lack of an indeterminate GC as a down-side, nor do I consider the it's a C wrapper as a problem. Compiles to native byte code and becomes a C library. It may have some C limitations - but greater flexibility than C#.Standush
@user274045: you kind of contradict yourself between points 2 & 3. It is a rather new language... and then ...be aware that it is slightly obsolete.... Even if you are discussing the language concept, it seems to be fusing some of the best of C# offerings with the power of C.Standush
No contradiction. If you were to e.g. make a new language like Fortran today, it would be both new and obsolete. C is 38 years old. It was designed for computers 1000 times slower and with 1000 times less memory than what I'm typing on. Processors were much simpler; it was possible to hand-optimize code by counting machine cycles. Performance wasn't limited by memory hierarchies and multicore. You didn't have the resources to implement optimizing compilers or VMs and JITs. We're in a new world now. Compiled low-level increasingly cannot compete with VM high-level for power and performance.Mauriciomaurie
M
24

My #1 piece of advice is to learn about GObjects. They are the backbone of Vala's power and flexibility, and learning how to wrap various libraries with GObject gives your Vala programs access to everything c can link against (which is a lot!).

Here are a few links that might be of interest:
* http://library.gnome.org/devel/gobject/stable/
* http://fosswire.com/post/2009/7/gobject-vala/
* http://developer.gnome.org/doc/tutorials/#gobject
* http://en.wikipedia.org/wiki/GObject

Magenmagena answered 14/2, 2010 at 6:22 Comment(0)
S
15
  1. For multiple resources, this will be a general resource for a bit: Vala - GNOME Live!.
  2. To get up close and personal with GObject: GObject Reference Manual.
  3. I don't know what background you're coming from, but you will find this helpful: Vala Quick Intro for C# Programmers

In any event, knowledge of C will be of great use. Our team is actually considering a progressive revamp and porting to Vala. We have members with strong backgrounds in C#/C++ and this change in direction (over time) will be beneficial to the performance and flexibility of our products.

Standush answered 15/2, 2010 at 5:28 Comment(0)
D
10

Tip: You can speed up your build time significantly by using TinyCC instead of gcc for development. Vala uses CC env variable for selecting backend compiler, so "export CC=tcc" will do the trick.

Dysplasia answered 6/2, 2010 at 0:3 Comment(0)
D
6

Here's my tip for you: Read the official documentation. :)

Dalury answered 17/2, 2010 at 0:3 Comment(1)
+1: If I had it to answer all over again, I think this would have been my answer.Standush
H
4

Generally, Vala is excellent, but the one big gotcha I've found is that either its handling of arrays is very primitive compared to the rest of the language or its documentation has a very gaping hole in it.

Despite a long, hard look through the documentation, tutorials, and Google, I've concluded that:

  • The only way to concatenate two arrays is either to fall back to C-style tricks or use foreach and += to manually add one array to the other element-by-element.
  • You can do a slice like argv[1:-1] but there seems to be no syntax for equivalent to Python's argv[1:], so you have to fall back to something more procedural for that.
  • Libgee is useless to me because, while Gee objects have methods like add_all, none of them take C-style arrays, so I'm back to using add with foreach and +=.
Hydraulic answered 28/12, 2011 at 19:6 Comment(0)
B
3

Caveat: I am not familiar with Vala, but hopefully my answer applies to learning any new language. I just want to offer some thoughts in case they help...I should definitely not get the bounty for my answer.

Bottom line: It depends on why you are learning it...

If you are intrigued because it is a cool new language, but you are not sure how you might use it in practice, try recreating/porting something with which you are deeply familiar to see how it compares.

If you are learning it because you believe it solves a specific problem you are facing, make sure it is worth the up-front investment, since learning any new language can be incredibly time consuming, and there may be a reasonable solution in a more familiar language.

Otherwise, it's all about how you learn best. Are you someone who needs to understand the internals of the language, or just get things done quickly? (Or, like me, somewhere in the middle?) For the getting things done approach, I just look for simple tutorials and try to get something basic up and running to see how it feels. If I am enjoying the language, then I'll start to read more in-depth information about the language and understand what's going on under the hood.

Whatever your approach, best of luck!

Buttonball answered 16/2, 2010 at 23:39 Comment(0)
H
2

my advice would be to read the documentation but i personally learned the language by looking at vala code examples:

The official vala tutorial

some documentation

the vala tutorial helped me alot and the documentation page contains alot of useful examples but the one site that helped me most was and still is valadoc.org:

valadoc.org

valadoc will help you alot with the different classes and functions also other librarys.

vala is very c# alike but you will often see java like interfaces too. any experince with C is good because all the librarys around vala is written in C and when calling functions you can almost see all the C code that is right under the surface.

for those people that say vala is too young: vala will continue to bee as young as it is now until somebody makes a VERY big documentation or starts a project as big as QT where thousands of people ask questions everyday.

vala is a little hard to learn in the start because of the bad documentation but don't give up! it's a great language when you have learned it's basics. good luck! and sorry for the bad english :)

Humanity answered 15/10, 2013 at 11:40 Comment(0)
D
1

If you are considering Vala to write a server application then you may like some object pooling features(object token feature) in Aroop. Aroop is a Vala fork that does memory pooling. And it has reference counted garbage collector. You may find a list of features here. Let me name some of the goals here in list,

  • Memory pooling
  • Writing network servers, shotodol_net,shotodol_web.
  • Lock-free queue based message passing
  • Plugin based development, shotodol.
  • Embedded development
Dilantin answered 23/10, 2014 at 12:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.