Closed nikitaeverywhere closed 8 years ago
Because of simplicity, and readability.
Remember, you write elegant code not for yourself, but for the "other guy" who will read it after you. The less he has to know to understand the whole context, the more it's obvious from teh code, the better for the long term.
That is a good reason for such languages as Javascript or Java, but for Caché I am sure that there are some outstanding syntax things which I am not aware of so far, like everybody else. But in case when I saw this construction (#class
referring to some class without the package name) first time, on my mind I had nothing less "Wow, yet another thing COS can". No missunderstanding, for me it was quite clear that this refers the class inside the package, I believe that it does for anybody else as well.
That is another idea, but it would be better to organize a brief but full "syntax cheatsheet" for Caché and name it close to "COS syntax guideline" to make people aware of all constructions almost in 5 minutes of reading, do you see this possible?
But why? What is the purpose of it?
- Project in several packages, with similar/same classnames in each package
- Refering to subpackages via this syntax
- Any project, where you don't remember the project class structure in it's entirety
- Faster compiling
Sounds earnestly :)
Refering to subpackages via this syntax
Could you give an example of this one, please?
Could you give an example of this one, please?
Let's say you have following classes:
In this situation, in Utils.Action
you can write:
Set a = ##class(Main).%New()
Set b = ##class(Package.Main).%New()
Set c = ##class(Utils.Main).%New()
Set d = ##class(Utils.Package.Main).%New()
Which could be confusing.
Which could be confusing.
Now I understood. The example you described has explained me this confuse well. Maybe we should make a hyperlink in the repository's description like thiswhy? to explain everything better.
Refering to subpackages via this syntax
But under this phrase I thought that there is one construction that I does not know like this.Something
:)
Thank you!
We have $this.Something
and ##this.Something
too.
@eduard93, good to know, thanks! What about to make a *.md file like is done here describing all the COS features in short? I'm sure the new one will be extremely useful.
@eduard93, ah, you have created it some moments ago, great! Also I wish GitHub make the work in branches more noticeable one day.
The issue might be closed, I think.
@eduard93, @tsafin
Because of simplicity, and readability.
Just found this slide in our Caché basic course program:
it turned out that some people still prefer using this short syntax :P
But why? What is the purpose of it?
I think this is a cool syntax feature which allow to refer classes inside the package without mentioning the package name itself. It is very helpful if someday you want to rename your package, which happened once in one of my projects (
%WebTerminal
->WebTerminal
).