Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 9th, 2004, 3:24 AM   #1
phrosys
Newbie
 
Join Date: Nov 2004
Posts: 24
Rep Power: 0 phrosys is on a distinguished road
sup all

I was doing of coding an a series of applications and noticed that I was cutting and pasting functions which are identical!

is there a better way? how do you all organize re-usable code?
phrosys is offline   Reply With Quote
Old Dec 9th, 2004, 9:20 AM   #2
ZenMasterJG
Hobbyist Programmer
 
ZenMasterJG's Avatar
 
Join Date: Nov 2004
Location: Boston, MA
Posts: 148
Rep Power: 5 ZenMasterJG is on a distinguished road
Send a message via AIM to ZenMasterJG
(Assuming your talking about C++)
I'd probably write a utility class and put the functions in that, and then all you'd have to do is include them. There may be a better way, but I don't know what it could be

If your using C, you should still make library and implementation files, its good for you. Anytime you copy / paste code generally means your doing somthing naughty
ZenMasterJG is offline   Reply With Quote
Old Dec 9th, 2004, 1:00 PM   #3
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
If you actually want inline expanded code like that you could also consider using inline functions.

Typically if you are copying and pasting code a lot you are not being very efficient, you should be able to reuse most of this code, and hence one of the underlying purposes of the OO paradigm.

Sometimes though this is not always as easy to do as breaking the code into smaller pieces may not fit very well with the way you wish to classify your code... in short it can be a difficult call to make and requires a lot of though about the overall design of your application.

I do typically design code to reduce copy and paste code blocks as much as possible.
__________________
Clifford Matthew Roche <geek@cliffordroche.com>
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote
Old Dec 9th, 2004, 1:25 PM   #4
phrosys
Newbie
 
Join Date: Nov 2004
Posts: 24
Rep Power: 0 phrosys is on a distinguished road
Quote:
Originally posted by ZenMasterJG@Dec 9 2004, 02:20 PM
(Assuming your talking about C++)
I'd probably write a utility class and put the functions in that, and then all you'd have to do is include them. There may be a better way, but I don't know what it could be

If your using C, you should still make library and implementation files, its good for you. Anytime you copy / paste code generally means your doing somthing naughty
i am not sure what you mean utility class

i have put some code inside a cpp file, and prototypes in a .h file and included the .h file in my main.cpp well mainDlg.cpp...

how can I create my own library? same sort of thing?
phrosys is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:24 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC