Hi Gilad,
Originally I was not sure I should be asking terminology questions but now I am glad I did. I think I am discovering too much I am unclear on, and feel I should not constantly take your time and do more homework by myself instead..
Having said that, let me continue for one more round here but I will slow down after.
On terminology: It was not my intention to invent any new terminology, but rather understand and use the established one, which after your comments I feel understand better now, and will start using it. I will comment on that inline
Questions (from the access modifier post and this post) I am pulling up here:
Question 1 context:
Hmm, despite my best intentions not to, after I realized there is some misunderstanding on my end around 'factory' - you also noticed that - I opened the specs, and got myself in trouble :) There is a sentence like this that maybe shows my deep misunderstanding, so before I continue: The sentence is like this:
Ch 2.3 version 0.101: "Class declarations create a class factory object that provides the means of producing instances of the class. The factory object supports at least one message that produces new instances. This is known as the primary factory method. By default, it is called new. "
So question 1 (with many follow up questions):
----
Does the specs sentence mean that, if I were to look in memory, given a class C I could see:
1) one object for class C.
2) one 'factory object'? This 'factory object' has at least one method (called 'primary factory method')? This 'factory object' produces instances of class C (items in 3))
3) one or more instance objects of class C - well this is the only thing I am sure about, so no question here :)
If it is correct, I have throughout the years, missed the existence of the 'factory object' - although it may be intentionally hidden, I feel like it's existence clarifies a lot .. would this 'factory object' be the object hosting the 'primary factory constructor' and also all 'static' methods (those in the third set of bracket)? ... If it is not correct, I will get back to thinking :)
So assuming such 'factory object' indeed exists, as I understand from the specs sentence:
- If I see written somewhere just the term 'factory' alone (as I am sure is used on occasions) - does that refer to the 'factory object' or to the 'primary factory method'? I think now the former (but need to ask)
- I should not be using the term 'constructor', as in 'primary factory constructor' (as I was), but instead, the term 'primary factory method' for the method on the first line of the class source, and 'factory method' for any (static) method in the 3rd set of brackets of class source, is that correct?
Question 2) From previous email
----
| mz>> I see most (all?) constructors on top level classes in the IDE are not public.
|| gb>> No. Top level classes don't have an explicit access modifier, ever, but primary factories are always public.
|| gb>> The modifier on a class dictates the classes' accessibility, not the factory method's.
|| gb>> Hence it makes no sense for top level classes - they are not members of any other object. Once you have access to a class, you can instantiate it (hence factory is always public).
I am trying to understand clearly (well, maybe I am trying not to understand fully, but create some rules for myself):
a) On a top level class: placing accesss modifier (private, public) on top level class' primary factory method (the first line of class source) is irrelevant - the access modifier will be ignored, is that right?
b) Can I 'imagine', purely as a thinking help, the primary factory method on a top level class always have 'public' access modifier on it? Anything wrong with such helper?
c) Given a top level class Top1 which code starts like this: "MOD class Top1 usingPlatform: platform = (..)(..)": Is it correct that any top level class Top2 can pull Top1 on it's slot, irrespective of access modier on Top1 primary factory method on the first line (even if MOD=private), for example like this:
top level class source: Top2 usingPlatform: platform andTop1: T1 = (|Top1_slot = T1|)
instantiation of Top2, e.g. in Workspace: Top2 usingPlatform: platform andTop1: Top1.
Ok, so having asked two questions, which have about ten more questions in them, just follow up notes inline
On Sunday, 8 August 2021 at 08:10:07 UTC-7 Gilad Bracha wrote:
I have also a few terminology / naming convention questions:
1. Definition or declaration?
If we see slots in a factory constructor such as
class MyClass myFactory: arg = (
|
something = arg something.
somethingElse
|)
Do we say we are 'defining a slot' "something" and 'declaring a slot' "somethingElse"?
This is very sensible, but not the scheme I adopted in the spec. Generally, we speak of declarations. Definitions have a technical meaning for top level classes: we distinguish module declaration (top level class source), module definition
(class object of top level class) and module (instance of top level class).
Ah this definitely clarifies things for me, a lot. I have struggled with terminology, and will have to change it in all notes I produced. So a summary for myself, hope this now matches the terms used:
Module Declaration: Source of top level class
Module Definition: class object of top level class
Module: instance of top level class (this one I was clear on)
Slot declaration: expression between | | in primary factory method, irrespective whether it has a "=", "=::" or nothing to the right of the slot name.
Variable declaration: expression between | | in instance method, irrespective whether it has a "=", "=::" or nothing to the right of the slot name.
See spec, section 6.4. Also see 3.5 which discusses methods and what defines them (mixins) as opposed to their declarations (again, essentially source).
2. Similarly, if the |..| section is in an instance method on MyClass defined as
"myInstanceMethod: arg = (|..|)"
Do we say we are 'defining a local variable' "something" and 'declaring a local variable' "somethingElse"?
Is the above terminology acceptable, reasonable, not reasonable, wrong? If the latter, what terminology should be used instead?
Cool, thanks. But I will use the terms currently used, as summarized above; I did not intend to invent new terms, but was not clear on the currently used terms.
3. visibility naming conventions: if we write "public class MyClass myFactory: arg = (|..|)", do we say the 'class MyClass is public' or 'the factory constructor of MyClass is public'? I think the latter, as there is no 'class visibility' - everything is a message send, so there is only 'method or constructor visibility' - but wanted to check .
I think there is a bit of a misunderstanding here. The modifier indeed applies to a method - but to the factory method. The access modifier applies to the class accessor - a hidden method that returns the class object.
In my previous email about access control, I said that
the modifier applies to classes - but technically that is imprecise as you
say. In practice, the class accessor method is an implementation artifact and you cannot detect it in the language, even via reflection, so the imprecision is harmless.
So I think part of my question was confusing when I spoke of 'class visibility', I actually meant 'object visibility' which should have been 'object accessibility'. The 'class accessor' you are mentioning here is another thing I am not aware of - good to be aware even if it is implementation.
I am satisfied with this until I read the document you sent in the other thread.
If I still feel misunderstandings I will ask about it later. As I mentioned, I need to do more homework.
Thanks
Milan