Readability > Writeability
I feel like it's just slow me down and barely has any benefit other
than organizing your code.
You are correct in that it (slightly) slows you down writing that code. However, you write it once in the beginning and from then on everytime you come back you are going to read it. So optimizing the reading speed will do much more good that optimizing the writing speed.
Naming things
Now, you might have difficulties seeing how draw_rect(Vector2(x, y), Vector2(width, height))
is supposed to be more readable than draw_rect(x, y, width, height)
, but to be honest, they both aren't as readable as they could be.
Look at this pseudocode:
position = Vector2(x, y)
size = Vector2(width, height)
draw_rect(position, size)
Yes, this takes 2 lines more and in the beginning I also thought that was bad. It isn't though.
Giving things names makes this take less brain power to read, which you will be very thankful for as soon as the program gets more complex. Especially when you're debugging it. Naming things well will also improve other things and make you faster in the long run.
The still very short, but slightly longer run
You mentioned
Object.x += 1
vs Object.pos += Vector2(1, 0)
Again you're right, your way is faster for this (a single line). But let's just look at a minimally more complex class, you can have:
position;
velocity;
void UpdatePosition(){
position += velocity;
}
Compare with:
xPosition;
yPosition;
xVelocity;
yVelocity;
void UpdatePosition(){
xPosition += xVelocity;
yPosition += xVelocity;
}
That is faster to read and to write. By the way, with such a small example it's not suuuper hidden, but did you notice the typo in the second version? That's easy to overlook, especially if the class is more complex than this unrealistically small example (There's a theme here...). It's one bug that can't happen when using Vector2.
IDEs
you cant shorten it by using something like Vec2 = Vector2
You might be working on a school assignment where you aren't allowed to use an IDE.
If you don't, use one and look up the autocomplete shortcut (most of the time it's Ctrl+Space).
Then you can write "Vec" and use that shortcut and the IDE will show you a list of all classes that start with "Vec". I don't think any professional coder works without this, because this is so much faster. The alternative is to learn every class by heart, with correct typing down to the single character. Ain't nobody got time for that, especially in the business world where time is money.
Object.pos += Object.mov;
is significantly faster and easier thanObject.x += Object.movX; Object.y += Object.movY;
\$\endgroup\$render_pos = object->pos; object = object->parent; while(object) { render_pos += object->pos; object=object->parent; }
Saves you a lot of writing on the long run. \$\endgroup\$