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

Stylistic issues #306

Closed
bkeroackdsc opened this issue Jul 7, 2015 · 6 comments
Closed

Stylistic issues #306

bkeroackdsc opened this issue Jul 7, 2015 · 6 comments
Labels
duplicate This issue is a duplicate. feature-request A feature should be added or improved. guidance Question that needs advice or information.

Comments

@bkeroackdsc
Copy link

On first glance, this library seems a bit "method happy" so to speak. For example, the usage of aws.String(foo) instead of the more idiomatic (and simpler/faster) &foo. There seems to be a similar aesthetic with the Credentials subpackage -- why can't I for example pass the access id/secret key directly to s3.New()?

Some code review should be done to make this library more Go-community friendly before freezing the API.

@lsegal lsegal added the guidance Question that needs advice or information. label Jul 7, 2015
@lsegal
Copy link
Contributor

lsegal commented Jul 7, 2015

@bkeroackdsc there are a few discussions about style going on in other issues, I would recommend looking through open issues and jumping in with specifics there, that said,

For example, the usage of aws.String(foo) instead of the more idiomatic (and simpler/faster) &foo.

Nothing stops you from using &foo when possible, and in fact, if you are actually have a variable foo, you should use &foo. The SDK does not make any recommendations in any of our documentation to use aws.String() on existing string variable values. The only place our documentation uses aws.String() and the like are for string (and number) literals, and this is due to a limitation in Go, namely, you cannot take the address of a literal without some variable assignment. For example, you cannot do:

input := &s3.CreateBucketInput{Bucket: &"bucket-name"}

And it would be awkward to have to do:

bucket := "bucket-name"
input := &s3.CreateBucketInput{Bucket: &bucket}

The aws.String() helper allows this to be written in one line:

input := &s3.CreateBucketInput{Bucket: aws.String("bucket-name")}

Hopefully that explains the logic there.

There seems to be a similar aesthetic with the Credentials subpackage -- why can't I for example pass the access id/secret key directly to s3.New()?

This was an intentional change to discourage the use of hardcoded credentials passed to constructors. I would suggest reading through the Getting Started Guide, specifically Configuring Credentials. It is not recommended to hardcode credentials and there is usually a better way to configure credentials in the SDK-- in fact, the SDK does pretty good automatic detection of credentials that, in most cases, should make it so you don't need to pass credentials into your constructor at all. This is the recommended way to initialize S3, for instance:

svc := s3.New(nil) // no credentials needed

@bkeroackdsc
Copy link
Author

Thanks for explaining some of the rationale behind the decisions. It brings up another point about the pervasive use of pointers in this library--any insight into why that was done? It makes using this library pretty cumbersome.

@lsegal
Copy link
Contributor

lsegal commented Jul 9, 2015

@bkeroackdsc you can find the discussion about pointers in a few of our existing discussion issues as mentioned above; #114, for example. Instead of rehashing the explanation, I would suggest reading there. The short explanation is that most parameters (if not all) can be omitted, and it is not easily (or feasible) to differentiate Go's zero values from omitted values. You can see the linked issue for more details.

@porjo
Copy link

porjo commented Jul 10, 2015

Some code review should be done to make this library more Go-community friendly before freezing the API.

+1 to this. I've just had a quick look over the API for the first time and it feels bloated. Just to take one example cloudformation.CreateStackInput vs cloudformation.UpdateStackInput are virtually identical. Is that duplication really necessary?

@lsegal
Copy link
Contributor

lsegal commented Jul 10, 2015

@porjo

Is that duplication really necessary?

The methods exposed mimic the operations of the underlying surface. The low-level SDK operations are designed to be a 1:1 mapping of the API operations in the exposed services. The benefit of this design is that you can always trace the parameters to the underlying API documentation. From a documentation perspective, you'll note that the docstrings are unique and occasionally provide fairly important details about contextual details in creating and updating stacks. This information would not be easily captured if these two structures were shared.

@jasdel
Copy link
Contributor

jasdel commented Oct 29, 2015

Thank you very much for your feedback. The design of pointers, style, and calling method is complex and very important to the long term maintainability of the SDK. We have a few issues which are duplicating each other and I'd like to collapse the discussion down to a single issue. Lets use #363 for further discussion.

Duplicates: #363
Related: #265, #284, #294

@jasdel jasdel closed this as completed Oct 29, 2015
@jasdel jasdel added duplicate This issue is a duplicate. guidance Question that needs advice or information. enhancement and removed guidance Question that needs advice or information. labels Oct 29, 2015
@diehlaws diehlaws added feature-request A feature should be added or improved. and removed enhancement labels Jan 4, 2019
skotambkar pushed a commit to skotambkar/aws-sdk-go that referenced this issue May 20, 2021
…ws#306)

Fixes the ExampleBuilder_WithKeyCondition example to include the
ExpressionAttributeNames member being set.

Fix aws#285
skotambkar pushed a commit to skotambkar/aws-sdk-go that referenced this issue May 20, 2021
Services
---
* Synced the V2 SDK with latest AWS service API definitions.
* Fixes aws#304
* Fixes aws#295

SDK Breaking changes
---
This update includes multiple breaking changes to the SDK. These updates improve the SDK's usability, consistency.

Client type name
---
The API client type is renamed to `Client` for consistency, and remove stutter between package and client type name. Using Amazon S3 API client as an example, the `s3.S3` type is renamed to `s3.Client`.

New API operation response type
---
API operations' `Request.Send` method now returns a Response type for the specific operation. The Response type wraps the operation's Output parameter, and includes a method for the response's metadata such as RequestID. The Output type is an anonymous embedded field within the Output type. If your application was passing the Output value around you'll need to extract it directly, or pass the Response type instead.

New API operation paginator utility
---
This change removes the `Paginate` method from API operation Request types, (e.g. ListObjectsRequest). A new Paginator constructor is added that can be used to page these operations. To update your application to use the new pattern, where `Paginate` was being called, replace this with the Paginator type's constructor. The usage of the returned Paginator type is unchanged.

```go
req := svc.ListObjectsRequest(params)
p := req.Paginate()
```

Is updated to to use the Paginator constructor instead of Paginate method.

```go
req := svc.ListObjectsRequest(params)
p := s3.NewListObjectsPaginator(req)
```

Other changes
---
  * Standardizes API client package name to be based on the API model's `ServiceID`.
  * Standardizes API client operation input and output type names.
  * Removes `endpoints` package's service identifier constants. These values were unstable. Each API client package contains an `EndpointsID` constant that can be used for service specific endpoint lookup.
  * Fix API endpoint lookups to use the API's modeled `EndpointsID` (aka `enpdointPrefix`). Searching for API endpoints in the `endpoints` package should use the API client package's, `EndpointsID`.

SDK Enhancements
---
*  Update CI tests to ensure all codegen changes are accounted for in PR (aws#183)
  * Updates the CI tests to ensure that any code generation changes are accounted for in the PR, and that there were no mistaken changes made without also running code generation. This change should also help ensure that code generation order is stable, and there are no ordering issues with the SDK's codegen.
  * Related aws#1966

* `service/dynamodb/expression`: Fix Builder with KeyCondition example (aws#306)
  * Fixes the ExampleBuilder_WithKeyCondition example to include the ExpressionAttributeNames member being set.
  * Fixes aws#285
* `aws/defaults`: Fix UserAgent execution environment key (aws#307)
  * Fixes the SDK's UserAgent key for the execution environment.
  * Fixes aws#276
* `private/model/api`: Improve SDK API reference doc generation (aws#309)
  * Improves the SDK's generated documentation for API client, operation, and types. This fixes several bugs in the doc generation causing poor formatting, an difficult to read reference documentation.
  * Fix aws#308
  * Related aws#2617
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue is a duplicate. feature-request A feature should be added or improved. guidance Question that needs advice or information.
Projects
None yet
Development

No branches or pull requests

5 participants