[Vala] { private set; public get; } with structs' methods



Hi,

All here below may be my misconception of { private set; public get; } but
I still want to share it.

Recently I run into problem with calling methods on structs that have {
private set; public get; } accessibility (well, I run into it every now and
then :( but now as I know about it, I am no longer going to use it for
structs).

Whenever I call method on such struct that should modify it, it runs, but
doesn't modify it. Which when you think about it makes sense, as it is
accessed via get() which returns value not reference.

I raise this issue but I have no idea how to fix it. My ideas:
1. Adding keyword to method definition which tells that this particular
modifies struct would help but may lead to bugs if not defined.
2. Compliator checking if something is modified? Wouldn't be that simple
probably.
3. Only const methods can be run by code without access? Probably the best
solution, but vala at the moment doesn't support const methods, right? (or
maybe that has changed?). I am big fan of const correctness, so that would
be additional gain for me too :)

Temporary solution is just to document code well enough and use
public/internal/protected (whatever makes sense in that particular case) or
private with separately defined get method. But if there would be a chance
to make it a part of language somehow, it would be great.

There is another problem with { private set; public get; } on objects. It
blocks changing object to different object but doesn't block changing
object itself.

Regards,

Jarek


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