instruction stringlengths 34 19.9k |
|---|
So let's say I have a 'Transformer' interface that can transform one file-type to another. Let's say I also wish to use streams to provide the data to the Transformer. Which is the approach that is considered 'best practise';
public InputStream transform(InputStream data);
OR
public void transform(InputStream original... |
From Martin Fowler's Mocks Aren't Stubs he states that Stubs provide canned answers to calls made during the test while Mocks objects pre-programmed with expectations which form a specification of the calls they are expected to receive.
In addition several sources state that Stubs shouldn't fail tests, but Mock could.
... |
I have several classes that all behave according to one interface. But in each class there are additional functions defined that give each class slightly different behavior. What I want to do is have th programmer using this API to simply create one instance based on some parameter which generates the correct class ... |
I am building a small website, in PHP and I am using MVC design pattern for the UI.
In the future I will need to add mobile support for my website. It will be in the sub domain "m" like everyone.
All the web is new for me, and I am new with MVC too. I did for each page View, Model and Controller. The Views and the Mode... |
It seems like F# code often pattern matches against types. Certainly
match opt with
| Some val -> Something(val)
| None -> Different()
seems common.
But from an OOP perspective, that looks an awful lot like control-flow based on a runtime type check, which would typically be frowned on. To spell it out, in OOP you'... |
I have tried looking for an answer to this question, but I couldn't find anything related.
To put it in a nutshell, I want to fork the existing Komodo Edit project, which is licensed under MPL Version 1.1, and create a new derived project/software. I would like to remove certain features from the current project, inclu... |
In the company I work at, developers also serve as internal tech support. This means we have to do three types of things:
Development: writing actual code to implement new features and new products
Maintenance: handle bugs and minor changes with existing customer-facing software
Tech support: handle internal issues ot... |
I'm developing a REST application and I allow my clients to authenticate in several ways (typically using Authorization: Token ... as in OAuth 2.0, but also there's session-based auth option for the web-browsable API). The application allows the client to provide their endpoint to which my application would later POST ... |
My game is a top down 2D shmup programmed in a functional style. I'm struggling with abstracting the code that is responsible for animating the projectiles. There are many types of guns with many types of projectiles. Here are a few that are very different:
A standard gun that shoots a bullet that travels a distanc... |
I recently wrote a little CLI Hangman game in Python; it's not anything huge, but I did write it all myself. I would like to keep the program open and free (GPL ver.3), but it's so small I don't know if I need to/can license it.
Is there a certain point where a program becomes "license-able", or can I license any progr... |
This is partly genuine curiosity, and partly a check on my understanding. I'm probably missing the point.
In Haskell, why does a monad use operations called return or unit to describe putting a type into the container -- lifting it into the monadic space? It seems more intuitive to call the operation lift.
Right now, i... |
TL;DR
Is there a data structure that'd quickly let me match words at any point (e.g., 'foo' matches 'foobar' and 'zoofoo'), and, ideally, returns a list of "characters that show up after the needle" (e.g., 'foo' should return ['b', $]).
I'm implementing an algorithm that generates random words from a training set of ... |
Learning how to develop a small embedded HTTP server for a class assignment, and the examples given on how to use com.sun.net.httpserver.HttpServer use an InetSocketAddress which extends SocketAddress as the link between client and server. However, all of my previous network programming assignments used Socket and Serv... |
I'm going to start developing an application in near future. This application consists of :
Back-end system. This system provides API to be used by client. This
system connects to data store and 3rd party API.
Data Store : Can be relational or nosql data store.
Client : Client will be a website and mobile application... |
I am a first-time azure developer and I am taking over a single-tenant cloud system and have been tasked with converting the system to multi-tenant. What is the correct practice to separate each tenant's sql server data?
Its a data collection & reporting system. Each tenant will want to build and run their own custom r... |
I'm working on Ruby on Rails. There is a feature in our app where doctors can "claim" cases for themselves.
I can either have the doctor perform the action and update the plate, or I can have the doctor send itself to the plate and have the plate update itself.
Should objects update itself? It just seems cleaner to me,... |
In my test environment we are running the same set of integration (and sometimes unit) tests against different systems that have different capabilities.
Some of the tests cannot be executed against some of the systems because a feature that enables this scenario is missing or we need completely different behavior.
Curr... |
I was looking for some answers in SO or here, but without any results, that's why I would ask you.
Let's assume I have a two different projects - for example server part and client part of an app. I'm developing my own part, while my friend is making the second one. But both of us should use some common interfaces like... |
According to the slides given by my lecturer, one of the disadvantages of MVC model is
additional code and complexity when data model and interaction are simple
Why is this so, I would assume it would make no difference since data model and interaction are on two different components of the MVC model?
|
As far as I know, there aren't a lot of differences between JDK 6 and JDK 7. At least, I haven't yet come across a difference (I coded with JDK 7 and with JDK 6).
A lot of computers run JRE 6 or JRE 7. Compiling my program using JDK 7 will narrow the number of potential computers that can run my application.
Is it gene... |
According to the Pragmatic Programmers, code should be for abstractions, while configuration and details should live in metadata. Rails seems to diverge dramatically from this pattern. Much config is done in code files such as application.rb, routes.rb and the various environment.rb files, while other types of config i... |
I just wrote the following piece of code (in delphi):
procedure Update(Value: Integer);
begin
// If the last update was yesterday, replace yesterday value
if CompareDate(FLastUpdate,Now) <> 0 then
begin
FYesterdayValue := FTodayValue;
end;
FTodayValue := Value;
FLastUpdate := Now;
end;
And I realized t... |
I have a lot of small projects, and while their source code is backed up and tracked with git, I don't know what to do with the rest of the files associated with a project.
These consist of small text files, some images, maybe a prototype or proof of concept, etc. They're not necessary to build or deploy, but I need th... |
This is a function in the d3.v3.js file (the graph library D3.js):
function d3_geo_areaRingStart() {
var λ00, φ00, λ0, cosφ0, sinφ0;
d3_geo_area.point = function(λ, φ) {
d3_geo_area.point = nextPoint;
λ0 = (λ00 = λ) * d3_radians, cosφ0 = Math.cos(φ = (φ00 = φ) * d3_radians / 2 + π / 4),
sin... |
I am a bit stuck with a design of a project, where many objects has to have access to the same piece of information. It could be some data, to construct a global-like object for themselves or the object itself (essentially a config object).
Essentialy these object are in a tree: On a top is a 'Router' object, which has... |
I have a class that runs as a service and returns html code of a website when supplied with a URL.
The code:
public interface IHtmlDownloader
{
IWebProxy Proxy { get; set; }
string UserAgent { get; set; }
string GetHtml(string url)
}
public class HtmlDownloader : IHtmlDownloader
{
WebClient _client;
... |
Context:
I have historical data about property (house) sales collected from various sources in a centralized/cloud data source (assume info collection is handled by a third party)
Planning to develop an application to query and retrieve data from this centralized data source
Example Queries:
Simple : for given XYZ pos... |
I've been making MVC programs for work (I'm an intern) and I feel like I'm doing a pretty good job at abstraction, single responsibility, etc. But I have this feeling about how I keep making objects properties of other objects and I'm not sure if it's a bad thing.
Example:
User
{
String Username;
Int32 UserID... |
We have a set of Java tools that are built and run locally. Whenever one of the devs commits a change, everyone else (including non-developers) need to do an update and build the tools.
Everyone uses windows machines so whoever designed the build processes decided to place everything in a folder called C:\build and dum... |
I am planning to make a simple rest service application, and I am currently deciding the architecture. I have decided that I want to write the middle layer in multiple languages, so that it is easy to deploy/integrate with as wide a range of systems as possible.
Due to the necessity of porting the code to multiple lang... |
I am running a zoo application.
My zoo includes an abstract class of 'animal', and several deriving classes - 'zebra', 'elephant', 'orangutan', 'baboon' and so on. Of each class I have several instances.
My question is: I want to check out if two animal instances can mate.
The business logic is divided to two parts:
I... |
gccand clang are both known to be compiler drivers. As such, the gcc executable does not compile anything itself. Rather, it calls the compiler (cc1), assembler (as) and linker (ld) with the right flags as needed.
Is this setup true also for the Microsoft C compiler, cl.exe? Is there actually some other executable that... |
I am interested in the idea of C++-like const not that particular execution (like casting away const).
Take for example C# -- it lacks C++-like const, and the reason for it is the the usual -- people and time. Here additionally
it seems the C# team looked at the C++ execution of const, marketing CLR and had enough at ... |
PHP's SplQueue does not include a clear() or reset() function to wipe data out of the data structure. My application requires that functionality. This leaves two options:
A) Create a subclass of SplQueue. Example:
class UserQueue extends SplQueue
{
public function clear() {
//dequeue everything
}
}
The problem... |
I work at a company that wants to be agile, but the business analysts often provide us "user stories" that are more solution than problem statement. This makes it difficult to make good design decisions, or in more extreme cases, leaves few design decisions to be made. It does not help the programmers understand the us... |
Could anybody, please, explain what is a Property Container or at least where can I get information about that pattern on the Internet?
I've found that it exists as one of the Fundamental patterns in this article.
Unfortunately, it is not described in the corresponding English article.
The only thing is a short descrip... |
We're trying to come up with a way to handle code that builds dynamic SQL for our application, which is very database centric. Things like Linq to SQL and Entity Framework are out of the question, so please no suggestions of that sort, our path has been defined for us.
Our main goal is seperation of the SQL from the re... |
I'm in development of a sample project in Android for a friend's phone that keeps track of his sales. At first, one of the requirements was to create yearly reports of this sales data. This would be stuff like most profitable week, total per quarter, total per month, and even yearly total, as well as compares for previ... |
If we are updating a field in SQL and ALTER the row also. After giving the COMMIT command, the system is crashed.
What will happen to the commands given, whether it will UPDATE and ALTER the table or not?
|
I have few CS textbooks with me which discuss languages, well actually 2 plus old course notes supplied a few years ago. I have been searching the web too any only seem to come up with vague responses just like the text books I have.
My question is about language recognisers verses generators.
I get the overriding prin... |
I have seen Exception Handling blocks that they were throwing the recently caught Exception in the catch block. Something like:
} catch ( Exception $e ) {
// Do some recovery here
callSomeFunction();
throw $e;
}
To me it doesn't make that much sense to throw the exact same Exception like this, but I'm not... |
I have two jee web apps that are going to be published on the same physical server, but on different network addresses.
APP A: Listens to a port on a public IP address and makes synchronous invocations to app B if necessary.
APP B: Listens to a port on a private IP address and makes synchronous invocations to app A if ... |
Let's say we have some class structure:
public interface IA { public void doA(); }
public class A implements IA { public void doA(){ System.out.println("A class doA");}
public class B extends A { public void doA(){ System.out.println("B class doA"); }
And now in a main I state this:
//in a main
... |
I would like to display some events in 'real-time'. However, I must fetch the data from another source. I can request the last X minutes, though the source is updated approximately every 5 minutes. This means that there will be a delay between the most recent data retrieved and the point in time that I make the request... |
I have been advocating lately that all string fields should be ntext / nvarchar(max) - we're using MS SQL Server. The objections seem to be either "it's not a good idea" (without any reason) or "that would allow the customer to send a lot of crap". Since I believe in filtering out the crap before it hits the database, ... |
There are many useful functions in <algorithm>, but all of them operate on "sequences" - pairs of iterators. E.g., if I have a container and like to run std::accumulate on it, I need to write:
std::vector<int> myContainer = ...;
int sum = std::accumulate(myContainer.begin(), myContainer.end(), 0);
When all I intend to... |
Being aware of the direct benefits of libraries having things wrapped in a package, making daily work easier, my question is leaning more towards the fact that many features not implemented in HTML/DOM/CSS, has become available using these libraries.
There is everything, from visual effects (13 a dozen) to more functio... |
I am writing an application for my graduation coursework, in C, using GTK+ UI library. Sometimes I ask for user input, which I need to save for later use.
The doubt comes on how to store this data. I didn't want to create global variables because I was told countless times not to use them. However, I need to interchang... |
Lately I've been studying a lot of javascript samples, both with/without libraries, jQuery to mention one.
As an old JavaScript developer, I learned early to make use of unobtrusive javascript where one were adding mouse click events to a global handler using document.onclick = mylib.document_onclick;
Then, by tagging ... |
Take for example this input array:
[2,7,1,4,9]
For this input, I need to produce an array of total 23 elements which contains two elements of 2, seven elements of 7, one element of 1, four elements of 4 and nine elements of 9.
Example of output array:
[2,2,7,7,7,7,7,7,7,1,4,4,4,4,9,...]
However, this array needs to b... |
Lets say I have the following code
// JS
$(function(){
$('[data-mc=logout]').click(function(){
if (!confirm(myconfig.msg['asklogout'])) {
return false;
}
});
$('[data-mc=ajax]').click(function(){
var target=$(this).data('targe... |
Python widely uses built-ins (or module function) and not class methods.
So
len([]) instead of [].length()
filter(f, []) instead of [].filter(f)
str(2) instead of 2.to_str
same for map, foreach etc
These prevent you from doing nice chaining which is possible in other languages like Ruby or Scala:
(sorry very artifici... |
I am completely new to using VCS and haven't settled on Git or Hg, but I do know that I will be using it soon. My old project folder has versions of files labeled v1, v2, etc. How easily can I fold this into a new [local] repo? There are only a few sets of files with version counters (so commit, then copy paste, then c... |
I like to raise a NotImplementedError for any method that I want to implement, but where I haven't gotten around to doing it yet. I might already have a partial implementation, but prepend it with raise NotImplementedError() because I don't like it yet. On the other hand, I also like to stick to conventions, because ... |
I've just read this article, and I'm confused.
Let's imagine 1 webapp and 1 distinct application acting as "worker", both sharing the same database.
Oh, I said "sharing"..but what does the article warns about? :
Fourthly, sharing a database between applications (or services) is a
bad thing. It’s just too tempting to... |
This problem feels rather basic, yet I've never known a great solution. I'm looking for a way for components in an application to notify each other while being as decoupled as possible (both at build/compile and run time), but also avoiding circular notifications in a way that components do not need to self-mitigate ag... |
I'm trying to adopt TDD in my daily programming practice. I use it at work very effectively, but I'm having trouble with my personal projects where I'm using some complex algorithms.
The particular algorithm that makes me ask this question is the Extended Kalman Filter. It's complex enough that I'm not confident in t... |
The following Scala code works and can be passed to a Java method expecting a function. Is there a cleaner way to do this? Here's my first pass:
val plusOne = new java.util.function.Function[Int,Int] {
override def apply(t:Int):Int = t + 1
override def andThen[V](after:function.Function[_ >: Int, _ <: V]):
f... |
I'm part of a 7 person software development team which supports a company with a few thousand staff. Our team is putting together a quick review process for measuring the success of a software project. Projects are mostly internal, which means our "customers" are more often than not other staff. Projects are reasonably... |
I just wrote a function that spans approximately 100 lines. Hearing that, you are probably tempted to tell me about single responsibilities and urge me to refactor. This is my gut instinct as well, but here is the issue: The function does one thing. It performs a complex string manipulation, and the function body consi... |
I'm in the need of widen my perspective on the framework libraries, to be able to make well aware choices of if/which/when to add a framework to a website.
One thing that got my attention was event handlers, as they seems to be somewhat more complex structured.
For me, in the early days, an event handler were added inl... |
I'm developing a java application to visualize time series. I need (at least) three linked views, meaning that interaction with one of them updates the others.
The views are:
A list represents the available and currently selected time series. The selected time series are used as input for subsequent computations. Chan... |
I'm writing some tests for a NodeJS module, but this question can apply for any language / platform. I've got the following situation:
// in moduleA.js
exports.foo = function (var1, var2) {
// do something to var1 and var2 here
baz(var1, var2);
};
exports.bar = function (var1, var2) {
// do something com... |
I totally believe in not repeating yourself in production code. I've accepted the idea that you shouldn't repeat yourself within test code. But what happens when you have production services that would simplify test code?
Let me pose an example. We have a service that accesses the Doohickey API. The Doohickey API is co... |
If this is tl;dr, scroll down to "The Question"
Why this is not a duplicate:
The linked question talks about version control (which I have), a one step build script (which I have) and to "have an issue tracker at all" (which I have, but I'm having trouble optimizing), none of the answers to that question answer any of ... |
I been reading a few things about using libraries and stuff but they all talk about not using it for commercial purposes.
Does commercial mean when you earn money by putting a ad to support you or is it something else like for a big company?
|
I'd like to validate I'm not in the wrong way.
My team project is using Visual Studio Scrum 2.x. Since each area/product has a lot of kind of requirements (security, user interface, HTTP/REST services...), I tried to manage this creating "parent backlogs" which are "open forever" and they contain generic requirements.
... |
I have a simple question: Slugify via helper or store the slug on database?
I mean, let's suppose that I have Guilherme Oderdenge on database and I want to transform it into a human-readable URL such as http://myapp.com/guilherme-oderdenge/, what's the best way to perform this? Storing guilherme-oderdenge in the datab... |
In quality engineering there are 3 phases:
1.quality assurance
2.quality control
3.quality measurement
Quality Engineering is defined as “the branch of engineering which deals with the principles and practice of product and service quality assurance and quality control”.
Quality assurance is a way of preventing mista... |
I'm trying to find an efficient algorithm for the following algorithm.
I have a sequence consisting of lists of indices denoting indices to be removed. The semantics are such that each sequence must be performed in order. I want to take these sequences and flatten them into one sequence of absolute indices to be remove... |
I have been doing some research on accessing a DB from mobile devices. There are so many different ways of doing it. There are also multiple ways to make it secure. What is a good way to access a database from a mobile device securely?
Also considering my specific case, where I have an existing WCF service which does ... |
Still learning .net and OOP and have a basic question I hope. This is an asp.net mvc app.
Looking at the code below, I am most concerned with the line in CheckShippingVendor that says ValidateDelivery(shipmentItem). Is it okay to pass in an object as a parameter and have the private static method update that item.
Wh... |
I was wondering the correct way to format a situation such as this, where I have a def, a foreach and an if clause all nested, requiring braces.
Currently I find it hard to read, and there is no obvious place to put the 'x =>' bit. Thank you.
def getAnswer(): String =
{
var sum = 0
(0 until 1000).foreach
{ ... |
Having worked on several different web application code bases, I've seen some divergence in how back-ends serving JSON to front-ends structure that data. In particular, when a backend wants to return a number of objects of the same structure. Do you just wrap up all of the objects in an array? What about the "key" of t... |
This is a front end project that is using socket.io for all communication with the server. This allows for push which is good, but recently we have been asked to provide a pause button. The pause button is intended on stopping the data from changing out on the ui if the user does not wish it to do so automatically.
We... |
In this slideshow on slide 26 it mentions ORM as an example of message coupling. How is that so?
With an ORM, certain code will call the ORM via an API, but that sounds like "control coupling". Also the ORM's api will take parameters to specify what you want, but that sounds like data coupling.
How is ORM an example of... |
Problem
I am building a PHP application which has a main menu, which in turn contains various "sections" or "subheadings" with various links. There are several user types such as SuperAdmin, Admin, Teacher, Student, etc, and each type should see a potentially different menu structure. It seems that my client would like... |
So... We have this fairly complex project (~10k LOC, but there's duplicated code so it's hard to tell) with hundreds of global variables. The project has more dependencies on other projects, and many other projects depend on it too. I have mostly inherited the responsibility to refactor just a part of this project by m... |
I have to write a dynamic algorithm for finding lowest cost path. So I have a point that I have to visit. I can jump only between points by distance - 5 I have an array of distance from 0-point for example (1 3 5 10 15 20 21 22). Each move cost me 1. So the best path will be to move 1->5->15->20->22 (3 and 21 I can ski... |
Suppose I'm setting up a website, and there are loads of images. These images won't change. But I would like that when any members of the team clone the project, they get the images so that they run the website immediately. Does this mean that I should add track the images as well? I'm just taking an example, it could ... |
My understanding is that Goto statements are generally frowned upon. But the publish-subscribe pattern seems to be conceptually similar in that when a piece of code publishes a message, it performs a one-way transfer of control. The programmer may have no idea what parts of the program are subscribing to this message.
... |
Procedural programming means coding the application is a series of tasks. Do A, then do B, then Do C. And often wrap these tasks in procedures or functions that can be easily called and run several times in the code.
Object Oriented Programming is also often done by doing A, then doing B, then doing C. But objects are ... |
It is sometime useful to write a script to perform a batch editing on
several files in a source tree. Such a script is usually very
specific and used only once.
Such scripts can be used to rework some identifiers in code, modify
file header comments, edit the path of a resource or the like. I want
to stress that I am... |
I understand that an interpreter could do one of the following things (and probably more):
Execute programming-language source code directly.
First translate the source code to some intermediate code (which is less human-readable and more efficient or easier for the interpreter to execute), and then execute this code.... |
Having recently returned from a Test Driven Development (TDD) course I had the following thought.
While writing unit tests using Mockito we came up against of the problem of mocking static methods. It was suggested by one developer we use PowerMock, which allows mocking of static methods, and then we got into a big dis... |
I am working on an academic research project whose results and some code we intend to publish. Research journals and conferences explicitly require that the authors have copyright over the work done in a paper. However, I would like to share the code with the community as it progresses using an open source license.
Is ... |
(define ls1 '((1 . 2) 1 . 2))
(set-car! (car ls1) 6)
ls1
(define ls2 (cons '(1 . 2) '(1 . 2)))
(set-car! (car ls2) 6)
ls2
After set-car!ing, ls1 will be ((6 . 2) 1 . 2) and ls2 ((6 . 2) 6 . 2). It seems that ls1 and ls2 have different storage model, and what does it mean when someone says x is bound to a list? is x st... |
I am designing a large application (a static code analyser) and I have a choice in how to organise the code into modules:
One approach is by what I'd call by technical function. This is where you have a package for data objects, another for service functions, views, controllers, etc.
Another approach is what I'd call ... |
I have a number of types that all relate to each other in terms of them being 'derived' from one another. I'd need a way to do is relationships, which made me initially think of classes, but I realized that other than the is relationships, there would be no reason to use classes as each 'type' of data function the exac... |
I have a desktop application where the user has tabular views on some data records. Now we got the requirement to let the user select multiple of these records at the same time and let the him edit some properties of the selected records all at once in a separate edit dialog. The idea is
to change only the properties ... |
I'm building a small reusable library for two systems our company manages.
Something that I've been caught up on is whether I should expose a set of properties of type Action<T> for events such as Completed, Aborted, ExceptionOccured, or if I should use the Event<T> T : EventArgs methodology.
In practice another intern... |
In Chapter 3 of his book The Art of Unit Testing: with Examples in C#, Roy Osherove illustrates the issue of undesirable external dependencies in code under test.
He shows this with a method named IsValidLogFileName which takes in a filename string as an argument, reads in a config file from the local filesystem an... |
I have an instance of a class UntouchableClass of which I need to access the member variables to use in my DotLiquid template. Problem is, UntouchableClass has to inherit from Drop if I want to use it in my template, but I can't change it since it is from an existing library.
I've read about the Adapter pattern, but Un... |
I couldn't find a question that was not too specific to some case, so I'll try to make this very generic.
We need an extractor base class to a set of documents, for example. Each document has its specific properties, but they're ultimately documents. So we want to provide common extraction operations for all of them.
E... |
My new boss has been working on this project for many years. I've only been here a few weeks, but I am not sure it's possible. He would like to design a system that is "100% data driven".
So if we put in enough data, we can define and generate any application. I've managed to at least get him to concede some things ... |
What would be the technical term for a tree that grows in both the directions, starting from the root in the middle?
The central idea being that new elements can be added to the tree (Now, I am not sure if it is even okay to call it one) in both the directions. But, when used for traversal purposes, you need to follow ... |
Is there a mathematical way to get the following:
For the the number 777,888,999 so 777 million and etc etc
getMillions(777888999) should return 777 only
getThousands(777888999) should return 888 only
getHundreds(777888999) should return 999 only
This should be done without using regex and without text processing but s... |
We work in Scrum with the caveat that we don't have a potentially shippable product at the end of each Sprint, instead requiring several hardening/stabilization Sprints before release.
One of the reasons for this is that our chief UX designer prefers that we'll complete all the visual work (such as colors, fonts, exac... |
Background
I work on a relatively large project (~570 KLOC) in a relatively small team (formerly 5 developers, now 2). Large amounts of code can appear and then vanish in months; for example, a few years ago an investment bank launched a new stock exchange, then shut it down 7 months later—thousands of LOC were written... |
I'm not sure if this is a subjective question, I hope not but I'm not proficient with LLVM so I'm just wondering: how come it's become so popular and so widespread used in the industry?
Were the optimization algorithms used in gcc/icc/msvc just worse than the LLVM ones? Is it possible that a university project managed ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.