Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
Some variables make sense to bundle together. For example, if you have a graphics method to draw an image, you will need to pass in an X and Y coordinate for where to draw the image. Those are two...
Answer
#1: Initial revision
Some variables make sense to bundle together. For example, if you have a graphics method to draw an image, you will need to pass in an X and Y coordinate for where to draw the image. Those are two separate variables. > DrawImage(double x, double y, Image img); But, logically, they're a single point. So it might make sense to have them bundled together into a single variable with an X and Y component. > DrawImage(Point p, Image img); // Point has the x and y Then you can work with them together, such as applying a translation or other common graphics transform on the point. In fact, in a graphics package, you'll routinely see methods like this having multiple ways to call it depending on whether you want to pass in X and Y as separate variables, bundled together in a point, or possibly bundled with width and height as a 4-part rectangle. > DrawImage(Rectangle r, Image img); // Rectangle has x, y, width, height I do not recommend passing your x & y together as an array. While simple here, code like that becomes harder to maintain over time as developers need to remember what each index in the array is supposed to represent.