Sign in to follow this  
Tradone

object oriented design using procedural programming?

Recommended Posts

Thank you. I think I have fully grasped the concepts of object oriented programming through this forum. I like to give a thank you to all the moderators, and members who have answsered my questions with such sincerity. Here's my story. I have developed a code using the procedural style through out my first 8 months of programming history. The code totaled out to be somewhere around 8000 lines, in one cpp file. As I carefully analyzed my code today, I have noticed that I was grouping my code by similar types. Now that I understand the concepts of oop, I have noticed that my procedural style was somewhat evolving the way to oop. But through this experience with procedural style, I have noticed that one can reach somewhat an object oriented approach using the procedural programming. ex)
main(){
input[256][2];
type=get_type();

if ( type == 1 || type == 2 || type == 3 ){
  //do for all 3 types
  code;
  code;

  //do for only type 1
  if( type == 1 ){
    code;
  }

  //do for only type 2&3
  if( type == 2 || type == 3 ){
    code;
  }

  //do for only type 1&3
  if( type == 1 || type == 3 ){
    code;
  }

  //if type is 1, also perform what is inside type 4
  if( type == 1 ){
    type = 4;
  }
}

if ( type == 4 || type == 5 || type == 6 ){
  //do for all 3 types

  //do for only type 4

  //do for only type 4&5

  //do for only type 4&6
}

and the list goes on.

}



Is this somewhat an object oriented design? well, I am completely switching all my functions to classes, but want to know the limitations of my previous styles.

Share this post


Link to post
Share on other sites
that's not opp?
not even close?
grouping into similar types?

hm... i guess i am still not grasping the concepts of opp...
I am redesigning my thing...

I thought there was some weak concepts inheritence ( the type structure has some sort of inheritence )
heirarchy would be like
class A
|
|-type 1
|-type 2
|-type 3 ( can later type 3 wil be transfered to type 4 thus isn't this kinda multiple inheritence?

class B
|
|-type 4
|-type 5
|-type 6

perhaps not..




Share this post


Link to post
Share on other sites
okay, maybe my program can not be written in object oriented?

come to think of it, my program is based on a dynamic input of a specific action such as delete, modify, or add.

when added, it saved into file.
when modified, it modifies.
when deleted, it deletes.

what would be the objects in this scenario?

Share this post


Link to post
Share on other sites
class A was just an example.

complicated thing explained simple...
my program receives an input from a user to either delete, modify, or add something to a database.
and whatever information that is stored in the database, it is saved in file.
later that file can be deleted. kind of like a word processor in a way.

thus it is based on actions by the user.
and object oriented is like the opposite of action orientated...

well there's more to this.. such as list and search.
so i grouped them into 3 categories

1) list, search.
what is in common: they both lists, except for search certain things are filtered.

2) write, modify
they both need to use i/o. the only difference is that modify will override the existing file, so in a modify, the file name must be specified.

3) delete
just delete the file.

now it is a bit more complex than this, but that's about what there is..
for example, the list is dynamically created by a certain language that i made, and depending on the source of that new language, it must do certain things, thus must be tokenized and parsed.
Now this new language has options such as simple adding, subtracting, concatenating strings, number/string comparisons, if clauses, loops, and some other functions.

Now I've already made this to fully function with almost minimal errors, for I have been testing and debugging my procedural source code for 8 months now. But the source code was extremely repetitive and disorganized. While I was looking into object orientated programming I thought this would solve the solution of "path finding" kind of thing, because my actions are based on path finding, and fitting into certain types. such as the list, write, delete types.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zahlman
Compare and constrast. Oh, and also read. :)


Zahlman thanks for the link.
the reason I'm changing all my code is because of the third link.
Hopefully I can fix that, but this is going to be my frist object oriented project, so I'm kinda nervous.

and I don't think I can quite understand the internal / external polymorphisms just yet because I don't understand internal polymorphisms completely for I have never coded in oop style.

but back to the original question, my code above does show some signs of oop. no? want to know if I am understanding oop correctly...

Share this post


Link to post
Share on other sites
Quote:
Original post by cherryhouse
You're above code shows no signs of OOP. but thats just my thoughts..


yea! no problemo!
but now I'm almost done brainstorming for my new implementation.
i'll post it up soon.

Share this post


Link to post
Share on other sites
The classic OOP-in-a-procedural-language example in plain C is the humble FILE *. A FILE * is an object and there are functions to create a FILE * (fopen), destroy a FILE * (fclose) and perform operations on a FILE * (fread, fseek, etc.).

Σnigma

Share this post


Link to post
Share on other sites
okay here's my new class design heirarchy.


root
|
|-----------------------------------------
| | |
write_type delete_type list_type
| | |
write i/o delete file |
and then and then |
goto list_type goto list_type |
|
-----------------------------------
| |
from write/delete or a none action search action
| |
generate_output filter
| |
parse my language code goto generate_output
|
group by similar functions
such as GROUPA=add, subtract
GROUPB=switch, if
GROUPC=for, while, while-do loops


is this object oriented programming?
even though it's not, I know this type of heirarchy would eliminate much of the repetitive codes.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
It sounds like logical objects for you are

1) Your list.

2) Actions, probably derived from a base 'Action'

3) A list of Actions you have performed on the 'List'

Then, instead of doing 'if type == 1 || type == 2...', you would simply do something like "action->execute();", where 'action' is derived from your base Action class in any manner you need.

Share this post


Link to post
Share on other sites
well, I'm very unsure,
I'm getting my oop cherry popped today :D
first time writing oop code.
does this seem reasonable?
and if it can be done better, please advice me!!

Thanks anonymous poster!
but I have no idea what you mean by :
Quote:
where 'action' is derived from your base Action class in any manner you need.

I only read about oop for 3 days, I don't know much.

but looks like i'm sort of on the right track, i'll keep rereading your post and try to understand what you mean there.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
This is only a bare bones outline:

#include <vector>
#include <string>

class List {
private:
std::vector<std::string> thingsC;
public:
void add(const std::string & str) {
thingsC.push_back(str);
}

void remove(unsigned int index) {
if (index < thingsC.size()) {
std::vector<std::string>::iterator it = thingsC.begin()+index;
thingsC.erase(it);
}
}

void change(int index, std::string newString) {
if (index < thingsC.size()) {
std::vector<std::string>::iterator it = thingsC.begin()+index;
(*it) = newString;
}
}
};

List * globalList;

class Action {
public:
virtual void execute() { }
};

class AddAction : public Action {
private:
std::string strC;
public:
AddAction(const std::string & str) : strC(str) { }
virtual void execute() {
globalList->add(strC);
}
};

int main(int argc, char* argv[]) {
List list;
globalList = &list;

//The following is the action:
AddAction actionA("My First String");
//But the 'list' won't contain the string until you do the following:
actionA.execute();

return 0;
}


Hope that helps. (The 'remove' and 'change' functions are kinda pointless as this stands...)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
PS - A better name for 'AddAction' is 'AddToList'

(ie class AddToList : public Action { ...)

Avoiding redundancy in your names can sometimes keep your brain from developing a thick glaze...

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
This is only a bare bones outline:

*** Source Snippet Removed ***

Hope that helps. (The 'remove' and 'change' functions are kinda pointless as this stands...)


That was really kind and helpful of you.
Thank you very much, you really didn't have to write all that down.
and just out of curiosity, how long did it take you to write this code?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Tradone
...and just out of curiosity, how long did it take you to write this code?


About three minutes? I wasn't really paying attention to the time, but as you become more familiar with OOP, you will find that something like that doesn't take much time at all.

Share this post


Link to post
Share on other sites
okay, the syntax is miserable..
but this is what I had in mind..
I can edit the syntax later. sorry i'm still learning!
and also i'm not good at using pointers.


main(){
const get parameters
cosnt get password

root new_object( env_var, cookies );

}

shenu::root( ){
public root::generate_error;
const skin=get.skin;

if ( no db )
generate_error
else ( db )
what are the actions?
if ( action == none || action == search || action == input_form || action == list || action == cont_form )
initialize.list()
else if ( action == write, modify, reply modify reply )
initialize.write()
else if ( action = delete, delete modify )
initialize.delete()

}

shenu::initialize_list(){
get list_of_cfg
get list_of_path
const skin_file;

there are only 3 types
cont, input, list
generate_html( skin_file )
}

shenu::initialize_delete(){
delete
initialize_list();
}

shenu::initialize_write(){
file i/o
serialize
initialize_list();
}

shenu::generate_html_except_body( filename ){
if( require_cookies_authentication == 1){
start parsing.
}
else{
generate_error ( permission_denied );
}
}

shenu::generate_error( type ){
switch depending on type.
}





you don't have to edit this for me.
or correct the syntax.
I need to learn the syntax as I fix up this big mess!!
but does this structure seem alright?

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Quote:
Original post by Tradone
...and just out of curiosity, how long did it take you to write this code?


About three minutes? I wasn't really paying attention to the time, but as you become more familiar with OOP, you will find that something like that doesn't take much time at all.


I don't think I can ever be able to do that.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest 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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this