Skip to content

Instantly share code, notes, and snippets.

Proposal: return? Keyword for Conditional Returns in Go

Abstract

This proposal introduces the return? keyword in Go, which allows concise early returns based on conditional assignments. It enables direct assignment to return values and a streamlined syntax for handling common error propagation patterns.

Background

Go's error handling is explicit and encourages checking return values. However, common patterns, such as propagating errors, often lead to verbose and repetitive code. Consider the typical error-checking pattern:

#include <mach/mach.h>
#include <mach/mach_time.h>
#include <sys/time.h>
#include <time.h>
static mach_timebase_info_data_t timebase_info;
int
clock_gettime_monotonic(struct timespec *tp) {
uint64_t mticks = mach_absolute_time();
@perj
perj / vpn.sh
Created February 16, 2016 21:20
#!/bin/bash
# Copyright 2016 Per Johansson
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#