1
vote
2answers
192 views

How do you guard against hidden overflows

consider the following: (i+j)/2 i and j are both 32 bit integers and the result should also be. But in the little equation, there's a hidden overflow, i+j could become larger then a 32 bit integer ...
3
votes
3answers
464 views

Functional programming strategies in imperative languages

I've been convinced for awhile now that some strategies in functional programming are better suited to a number of computations (i.e immutability of data structures). However, due to the popularity of ...
1
vote
2answers
94 views

Logging events for reporting purposes

Are there any design patterns or best practices around logging events for use in reporting and BI systems. For example in a system which manages orders from a website, it would be beneficial if a ...
3
votes
4answers
266 views

How to handle affinities?

Assume we have an abstract class having several concrete classes which interfaces publish an information under several equivalent forms, with the difference that each class has a preferred form which ...
5
votes
1answer
369 views

How can I implement a modular “save” function for a game?

I have to implement a method to save my game in such a way that I can change the storage medium with the change of only a single variable. Ideally I'd use an interface to designate the required ...
8
votes
4answers
797 views

How do we keep dependent data structures up to date?

Suppose you have a parse tree, an abstract syntax tree, and a control flow graph, each one logically derived from the one before. In principle it is easy to construct each graph given the parse tree, ...
3
votes
2answers
557 views

Confusion with Factory pattern regarding Liskov's Substitution Principle, code maintainability and Unit Testing?

I have a confusion regarding Factory Pattern there are basically two ways You can implement that. Approach 1: public interface IProductFactory { IProduct GetProductA(); IProduct ...
2
votes
1answer
166 views

Strategy for normalising and interpreting location data

I'm a bit stuck with a problem involving the normalisation of location input data from the user (which comes from a third party). Aim To logically breakdown and interpret the user location input ...
1
vote
2answers
102 views

Creating documents from snippets [closed]

From time to time I create whole documents (e.g. XML or proprietary) programmatically. If it easy enough, I just write something like stringbuilder.append("<blah>"); ...
7
votes
2answers
429 views

When is it inappropriate to make objects immutable?

I have a class which represents an entity object in our system (for sake of argument, a Customer object) public class Customer() { private int id; private String name; ... // 30+ fields ...
22
votes
7answers
1k views

Pattern for a class that does only one thing

Let's say I have a procedure that does stuff: void doStuff(initalParams) { ... } Now I discover that "doing stuff" is quite a compex operation. The procedure becomes large, I split it up into ...
0
votes
2answers
174 views

When modeling a virtual circuit board, what is the best design pattern to check for cycles?

To make it simple assume you have only AND and OR gates. Each has two inputs and one output. The output of two inputs can be used as an input for the next gate For example: A AND B -> E C AND D -> F ...
5
votes
5answers
484 views

When decomposing a large function, how can I avoid the complexity from the extra subfunctions?

Say I have a large function like the following: function do_lots_of_stuff(){ { //subpart 1 ... } ... { //subpart N ... } } a common pattern is to decompose it ...
3
votes
3answers
228 views

Patterns for Maintaining Model State in Real Time

While some platform in some languages already address this issue, I would like to keep this semi-language agnostic and to focus on patterns associated with this issue. I have a data model that ...
11
votes
8answers
526 views

What is a good code practice of when to make a function/method for small repetitive code segments?

Many times throughout writing larger programs I have questioned after how many copy and pastes does it make sense to put the code into a function or method and what is a good rule of thumb? I have ...
3
votes
4answers
893 views

Can the strategy pattern be overused?

Example: A file, representing a serialized version of an object, needs to be read and deserialized. It would simple to implement this if we only cared about a single serialization format, but many ...
17
votes
8answers
693 views

How do “You Ain't Gonna Need it” and “Now is better than never” play together?

I often find myself embracing "now is better than never" when I'm advancing the DRYness of a design. Typically, I find that I need to cultivate an understanding of the One Authoritative Location for ...