# Caffeware

Member

11

151 Neutral

• Rank
Member

• Website

congrats
2. ## What's your take on protected variables?

I believe the context here can't be too obscure. This is a video game dev site after all. [quote name='Servant of the Lord' timestamp='1352536318' post='4999582'] Hodgeman rightly mentioned the warning bells that emerge when "Circle" has to ignore either width or height. The warning bells are actually telling you that Circle doesn't have a width or a height, it has a radius or a diameter. You use the diameter to "calculate" the circle's width or height - except that the diameter is exactly equal to the height and is exactly equal to the width, so nobody bothers explicitly calculating it with circles. But just because a circle's width and height happen to be equal to the circle's diameter, that doesn't mean the circle's width and height are the diameter (or vise-versa). You'd actually be reusing the variable "width" or the variable "height" for an entirely different purpose that just happens to be equal, which wouldn't be good (in this situation, it's a very mild issue - but it's still not a good habit to get into). [/quote] No. As I see it, the Circle class will include all three: width, height and diameter. The width and height still serves the same purpose for Circle class as it did for Rectangle class. Now, the diameter variable (or maybe radius), will be used to calculate the area of the circle. [quote] There's a more serious, but more subtle issue with re-using the Shape's width, height, x, and y. As I already mentioned, you'd actually be re-purposing either width or height for a different purpose. But how many people here realize you'd also be re-purposing x and y for a different purpose as well? ... What is x and y? A coordinate on a Cartesian grid. Right? But in naming it 'x' and 'y' you are actually naming it what it is, instead of what it's for (Which is why it would be better off wrapped in a Point or Coord class). A variable's type should say what the variable is, but the variable's name should describe it's purpose. What does 'x' mean to a Shape? 'x' does not describe the purpose, it only describes that it is a horizontal location in space. It could serve any purpose - the name isn't describing the purpose. It's precisely because it's so generically named that you tricked yourself with your Shape class, and also trick future users of your class: [/quote] I don't agree with this. The width and height variables are raw data. Data should be used for whatever it needs to be used. Of course, the 'x' variable could be named better, let's say 'x_coordinate', or even better, as you say, it could be a point. But my argument is that EVERY child of the Shape class will need a x variable and a y variable, or a point, etc. It doesn't matter where the point will be located in the shape, the object stills need it. The Circle class example is the 'whale' of the mammals class. I must say, I have nothing against composition. I use it much in my code. Yet some things simply belong in a class. And I can't conceive how the child can't have access to the parents data when he is INHERING from that same class. If you permit to me make another example: [source lang="cpp"]class Dog{ private: Fangs fangs; //many other variables }; class GermanShepherd : public Dog{}[/source] So you are telling me that class GermanShepherd can't have access to Dog class's private variables? Or are you going to argue that some dogs don't howl, so they don't fit together in a class. Should I compose GermanShepherd class from Dog class? You are arguing against inheritance, not against protected variables! [font=courier new,courier,monospace]inhere [?n?h??] vb (intr; foll by in) to be an inseparable part (of)[/font]
3. ## What's your take on protected variables?

[quote name='Hodgman' timestamp='1352523806' post='4999545'] Can every shape derivative be descrived with those 4 variables? Bregma hinted earlier that this probably isn't true -- e.g. polygons have a collection of vertices and edges, circles have a radius, squares have an edge-length... If you're making a polymorphic base class, you shouldn't include any variables that aren't going to be common to all derived classes. If you do have variables that are common to all derived classes, you probably don't need to be using polymorphism either... [/quote] First, thanks for the your time and replies; I really appreciated it. Now, in Bregma's example, I don't see the 'trouble', since the Circle class would include the necessary variables to calculate it's own area. Yet, the Circle class needs the x, y, width and height variables. I believe it's not in-logic to say the a circle has a width, for example. "In object-oriented programming (OOP), inheritance is a way to reuse code of existing objects..." [url="http://en.wikipedia.org/wiki/Inheritance_%28object-oriented_programming%29"]http://en.wikipedia.org/wiki/Inheritance_%28object-oriented_programming%29[/url] I know Wiki is not the best source, but...
4. ## What's your take on protected variables?

I know I'm against the fence here, but I'm gonna try anyway . [quote name='Hodgman' timestamp='1352521684' post='4999533'] The example code is a straw-man argument. It should look like: [source lang="cpp"]class Shape{ public: virtual void CalculateArea(); }; class Rectangle : public Shape{ public: void CalculateArea(){ return width * height; } Rectangle( int w, int h ) : width(w), height(h) {} private: int width, height; };[/source] [/quote] The thing about this is that for every 'Shape child' I have to include the width, height, x, y variables separately. Isn't one of the advance of class hierarchy not having to repeat oneself. By the way, I do AGREE that using setter/getters isn't a good idea.
5. ## What's your take on protected variables?

What's your take on protected variables? In the context of c++, it seems most experts (Scott Meyes, Herb Sutter) think is not a good idea. I don't agree. In fact, some languages, for example Ruby, have only automatic protected variables. It seems silly to make a 'setter' and 'getter' functions for a variable when the derived object is employ in terms of "is-a". Also, making 'setter' functions opens the variable to be manipulated from outside the object! Of course, one could make in the 'setter' protected, but isn't that 'running in a loop'? Please, discuss. EDIT: Let's say I have: [source lang="cpp"] class Shape{ public: virtual void CalculateArea(); private: //private! int x, y; int width, height; }; class Rectangle : public Shape{ public: void CalculateArea(){ /* I need width and height to calculate, but can't access it. What can I do? */ } }; [/source] If I make 'getters' for Shape class: [source lang="cpp"] class Rectangle : public Shape{ public: void CalculateArea(){ get_width(); //isn't this silly, as width is a fundamental part of Rectangle //also, now everyone knows my width! } }; [/source]
6. ## C-Lesh and the Super Mario World Game Engine

I'm not familiar with this project as I'm new here, but why did you switch from c++ to c-lesh? Was the former too slow?
7. ## OpenGL Time to write rendering engine from scratch

[img]http://public.gamedev.net//public/style_emoticons/default/huh.png[/img]
8. ## Chat Faliszek from Valve gives advice on breaking into industry

Is it true you guys are making ff xiii - 3 ?
9. ## Chat Faliszek from Valve gives advice on breaking into industry

[quote name='Orymus3' timestamp='1349198853' post='4986108'] My company (tri-Ace) ... L. Spiro [/quote] I'm a fan... Not to derail the thread, but how long have you been working there?
10. ## 10 steps to becoming a better programmer

Thank you sir.
11. ## Seiken Densetsu / Mana Fan Game

Hi guys, I'm new here. I been making this game for quiet some time. The idea is to combine the assets from the Seiken Densetsu / Mana franchise into a single game. The game will have a back-story as for why things are "mix-up". I'm thinking something in terms of the "Turtles Forever" TMNT movie. [spoiler][media]http://www.youtube.com/watch?v=GRz2UXFA5yM&noredirect=1[/media][/spoiler] Obviously, the game wiil be free to play once finished. As for now it is only a demo. BTW: The Chrono Trigger map is only a place holder and soon will be removed! [img]http://picoyespuelaspr.com/caffeware/images/screenshot001.png[/img] [img]http://picoyespuelaspr.com/caffeware/images/screenshot002.png[/img] [img]http://picoyespuelaspr.com/caffeware/images/screenshot003.png[/img] [img]http://picoyespuelaspr.com/caffeware/images/screenshot004.png[/img] [img]http://picoyespuelaspr.com/caffeware/images/screenshot005.png[/img] [img]http://picoyespuelaspr.com/caffeware/images/screenshot006.png[/img] [b]DOWNLOAD:[/b] [url="http://www.picoyespuelaspr.com/caffeware/files/mana001.zip"]http://www.picoyespu...les/mana001.zip[/url] [b]CONTROLS:[/b] [b]Run :[/b] Press Cancel key. [b]Open Ringmenu :[/b] Press Cancel and Confirm keys. [b]Attack:[/b] Trigger Confirm key. Use can use the [b]KEYS.exe[/b] located in the game folder to map the controls to the keyboard keys. A standard gamepad can be used to play the game. However, buttons can't be set for the gamepad. [b]Field map:[/b] Use the [b]Direction[/b] keys to move the character. To attack, use the [b]Confirm[/b] key. To run press and hold the [b]Cancel[/b] key while using the [b]Direction[/b] keys. Finally, press and hold both the [b]Confirm[/b] and [b]Cancel[/b] keys to open the Ringmenu. [b]Ringmenu:[/b] The Ringmenu is used to select healing items, to change the controlled character, and to select and use magics. The battle will keep running while the Ringmenu is open. If the character with the Ringmenu is hit by an enemy, the Ringmenu will automatically be closed. The cotrols for the Ringmenu are the following: Direction keys [b]Left[/b] and [b]Right[/b] to rotate among the icons available. Directions keys [b]Up[/b] and[b] Down[/b] to change rings. The [b]Confirm[/b] key is used for selecting the icons. In some cases when selecting an icon, the Handcursor will appear. With the Handcursor you can select allies or foes depending on current ring. The [b]Cancel[/b] key will close the Ringmenu. [b]MAGICS:[/b] At the moment, only the Tamber character can use magics. There are various magics, each with different reactions. For example, one will hit a single enemy, while other will hit multiple. Try them all and discover the different effects! [b]OBJETIVES:[/b] The characters [b]DO NOT[/b] earn experience points or gain levels. Nevertheless you can 'farm' items and can earn money in order to buy in the shops. A good inventory will be necessary when encountering a 'mysterious' someone! [b]Please tell me what you think![/b]