Hacker News new | ask | show | jobs
by fferen 1377 days ago
> For example, if I have a `Point` object with `x` and `y` fields, and I make a function called `lowest_point`, it knows I want to the point with the minimum `y` value. Because it knows the name `y` is most typically used for vertical direction, and the word `lowest` also implies vertical direction.

Unless, as in many systems, y=0 is the top and y increases downward.

1 comments

The magical thing is once shown examples of this in your code, or a comment saying as much, Copilot will adapt.

For example, I just gave Copilot:

    # The screen is inverted, so bigger y values are lower
    def lowest_point(points):
and it completed:

    # The screen is inverted, so bigger y values are lower
    def lowest_point(points):
        lowest = points[0]
        for point in points:
            if point.y > lowest.y:
                lowest = point
        return lowest
Even if you write some code that implies that bigger y is lower, Copilot will pick up on it.
Notably, I think writing with copilot encourages you to write comments that provide necessary context.

Naturally, this makes it easier for other programmers to understand the code.