Software Engineering
To make life for developers easier, be explicit in what exactly is being returned. In the Stripe API, we have an object field in the response that makes it abundantly clear what we’re working with. For example, the API route
/v1/customers/:customer/payment_methods/:payment_method
Enter fullscreen mode
Exit fullscreen mode
returns a PaymentMethod... See more
/v1/customers/:customer/payment_methods/:payment_method
Enter fullscreen mode
Exit fullscreen mode
returns a PaymentMethod... See more
Common Design Patterns at Stripe
The complete Protobuf platform
Accelerate gRPC adoption with the Buf Schema Registry — built by the world's Protobuf experts.
Accelerate gRPC adoption with the Buf Schema Registry — built by the world's Protobuf experts.
Buf
But now we are only logging that error message. It would be better to define a custom Exception that we can then handle in our API in order to return a specific error code to the user:
import pandas as pd
import logging
class DataLoadError(Exception):
"""Exception raised when the data cannot be loaded."""
def __init__(self, message="Data could not be... See more
import pandas as pd
import logging
class DataLoadError(Exception):
"""Exception raised when the data cannot be loaded."""
def __init__(self, message="Data could not be... See more
How to Write Clean Code in Python
And then, in the primary function of your API:
try:
df = load_data('path/to/data.csv')
# Further processing and model prediction
except DataLoadError as e:
# Return a response to the user with the error message
# For example: return Response({"error": str(e)}, status=400)When a test fails, you should be able to begin investigation with nothing more than the test’s name and its failure messages —no need to add more information and rerun the test.
Effective use of unit test frameworks and assertion libraries (JUnit, Truth, pytest, GoogleTest, etc.) serves two important purposes. Firstly, the more precisely we express... See more
Effective use of unit test frameworks and assertion libraries (JUnit, Truth, pytest, GoogleTest, etc.) serves two important purposes. Firstly, the more precisely we express... See more
Test Failures Should Be Actionable
Here's a list of those log levels from lowest precedence to highest:
notset (0) - Indicates that ancestor loggers should be consulted for the log level or that all events are logged (default setting)
debug (10) - Detailed information that would be of interest to the developer for diagnostic purposes
info (20) - Information that confirms that your... See more
notset (0) - Indicates that ancestor loggers should be consulted for the log level or that all events are logged (default setting)
debug (10) - Detailed information that would be of interest to the developer for diagnostic purposes
info (20) - Information that confirms that your... See more
Shortwave — The smartest email app on planet Earth
1. Streamlining data exploration and analysis:
- Context-Aware Suggestions: Receive AI-powered suggestions for relevant tools, functions, and libraries based on your specific dataset and analysis goals.
- Contextual search for functions and libraries: Quickly find relevant functions and libraries from various programming languages, such as Python and R,
Martha J. Lindeman • How Data Science AI Tools are Simplifying Workflows
Some important formatting rules available in this style guide:
But remember: The formatting rules should make the code more readable. Sometimes,... See more
- Use four spaces for code indentation
- Limit all lines to a maximum of 79 characters
- Avoid extraneous whitespace in certain situations (i.e., inside brackets, between trailing comma and close parenthesis, ...)
But remember: The formatting rules should make the code more readable. Sometimes,... See more
How to Write Clean Code in Python
Use nested objects for future extensibility
A follow on from the previous tip: try to logically group fields together. The following:
customer.address = {
line1: "Main Street 123",
city: "San Francisco",
postal_code: "12345"
};
Enter fullscreen mode
Exit fullscreen mode
is much cleaner than:
customer.address_line1 = "Main street 123";
customer.address_city... See more
A follow on from the previous tip: try to logically group fields together. The following:
customer.address = {
line1: "Main Street 123",
city: "San Francisco",
postal_code: "12345"
};
Enter fullscreen mode
Exit fullscreen mode
is much cleaner than:
customer.address_line1 = "Main street 123";
customer.address_city... See more
Common Design Patterns at Stripe
Before you start working, figure out:
After you’ve finished your work, check:
4. Did I miss anything?
- What does the business want?
- Which criteria should I fulfill to call my work “good”?
- What do I need to do to complete this particular task?
After you’ve finished your work, check:
4. Did I miss anything?