objectscript / cos-guidelines

Caché ObjectScript contibutors guidelines
MIT License
15 stars 15 forks source link

Full class name instead of short #15

Closed nikitaeverywhere closed 8 years ago

nikitaeverywhere commented 8 years ago

2015-12-20_233143 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).

tsafin commented 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.

nikitaeverywhere commented 8 years ago

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?

eduard93 commented 8 years ago

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
nikitaeverywhere commented 8 years ago

Sounds earnestly :)

Refering to subpackages via this syntax

Could you give an example of this one, please?

eduard93 commented 8 years ago

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.

nikitaeverywhere commented 8 years ago

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!

eduard93 commented 8 years ago

We have $this.Something and ##this.Something too.

nikitaeverywhere commented 8 years ago

@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 commented 8 years ago

@ZitRos see https://github.com/intersystems-ru/cos-guidelines/pull/17

nikitaeverywhere commented 8 years ago

@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.

nikitaeverywhere commented 8 years ago

@eduard93, @tsafin

Because of simplicity, and readability.

Just found this slide in our Caché basic course program: 2016-02-05_005307

it turned out that some people still prefer using this short syntax :P