instruction stringlengths 34 19.9k |
|---|
I recently came across sorting techniques and of particular, 'insertion sorting'.
Although the logic and method is fairly understandable, the actual function seemed a bit complex (given below).
void InSort(int AR[], int size)
{
int tmp,j;
AR[0]=INT_MIN; //defined in limits.h , basically the smallest possible... |
I have the following simple implementation:
var VALIDATION_TYPES = {
ERROR: 1,
WARNING: 2
};
var validationRules = {};
this.addErrorRule = function (event, rule) {
addValidationRule(event, VALIDATION_TYPES.ERROR, rule);
};
var addValidationRule = function (event, type, rule) {
if (!validationRules[eve... |
We are overhauling a legacy accounting app that has some large reports. One concern that has been raised is due to the transactional nature of the data, if we start a long running report how do we ensure the data is not modified before we get around to processing it?
Locking everything on the transaction db is out, wha... |
I'm referring to the pattern (aka Universal Design Pattern) as discussed in this blog post
Universal Design pattern
I guess I'm not entirely clear how to use this in practice. And how it works to accomplish operations or tasks.
In particular regarding this explanation
It's the core API for any collection that maps na... |
I've been working for a time with some researches developing a tool to fetch tweets from Twitter and process them in some way. The first prototype "worked" but became a pain as we used sockets to connect different components. The architecture was similar to this:
The controller had to create tasks (information about t... |
I'm creating application in C++ and found out that storing information in XML file was very prodigally. Despite the possibility to read it without any specific application, random access via DOM or VTD library and possibility to backup by simple copying XML file, it's very RAM-expensive (even while using VTD it's neces... |
Is it a bad idea? I need to compare each entry.Key value in a Dictionary of strings to a SQL table. If there is a match, then I pull the data from that row.
I was originally going to use a foreach loop to query each entry.Key value.
I was told by someone that doing this is a bad idea.
Is it bad because I'm doing too ma... |
I need to use instances which represent mathematical functions along with their parameters end enable their evaluation. I can take 2 approaches:
1: have a single class representing all the math functions:
class TrigonometricFunction extends Function {
private double param;
private String name;
public Tri... |
I work in a small company, where I used to be the only developer. We recently welcomed a few other people on the team, and started thinking about how to organize development efforts.
I am pretty much a novice in terms of code management, as this is my first job out of college. As part of a test, I tried working using p... |
In my Application, I wanted to seperate GUI and business logic with some kind of ModelViewPresenter-Design.
Therefore I made some Presenter classes, which have not much more code than the properties my forms are databound to.
To provide persistance (load and save) I made new classes with methods setting the properties... |
Suppose we have a file copy program. It has two threads, a UI thread displaying the progress of the copy operation and a work thread copying the file.
The UI has a button for canceling the process. Which pattern are you suggest here for transfering cancel event to copy thread?
I want an object-oriented solution.
|
When programming sometimes things break. You made a mistake and your program tries to read from a wrong address.
One thing that stands out to me that often those exceptions are like :
Access violation at address 012D37BC in module 'myprog.exe'. Read of address 0000000C.
Now I see a lot of error logs and what stands ou... |
First, sorry if that title makes no sense. I am a little out of my depth here with the terminology.
So, imagine that I'm writing a text editor in Haskell. For the purposes of this question, let's consider a toy text editor that only operates on a single line of text, and has three primitive operations:
Insert a charac... |
I am aware of this question, and I think I know why it has been closed. I hope that my question manages to be more specific.
My skill level: I have a "Computer Science" degree. I have programmed in many languages. Back in the day I programmed in C on an embedded microcontroller (TI MSP430), and in Python and Prolog. I ... |
I had a question, about how to remove an element from middle of the queue , without disturbing the order of other elements.
E.g.
Queue before operation:- <| a b c d e |<
Queue after operation:- <| a b d e|<
Note:- I know the generic way of removing a,b and inserting on queue again, followd by d and e.
But I Need... |
I have a model for an app that is fairly large, all of which needs to be on a users' device at the same time. For example, a spreadsheet. If a user makes a change to the model on one device, I want this change to propagate to all other users, via updating a centralised server.
I'm not quite sure the best way to achieve... |
I have got 2 days for making a very serious decision about the tools and platforms that my company is going to use in order to port its WPF application to Linux / Android / iOS whatnot.
Obviously I can point to my seniors that 2 days is hardly enough for reading about all possible options, and what about trying, making... |
I have observed a correlation between a customer ordering software of "good enough" quality and the same customer not willing to pay for good engineering practices (unit testing, code reviews and the like) that many times that I would call it causality. Still, I am having hard time coming up with any logical reasoning ... |
Our web application has a certain resource type that is shared accross multiple users, and may thus be read and written by anyone at anytime. We resorted to the usual suspects, database transactions and software locks with expiration times, and with a low user base and low concurrency this worked well and prevented man... |
We are having a heated discussion about this at work:
For sake of simplicity, I will use examples in the question.
Assume there is an application with an account request form, for which we have these requirements:
Dates and Email must match a regex
If the user already has an account request, he should not request for ... |
One of my team members committed a huge mistake; a clear SQL injection-vulnerability. It obviously didn't pass my peer review and I made very clear that this is unacceptable. I never saw this programmer make this mistake before and I'm unaware of any other security holes this particular programmer committed. The proble... |
suppose i have an interface in some language with two simple methods
interface IConverter{
String toString(Object o)
Object fromString(String s)
}
this interface is implemented by many classes and there is always just the implementation of those 2 methods nothing more.
my question is, does it make sense to use d... |
I am relatively new to class design and I have a task that I'm not sure how best to complete, or whether my idea in general is a code smell.
I'm developing a RPG where people can own monsters, so each one is an object instance of the Monster class. Since the sprite of a monster changes depending on a few different fact... |
I am creating an open source tool which leverages some XSLT stylesheets in order to do its work, which is transforming XML to Java code. One of the stylesheets that I want to use is licensed under LGPL v2.0. My tool will be license under the Apache License v2.0.
I read somewhere that if you link your Apache-licensed pr... |
When a client requests my .../resources/user URL with a HTTP GET I get the following response:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<collection>
<User id="5">
<Password>DC647EB65E6711E155375218212B3964</Password>
<FirstName>Super</FirstName>
<LastName>Admin</LastName>
... |
I'm working in a tool that downloads tweets from Twitter to process them later. For this purpose I'm using Celery with RabbitMQ, sending task with the keywords that must be tracked by the workers.
My problem now is that I must pre-process the tweets downloaded by a worker in a second task so I should merge both tasks t... |
I've been programming in JS for over a year now, mainly in angularJS. And I can honestly say I've never made a function use prototypical inheritance. When ever i need a class like object that has private data, I use the factory pattern and closures to create classes. I can honestly say I've never needed to use the this... |
I read Object-Oriented Analysis and Design with Applications Notes written by Grady Booch. In the book there is a sentence:
There are three important parts to this definition: (1) Object-oriented programming uses objects, not algorithms, as its fundamental logical building blocks (the “part of” hierarchy we introduce... |
I have the following problem to solve:
Given a ferry with length d and a list of n cars conataining their length we must load the cars on the ferry in an order in which they appear in the list on 2 different lanes (each one having length d). Write a program that given length d and the list of cars outputs maximal numbe... |
Let's say I have a list of points (in my case, point objects in a Python implementation). I then have a line segment connecting two of these points.
I want to know if there's a way to efficiently find the point from the list that is closest to the line segment. I realize I could step through all of the points and check... |
I'm looking for the most efficient algorithm to take a tree (stored as either a list of edges; OR as a list of mappings from parent node to a list of child nodes); and produce, for EVERY node, a list of all nodes descended from it (leaf level and non-leaf level).
The implementation must be via loops instead of recusion... |
Take the following examples, which have been abbreviated:
BasicButton:
public class BasicButton
{
private var m_fOnClick:Function;
public function BasicButton(pOnClick:Function)
{
m_fOnClick = pOnClick;
}
.
.
.
// when the button has been clicked:
m_fOnClick();
... |
By proof based programming, I mean, you can somehow prove the correctness of your program without testing.
I heard that Ada has a feature called contract, I also heard that, if you can pass Haskell's type checker, your program probably is right.
Can I write correct program without a single line of test code in these tw... |
Is it an acceptable practice to initialize physical/external resources from a constructor when the resource is needed for the object to do it's work?
For instance, let's say I wanted to create an object that proxies a durable message queue and that the message queue is a physical database table.
Would that make sense t... |
I'm designing a procedural city generator, and the first step of the generation process is the creation of city streets. These streets extend out in a straight line to a point, then they can either branch, rotate, or continue in the same direction. If a street would hit another street, it can either stop growing or att... |
I am newbie for scrum. Lets say we have all the user stories for the product, and the product owner gave them the priorities. Now as a team, when we should estimate times for these stories? Should we estimate times for all the stories roughly before the sprint planning then updating them if it is necessary during sprin... |
In "Pattern Oriented Software Architecture - Vol 1" (p. 131), the author said that View is responsible for creating Controller. But in "Head First Design Patterns" (p. 562) it is the Controller that creates the View. In some other references I see that nor View niether Controller create each other. Only Controller has ... |
I am going to create a person to person store with Laravel, a website where its users can share and sell their product or their mobile, TV, Computer, Shoes, Shirts, Books, Cars, Bags, Animal, etc.
I am going to create a table named products and other tables about products are, for example, bugs, Animals, Cars, Shirts, ... |
I have been using the command pattern for quite some time but I'm never really sure how much logic I can actually put in the Execute method.
My current implementation of the command pattern looks similar to this:
public abstract class Command
{
public static event EventHandler Completed = delegate { };
... |
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 to a dynamically created URL server side.
But some programmers My colleagues keep saying that plain Javascript in the JSP... |
In programming language theory, a type is a set of values. E.g. the type "int" is the set of all integer values.
In OOP languages, a class is a type, is it?
When a class is defined with more than one members, e.g.
class myclass{
int a;
double b;
}
When we talk about a class, do we mean
"(a,b) where a is an... |
We have an application where the customer has changed their mind about a large area of functionality and this area requires a large amount of re-work.
Whilst the re-work itself is not an issue, it has introduced a situation where the impact of the changes is wide ranging including:
Data
Query Logic / Table structure
B... |
There are two other questions I've posted that dealt with specific cases of this:
Where does the Liskov Substitution Principle lie in a subclass passing extra arguments to similar, tightly-related callbacks?
Matching the superclass's constructor's parameter list, is treating a null default value as a non-null value wit... |
I think that abstraction represents only the essential things needed for the purpose as there are so many unnecessary properties. So why is it said that a class represents an abstraction?
|
We are currently porting our huge svn repo to git and we are thinking to export subdirectories of repository, each one containing source code of independent binaries, documentation or robot tests, into separate git projects.
One of those is a library that is currently being developed and all of the binaries depend on i... |
When creating routes for your MVC web application I have seen two possible ways to pass variables to a controller method:
With the first approach the variable is passed to a parameter of the controller method and utilized as such:
1a. http://domain.com/controller1/method1/variable1
1b. class controller1 extends main_c... |
I have a question whether it is a good or bad practice to use an SOA layer for the application servers to talk to the database. A web application server can obviously directly connect to a database, but in the hype to make everything SOA, the architects are mandating that everything has to make an SOA call to midtier s... |
My manager recommended I consider the technique of 'branching by abstraction', in which, rather than creating feature branches, multiple developers work in the same version control branch, and abstract the functionality they are working on e.g. using feature toggles.
I'm sceptical about this approach, but feel obliged... |
I am trying to determine the differences between systems analysis and domain analysis. It seems that any systems analysis occurs within a domain--so are there techniques, concepts, tools, etc. that a domain analyst would use and a systems analyst would not?
|
In my Node.JS projects, I save my project metadata into package.json: dependencies, version number, author, description, and so on. This makes it so anyone can clone my project and run npm install to create a virtually identical local environment.
Is there a such thing for Python? Some sort of standard file where I c... |
I am trying to figure out how to write BDD scenario where it seems like I need a chain of "Then" conditions. How do I write it? As one scenario? As two scenarios?
Here is how I've written as one scenario:
Scenario: Take user directly to their message on swipe after login
Given Dee has received a push notification
An... |
In a multithreaded programming environment, lock contention on the heap is often enough a performance bottleneck.
Theoretically at least, the cream-of-the-crop solution for this problem is to have the scalable/parallel[izing] allocator be entirely lock-free. However, it seems to me that besides a few research papers (e... |
I was reading a Hacker News thread where one user posts a link from 2011 explaining that IIS is much faster than most other (*nix) web servers. Another user replies, explaining that IIS gets that advantage by having a kernel module called HTTP.sys. To my knowledge, most other popular web servers in 2015 do not do this.... |
Originally, We have two applications communication with TCP/IP, and both of them are implemented by C++. The messages between them are custom message type.
Now the client program will be changed to web application based on nodejs and the communication between them will be changed to message bus such as rabbitmq
So th... |
A while ago I was experimenting with evolving virtual creatures using neural network + genetic algorithm, but that didnt go well (simulation speed was too slow, mainly because bad programming habbits of creatures, not neural network).
I used Feedforward neural network and now I can see it isnt exactly right choice for ... |
Given an HTTP server (e.g. Apache, IIS) and a web application (user code running in the server using PHP, ASP.NET and the likes), which of those can decide which HTTP status code to return for any request?
Or rather, is a "web application" to be interpreted as an integral part of "server" as used in the HTTP RFCs? The ... |
I have this software package which installs itself to /usr/local/mypackge, with a bunch of subdirs. In bin/ I have linked code, as ELF executables, in /share/doc I have documents, etc. Now suppose I've written some wrapper script(s) calling binaries from bin/, and I want it to be part of the package. Where should it be... |
In the third last paragraph at page number 26 of the ebook "The C Programming Language" the author(s) say,
"We will generally use parameter for a variable named in the parenthesized list in a function. The terms formal argument and actual argument are sometimes used for the same distinction."
And in the hard copy of ... |
I have a graph in which each node is a geographical point on the surface of the earth, defined by it's latitude / longitude coordinates.
Correct ways to calculate the distance between two such points could be the Haversine Formula for spherical earth models, or Vincenty's inverse problem for spheroidal earth models.
Bu... |
Imagine a coiffeur, with his services:
+----+-----------------+--------+
| id | name | amount |
+----+-----------------+--------+
| 1 | hair cut | 40 |
| 2 | shampoo | 10 |
| 3 | french manicure | 90 |
+----+-----------------+--------+
Imagine a table of transactions:
+----+---... |
I started working again on a Genetic Algorithm and i'm trying a lot of operators and ways of selection. When I made the Tournament Selection , I noticed that it gets really easy to always get the top individuals to be selected, and the small ones get less chances of being selected. I saw some workaround methods like im... |
When creating a viewmodel for Knockout, what's the difference here? I see these different implementations and I've tried a few and some don't work the same.
//the most common example.
function ViewModel(data){
data = data || {}; var self = this; //note self = this
self.property1 = ko.observable(data.proper... |
I have a class that acts as a library of functions for various products. To compute its data, the function currently needs to be aware of all product names. Depending on which product calls the function, it returns product-specific answers.
The codebase is convoluted enough to where classes are tied to each other i... |
I've asked this question on stackoverflow, but i think this is a more appropriate place for it.
I'm creating an app for iOS, Android and the Web. I created a separate Restful Data Service that is meant to be consumed by all three environments, so I separated the Logic, and all of the apps can consume it at api.mysite.c... |
I'm working on the implementation of a few related algorithms in CUDA, all of which require a primitive that we'll call f(). The related algorithms can't simply call f though, as they require f to have slightly different behavior for each algorithm.
f is highly optimized feature though, so I don't want to overload f fo... |
Are there any good tips, when one should subclass and when should not?
It's clear that we should not subclass when
we want to reuse a single method of some class
we override all methods, changing the behavior of superclass completely.
But in real life, it's more difficult to decide. For example, I have a BasicToolba... |
I am in the final stages of creating a mobile responsive customer relations management platform. Presently it is written in php as a stand-alone self-installing script.
I would like, however, to convert it to being hosted on my server where the client points their domain to my server via the use of the cname and their ... |
I'm trying to run a computation-heavy program that creates an image on a website. Is it possible to compute in C++ and have an output stream that connects to an input stream in Node.js to display an image, or alternatively, stream is to the user and display it through JavaScript?
Also, I'm using Monte-Carlo Sampling so... |
I've got a question for all the frontend guys here. First of all, this is not about placeholders vs mixins as I've already have an idea about, whether to use one or another.
So the question is - do you use SASS placeholders with just one, or perhaps two rules to avoid multiple occurrences in the resulting CSS output?
A... |
I am wondering if there are any pros and cons against this style:
private void LoadMaterial(string name)
{
if (_Materials.ContainsKey(name))
{
throw new ArgumentException("The material named " + name + " has already been loaded.");
}
_Materials.Add(
name,
Resources.Load(string.F... |
For example for the following method signature:
def genClusters(n_clusters, n_nodes, cluster_distribution):
n_clusters should be an integer of more than 1.
n_nodes should be an integer of more than n_clusters
cluster_distribution should be a float between 0 and 1.
Should I use a series of if then raise exception stat... |
i was thinking it would be cool to implement native torrent support in a web browser so that the following html would render an image on the page:
<img src="magnet:?xt=urn:sha1:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C" alt="smiley face" height="42" width="42">
i have looked around and such a thing doesn't appear to have been ... |
What I want to represent
Let's assume I have several schemas of the following kind:
It is a tree on which positions of squirrels are represented by a blue dot. The number of bifurcations differ from one tree to another, the number of squirrels varies from one tree to another, the positions of the squirrels vary (and a... |
I like the idea of using Free monads to "purify" code and I've used it in some simple scenarios. However, I can't seem to figure out how to write an interpreter for a Free monad transformer. In particular a stack of free monads.
Here's a simple example of what I have in mind. Say I'm purifying access to two database... |
I've read Git branching and tagging best practices and git tagging comments - best practices, but I don't see a direct answer to something I've wondered for a long time:
Why does Git have tags? (instead of just branches)
They seem to be second-class citizens, or at least "different." They aren't pushed unless you speci... |
Let's say I have three resources that are related like so:
Grandparent (collection) -> Parent (collection) -> and Child (collection)
The above depicts the relationship among these resources like so: Each grandparent can map to one or several parents. Each parent can map to one or several children. I want the ability t... |
Do you have best practices regarding to which tense to use in message when you're coding exception-throwing or message-logging code: "Could not acquire connection from DataSource" versus "Can not acquire connection from DataSource"?
|
I am a little bit confused about this code. Why does the else block get executed?
Please explain it.
int a=10,b=20;
char x=1,y=0;
if(a,b,x,y){
cout << "A" << endl;
}else{
cout << "B" << endl;
}
|
We have TFS 2013 only for version control, Team City for building, a Nuget server and Visual Studio 2013. Little late in the game but we haven't set guidelines for getting code from development into a build and package management process. Git-Flow as shown below will work for most of our projects (i.e. we need only o... |
Joshua Bloch claims that
"a single-element enumeration type is the best way to implement a
singleton"
Why? I totally disagree with this statement because enumeration is data type with some type-safe constants, like NORTH, SOUTH, WEST, EAST. I think that stable singleton can be creating using class with adding some... |
I am writing a solver for the game sudoku. I am trying to implement the hidden set check in it and I can't figure out a way to do it well.
I need to find out if there is a set of cells of size N in which a number of N candidates appear, where those N candidates are not present in any of the cells outside the set. For e... |
According to Java's commenting conventions, classes comments should describe a "thing", rather than "actions". It is easy when the class IS a thing (ex. a Clown), but what if it isn't?
In this case, the ShapeProvider is a proxy class that requests "stringified" Strings to a small server application via the get method.... |
The situation. Let's say a background process puts stuff into data containers. It runs all the time, observes system events, and populates the data accordingly.
The user may launch a control panel application. With this application, the user can define new containers, rename or delete old ones. The panel is separated f... |
Methods with many parameters are often sometimes unavoidable. In my own experience I often find this is the case for program entry points and complex mathematical procedures - where refactoring is either not possible, or would obscure the meaning of the method. Although there are no concrete limits for the number of pa... |
I am interested in using Spring's Cache Abstraction on a module that I am working with but all data operations are on collections to avoid multiple datasource invocations, so I am not sure I have a decent "pointcut" at which to method-level cache. This is not a Spring or Java specific issue but more of a design problem... |
I am new to concepts like DAO, DAL and Domain Driven Design. In the end I want to decouple the persistence layer (mysql database) from my business objects and logic in a web application. I liked the DAO concept but I got stuck implementing it when I want to create a Business Object from database that has other entities... |
I'm implementing a simple Quota object which determines a usage percentage based on the maximum and the used.
private int maximum;
private int used;
public Quota(int used, int maximum) {
this.maximum = maximum;
this.used = used;
}
public double getUsagePercentage() {
return ((double) used / (double) maxim... |
We are developing multiple web services in C# using WCF, but we´re new doing it.
So, for what we have read and learnt, this is our approach:
We have a class library that we called CommonLibrary that has a few classes that are going to be used on all our services (language stuff, type of user connected and a common obj... |
How do software developers manage to know if their software will run on the target hardware they are developing to? Many developers today work on machines much faster than the intended platform. What kind of tools do they use to understand when they are going overboard?
I'm asking from the perspective where you for exa... |
I am currently in a beginning programming course at my University (I've got plenty of experience in the subject already, but I still have to pay for that piece of paper with time and money.) and the professor has been stressing since the beginning of the course that the break primitive that many languages provide is ba... |
import java.util.List;
import java.util.ArrayList;
public class Test {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Deque queue = new Deque();
int random = (int)(Math.random() * 10... |
Say I have a simple object created by from user input:
var input = { url: 'http://example.com/', path: 'abc', user: 'adam' };
And I am to write function(s) that update url and path properties according to some business logic, there are many approaches:
A. functional
input.url = validate(input);
input.path = convert(in... |
In boundary analysis testing, some authors suggest testing MIN-1, MIN, MIN+1 (and the same for MAX).
Also for 1-100 range (if A>=1 && A<=100), test cases would be: 0,1,2 and 99,100,101.
I do not see the point - if 100 works, then 99 must work too (in my opinion but this is why I ask).
|
I have a huge class (>1000 lines), in which all methods depend on a small set of attributes in that class. I can think of 2 quick ways of refactoring.
I keep it as a huge object, but split related methods into separate classes from which I inherit (but I don't instantiate those separate classes, only the last one in t... |
I am trying to determine how to manage types and conversions between types within a compiler that I am writing. The compiler is being written in C#.
There are a number of different kinds of types.
Classes (read only / not mutable)
Mutable Types (Which contain another type. Think the opposite of C++ const.)
Generic Typ... |
I've come across this problem a few times:
Is there any "programming rule" for checking for an condition (error checking for example) before you want to do execute code, or only execute the code when that condition is true.
Checking before running the code:
$condition = false;
function someFunction() {
if(!$condit... |
I'm facing a new enterprise project in Java about data migration.
I did one of them in the past, now I want to do a better work and I think I need your considerations.
So, let me explain the problem:
I have a lot of DB tables without any logical wire. So in the most of the cases I need to perform a huge logic in the J... |
I regularly write classes which can only have immutable instances, much like string.
I am wondering why Java or C# or VB.NET don't have immutability built-in into the language? That way, I can communicate immutability better to my fellow programmers and also make assumptions about state in the class.
For instance:
... |
In Entity Framework, the DBContext class is said to implement the unit-of-work pattern. As I interpret this, it means that if you make a DBContext, manipulate its data, and then dispose of it, then these manipulations will either all succeed together or all fail together, and get rolled back. Moreover, there is the pot... |
I have a ServiceCallContext object that must be passed in as the first parameter of any service call. I would like to put a User object on the context object but I know I can't force the caller to send back the User object they received from the service and I can't prevent them from filling that in with any information... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.