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

Why use classes/new #49

Open
wclr opened this issue Sep 12, 2020 · 2 comments
Open

Why use classes/new #49

wclr opened this issue Sep 12, 2020 · 2 comments

Comments

@wclr
Copy link

wclr commented Sep 12, 2020

You are defining pure configuration using functions why are you using classes and new keywords which is a sign of side effect. It seems excessive and totally unnecessary.

Current config form:

        VPC: new EC2.VPC({
            CidrBlock: NetworkingConfig.VPC.CIDR,
            EnableDnsHostnames: true,
            Tags: [
                new ResourceTag('Application', Refs.StackName),
                new ResourceTag('Network', 'Public'),
                new ResourceTag('Name', Fn.Join('-', [Refs.StackId, 'VPC']))
            ]
        }),

Why no let it be just:

        VPC: EC2.VPC({
            CidrBlock: NetworkingConfig.VPC.CIDR,
            EnableDnsHostnames: true,
            Tags: [
                ResourceTag('Application', Refs.StackName),
                ResourceTag('Network', 'Public'),
                ResourceTag('Name', Fn.Join('-', [Refs.StackId, 'VPC']))
            ]
        }),
@miensol
Copy link
Member

miensol commented Sep 12, 2020

Thanks for the suggestion.
I don't quite understand the side effects remark. Could you please elaborate?

@wclr
Copy link
Author

wclr commented Sep 13, 2020

This is not the law, but to me using the new keyword is a sign of impure parts of the code that is going to perform some side effects. This is a new Car() and I'm going to do with it whatever I want, when it is crushed or can no longer drive well I will make another new Car(). You are not going to do anything with those EC2 configs, ResourcesTags, etc , not going to dispose of them or something, they are just pure data objects and fabrics to create another pure thing, so no need to create them with new in my view. The code will just become cleaner.

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

No branches or pull requests

2 participants