473,434 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,434 software developers and data experts.

duplicate C++ code

I need to clean up some sloppy programming in a project I am working
on. The previous coder did not believe in functions, they just
duplicated the same code a lot. Is there some utility that can give me
some type of listing of duplicated sections of code so I can make them
into functions?
I expect this could be a utility that could be easy to write, but take
a long time to run depending on the length of duplication it was
looking for.

Feb 13 '06 #1
8 2178
Greg Coles0n wrote:
I need to clean up some sloppy programming in a project I am working
on. The previous coder did not believe in functions, they just
duplicated the same code a lot. Is there some utility that can give me
some type of listing of duplicated sections of code so I can make them
into functions?
I expect this could be a utility that could be easy to write, but take
a long time to run depending on the length of duplication it was
looking for.


Regular expression search: (.+).*\1

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Feb 13 '06 #2
Hi

Pete Becker wrote:
I expect this could be a utility that could be easy to write, but take
a long time to run depending on the length of duplication it was
looking for.


Regular expression search: (.+).*\1


Doesn't look like a regular expression to me.

Markus
Feb 14 '06 #3
> The previous coder did not believe in functions, they just
duplicated the same code a lot.

Tell them I said they're retarded.

-Tomás
Feb 14 '06 #4
Greg Coles0n wrote:
I need to clean up some sloppy programming in a project I am working
on. The previous coder did not believe in functions, they just
duplicated the same code a lot. Is there some utility that can give me
some type of listing of duplicated sections of code so I can make them
into functions?
I expect this could be a utility that could be easy to write, but take
a long time to run depending on the length of duplication it was
looking for.


Finding copied and pasted code:
http://pmd.sourceforge.net/cpd.html

Shareware:
http://www.topshareware.com/AntiCutA...load-10608.htm

I apologize for my e-comrades' answers (except Tomás's).

As you go, add unit tests to your code. These are amazingly important, and I
apologize again for we never told you about them.

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Feb 14 '06 #5
I found what I was looking for and it works great

http://pmd.sourceforge.net/cpd.html

Feb 14 '06 #6
Greg Coles0n wrote:
I found what I was looking for and it works great

http://pmd.sourceforge.net/cpd.html


Next tip:

Given two functions that are similar, don't just cram them back together.
Use "Extract Method Refactor" on the smallest set of lines inside them that
are the same. These will become the new abstraction. Always refactor in
order from the low-hanging fruit.

And read /Working Effectively with Legacy Code/ by Mike Feathers.

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Feb 14 '06 #7
This is a site on refactoring that might be helpful.

http://www.refactoring.com/

Feb 15 '06 #8

"Greg Coles0n" <gr**************@yahoo.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
I need to clean up some sloppy programming in a project I am working
on. The previous coder did not believe in functions, they just
duplicated the same code a lot. Is there some utility that can give me
some type of listing of duplicated sections of code so I can make them
into functions?
I expect this could be a utility that could be easy to write, but take
a long time to run depending on the length of duplication it was
looking for.


Easy to write? No. A good one parses the source code to
determine reasonable boundaries of entities to match,
and will find both exact and near misses (clones that
have been edited).

See http://www.semanticdesigns.com/Produ...one/index.html
--
Ira Baxter, CTO
www.semanticdesigns.com
Feb 16 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mohammed Mazid | last post by:
Hi, Basically I have a problem with registering to my quiz system. I had borrowed some code from an existing program but I just do not know why it doesn't work. If (txtUsername = "" Or...
7
by: Lowell Kirsh | last post by:
I have a script which I use to find all duplicates of files within a given directory and all its subdirectories. It seems like it's longer than it needs to be but I can't figure out how to shorten...
9
by: vbportal | last post by:
Hi, I would like to add BitArrays to an ArrayList and then remove any duplicates - can someone please help me forward. I seem to have (at leaset ;-) )2 problems/lack of understanding (see test...
7
by: ucfcpegirl06 | last post by:
Hello, I have a dilemma. I am trying to flag duplicate messages received off of a com port. I have a software tool that is supposed to detect dup messages and flag and write the text "DUP" on...
8
by: Iona | last post by:
Hi Allan, I'm using a nifty piece of code you put on here some time back to do a duplicate entry check as below. I'm using to check for duplicate names. However I am getting an error message on...
5
by: baur79 | last post by:
Hi guys i try to run this code in loop and to pass even the entry is duplicated def email_insert_in_db(email): sql="INSERT INTO emails (email) values ('%s') "%(email)...
2
by: Harry Haller | last post by:
I want to duplicate the form data, edit it to remove some items (such as __EVENTTARGET, __EVENTVALIDATION, etc) and save it to a log. How can I make a duplicate (editable) copy of the Form...
1
by: oaklander | last post by:
I would like to make sure there are no duplicate data entries in my Oracle 9i table (called MainTable) which has an Id field that is the primary key, ValData with a varchar data type, Fid and Fid2...
2
by: raphael001 | last post by:
In my Visual Basic program I'm just trying to find duplicate values entered into an array from an inputbox, but i can't seem to get the coding right on the final part to check for duplicate values...
1
by: xraive | last post by:
I have a problem with this. Currently I am trying Allen's code and i am not successful. Current Design Table1 (Main Form) TravelID (PK) ApprovedBY EntreredBy BudgetCode ExpenseCode
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.