The tag has no usage guidance.

learn more… | top users | synonyms

1
vote
1answer
80 views

Pattern for passing in a field as a parameter

I'm writing a Rails app which uses ActiveRecord ORM and a Postgres DB. I've got two attributes which are similar but are separate fields in the database. The assignment and saving of these is kinda ...
4
votes
1answer
230 views

How to make sure people call methods in the right order?

Situation I'm designing a database abstraction layer for sql (mysql, sqlite) and mongoDb. The goal is to give the user/developer a library which is able to create queries for different databases. ...
3
votes
4answers
374 views

Where to store average value in db?

I have a restaurant review app which stores reviews in a db, MySql. There's 2 tables. 1 for Restaurant. Another for reviews. To increase the performance, I am considering to store the avg review of ...
6
votes
3answers
250 views

Is there a Haskell idiom for trying several functions and stop as soon as one succeeds?

In Haskell, I can use the type a -> Maybe b to model a function that either returns a value of type b, or returns nothing (it fails). If I have types a1, ..., a(n+1) and functions f1, ..., fn, ...
1
vote
2answers
254 views

Is there a name for this pattern?

A while loop can be written as follows in C# (and many other languages): int someValue; int someTerminatingValue; while ((someValue = GetSomeValue()) != someTerminatingValue) { // Do something ...
1
vote
2answers
118 views

Joshua Bloch Enum Singleton and Third Party APIs

In the book Effective Java he give the best Singleton pattern implementation in his, that is implement by a Enum. I have doubt to how to implement this pattern with a third party API. I'm using an ...
2
votes
2answers
139 views

Does it break SRP to have concerns of data handling and object mapping inside a single class, as part of the DataMapper pattern?

Summary I want to look into separating the concern of "creating a populated object from database", to use inside my application. DataMapper pattern seems to be doing just that for me. DataMapper ...
9
votes
4answers
382 views

Reducing boilerplate in class that implements interfaces through composition

I have a class: A that is a composite of a number of smaller classes, B, Cand D. B, C, and D implement interfaces IB, IC, and ID respectively. Since A supports all the functionality of B, C and D, A ...
1
vote
1answer
45 views

Name pattern for quickly find descendents with SQL (PATH column with [TopId]…[DirectAncestorId].[OwnId]) NO nested sets

I read a long time ago about a pattern/technique for easily querying for all "descendants" of a record (no need to use CONNECT TO, which is not standard and not available with JPA). I remembered the ...
3
votes
4answers
234 views

Function wrappers with no args: bad practice?

My colleague likes to write classes containing methods looking like this: public function doTaskA() { return $this->doTask('A'); } public function doTaskB() { return $this->doTask('B'); ...
1
vote
2answers
281 views

Are the Repository Pattern and Active Record pattern compatible?

Currently I am developing a webapp where I have defined models implementing the Active Record pattern. Each model also is defined by an interface that specifies the Entity properties and makes it easy ...
1
vote
2answers
141 views

Is it a good idea to install more libraries than you need? [closed]

I decided to try Anaconda, it seems that too many large companies are using it. I was amazed by the number of libraries included by default installing: python-2.7.9-2 ... installing: ...
0
votes
1answer
296 views

JSP in Javascript file or multiple AJAX requests

I've been thinking about how I want to load my data for some checkboxes in an AngularJS app. I'm generating multiple checkboxes based on 2 JSON objects that are currenty hard-coded in the a Javascript ...
2
votes
2answers
113 views

Is it OK for an MVC view to request data from other sources than just the model?

I'm working in ASP.NET MVC, but this question is pretty much applicable to any MVC framework (and maybe even others). In a typical MVC application a request arrives at the controller, which then ...
2
votes
1answer
45 views

Queue rescheduling naming convention (Command pattern)

For my project I'm creating a queueing mechanism based on the Command Pattern, which can execute one of a number of jobs. Jobs can add other jobs to the queue or can be added by a human. Most of the ...
7
votes
1answer
254 views

Should I build undo stack in model or its wrapper?

I am building an application (Python/PyQt). The first-order item will be a tree view/model with many helper functions to add new items, move them around in the tree, etc.. Then I will have a main ...
5
votes
3answers
401 views

How to solve the Lava flow anti-pattern?

In this blog post, the author describes an anti-pattern called the "lava flow" In a nutshell, the lava flow anti-pattern happens when many programmers lead the development of an application, each of ...
5
votes
1answer
171 views

Is it poor decision making that using promises for GUI inputs?

So as you know the context: DOM with JavaScript, even though I think it is mostly a language agnostic issue (I know I put both language-agnostic and JavaScript tags, but it's only to let you see ...
0
votes
4answers
291 views

2 methods that are 75% the same? [closed]

I have code that violates the DRY principle and I would like to consolidate 2 methods as much as I can, but the problem I am facing is that they have some differences, I would say they are about 75% ...
0
votes
1answer
137 views

Why use the Singleton pattern over class functions and fields? [duplicate]

I'm going to start by saying that I understand that programming in mostly class functions and variables can be harmful to object-orientation, and that most of the time an instance is preferred. I'll ...
0
votes
3answers
221 views

Check a boolean before setting it in a loop, or just set it

I have a rather tight loop with the following check to see if balance had ever been positive: balance_null = True while (crazy_loop()): ... if 0.0 < balance: balance_null = False ...
2
votes
3answers
721 views

How to implement the repository pattern for an app that will change its database from sql to nosql on in couple of years?

I have been reading a lot about repository implementation. I am confused about which way to implement it for a project I am sure would change its data layer methods because of db migration from MS Sql ...
3
votes
3answers
965 views

Why is it a good practice to keep Javascript code in separate files?

In web development we are commonly used to keep Javascript code in separate files, but sometimes we need this Javascript code to manipulate server side data locally. For example, making an Ajax Call ...
4
votes
2answers
102 views

Is it a good idea to have a database row that represents an unknown value within a system [closed]

We have two systems, System A imports a list of sports events from system B, it only wants to import the events we will be providing live data for, the filter used to hide events that we are not ...
2
votes
1answer
83 views

Combining Patterns: Fluent Builder and Null Object Pattern

I am currently wrestling around with some GUI code where I have a table whose rows correspond to some object, let's say a Person object. When the table initializes, it fills the table with the Person ...
2
votes
2answers
380 views

TDD with repository pattern

In my new project, I decided to try with TDD. And in very beginning I encountered a problem. First thing that I want to do in my application is to give ability to read data from data source. For this ...
0
votes
1answer
620 views

Design Pattern for Cron/Schedule in MongoDB

I am looking for a good pattern to handle cron-type data in a MongoDB collection (or collections). I have been peeking at the O'Reilly book MongoDB Applied Design Patterns and poking around the ...
2
votes
1answer
153 views

In a Table Data Gateway, where do I put queries that use joins

The book Pattern of Enterprise Application Architecture has the following description over the Table Data Gateway pattern: “A Table Data Gateway holds all the SQL for accessing a single table or ...
0
votes
1answer
82 views

Does a create() method exist as part of a pattern? [closed]

Is there something special(i.e. a design pattern being related) to a method named create()? Background The case is, I often make some instances of objects (of the same class/prototype). These ...
4
votes
3answers
774 views

DDD, modularizing the application and domain layers without breaking the DIP

Quoting DDD theory: The application layer is thin in terms of domain logic - it merely coordinates the domain layer objects to perform the actual work. When it comes to modularization, and ...
0
votes
1answer
72 views

Control (avoid) changing fields with side-effects

I have been thinking about a design problem and possible solutions in my own. I am pretty sure I am not the first one to have noticed it, but I cannot google for it since I do not know the standard ...
1
vote
0answers
88 views

Decreasing MongoDB Load

I have some stream workers. They are listening to twitter stream and save into mongodb. I need to aggregate saved tweets for intermediate analyze result. I have analyzer workers. They are periodically ...
1
vote
1answer
109 views

Obsessed with filling hashmaps instead of using else if cascades or switch statements [duplicate]

Whenever I feel like choosing from a list of implementations I always prefer to fill a map first and then call whatever I need based on a parameter, instead of using switch or else if statements. ...
12
votes
5answers
4k views

What is the best way to initialize a child's reference to its parent?

I'm developing an object model that has lots of different parent/child classes. Each child object has a reference to its parent object. I can think of (and have tried) several ways to initialize the ...
2
votes
0answers
155 views

Callback pattern handling exceptions - Best practices in .NET 3.5

I am looking to implement the callback pattern with error handling such that error is caught and pass to the callback code with the response. Since I am using .NET 3.5, I cant use Task (TAP) pattern ...
0
votes
1answer
84 views

How to save entities relations using unit of work pattern

I use Unit of work pattern to commit all new, dirty, deleted entities to the DB (using a db_mapper). Example of entities are: Student and Class So Student->registerDirty() will add this entity to ...
-1
votes
1answer
115 views

Best solution for future maintenance of a website with hardcoded ids, custom CMS using bad database design [duplicate]

Recently I was put into a position of a tech-lead on a very interesting project that I have been partially working for two years. This project carries a lot of legacy stuff with it even though we try ...
4
votes
2answers
104 views

Factors for choosing between using a wrapper library or issuing command line process from my web application

I have a Java web application that makes use of certain libraries for example: Ghost Script for converting PDFs to TIFFs and Tesseract for OCR. There are java wrappers for both of these: Ghost4J and ...
0
votes
2answers
122 views

When should you create/destroy underlying object in a class that wraps it

(note: I used Java to make it easer to explain my question, but the actual language is irrelevant for this dilemma) TL; DR: I have a wrapper around some underlying class. At which point should I ...
0
votes
1answer
84 views

Strategy vs Publiser-subscriber pattern

Let's say I have a channel endpoint where I receive messages. Because I want to process messages in a different way depending on its Header property, rather than create a massive switch I create ...
1
vote
3answers
173 views

How to signal that a method chain should not continue?

When doing method chaining, you have methods that return the object allowing you to continue the chain. However, you need to get values out of the object somehow. Usually I've added a method that ...
7
votes
2answers
743 views

Which is a better pattern (coding style) for validating arguments - hurdle (barrier) or fence? [duplicate]

I don't know if there are any accepted names for these patterns (or anti-patterns), but I like to call them what I call them here. Actually, that would be Question 1: What are accepted names for these ...
0
votes
1answer
96 views

SQL Dev and Prod Environments

I have been tasked with setting up a SQL Development environment, and i was wondering if anyone has any advice on getting this right? So far, I have restored the prod DB onto another box, and ...
-1
votes
2answers
153 views

How do developers deal with “where to start” problem in a context of overwhelming difficulties caused by too much heterogeneous information? [closed]

A friend of mine, a beginner PHP programmer, needs to link the product his company develops with a third-party product (a set of web services). He received the "relevant" documentation (a few hundred ...
2
votes
1answer
587 views

Best practice for unused inherited virtual functions (implementing superclass methods)

Let's assume I have a hierarchy of several classes each derived from each other using virtual functions. The base class acts as an interface and defines functions, which may not be required by all of ...
20
votes
6answers
1k views

Should I place functions that are only used in one other function, within that function?

Specifically, I'm writing in JavaScript. Let's say my primary function is Function A. If Function A makes several calls to Function B, but Function B is not used anywhere else, then should I just ...
2
votes
5answers
569 views

I have generally read that having many (>4) arguments to a function/constructor is a bad practice. Is this still considered a bad practice? [closed]

I have generally read that having many (>4) arguments to a function/constructor is a bad practice. Is this still considered a bad practice? And is there a non-obvious reason? In something like a ...
5
votes
1answer
534 views

Which patterns/architecture to apply for “Import Data, Process Data, Export Result”

I was wondering which architecture/patterns to choose for the following problem divided into three steps: Import TestScript Description from File (e.g. .xls, .txt) Process Described TestScript ...
39
votes
11answers
5k views

Are error variables an anti-pattern or good design?

In order to handle several possible errors that shouldn't halt execution, I have an error variable that clients can check and use to throw exceptions. Is this an Anti-Pattern? Is there a better way to ...
0
votes
0answers
133 views

How to cleanly write a multi step process with user feedback and multiple callback

When you have some process that has several steps and you multiple entry points the code gets ugly pretty fast. I encountered this with Facebook integration in my mobile app: User wants to share ...