Skip to main content
gamedev.net
🔒 Locked

Writing Clean Code....?

Started by cippyboy 9 replies 450+ views
Original Post
cippyboy
cippyboy
Can anyone lend me some theory about how some clean code would look like ? I`m trying to imagine the code with lots of classes and also well arranged in a page... like buga buga() { buga1(); buga2(); ....... bugaX(); } Can anyone give me some more examples/tips ? PS:Just curios about how other people write code....
Relative Games - My apps
Arild Fines
Arild Fines
Clean code doesn''t have names like "buga"



"If there is a God, he is a malign thug."
-- Mark Twain
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
origil
origil
quote:
Original post by Arild Fines
Clean code doesn''t have names like "buga"



"If there is a God, he is a malign thug."
-- Mark Twain



Well, if you ask me, "buga" is the way to go!
I''d be able to answer if you were a bit more specific.
v_d_d
v_d_d
I would rename your functions to MyBuggyFunc1(), MyBuggyFunc2()... etc...

At least, if not clean, it will be honest...

;-)
redragon
redragon
quote:
Original post by cippyboy
Can anyone lend me some theory about how some clean code would look like ?
I`m trying to imagine the code with lots of classes and also well arranged in a page...
like
buga buga()
{
buga1();
buga2();
.......
bugaX();
}
Can anyone give me some more examples/tips ?


PS:Just curios about how other people write code....


Don''t know exactly what you mean, but:
http://www.doc.ic.ac.uk/lab/cplus/c++.rules/

Here is a good start. Really, you don''t want to just break out segments of code like:

  
doSetup();
doProcessing();
doDrawing();
doPostDraw();
doSomeStuff();


What you want to do is try to break things down so you can explain it easily (IMHO).


  
// Transform the current entity object by it''s possition and rotation.

CMatrix matTransform;
CMatrix matRotation;
matTransform.setToTranslation(entCurrent.getPosition());
matRotation.setToRotation(entCurrent.getRotation());

entCurrent.transformBy(matTransform * matRotation);

Now obviously there are holes in what I''m saying here, but try to simplify without obscuring what you''re doing. You want it to make logical sense. You''ll notice that I don''t follow the rules in the document I attached, but I just recommend it as a guideline. Don''t know if I''ve helped or not. Good luck.

- sighuh?
sighuh?
TheAIDSVirus
TheAIDSVirus
This is a question that has a thousand not right, but not wrong, answers.

Clean code is consistent code. That''s about the only solid rule. Decide on a style and stick with it.

----
AIDS
----AIDS
llvllatrix
llvllatrix
I also find that clean code means encapsulation. As you program grows, encapsulation will really help you keep it from becomming spaghetti (or in my case, soup ).

With demos its usually easier to separate classes into modules - one class per module. That way if you need it for another project, you just include the module and you''re done - that is a sign of clean coding.
RipTorn
RipTorn
if another programmer can look at a RANDOM block of your code and know what it is doing the first time they read it, it''s good code.

| - Project-X - my mega project.. getting warmer - | - adDeath - an ad blocker I made - | - email me - |
Arild Fines
Arild Fines
quote:
Original post by cippyboy

Can anyone give me some more examples/tips ?


Just post some of your own code, and I''m sure everyone will be happy to tell you everything that is wrong with it





"If there is a God, he is a malign thug."
-- Mark Twain
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Hawkeye3
Hawkeye3
I write my code using Lysol, that seems to keep it clean

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.