Re: [Vala] Cannot have field and method with the same name

2010-12-05 Thread Jan Hudec
On Fri, Dec 03, 2010 at 15:38:38 -0800, Anatol Pomozov wrote:
> I have a class that contains a field and method with the same name,
> and Valac does not like it. What is the reason? Other languages
> (C#/Java) allow it.

Pardon me. C# does NOT allow that:

test.cs(3,17): error CS0102: The type `Foo' already contains a definition for 
`stop'

Java allows it, but Java is one of very few languages where method isn't an
object (it is an object -- function pointer -- even in C and C++).

> You have to use () for method so you know whether
> you access method or field.

No, you don't. If there was just the method, this.stop would return
a delegate calling it, so when there's also field stop, the statement would
not be defined.

> public class Foo {
>   public boolean stop = true;
> 
>   public boolean stop() {
> return true;
>   }
> }

-- 
 Jan 'Bulb' Hudec 
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Cannot have field and method with the same name

2010-12-04 Thread Jiří Zárevúcky
Anatol Pomozov píše v So 04. 12. 2010 v 11:22 -0800:

> Sorry for stubbornness - I learn Vala and trying to illuminate all
> dark corners. I am looking for an example that clearly shows why we
> cannot have field/method with the same name.
> 

In Vala, you can access any method as if it was a constant field of a
delegate type (they behave pretty much the same actually). There is very
little or no semantic difference so separate namespaces are not
possible / would make no sense.

> > Actually, now that I think about it, I don't think Java does type
> > inferencing either.
> It is planned for Java7.

Java does plan some kind of "delegates", but with weird calling syntax
exactly because of separate namespaces.



signature.asc
Description: This is a digitally signed message part
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Cannot have field and method with the same name

2010-12-04 Thread Anatol Pomozov
On Fri, Dec 3, 2010 at 5:08 PM, Evan Nemerson  wrote:
> On Fri, 2010-12-03 at 15:38 -0800, Anatol Pomozov wrote:
>> Hi,
>>
>> I have a class that contains a field and method with the same name,
>> and Valac does not like it. What is the reason? Other languages
>> (C#/Java) allow it. You have to use () for method so you know whether
>> you access method or field.
>
> I'm not a C# or Java programmer, so feel free to correct me if I'm wrong
> but...
>
> Java doesn't have delegates. In this example, what is X?

Ah, delegates, functions that act as variables. Now it a little bit clearer.

>
> public class Foo {
>  public boolean stop = true;
>
>  public boolean stop () {
>    return true;
>  }
>
>  public Foo () {
>    var X = this.stop;
>  }
> }
This example does not work. valac 0.11 complains with quite weird message

a.vala:11.7-11.18: error: Assignment: Cannot convert from `Foo.stop'
to `Foo.stop'
var x = this.stop;

We cannot use var - we need to declare Delegate type here. Something like

MyDelegateType x = this.stop;

But in this case it is clear that we want function. We cannot assign
field/property to a delegate, isn't it?

Sorry for stubbornness - I learn Vala and trying to illuminate all
dark corners. I am looking for an example that clearly shows why we
cannot have field/method with the same name.

> Actually, now that I think about it, I don't think Java does type
> inferencing either.
It is planned for Java7.
>
> In addition to type inferencing issues, this could cause problems with
> generics, and would generally be a pain to read.
Not sure what do you mean here.

>
> C# doesn't allow this either. AFAIK, in C# you can overload methods so
> that the most appropriate method is called, but you can't have a method
> and a property with the same name. Example:
>
> class Foo {
>  bool stop () {
>    return true;
>  }
>
>  // No problem
>  bool stop (bool a) {
>    return false;
>  }
>
>  // Problem
>  bool stop = false;
>
>  public static void Main () {
>    var foo = new Foo ();
>  }
> }
>
> Overloading methods is a separate issue, which Aleksander Wabik already
> explained.
>
>> anatol:vala $ valac a.vala
>> a.vala:4.3-4.21: error: `Foo' already contains a definition for `stop'
>>   public boolean stop() {
>>   ^^^
>> a.vala:2.3-2.21: note: previous definition of `stop' was here
>>   public boolean stop = true;
>>   ^^^
>> Compilation failed: 1 error(s), 0 warning(s)
>
> Amusingly, this is basically the same error message as you get in C# (at
> least from mcs):
>
> test.cs(12,8): error CS0102: The type `Foo' already contains a
> definition for `stop'
> test.cs(2,8): (Location of the symbol related to previous error)
> Compilation failed: 1 error(s), 0 warnings

Oops, my statement that it works in C# is wrong. I was looking at
incorrect C# example.
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Cannot have field and method with the same name

2010-12-04 Thread Anatol Pomozov
2010/12/3 Aleksander Wabik :
>>I have a class that contains a field and method with the same name,
>>and Valac does not like it.
>
> Generally Vala does not have any usable symbol mangling engine. It's
> good, because Vala generates a C api and you obviously don't want to
> have obfuscated symbols there (the way that C++ does it is just awful).
> The drawback is that you can't have symbols with the same name but
> different semantics (eg. no function overloading). It's possible that
> the problem you have is the same, but if not - well, maybe it could be
> improved (as Vala has no function overloading and similar things, the
> semantic analyzer may be - and probably is - much simpler than in other
> languages, and it does not allow symbol 'overloading' on any scope -
> Vala, or C api).

In this particular case we don't need any method name obfuscation. If
I understand GObject correctly then method names never clash with
field names, as (virtual) methods are defined on the Class structure,
so generated C can have fields & virtual functions with the same name.
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Cannot have field and method with the same name

2010-12-03 Thread Evan Nemerson
On Fri, 2010-12-03 at 15:38 -0800, Anatol Pomozov wrote:
> Hi,
> 
> I have a class that contains a field and method with the same name,
> and Valac does not like it. What is the reason? Other languages
> (C#/Java) allow it. You have to use () for method so you know whether
> you access method or field.

I'm not a C# or Java programmer, so feel free to correct me if I'm wrong
but...

Java doesn't have delegates. In this example, what is X?

public class Foo {
  public boolean stop = true;

  public boolean stop () {
return true;
  }

  public Foo () {
var X = this.stop;
  }
}

Actually, now that I think about it, I don't think Java does type
inferencing either.

In addition to type inferencing issues, this could cause problems with
generics, and would generally be a pain to read.

C# doesn't allow this either. AFAIK, in C# you can overload methods so
that the most appropriate method is called, but you can't have a method
and a property with the same name. Example:

class Foo {
  bool stop () {
return true;
  }

  // No problem
  bool stop (bool a) {
return false;
  }

  // Problem
  bool stop = false;

  public static void Main () {
var foo = new Foo ();
  }
}

Overloading methods is a separate issue, which Aleksander Wabik already
explained.

> anatol:vala $ valac a.vala
> a.vala:4.3-4.21: error: `Foo' already contains a definition for `stop'
>   public boolean stop() {
>   ^^^
> a.vala:2.3-2.21: note: previous definition of `stop' was here
>   public boolean stop = true;
>   ^^^
> Compilation failed: 1 error(s), 0 warning(s)

Amusingly, this is basically the same error message as you get in C# (at
least from mcs):

test.cs(12,8): error CS0102: The type `Foo' already contains a
definition for `stop'
test.cs(2,8): (Location of the symbol related to previous error)
Compilation failed: 1 error(s), 0 warnings


-Evan

___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Cannot have field and method with the same name

2010-12-03 Thread Aleksander Wabik
One more note (sorry for flood):

>You have to use () for method so you know whether
>you access method or field.

It's not so simple, because you can assign this function as a callback
(delegate or signal) somewhere:

object1.delegate_instance = object2.stop;
object1.signal_instance.connect(object2.stop);

So simple syntax rule: "foo() = function, foo = not function" does not
apply here. It's a semantic issue.

best regards,

-- 
Mój klucz publiczny o identyfikatorze 1024D/E12C5A4C znajduje się na
serwerze hkp://keys.gnupg.net

My public key with signature 1024D/E12C5A4C is on the server
hkp://keys.gnupg.net


signature.asc
Description: PGP signature
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Cannot have field and method with the same name

2010-12-03 Thread Aleksander Wabik
>I have a class that contains a field and method with the same name,
>and Valac does not like it.

Generally Vala does not have any usable symbol mangling engine. It's
good, because Vala generates a C api and you obviously don't want to
have obfuscated symbols there (the way that C++ does it is just awful).
The drawback is that you can't have symbols with the same name but
different semantics (eg. no function overloading). It's possible that
the problem you have is the same, but if not - well, maybe it could be
improved (as Vala has no function overloading and similar things, the
semantic analyzer may be - and probably is - much simpler than in other
languages, and it does not allow symbol 'overloading' on any scope -
Vala, or C api).

best regards,

-- 
Mój klucz publiczny o identyfikatorze 1024D/E12C5A4C znajduje się na
serwerze hkp://keys.gnupg.net

My public key with signature 1024D/E12C5A4C is on the server
hkp://keys.gnupg.net


signature.asc
Description: PGP signature
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


[Vala] Cannot have field and method with the same name

2010-12-03 Thread Anatol Pomozov
Hi,

I have a class that contains a field and method with the same name,
and Valac does not like it. What is the reason? Other languages
(C#/Java) allow it. You have to use () for method so you know whether
you access method or field.

public class Foo {
  public boolean stop = true;

  public boolean stop() {
return true;
  }
}

anatol:vala $ valac a.vala
a.vala:4.3-4.21: error: `Foo' already contains a definition for `stop'
  public boolean stop() {
  ^^^
a.vala:2.3-2.21: note: previous definition of `stop' was here
  public boolean stop = true;
  ^^^
Compilation failed: 1 error(s), 0 warning(s)
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list