Re: [Vala] empty List<T> is null - bug or feature?



Filed under Bug #578198 with a patch.


On Tue, 2009-04-07 at 00:27 +0200, Jan Spurny wrote:
Hi Yu,

thanks for reply - that's exactly what I did in order to get it working now. I know empty list is null in 
glib, but I'm still a bit troubled by the fact that (as some Java programmer may think):

1) I've created new object by "var list = new List<Something>;"
2) I can call methods on this new object: "var len = list.length();" - which work as anyone would expect
3) but when I pass it to some other function it fails (CRITICAL-y!)

Let me explain this - I've "discovered" vala few weeks ago when I was looking something up in gobject 
documentation and I thought it can be a great tool for our company's libraries (which are then used from 
Java and maybe Python) as it can dramatically (I still hope..) increase development (and maintenance, I 
hope..) of some components - the fact is that we have many Java programmers but only few C programmers - so 
it could allow these Java people to help me in developing these libraries..
But there are some things, like this empty null glist, a bit complicated (from java/c# programmer's point 
of view) object construction and "memory management" which requires much deeper knowledge of C and 
GLib/GType/GObject - don't get me wrong - I do not say that vala is bad language - even if no java 
programmer will be able to help me soon, it's still a great help for me and my colleagues

BTW: you haven't seen my c programs :) - but I'm definitelly not the best programmer in the world, so can 
you explain to me if the fact that you havent seen that is because it's not a good programming practice 
(why?), or it's just that you've never seen it :) ?

Jan Spurny

On Mon, 06 Apr 2009 23:05:16 +0200 (CEST)
Yu Feng <rainwoodman gmail com> wrote:

Try List<int>? list

In Glib an empty list is by definition null.

BTW: I have never seen any of c program passing a GList around.

-Yu
On Mon, 2009-04-06 at 19:05 +0200, Jan Spurny wrote:
Hi,

I'd like to know if this is considered to be a bug or feature:
when I pass an empty list to some function/method, it generates critical error - but to any 
Java/C#/C++/Whatever programmer this would be very confusing..
I know the reason for this as I've been working with glib for some time, but those without any previous 
glib experience may be severely confused..

In case of this being classified as a bug I humbly suggest removing "g_return_if_fail (list != NULL);" 
in generated code as NULL is valid (empty) GLib.List

here is an example of what I mean:
---------------------------------------
using GLib;
void print_list(List<int> list) {
    foreach (int x in list)
        stdout.printf("%d\n", x);
}
int main (string[] args) {
    var xy = new List<int>();
    print_list(xy);
    return 0;
}
----------------------------------------
valac -o list list.vala 
./list 

** (process:6750): CRITICAL **: print_list: assertion `list != NULL' failed
----------------------------------------

Thanks in advance for any reply.

Jan Spurny
_______________________________________________
Vala-list mailing list
Vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]