Don’t DRY Your Code Prematurely

This is another post in our Code Health series. A version of this post originally appeared in Google bathrooms worldwide as a Google Testing on the Toilet episode. You can download a printer-friendly version to display in your office.

By Dan Maksimovich

Many of us have been told the virtues of “Don’t Repeat Yourself” or DRY. Pause and consider: Is the duplication truly redundant or will the functionality need to evolve independently over timeApplying DRY principles too rigidly leads to premature abstractions that make future changes more complex than necessary. 

Consider carefully if code is truly redundant or just superficially similar.  While functions or classes may look the same, they may also serve different contexts and business requirements that evolve differently over time. Think about how the functions’ purpose holds with time, not just about making the code shorter. When designing abstractions, do not prematurely couple behaviors that may evolve separately in the longer term.

When does introducing an abstraction harm our code? Let’s consider the following code: 

# Premature DRY abstraction assuming # uniform rules, limiting entity-

# specific changes.

class DeadlineSetter:

 def __init__(self, entity_type):

  self.entity_type = entity_type


 def set_deadline(self, deadline):

   if deadline <= datetime.now():

    raise ValueError(

      “Date must be in the future”)

task = DeadlineSetter(“task”)

task.set_deadline(

datetime(2024, 3, 12))

payment = DeadlineSetter(“payment”)

payment.set_deadline(

datetime(2024, 3, 18))

# Repetitive but allows for clear,

# entity-specific logic and future

# changes.

def set_task_deadline(task_deadline):

  if task_deadline <= datetime.now():

raise ValueError(

    “Date must be in the future”)

def set_payment_deadline( payment_deadline):

  if payment_deadline <= datetime.now():

    raise ValueError(

    “Date must be in the future”)

set_task_deadline(

datetime(2024, 3, 12))

set_payment_deadline(

datetime(2024, 3, 18))

The approach on the right seems to violate the DRY principle since the ValueError checks are coincidentally the same.  However, tasks and payments represent distinct concepts with potentially diverging logic. If payment date later required a new validation, you could easily add it to the right-hand code; adding it to the left-hand code is much more invasive.

When in doubt, keep behaviors separate until enough common patterns emerge over time that justify the coupling. On a small scale, managing duplication can be simpler than resolving a premature abstraction’s complexity. In early stages of development, tolerate a little duplication and wait to abstract. 

Future requirements are often unpredictable. Think about the “You Aren’t Gonna Need It” or YAGNI principle. Either the duplication will prove to be a nonissue, or with time, it will clearly indicate the need for a well-considered abstraction.


Introducing audit logs for these API-based actions

What’s changing

Drive log events provide admins with visibility into their organization’s user activity in Drive. Previously, download activity for files triggered by the use of Google Workspace APIs was not visible to admins as a Drive log event. 

Today, we’re adding audit logs for these API-based actions to the security investigation tool and the audit and investigation tool to expand upon an admin’s ability to identify, triage, and take action on security and privacy issues in their domain. 


Getting started 


Rollout pace

  • This feature is now available 


Availability

Available for Google Workspace: 
  • Business Starter, Standard, Plus 
  • Enterprise Standard, Plus 
  • Essentials Starter, Enterprise Essentials, Enterprise Essentials Plus 
  • Education Fundamentals, Standard, Plus, Teaching and Learning Upgrade 

Resources 

Chrome Dev for Desktop Update

The Dev channel has been updated to 127.0.6496.3 for Windows, Mac and Linux.

A partial list of changes is available in the Git log. Interested in switching release channels? Find out how. If you find a new issue, please let us know by filing a bug. The community help forum is also a great place to reach out for help or learn about common issues.

Daniel Yip
Google Chrome

Google Workspace Updates Weekly Recap – May 24, 2024

2 New updates

Unless otherwise indicated, the features below are available to all Google Workspace customers, and are fully launched or in the process of rolling out. Rollouts should take no more than 15 business days to complete if launching to both Rapid and Scheduled Release at the same time. If not, each stage of rollout should take no more than 15 business days to complete.


Expanding row limits in Connected Sheets for BigQuery 
Last year, we increased the maximum number of rows of results returned from BigQuery to 50,000 for pivot tables and data extracts. This week, we’re excited to announce this has been expanded to 100,000 rows for pivot tables and 500,000 rows for extracts (with a cell limit of 5 million). This will allow you to analyze even more results in Sheets from the petabytes of data in BigQuery. | Rolling out to Rapid Release and Scheduled Release domains now. | Available to all Google Workspace customers, Workspace Individual Subscribers, and users with personal Google accounts. | Learn more about analyzing & refreshing BigQuery data in Google Sheets using Connected Sheets, Google Sheets limitations, and getting started with BigQuery data in Google Sheets.

Custom text fields are now available for eSignature in Google Docs and Google Drive 
You can now input custom text fields when using eSignature. This gives you the flexibility to collect specific information as needed, including a phone number, job title, company name, and more. | Available to Google Workspace Individual users and other eligible Google Workspace customers who are on the eSignature alpha. | Rolling out to Rapid Release domains and Scheduled Release domains now. | Learn more about sending signature requests & signing documents with eSignature.




Previous announcements

The announcements below were published on the Workspace Updates blog earlier this week. Please refer to the original blog posts for complete details.


Filter, sort, and display your Google Meet hardware devices by product service status 
You can currently filter, sort, and display your Google Meet hardware devices by whether they are online, offline, or experiencing an application load-failure. This week, we’re expanding these parameters to include whether the Calendar and Jamboard services are turned OFF. | Learn more about filtering, sorting and displaying Meet hardware devices. 

Introducing adaptive audio in Google Meet: creating ad-hoc meeting spaces with multiple laptops 
With “adaptive audio,” you and your team can join Google Meet using multiple laptops in close proximity without awkward echos and audio feedback. | Learn more about adaptive audio in Google Meet. 

Send emails to spaces in Google Chat 
After a space manager generates an email address for a space, members (or anyone in your domain with the email address) can send or forward any email to that space. This provides a great way for teams to easily triage or discuss email content with stakeholders within the space. The email will appear as a clickable card showing a snippet of the email in the designated space. | Learn more about sending emails to spaces. 

Manage spaces at scale with new Chat API functionality 
We are pleased to announce the launch for additional features of Chat API via the Developer Preview Program, enabling space management at scale on behalf of admin users. These new features are available to all users currently enrolled in the Developer Preview Program. | Learn more about new Chat API functionality. 

Introducing Gemini offerings for Google Workspace for Education customers 
Beginning May 23, 2024, Google for Education customers will be able to leverage new and powerful ways of working, teaching and learning with Gemini for Google Workspace with two new paid add-ons. | Learn more about Gemini Education and Gemini Education Premium add-ons.

Expanding voice typing and automatic captions to additional browsers 
We’re expanding support for voice typing and captions features to additional browsers, such as Edge and Safari. When a user turns on voice typing or captions, the web browser controls the speech-to-text service, determines how speech is processed, and then sends text data to Google Docs and Google Slides. | Learn more about voice typing features in additional browsers.



Completed rollouts

The features below completed their rollouts to Rapid Release domains, Scheduled Release domains, or both. Please refer to the original blog posts for additional details.


Rapid Release Domains: 

For a recap of announcements in the past six months, check out What’s new in Google Workspace (recent releases).   

Announcing v202405 of the Google Ad Manager API

We're pleased to announce that v202405 of the Google Ad Manager API is available today. This release brings support for contextual targeting.

It also includes a number of deprecations, such as the removal of the ActivityService, ActivityGroupService, and ACTIVITY reporting dimensions to support the Spotlight deprecation.

For the full list of changes, check the release notes. Feel free to contact us on the Ad Manager API forum with any API-related questions.