GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Remove examples if-then-else pattern · Issue #618 · googleapis/google-cloud-java

Remove examples if-then-else pattern #618

New issue
Copy link
New issue
Copy link
Closed
Closed
Remove examples if-then-else pattern#618
Copy link
Assignees
mziccard

Description

@mziccard
mziccard
opened on Feb 4, 2016
Issue body actions

In bigquery example we have the following patttern:

Table table = getTable(...);
if (table == null) {
  // create table
} else {
  // load data
}

in storage we have:

Blob blob = getBlob(...);
if (blob == null) {
  // create blob
} else {
  // get and update blob's content
}

In both cases we should remove the else branch and rather execute it after table/blob creation.

Also in datastore we do:

Entity entity = getEntity(...);
if (entity = null) {
  // create entity
} else {
  // update entity access type
}

@ajkannan @aozarov @mderka Do you guys think we should remove the else branch also for datastore's example? It makes slightly less sense to me.

Activity

  1. mziccard
    added
    docs
    on Feb 4, 2016
  2. ajkannan commented on Feb 4, 2016

    @ajkannan
    ajkannan
    on Feb 4, 2016
    More actions

    I agree that the datastore "else" makes a more sense because users typically won't create an entity and right away modify it.

  3. aozarov commented on Feb 4, 2016

    @aozarov
    aozarov
    on Feb 4, 2016
    Contributor
    More actions

    My first reaction was that we should not change the datastore example as it is different from the big query example in that the create (the then part of the if~else) also populate the content.

    However, this is also true for storage as both parts of the if~else also set the content.
    Indeed, the datastore example makes more sense to me as the "else" part
    is showing a way to update an entity that already exists by splitting name into
    first and last name (as oppose to a complete override of the content as we do for storage)
    but maybe that is too much to show for such example (not to mention that typically
    this should be done transactionally which would even further complicate the example).

    I do think we should modify the big query example, as suggested earlier, to remove the else
    so that in the same request we create the table if needed and upload data to it.

    Honestly, I think for storage best would be to split the example into 2 separate example
    snippets. One for get and display (meta data and content) and one for create.

    We could probably do the same for datastore or maybe add some comments to the existing
    example and even big query can add a snippet for reading data.

    Also, while at it, should resource manager example modified as well? replace just after create is not a typical usage pattern.

    Thoughts?

  4. ajkannan commented on Feb 4, 2016

    @ajkannan
    ajkannan
    on Feb 4, 2016
    More actions

    I agree with the idea to split "create" and "update" actions in the snippets for storage, datastore, and resource manager.

    This is probably slightly more convenient for users as well. If they run a snippet with create/update combined and creation works, but adding/updating data errors, a user can't simply run the same snippet over again. They'll have to modify their code because they can't create the same exact resource again.

  5. mderka commented on Feb 4, 2016

    @mderka
    mderka
    on Feb 4, 2016
    More actions

    I agree with both @ajkannan and @aozarov, i.e., splitting storage and data store into snippets, and modifying big query to create-if-needed-and-load meaning. All of them make sense. Same for resource manager---short snippets would be my preferred way.

  6. mziccard commented on Feb 5, 2016

    @mziccard
    mziccard
    on Feb 5, 2016
    ContributorAuthor
    More actions

    I agree that we should split create and update, even though I wouldn't expect users to simply copy-paste snippets but rather use them to write their own first simple program.

    I will take care of fixing the snippet situation as soon as #614 is merged in. I'll also try to fix #607.

  7. mziccard
    self-assigned this
    on Feb 5, 2016
  8. aozarov commented on Feb 10, 2016

    @aozarov
    aozarov
    on Feb 10, 2016
    Contributor
    More actions

    Fixed by #635

  9. aozarov
    closed this as completedon Feb 10, 2016
  10. github-actions
    added 2 commits that reference this issue on Jun 29, 2022

    chore: release 1.1.1-SNAPSHOT (googleapis#618)

    8f7c196

    chore(deps): update dependency com.google.cloud:google-cloud-monitori…

    36c4d12
  11. suztomo
    added a commit that references this issue on Feb 1, 2023

    chore: update github actions (#1361) (#618)

    e3b484b
  12. meltsufin
    added a commit that references this issue on Dec 22, 2025

    chore: release 3.0.2-SNAPSHOT (#618)

    63a79ab
  13. chingor13
    added a commit that references this issue on Jan 6, 2026

    Enable staleness and pull request size bots on repository (#618)

    60a92cd
  14. chingor13
    added a commit that references this issue on Jan 22, 2026

    build(deps): update dependency com.google.cloud:google-cloud-shared-c…

    63080eb
  15. chingor13
    added a commit that references this issue on Feb 24, 2026

    chore: add GCS_BUCKET env var (#622)

    This issue will close once commit b296e81 is merged into the 'main' branch.
    b296e81
  16. suztomo
    added a commit that references this issue on Mar 11, 2026

    chore: release 3.0.2-SNAPSHOT (googleapis#618)

    b0ef429
  17. chingor13
    added a commit that references this issue on Mar 12, 2026

    chore: add GCS_BUCKET env var (#622)

    This issue will close once commit f0a3e4e is merged into the 'main' branch.
    f0a3e4e
  18. suztomo
    added a commit that references this issue on Mar 23, 2026

    chore: release 2.4.5-SNAPSHOT (googleapis#618)

    e8058ac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @mziccard
    mziccard

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.