473,383 Members | 2,005 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,383 software developers and data experts.

is there an existing pattern/algorithm to solve my oft occurring softw. requirement?

Hey,

I've been developing for about 4 years now, and in that time I must have written the same particular piece of code umpteen times to solve the same requirement that popped up in many different projects. I'm not looking for a debate on code reuse, but yeah, I should probably have done some of that! I think it's a requirement that many of you will also have knocked up as bread and butter coding on any normal dev day. Put simply, that requirement asks that the dev should take a collection of data (let's say it's a list of sales of comic books) and produce a table (can be HTML, doesn't matter) that contains those transactions with a subtotal summing all the transactions of each individual comic book, and a grand total at the very end. Wow, easy huh!?

Like This :

|| Book || Sale Date || Salesman || Cost($) ||
| Batman | 1-Jan | Jon | $5 |
| Batman | 8-Jan | Tom | $4 |
| *SubTotal *| N/A | N/A | $9 |
| Spiderman | 1-Jan | Jon | $6.5 |
| Spiderman | 8-Jan | Tom | $7 |
| *Sub Total *| N/A | N/A | $13.5 |
| *Grand Total*| N/A | N/A | $22.5 |


This code doesn't take long to write and anyone worth their salt should be able to knock it up pretty quickly by :
* grouping/sorting the data in the collection so all comic sales of a particular comic book are together
* iterating through the collection, keeping track of the running sub total and grand total, and simply recognising when to display the subtotal.

That's all people - no biggie right, but it bother me I end up spending 60 mins writing and debugging this code every few months. Surely this is something nearly everyone has had to build at some point?

On a sleepy day this is ever-so-slightly tricky code to write because it requires a surprisingly decent short term memory and there are a few places where you can trip up.

Accordingly, is there a pattern that exists so I dont ever need to write this code again? Is there a name for this particular algorithm? I'll try and make my own if there isn't.

Let me know what you think, any help is appreciated.
Cheers in advance,
Chris
Jul 19 '10 #1
0 1083

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Andy Read | last post by:
Hello all, I have the requirement to produce source code that produces an object hierarchy. Example: Root | Folder 1
16
by: cody | last post by:
I have to write an algorithm with must ensure that objects are put in buckets (which are always 4 in size). The objects have two properties: A and B. It is not allowed that in a bucket are objects...
7
by: Séb | last post by:
Hi everyone, I'm relatively new to python and I want to write a piece of code who do the following work for data mining purpose : 1) I have a list of connexion between some computers. This...
3
by: Brad Quinn | last post by:
Friday, no brain power remains... I have three assemblies; Client, Interface and Implementation. The Client uses Implementation through remoting. Client has a reference to Interface, but not...
4
by: Ben Fidge | last post by:
Hi What is the most efficient way to gather a list of files under a given folder recursively with the ability to specify exclusion file masks? For example, say I wanted to get a list of all...
113
by: Bonj | last post by:
I was in need of an encryption algorithm to the following requirements: 1) Must be capable of encrypting strings to a byte array, and decyrpting back again to the same string 2) Must have the same...
6
by: Daniel Santa Cruz | last post by:
Hello all, I've been trying to go over my OO Patterns book, and I decided to try to implement them in Python this time around. I figured this would help me learn the language better. Well,...
1
by: =?Utf-8?B?RXJpYw==?= | last post by:
I am using the factory method to solve a problem where a factory can produce product. I have a base factory class and a base product class. The problem that I am having is that for every product...
4
by: dustin | last post by:
I've been hacking away on this PEP for a while, and there has been some related discussion on python-dev that went into the PEP: ...
0
by: philT | last post by:
Hi, i have have to parse server messages on the client side. Now i need a perfect design pattern to solve it in a clean way. I have up to 100 messages, if i got a packet with a correct ID for a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.