remove all this. use

Bug #1487989 reported by kay van der Zander
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Switchboard Mouse & Touchpad Plug
Won't Fix
Medium
Unassigned

Bug Description

In the code there are many 'this.'use this is not the way to go.
This pointer points to the hole class object using this. takes more time and are more actions for the cpu.
Why would you use this when it is not needed.

developers shouldn't use this pointer in any OO (Object Oriented) language

Changed in switchboard-plug-mouse-touchpad:
status: New → Confirmed
importance: Undecided → High
assignee: nobody → Marcus Wichelmann (l-admin-3)
Changed in switchboard-plug-mouse-touchpad:
milestone: none → loki-beta1
Cody Garver (codygarver)
Changed in switchboard-plug-mouse-touchpad:
assignee: Marcus Wichelmann (l-admin-3) → nobody
importance: High → Medium
Revision history for this message
Marcus Wichelmann (l-admin-3) wrote :

Hi,

please compare the by valac generated code when compiling a vala class with and without "this". Right, it's exactly the same, because C doesn't know anything about "this" references. It links the reference to the object anyway when calling the related method, so removing this wouln't have an advantage. Also the scheme I am using for placing "this" references to improve the code-readability is even recommended by some big vala projects, so Imo we should add it to our codestyle-guidelines instead of removing it from our projects.

Changed in switchboard-plug-mouse-touchpad:
status: Confirmed → Won't Fix
Changed in switchboard-plug-mouse-touchpad:
milestone: loki-beta1 → none
Revision history for this message
kay van der Zander (kay20) wrote :

hi marcus,

That the valac compiler doesn't use it as it is meant to use it doesn't mean it is good or oke for use.
This reference can only be used in an OOP language like vala in certain design patterns like inheritance and some others, to address the parent class.

When This is used as standard it will teach developers the wrong way to do thing. so i strongly disagree on making it the standard way and also to use it for readability. IMO it makes it worse. Most developers dan do more than one language while vala is good but most of the time the not the professional first language they use or learn.
When developers which are used to c++ language this confuses and mark it as a red flag.

this is because this is used to address a class object when you need to specify as developer to a specific class that mean you have named the object wrong or named it confusing.

like i said in inherentance it is oke to use this. but when this is not the case this shouldn't be used. then just name the varaibles right.

also like you said c doesn't know about the this reference it, reference to the right object anyway. then why make effort to add this. in front of all the propperties in constructors. the question isn't "why not add it?" it is "why add it" if there is no advantage dan don't add it.

Revision history for this message
Marcus Wichelmann (l-admin-3) wrote :

> This reference can only be used in an OOP language like vala in certain design patterns like inheritance and some others, to address the parent class.

Yes, that's what we're using it for.

> like i said in inherentance it is oke to use this. but when this is not the case this shouldn't be used. then just name the varaibles right.

We're only using it in inheritance to show to the one who reads the code that the property/method we're accessing is in the inherited class and the user shouldn't even try to find it in the current file. Imo this is a big advantage and saves much time.

> When This is used as standard it will teach developers the wrong way to do thing.

Then let's don't use lambda-expressions because they might be slower in some damn language out there... ;-)

> also like you said c doesn't know about the this reference it, reference to the right object anyway. then why make effort to add this.

Exactly:
Why? => Because it improves code-readability
Why not? => There is no reason, because there isn't any difference in the generated C-code.

Using "this" improves the readability of our code without being affected by any disadvantages. Teaching developers how to do things correctly in other languages isn't job of our vala-only coding style guidelines.
Of course following this scheme is only useful, when you're doing it consistent (for example like in this and some other branches by me), so imo we should add it to our docs:
    Use the "this" prefix to mark methods/properties that aren't contained in the current class/file to tell other
    developers that they can find the method/property in the class the current class inherits from.
When the use of "base" would make sense needs to be decided, too.

Revision history for this message
kay van der Zander (kay20) wrote :

Oke i can agree with you now. It is also clear to me.
Then i would say check if all this. Is inherentance related then this bug can de discarded or set solved.

I also think to put it in the readme of hacking file or something would be fine.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.