Note that self and $"." are only equivalent for nodes. For objects that donât inherit node classes, using $"." make no sense and wonât work, but they still can use self.
You should always use the first one IMO. There are never namespace collisions in GDScript that require you to use self. And you should never use $ references in code, they should always be assigned to an @onready variable. So using @onready var myself = $"." becomes a bit ridiculous because now youâre referring to a variable which you already have a representation of, and you donât need.
I have just seen a post with this exact initializer !
I also sometimes stumble upon scripts filled with $"." and I alaways wondered why.
Now about the usage of self, I guess that depends on preferences and code style guidelines !
Personally I prefer to avoid using self as much as I can, but I have seen teams enforcing its usage in the past.
Because they are coming from another language, or learned that habit from someone else. Itâs a bad habit.
What @normalized said. Like I said before, itâs used for namespace conflicts, but thatâs not an issue in GDScript. The only time you should use self is when passing yourself off to another function, either with a Signal or in use of a recursive search of all nodes (like in an import script).
Otherwise, no offense, itâs a sign that you do not know how to read scope in code and are a newbie. If I had a developer check in code that used self their PR would be rejected with a comment to remove all references to self because itâs redundant. Itâs like RAS Syndrome and saying ATM Machine (Automatic Teller Machine Machine).
And before you tell me that youâve seen senior developers do that, you should know my job is to go into companies and teach senior developers how to be better at their jobs.
There a lot of things that GDScript lets you do that arenât the best habits. Part of it I think is keeping things backwards compatible. Others, like AnimatedSprite2D are created to be better versions of things like Sprite2D that allows animations, and then you get questions about which to use. The fact that you can use node notation to call yourself makes sense from a technical implementation point of view, but just because you can, doesnât mean you should.