object oriented design using procedural programming?

Started by
22 comments, last by GameDev.net 18 years, 1 month ago
you guys will never guess what happens when you don't plan & read and just start coding until you see this:


					else if ( Db_Holder == "shortcont" || Db_Holder == "shortReplycont" ){						filename_holder="system/db/";						filename_holder+=GetPar("db", SystemVarPar_String, SystemVarPar_Count);						filename_holder+="/config.cgi";						if(AreTheyNumbers(GetCfg("SnShortCont", filename_holder.c_str(), SystemVar_String, SystemVar_Count))){							Db_Short_Int=(int)ToInt(GetCfg("SnShortCont", filename_holder.c_str(), SystemVar_String, SystemVar_Count));						}						if ( Db_Holder == "shortcont" ){							Db_Short_Holder=InputParser("cont", dbf-1, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count);						}						else{							Db_Short_Holder=InputParser("Replycont", dbf-1, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count);						}						if( Db_Short_Int != 0 ){							cout << Db_Short_Holder.substr (0,Db_Short_Int);						}						else{							cout << Db_Short_Holder;						}					}					else if (Db_Holder == "shortcont2"){						filename_holder="system/db/";						filename_holder+=GetPar("db", SystemVarPar_String, SystemVarPar_Count);						filename_holder+="/config.cgi";						if(AreTheyNumbers(GetCfg("SnShortCont", filename_holder.c_str(), SystemVar_String, SystemVar_Count))){							Db_Short_Int=(int)ToInt(GetCfg("SnShortCont", filename_holder.c_str(), SystemVar_String, SystemVar_Count));						}						Db_Short_Holder=InputParser("cont", dbf-1, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count);						if( Db_Short_Int != 0 ){							cout << Db_Short_Holder.substr (0,Db_Short_Int);						}						else{							cout << Db_Short_Holder;						}					}					else if (Db_Holder == "shortcont3"){						filename_holder="system/db/";						filename_holder+=GetPar("db", SystemVarPar_String, SystemVarPar_Count);						filename_holder+="/config.cgi";						if(AreTheyNumbers(GetCfg("SnShortCont", filename_holder.c_str(), SystemVar_String, SystemVar_Count))){							Db_Short_Int=(int)ToInt(GetCfg("SnShortCont", filename_holder.c_str(), SystemVar_String, SystemVar_Count));						}						Db_Short_Holder=InputParser("cont", dbf-1, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count);						if( Db_Short_Int != 0 ){							cout << Db_Short_Holder.substr (0,Db_Short_Int);						}						else{							cout << Db_Short_Holder;						}					}					else if (Db_Holder == "previewshortcont"){						filename_holder="system/db/";						filename_holder+=GetPar("db", SystemVarPar_String, SystemVarPar_Count);						filename_holder+="/config.cgi";						if(AreTheyNumbers(GetCfg("SnPreviewShortCont", filename_holder.c_str(), SystemVar_String, SystemVar_Count))){							Db_Short_Int=(int)ToInt(GetCfg("SnPreviewShortCont", filename_holder.c_str(), SystemVar_String, SystemVar_Count));						}						Db_Short_Holder=InputParser("cont", dbf-1, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count);						if( Db_Short_Int != 0 ){							cout << Db_Short_Holder.substr (0,Db_Short_Int);						}						else{							cout << Db_Short_Holder;						}					}					else if (Db_Holder == "contforreply"){						Db_Short_Holder=InputParser("cont", dbf-1, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count);						Db_Short_Holder=Db_Short_Holder.replace(0,0,">> ");						for ( int j=1; j <= Db_Short_Holder.length(); j++ ){							if ( Db_Short_Holder.substr(j,1) == "\n"){								Db_Short_Holder=Db_Short_Holder.replace(j,1,"\n>> "); 							}						}						Db_Short_Holder=Db_Short_Holder.replace(0,0,"\n\n\n");						cout << Db_Short_Holder;					}					else if (Db_Holder == "date.modify"){						filename_holder="system/db/";						filename_holder+=GetPar("db", SystemVarPar_String, SystemVarPar_Count);						filename_holder+="/config.cgi";						cout << InputParser("date", dbf-1, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count);					}					else if (Db_Holder == "todayvisits"){						filename_holder="system/db/";						filename_holder+=GetPar("db", SystemVarPar_String, SystemVarPar_Count);						filename_holder+="/today.cgi";						if(ifstream(filename_holder.c_str())){							if ( GetCfg("date", filename_holder, SystemVar_String, SystemVar_Count) == GetDate() ){								string temp_1=GetCfg("today", filename_holder, SystemVar_String, SystemVar_Count);								ofstream make_today(filename_holder.c_str(),ios::out);								make_today << "today=" << ToString((int)ToInt(temp_1)+1) << "\n";								make_today << "date=" << GetDate() << "\n";								make_today.close();							}							else{								ofstream make_today(filename_holder.c_str(),ios::out);								make_today << "today=1\n";								make_today << "date=" << GetDate() << "\n";								make_today.close();							}						}						else{							ofstream make_today(filename_holder.c_str(),ios::out);							make_today << "today=1\n";							make_today << "date=" << GetDate() << "\n";							make_today.close();						}						//chmod 666;						string change_perm="chmod 666 ";						change_perm+=filename_holder;						system(change_perm.c_str());						//refresh today when date is same.						cout << GetCfg("today", filename_holder, SystemVar_String, SystemVar_Count);					}					else if (Db_Holder == "totalvisits"){						filename_holder="system/db/";						filename_holder+=GetPar("db", SystemVarPar_String, SystemVarPar_Count);						filename_holder+="/total.cgi";						if(ifstream(filename_holder.c_str())){							string temp_1=GetCfg("total", filename_holder, SystemVar_String, SystemVar_Count);							ofstream make_total(filename_holder.c_str(),ios::out);							make_total << "total=" << ToString((int)ToInt(temp_1)+1) << "\n";							make_total.close();						}						else{							ofstream make_total(filename_holder.c_str(),ios::out);							make_total << "total=1\n";							make_total.close();						}						//chmod 666;						string change_perm="chmod 666 ";						change_perm+=filename_holder;						system(change_perm.c_str());						cout << GetCfg("total", filename_holder, SystemVar_String, SystemVar_Count);					}					else if (Db_Holder == "count"){						filename_holder="system/db/";						filename_holder+=GetPar("db", SystemVarPar_String, SystemVarPar_Count);						filename_holder+="/data/";						filename_holder+=ToString(dbf-1);						filename_holder+="_read.cgi";						if(ifstream(filename_holder.c_str())){							cout << GetCfg("read", filename_holder, SystemVar_String, SystemVar_Count);						}						else{							cout << 0;						}					}					else if (Db_Holder == "Replycount"){						filename_holder="system/db/";						filename_holder+=GetPar("db", SystemVarPar_String, SystemVarPar_Count);						filename_holder+="/data/";						filename_holder+=ToString(dbf-1);						filename_holder+="_replyread.cgi";						if(ifstream(filename_holder.c_str())){							cout << GetCfg("replyread", filename_holder, SystemVar_String, SystemVar_Count);						}						else{							cout << 0;						}					}					else if (Db_Holder == "downcount"){						filename_holder="system/db/";						filename_holder+=GetPar("db", SystemVarPar_String, SystemVarPar_Count);						filename_holder+="/data/";						filename_holder+=ToString(dbf-1);						filename_holder+="_down.cgi";						if(ifstream(filename_holder.c_str())){							cout << GetCfg("down", filename_holder, SystemVar_String, SystemVar_Count);						}						else{							cout << 0;						}					}					else if (Db_Holder == "file1.preview"){						filename_holder="system/db/";						filename_holder+=GetPar("db", SystemVarPar_String, SystemVarPar_Count);						filename_holder+="/data/";						filename_holder+=ToString(dbf-1);						filename_holder+=".cgi";						if ( InputParser_file("file1.preview", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count) == "" ){							cout << InputParser_file("file1", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count);						}						else{							cout << InputParser_file("file1.preview", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count);						}					}					else if (Db_Holder == "file2.preview"){						filename_holder="system/db/";						filename_holder+=GetPar("db", SystemVarPar_String, SystemVarPar_Count);						filename_holder+="/data/";						filename_holder+=ToString(dbf-1);						filename_holder+=".cgi";						if ( InputParser_file("file2.preview", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count) == "" ){							cout << InputParser_file("file2", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count);						}						else{							cout << InputParser_file("file2.preview", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count);						}					}					else if (Db_Holder == "file3.preview"){						filename_holder="system/db/";						filename_holder+=GetPar("db", SystemVarPar_String, SystemVarPar_Count);						filename_holder+="/data/";						filename_holder+=ToString(dbf-1);						filename_holder+=".cgi";						if ( InputParser_file("file3.preview", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count) == "" ){							cout << InputParser_file("file3", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count);						}						else{							cout << InputParser_file("file3.preview", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count);						}					}					else if (Db_Holder == "file4.preview"){						filename_holder="system/db/";						filename_holder+=GetPar("db", SystemVarPar_String, SystemVarPar_Count);						filename_holder+="/data/";						filename_holder+=ToString(dbf-1);						filename_holder+=".cgi";						if ( InputParser_file("file4.preview", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count) == "" ){							cout << InputParser_file("file4", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count);						}						else{							cout << InputParser_file("file4.preview", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count);						}					}					else if (Db_Holder == "file5.preview"){						filename_holder="system/db/";						filename_holder+=GetPar("db", SystemVarPar_String, SystemVarPar_Count);						filename_holder+="/data/";						filename_holder+=ToString(dbf-1);						filename_holder+=".cgi";						if ( InputParser_file("file5.preview", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count) == "" ){							cout << InputParser_file("file5", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count);						}						else{							cout << InputParser_file("file5.preview", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count);						}					}					else if (Db_Holder == "file6.preview"){						filename_holder="system/db/";						filename_holder+=GetPar("db", SystemVarPar_String, SystemVarPar_Count);						filename_holder+="/data/";						filename_holder+=ToString(dbf-1);						filename_holder+=".cgi";						if ( InputParser_file("file6.preview", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count) == "" ){							cout << InputParser_file("file6", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count);						}						else{							cout << InputParser_file("file6.preview", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count);						}					}					else if (Db_Holder == "file7.preview"){						filename_holder="system/db/";						filename_holder+=GetPar("db", SystemVarPar_String, SystemVarPar_Count);						filename_holder+="/data/";						filename_holder+=ToString(dbf-1);						filename_holder+=".cgi";						if ( InputParser_file("file7.preview", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count) == "" ){							cout << InputParser_file("file7", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count);						}						else{							cout << InputParser_file("file7.preview", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count);						}					}					else if (Db_Holder == "file8.preview"){						filename_holder="system/db/";						filename_holder+=GetPar("db", SystemVarPar_String, SystemVarPar_Count);						filename_holder+="/data/";						filename_holder+=ToString(dbf-1);						filename_holder+=".cgi";						if ( InputParser_file("file8.preview", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count) == "" ){							cout << InputParser_file("file8", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count);						}						else{							cout << InputParser_file("file8.preview", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count);						}					}					else if (Db_Holder == "file9.preview"){						filename_holder="system/db/";						filename_holder+=GetPar("db", SystemVarPar_String, SystemVarPar_Count);						filename_holder+="/data/";						filename_holder+=ToString(dbf-1);						filename_holder+=".cgi";						if ( InputParser_file("file9.preview", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count) == "" ){							cout << InputParser_file("file9", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count);						}						else{							cout << InputParser_file("file9.preview", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count);						}					}					else if (Db_Holder == "file10.preview"){						filename_holder="system/db/";						filename_holder+=GetPar("db", SystemVarPar_String, SystemVarPar_Count);						filename_holder+="/data/";						filename_holder+=ToString(dbf-1);						filename_holder+=".cgi";						if ( InputParser_file("file10.preview", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count) == "" ){							cout << InputParser_file("file10", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count);						}						else{							cout << InputParser_file("file10.preview", filename_holder, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count);						}					}					else{						cout << InputParser(Db_Holder, dbf-1, SystemVar_String, SystemVar_Count, SystemVarPar_String, SystemVarPar_Count);					}					//if the value == no					//if the value == whatever.				}			}			else {				cout << "($db" << ch;			}		}		else {			cout << "($d" << ch;		}		Db_Holder="";		System_Count=0;	}


this is a piece of my source code.
Shouldn't be that long when efficiently programmed.
That's why I breifly skimmed through 3 c++ books, and realized how dumb i was being.
i really need to change my whole source code.
it's so bad, it's like a horror movie.
if i want to change one thing, look at how many things i need to change.
I wanted to die when I needed to change something.
So please, have sympathy and help me.
just look at the above source code.
imagine you have something like that.
Advertisement
Quote:Original post by Tradone
I don't think I can ever be able to do that.


If you can write a 10,000 LOC procedural program, and have it all work, your mind, once it understands OOP, will easily be able to write that code in about three minutes or less. OOP makes it so much easier in the end that you will probably never look back. Therefore, if you pursue OOP, I almost guarantee you that you will be able to write code like that quickly. It will take some time (about 1 to 2 years, probably), but you will find yourself doing it.

Enjoy your learning!
Quote:Original post by Anonymous Poster
Quote:Original post by Tradone
I don't think I can ever be able to do that.


If you can write a 10,000 LOC procedural program, and have it all work, your mind, once it understands OOP, will easily be able to write that code in about three minutes or less. OOP makes it so much easier in the end that you will probably never look back. Therefore, if you pursue OOP, I almost guarantee you that you will be able to write code like that quickly. It will take some time (about 1 to 2 years, probably), but you will find yourself doing it.

Enjoy your learning!


the only reason it's 10,000 lines is because of the above post.
look how repetitive it is.
if all that was gone, probably 2000 or less.
Quote:Original post by Tradone
the only reason it's 10,000 lines is because of the above post.
look how repetitive it is.
if all that was gone, probably 2000 or less.


It sounds like you have your work cut out for you! Get 'a crackin!

Many people here have seen code that bad using procedural programming. I know I had something that was similar!

So start by learning the basics to OOP, using code like I posted, or a good book. Read the sections on 'virtual' functions very carefully, as 'virtual' is the cornerstone of what you are trying to learn at this point. (Many books don't go over it well enough.) (And no, I can't recommend a good book. It took me way to long to master 'virtual', because the books I had did not treat it in a way that made it obvious to me.)

Then design a simple OOP framework for a program that does what you want it to do. (Do NOT use any existing code from your project at this stage. You may not use any of your procedural code in the end - I don't know.) Then slowly implement one item, play with it, revise the framework from what you have learned, then add another item and repeat the process.

Ask any questions along the way, and people here will probably answer.

Have fun!

This topic is closed to new replies.

Advertisement