3 ms·
This post touches on a hypothesis of mine: the more the context looks like homework or low quality code, the worse the suggestions will be. Like a LLM that auto
by BoppreH 3y ago
This post touches on a hypothesis of mine: the more the context looks like homework or low quality code, the worse the suggestions will be. Like a LLM that autocompletes a childish question with a childish answer, a homework code prompt will autocomplete with more homework code, bugs and all. So getting high quality completions is less about descriptive prompts, and more about framing and vibes.
Here are three "homework-looking" functions that were generated by Copilot based on their signatures, with comments added by me:
# "Load" and "file" instead of more precise terms.
def load_numbers(file):
with open(file) as f:
# both .strip() and .readlines() are redundant and should be removed.
return [int(line.strip()) for line in f.readlines()]
# Verbose and imprecise naming.
def calculate_differences(numbers):
numbers = sorted(numbers) # Inefficient cloning instead of .sort().
differences = [numbers[0]] # Breaks on empty lists.
for i in range(1, len(numbers)):
differences.append(numbers[i] - numbers[i-1])
differences.append(3) # Where did 3 come from?
return differences
# Vague. Redundancy with param name. Sounds too much like English.
def count_increasing_numbers(numbers):
increasing = 0
for i in range(1, len(numbers)):
# Homework looking if/else.
if numbers[i] - numbers[i-1] == 1:
increasing += 1
else:
increasing = 0 # Why would it reset?
return increasing
And here are three similar functions from signatures where I tried to give better "vibes":
# "parse" and "filename" are more precise, and out params indicate higher performance code.
def parse_numbers(filename, out_numbers):
# Explicit file-mode!
with open(filename, 'r') as f:
# Reading lines by iterating over the file object!
for line in f:
# Explicit error handling!
try:
# No redundant .strip()!
out_numbers.append(int(line))
except ValueError:
pass
# "get", "adjacent", and "diff" all show familiarity with vocabulary.
def get_adjacent_diff(numbers):
# Simple one liners! No off-by-1 errors!
return [numbers[i] - numbers[i-1] for i in range(1, len(numbers))]
# "Pairwise" is more technical, and avoiding name/arg redundancy. Less like English.
def count_pairwise_increasing(numbers):
# Another good one liner, making full use of list comprehension.
return sum([1 for i in range(1, len(numbers)) if numbers[i] - numbers[i-1] == 1])
Unfortunately this is not objective at all, and subject to changes on GitHub's whims.