16
General / Is this a bad programming habit?
« on: December 15, 2014, 07:25:21 pm »
Hello, I would like to ask whether this habit is good or bad, I have read FAQ about using global variables, but I'm not sure does this situation is exactly the same bad as this described in wiki.
Let's assume I'm trying to write a player class, so i have a cpp and hpp file. In cpp file I write something like this:
Someone may ask, why I'm doing something like this. Well when I have 6-7 parameters it's very nice to have them in one place, so configuration takes 3 seconds instead of 30, because I don't need to look for them. What should I do if this is not the best solution? I was thinking of static variable, but I'm not sure about this.
Let's assume I'm trying to write a player class, so i have a cpp and hpp file. In cpp file I write something like this:
#include "Player.hpp"
constexpr sf::Vector2f playerPos{100.0,300.0};
void Player::Player()
{
player.setPosition(playerPos);
...
...
}
constexpr sf::Vector2f playerPos{100.0,300.0};
void Player::Player()
{
player.setPosition(playerPos);
...
...
}
Someone may ask, why I'm doing something like this. Well when I have 6-7 parameters it's very nice to have them in one place, so configuration takes 3 seconds instead of 30, because I don't need to look for them. What should I do if this is not the best solution? I was thinking of static variable, but I'm not sure about this.