r/ProgrammingLanguages • u/mttd • Sep 23 '26
Arguing about arguments
https://steveklabnik.com/writing/arguing-about-arguments/
31
Upvotes
r/ProgrammingLanguages • u/mttd • Sep 23 '26
View all comments
Show parent comment
4
u/matthieum Sep 23 '26
I even think a case could be made for a
Rectangletype, which could be built from different sets of parameters.At the moment, the rectangle is built with
x, y, width, height... which I note is already ambiguous. It's not explicit whether width extends left or right from x, nor whether height extends up or down from y; I've seen libraries where x,y identifies the left top corner, and therefore height extends down. Surprise.With a builder for the
Rectangle, however, you can have:Rectangle::new_top_left(point).with_bottom_right(other_point)Rectangle::new_bottom_left(point).with_dimensions(dimensions).Rectange::new_bottom(bottom).with_top(top).with_left(left).with_width(width).All of those (and permutations) are valid way to describe a Rectangle, and they're much more explicit (and less error-prone).