Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(concepts): "scope" instead of "parent" #1

Closed
wants to merge 1 commit into from

Conversation

eladb
Copy link
Contributor

@eladb eladb commented Jan 8, 2019

Shift the conceptual mental model to talk about the scope
hierarchy instead of a tree with parents and children.

See aws/aws-cdk#1444

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Shift the conceptual mental model to talk about the scope
hierarchy instead of a tree with parents and children.

See aws/aws-cdk#1444
Copy link

@sam-goodwin sam-goodwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, i love the decision to call the parents scopes.


The low-level resources are automatically generated from the [AWS CloudFormation Resource Types Reference](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html). Low-level constructs are named `CfnXyz` (where "Xyz" represents the name of the resource) and provide direct, one-to-one access to how a resource is synthesized in the CloudFormation template produced by your CDK app. Using low-level resources require explicit configuration of all resource properties, IAM policies and requires deep understanding of the details.

High-level resources are hand-written by AWS and offer a rich, intent-based API for using AWS services. They offer the same functionality as the low-level resources but encode much of the details, boilerplate and glue-logic required in order to use AWS. High-level resources offer convenient defaults and additional knowledge about the inner workings of the AWS resources they represent\. In general, you will be able to express your intent without worrying about the details too much, and the correct resources and configuration will automatically be defined for you\.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought-provoking example such as granting access/enabling encryption etc. ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me noodle this.

});
```

Avoid specifying physical names\. Instead, let AWS CloudFormation generate names for you\. Use attributes, such as `bucket.bucketName`, to discover the generated names\.
In general it's recommended to avoid specifying physical names\. Instead, let AWS CloudFormation generate names for you\. Use attributes, such as `bucket.bucketName`, to discover the generated names\.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we mention how discovered names maps to cloud formation functions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe in the CloudFormation topic?

```

In almost all cases, you should pass the keyword `this` for the `parent` argument, because you will generally initialize new constructs in the context of the parent construct\. Any descriptive string will do for the `name` argument, and an in\-line object for the set of properties\.
The first argument to every construct is always the scope in which it is created, and will almost always be simply `this` because most constructs will be defined within the current scope.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps clarify that 'current scope' means within the constructor or method of another construct. Might be confusing to new-comers without sample code. Or expand the example to include the outer scope?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to explain scope. It's a fundamental programming concept.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kind of agree with @sam-goodwin - maybe we could say something like "...defined within the current scope, which is normally the initializer (constructor) or a method of some construct defined in your app".

Something like that...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a fundamental programming concept, but it is ambiguous in this context since we are just now introducing them to the CDK's implementation of scopes. For example, will a novice understand that the scope is also a construct?


```
Scopes enable constructs to be composed together to form higher-level abstractions by enabling the framework to group them together into logical units, allocate globally unique identifiers and allow them to consult __context information__ such as the region in which it is going to be deployed into, which AZs are available for my account, etc.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introduce the scope hierarchy? You haven't described how they are grouped together, only implied it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added an earlier explanation.

});
```

**Note**
Associating the construct to its parent as part of initialization is necessary because the construct occasionally needs contextual information from its parent, such as to which the region the stack is deployed\.
The `construct.node` property can be used to interact with the construct's node representation:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're introducing the concept of a 'node' before explicitly describing the tree.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reworded the intro.


The AWS CDK includes two different levels of constructs:
This composition of constructs also means you can easily create sharable constructs, and make changes to any construct and have those changes available to consumers as shared class libraries\.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you should briefly define the 'scope hierarchy'/'construct tree' here to explain the encapsulation and composability. Having the High/Low level explanation in between seems out of order to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added some more explanatory text.


## Construct Names<a name="constructs_EVER"></a>
Every construct in a CDK app must have an **id** unique within the scope in which the construct is defined. IDs are used to find constructs in the construct hierarchy, and to allocate logical IDs so that AWS CloudFormation can keep track of the generated resources\.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First mention of the hierarchy is here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scope and hierarchy are fundamental concepts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They still need to be explained in the context of the CDK in my mind.

@Doug-AWS
Copy link
Contributor

Doug-AWS commented Jan 8, 2019

I've incorporated the comments into the docs and will refresh shortly.

@Doug-AWS Doug-AWS closed this Jan 8, 2019
@Doug-AWS
Copy link
Contributor

Doug-AWS commented Jan 8, 2019

As soon as a release with 1444 is published, I'll update the docs.

@eladb
Copy link
Contributor Author

eladb commented Jan 8, 2019

@Doug-AWS can you please make sure you also incorporate @sam-goodwin's comments?

@Doug-AWS
Copy link
Contributor

Doug-AWS commented Jan 9, 2019

Yes, I've got most of them incorporated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants