• Forum
  • Lounge
  • whats the best way to plan a code, whats

whats the best way to plan a code, whats the best way to plan it to use re-usable classes

Pages: 12
I would like to be able to build a whole load of classes and think of them as blocks so i can draw a little pattern of boxes with lines between and then when it comes to building i can just sketch on a piece of paper how my code will work and then i just hook them up [the classes] :)

devonrevenge wrote:
I would like to be able to [...] think of them as blocks so i can draw a little pattern of boxes with lines between and then [...] just sketch on a piece of paper how my code will work
When you do that, patent it ASAP. You'll make trillions. People would kill for that kind of technology.

As for making code reusable, follow common design patterns such as encapsulation, generic programming, and modularity.
Last edited on
so theres no system for designin sturff?
There's plenty, but obviously they're not as superbly awesome like yours or they would be much more popular.
one day :D but i need help planning the most basic stuff at the moment, what are these helpful code planning techniques? what to search for?
The ancient and magical technique is to draw rectangles for classes and connect them with arrows if they are somehow related. Now, if you want to be extra neat, you can use different kinds of arrows for different kinds of relations ("inherits from", "contains", "contains a list of", "points to", etc.). You could also think up other things worth drawing, such as, bubbles for different components and arrows for how information is exchanged between them. You could even write a few hundred page specification of your pictures and call that UML, though, to be honest, that would be just silly.

Seriously though, UML is a thing, I don't hate it, but you'll be better off just making up the diagrams you want yourself.

Note though that this will almost never help you with being unable to write the right algorithm, and it isn't even applicable to absolutely every project. It's better than planning in your head though.
ive tried drawing little rectangles, the rectangles lie.

but my code doesnt ever really translate into them :/ if I showed you my code and an img of my rectangles (i will spare you from being ashamed of yourself for laughing in the face of a novice) you will see they bare no relation
Last edited on
Is there a way of automatically rectangling my code up to some kind of rectangle convension? this reminds me of dj rectangle, he was fun.

Last edited on

struct Base

struct Derived : public virtual Base
Your arrow is backwards.
It depends on what way you interpret it. I'd say it's correct. I see it as "Base goes into Derived".
I think VS2012 does a crude version of this.
closed account (3qX21hU5)
You know I was going to do out and buy a couple 4x4 foot whiteboards for my office to do class designing and UML type things on the other day. I got the to the store and you know how much they want for a frickin whiteboard like that? I believe it was $200 frickin dollars for a 4 foot by 4 foot and for a 6x4 or anything bigger it just got to be outrageous.

Anyways enough of my off topicness as for planning your class relationships just use a whiteboard and draw shapes like hamst said ;p
> I see it as "Base goes into Derived".
But you don't touch Base.
Even in smalltalk, where you say Base subclass: Derived. you are not modifying Base definition

The visibility is from Derived to Base.
A father does not (should not) recognize its children.
Last edited on
On Linux, I have a program called Umbrello (A UML modeller), which lets one specify classes using a GUI, then draws boxes with all the arrows, using UML. You can then get it to create the code.

It is a great planning tool.

You can do all kinds of relationships - not just the class ones.


There is a link to
as well.
Last edited on
But you don't touch Base.
That makes sense. It's just that for the purposes of the example, it didn't really matter so long as the writer of the diagram knew what the arrow really meant.

Visual Studio comes with a UML diagram tool, plus a Class Diagram system that directly turns your diagrams into C++ classes. If you're a college student, you can probably get a copy of it for free. Ask about DreamSpark or MSDNAA. I really do like their design tools.
Last edited on
it didn't really matter so long as the writer reader of the diagram knew what the arrow really meant.

> DreamSpark
That's very nice of them.
@ne555 I was using the notation used by the Dylan Reference Manual:
Obviously C++ isn't Dylan, but the OP didn't explicitly limit content to C++.
@devonrenge, do actually show your code and your rectangles. That sort of thing is what this site is for, after all. I'm not sure what other kind of help you could expect. Magical solutions to all of your problems tend not to exist.

Also, if your rectangles don't match your code, why did you draw them like that (or why did you write your code like that, depending on which you did first)?
Pages: 12