![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2004
Posts: 24
Rep Power: 0
![]() |
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? |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
|
(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 ![]() |
|
|
|
|
|
#3 |
|
Expert Programmer
|
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 |
|
|
|
|
|
#4 | |
|
Newbie
Join Date: Nov 2004
Posts: 24
Rep Power: 0
![]() |
Quote:
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? |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|