instruction stringlengths 34 36.1k |
|---|
I have a SQL database to which I store and from which I read several objects into my C++ code.
I wrote a single database wrapper which handles all the reads and writes to the DB.
Of course this class got too large. I could make a Database wrapper for each business object but then I have to instantiate all these diffe... |
I'm creating my first online game using socket.io, and I'd like it to be a real-time multiplayer game like agar.io or diep.io.
But I've run into the issue of trying to figure out how to get all the computers to work at the same speed.
I have three ideas for models, but none of them seem right, and I'm wondering how nor... |
Let's say you have many paths that an application can take at a certain point based on the value of a specific input (for example a simple int). Is there a certain method that is most efficient for picking which path to follow? A nice and organized way would be a simple switch statement, but does that scale as the numb... |
let's say I have a database connection in the class Database which offers the following public methods
public synchronized void open() {}
public synchronized void close() {}
public synchronized void addData(Object data) {}
My main program looks as follows:
Database databaseConnector = new Database();
for (Feed feed :... |
In an ASP.NET app, I've got to decide whether to put a complex piece of code on either the client in JS or on the server in C#.
I've considered performance (if on server, it would be a small callback), IP protection (all behavior is visible on the page), need for server interaction (none during the execution of this ... |
I'm a building a registration form for my website and need to populate the country, state and city field. All these fields are inter-linked i.e depending on country, state field will be set and depending on state city will be set. I'm trying to figure out what's the best approach to model this using Neo4j. Do I need to... |
The last time I used asp.net 4 years ago, the "ASP.Net Membership provider" was the best way to do user authentication in an ASP.Net application.
Nowadays, is using the "ASP.Net Membership provider" still a good way of authenticating users in an ASP.Net MVC application or is there something new for this purpose?
Is the... |
I am writing a game in c++ with the v8 javascript engine embedded in it. I have a c++ workflow system I use to tell things how to do specific things. It's nice and I like it, but I need it to work in javascript as well.
The code describes the whole process, but it is asynchronous-ish and only selectively runs the p... |
In many of my personal and professional projects inevitably comes the moment where we have to weight pros and cons of integrating third parties versus developping a home solution. I've always been a fervent user of open source resources and faced programmers I respect who were following other path. The arguments are co... |
When I'm working on a project, I tend to write a lot of code. A lot of code means alot of bugs. If I commit my work early on , I have to edit that commit when I encounter a bug and fix it. This is why I have started to commit at the end of the work on the component I'm working on. This means I could do changes without ... |
I am designing a data warehouse for a sales platform. There exists a group of users that offers and a group of users that demand entities.
The production data base holds two sources of information:
The current status of each entity and to which users it is assigned (this can be versatile, "placed a price for an order"... |
The setup
So we have a RESTful JSON API. There are iOS and Android applications that consume the said API (one of each).
The code for the applications is such that the endpoints are hardcoded to "http://api.mycompanyname.com/json/someEndpoint".
In order to test the applications our sysadmins have setup DNS poisoning ... |
I made an extensive research in previousv related questions, but since my questions is somewhat peculiar, I decided to create this new one.
I am implementing a visualisation application (in JS). There is a class, called Graph, that contains the visualisation of a graph, along with all the necessary components (nodes, ... |
I am working on a project where you have controllers that expose an API and services that implement some logic.
In this project, each service* checks for the user's permissions to use the service.
When asked, I am told it makes life easier to the service's consumers because they don't have to bother themselves with p... |
Functional programming is often explained to agree with lazy evaluation.
As far as I know lazy evaluation means that a method gets called if the evaluator/browser/etc. thinks that is the next best thing to do.
I've read about lazy evaluation here.
That makes me think; promises are designed to run, and after they are do... |
I often find that "!" characters (meaning "not" in C-based languages) are easy to overlook. So I sometimes create methods that return the inverse result.
For example, instead of doing this:
if (!dataContext.Permissions.HasAccessToFeature("FeatureX")) { ... }
...I create a second method that is the inverse of the othe... |
I've been working on a project based off of this tutorial.
Unfortunately, the controller classes in this are quite dense and have terrible separation of concerns. I should have realized this originally but, I ran with it and now am stuck dealing with the terrible design from this tutorial with my added features/bad de... |
We are using ORM with bunch of database models and those ORM database queries (and models, of course) - are literally all over application from top to bottom.
And when change in model structure happens it wreaks havoc. Changes are expensive, difficult and stressful.
My suggestion is to surround database schema with nic... |
Assuming the compiler is smart enough to only evaluate the if in the second example once, which version should one (semantically) use and why?
if (b) {
for (auto a : as) {
foo(a);
}
} else {
for (auto a : as) {
bar(a);
}
}
vs:
for (auto a : as) {
if (b) {
foo(a);
} else {
bar(a);
}
}
I... |
I suppose that maybe what made me ask this question is, that every time I do a commit in Git the .sln files comes up whenever there were changes. So, as a person who reviews all my changes when I do a commit I tend to look at the solution file as well (just observing what projects may have been added, or maybe configu... |
As I'm sure most of you are aware; tmux and screen have features that allow the sharing of a concurrent terminal session with a remote host.
At first this seems great, and for some purposes it is, but there's one problem: Even though both users (local and remote) are able to send keys and observe the changes live (i.e... |
I am dealing with a lot of legacy, reverse engineered binary file formats, often with lost source code and reading/writing these files needs to be recoded in C++.
I am wondering if there are good examples or ideas on simplyfing the process of converting documentation of the file format into code with goal being to load... |
I am learning how to read Excel workbooks in Java and want to know what a good Data Structure will be for holding Column names with the values under them.
Example:
I want to be able to call a method: getColumnValue(String columnName, int indexOfValue) and get the value at that position for the specified column name.
I... |
I was reading the Spring Cloud Netflix documentation when I found out about a way to share an interface between an HTTP server and its client. They use this example for microservices, although there's no reason why it can't extend to generic HTTP communication:
// The shared interface, in a common library
public interf... |
I am concerned about whether or not I am using FactoryMethod correctly.
Background:
I am refactoring legacy code and I have identified a pattern: there is a God Object that is created in memory, and later various parts of it is saved to many different tables. For example, various parts are called Selection, Design... |
I know that most of the pos tagger algorithms measure their accuracy token wise I.e. whether the token is tagged correctly or not
Some pos taggers provide sentence accuracy too. How is sentence accuracy calculated. Is it like if one token in sentence is wrong then entire sentence is wrong or a sentence is correct if th... |
I was finishing one of my earliest C++ projects which is (according to the framework) supposed to be cross-platform. I developed the project fully in Windows and Visual Studio, thinking that since the libraries are all cross-platform, then doing the OSX build "later on" would be trivial. This turned out not to be the c... |
I'm in the process of building out an architecture that will heavily leverage DynamoDb. My organization is considering the possibility of storing sensitive data (config info) in DynamoDb, as well as non-sensitive data (e.g. telemetry data).
Historically, our SQL Servers have been protected by numerous layers of network... |
The question can be summarized as:
In a database (regardless of type), would it be considered a good practice to always include updated, created (and possibly deleted) properties, for all entities, regardless of nature?
The question is asked in the abstract, but I'm looking for real life answers, common - and hopefull... |
Suppose I have two blocks of code, A and B. A is to be executed before B. As I understand, I can do one of two things: 1) Put B in a separate thread that is to be executed after A's thread, or 2) Put A and B in the same thread, with A preceding B in the order of execution.
Option #1 means more memory will be allocated ... |
I am maintaining an app that uses a lot of sql server 2008r2 stored procs, views etc.
The problem that I have is that certain stored procedures/views have code that is specific to the environment: production, test or development. That's how I inherited the system. The differences come from the way the linked servers h... |
I wrote a command-line utility and I want to develop a GUI for it. I saw that almost every tool on linux comes command-line, and it eventually has a GUI which interacts with the command line utility making life easier for those who aren't familiar with command-line.
I want to do something similar, what is the standard ... |
I work at a mostly .NET shop.
A coworker has more of a background in open-source MVC (think RoR and Spring MVC). She seems to really enjoy .NET MVC, but she practically refuses to work on Web Forms, and has a hard time switching gears/working in Web Forms apps. And I hear similar things from others.
I for one also much... |
I've a web application that consists of 3 main technologies: JSF, jax-rs and websocket. All three are coupled together with the help of CDI injection and JPA.
That means that when a user login, he does so through a managed bean. Then he can use websocket (chat) and Rest service (to have notifications) and JSF for norma... |
Consider a function like this:
function savePeople(dataStore, people) {
people.forEach(person => dataStore.savePerson(person));
}
It might be used like this:
myDataStore = new Store('some connection string', 'password');
myPeople = ['Joe', 'Maggie', 'John'];
savePeople(myDataStore, myPeople);
Let us assume that S... |
As I know, according to "composition over inheritance" rule, we should avoid reusing a method by inheritance, but how about class members? Suppose I have parent and child classes like the following:
public class Animal{
protected String name;
protected int _id;
public String getName(){
return name;
... |
The idea is inspired by the fact operators such as +, -,%, etc. can be seen as functions with either one or two arguments passed, and no side-effects. Assuming I, or someone else, writes a language which stops more than two arguments from being passed, and also only works via return value:
a) would such a language lead... |
So my problem is, I have users entering their data(names, address) in a mixed form- some with first letter in caps and some without, some inserting more than necessary spaces and so forth.
Also, since there are some with titles in their names(happens in some parts of Europe), the title words have to be in small.
Now ... |
I've found it difficult to find a definitive answer to this question. Using Semantic Versioning and GitFlow should my release branch include the minor version number? I'm not referring to tags.
My application tags looks like this:
v1.9.1
v1.9.2
v1.9.3
I'm now ready to do a release candidate. Should my release branch i... |
I want to be clear when discussing an implementation that we're using soft-deletes (not immediately removing data from the database). What can I call our approach? The best I have is "CRUD with soft delete", just "CRU", or CRUH (create, read, update, hide), which afaik is a neologism.
|
There are times when I will need to modify a value passed into a method from within the method itself. An example would be sanitizing a string such as this method here:
void SanitizeName(string Name)
{
Name = Name.ToUpper();
//now do something here with name
}
This is purely harmless since the Name argument ... |
In the new java.time package the core classes are using the factory method of instead of a public constructor. Even though I like the cosmetics of the of method I can't see a good reason to not use a constructor. The documentation I've found just explains that this is the case and doesn't really go in to why it's the c... |
I currently have a setup looking like this:
__________________ _________ ________ ___________
| Front end server |----| Varnish |----| NodeJS |----| C-service |
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ ‾‾‾‾‾‾‾‾‾ ‾‾‾‾‾‾‾‾ ‾‾‾‾‾‾‾‾‾‾‾
NodeJS and C-service runs on the same virtual server.
The front end server ... |
I am developing a simple RESTful service for tournaments and schedules. When a tournament is created through a POST request containing a JSON body, the tournament is inserted in a BiMap, declared as follows in a DAO implementation:
private BiMap<String, Tournament> tournaments = Maps.synchronizedBiMap(HashBiMap.create(... |
It's really nice to have automatic binding with Jersey-Jackson (well, I believe it's actually MOXy the one who manages the bindings), so object serialization and deserialization is done under the hood.
Examples of both that I use in my RESTful service:
@POST
@Consumes(MediaType.APPLICATION_JSON)
public String createTou... |
I recently picked up learning PHP and MySQL and I am trying to build a small usersystem as a coding exercise. While learning to use classes and functions, I also stumbled upon the MVC model and would like to implement the model in my code.
Is the following approach correct MVC?
index.php, message.php, user.php are all... |
I have an ASP.NET Web API 2 web service. This is the interface customers will use to submit data.
I have a Windows Service running on an internal server. I will be sending the customer's POST data to this service adding a unique ID to the message.
There exists another service running on another internal server that wil... |
After many hours of research and thinking I have found an understanding, then coming to question it again, I am struggling to find something concrete which I can grasp and apply to my code in a practical sense going forward.
I think I am referring to presentation logic and a domain model. I have read numerous articles ... |
I don't know if this is a thing but here's a silly idea. Often there are cases when you have to refactor code such that you need to change code pertaining to some particular area. This may involve changing functions or variable calculations spread across multiple files. Let's say I tag these places with a comment sayin... |
I have the following requirements:
Load data from a variety of sources and fill a list with it
Use a batch of data to perform some computation
Some additional information:
The algorithm for computation expects the list of data to be ordered by a key that comes with the data.
I want to use a queue instead of a list i... |
I have some data that I need to represent in a form. As an example, it might look like this (in psuedo-json):
[
{
"value1" : "int"
"value2" : "{1, 2, 3, 4, 5}"
"value3" : "int"
}
{
"value1" : "{1, 3, 5}"
}
]
So when I display the first form, the user should have an integ... |
Someone in a Stackoverflow post (I didn't bookmark the question unfortunately) commented, that Factories that only return one type of object are a code smell.
I find myself writing these kinds of factories pretty often. Sometimes because i don't want to bloat my code with constructor overloads and sometimes because i j... |
Is it possible to design an Applicative Functor with a few extra stack manipulation functions push, pop, and a specialized branching function ifA :: forall a. f Boolean -> f a -> f a -> f a, and achieve a model for computation that is equal in expressive power to a Monad? (Can express any program that a Monad can expre... |
With event sourcing, you can project an event to create query-optimised read models. This I understand. What I'm unsure about is whether these read models can depend on each other?
I'm considering pre-generating HTML pages and PDF reports in a certain part of an application. The HTML pages are not interactive, but rath... |
What exactly happens underneath (I know it changes the paragraph tag's HTML when the circular div is clicked) when I run this piece of code? Could you please explain the callback function as well.
<script type="text/javascript">
$("#circle").click(function() {
$("p").html("You clicked the circle");
}
<... |
I'm developing a Java application that will handle huge XML files (up to 300mb each and hundreds of thousands of lines). They are grouped usually with 20 to 40 similar XML files that also need processing. Work will be mainly CPU-bound, with some IO-bound related to opening the files and saving back the results.
I was w... |
I have often wondered about the implications of shortening code by assigning temporary variables with shorter names to data accesses with long names. It's best illustrated by an example (in Ruby, but not that it matters):
This long code is ugly, IMO:
# Trim the description to MAX_LENGTH characters followed by "..."
# i... |
I'm working on an interface for implementing business rules in order to improve SOLID-ity; so I can move a lot of logic out of Web API controllers and into a business library. The Common Problem being that an action should occur if one or several conditions are met, and some of these conditions are likely to be require... |
I have a system which consists of two applications.
Currently, two applications communicate using multiple zeromq publish/subscribe sockets generated for each specific type of transmission.
Sockets are programmed in C.
For example, AppX uses a subcriber socket for receiving an information struct from AppY and uses a ... |
The problem is maintaining in .net a list of rows that have a specific sequence where rows can be inserted, moved and deleted, and being able to save and restore that sequence from disk.
In memory I can use a .net list with insert and delete by index position. The alternatives that I see for converting that to a disk... |
An enterprise utilizes the source code of a network software product licensed under the AGPL v3. It modifies the source code but does not share the changes with the original developer and copyright holder, and keeps the changes private. It then hosts the modified version within its servers, but does not distribute the... |
I know it's generally a design flaw to have an empty class, yet I'm wondering whether there are some cases where it isn't to have an empty (abstract) class to group objects. Especially when polymorphism is needed.
For example I have a group location. They can consist of an area, a line (a road for example) or a specif... |
This is a question more about using volatile to prevent optimization than about caching write/read of a variable. Particularly timer delay variables since I don't want to declare everything volatile and waste optimization in doing so.
First off, I know the following snippet will not work if optimization is turned on un... |
I'm developing a video web system like YouTube where users can upload, view, update and delete their own videos (CRUD operation). Original I drawn the use case diagram like this:
But I learned later that it's better to use one use case called "manage video" to simplify the whole diagram where there are a lager number ... |
I am using an array of objects to store data to render a page.
A few examples of the type of data each object can contain:
PHP filepath for an include
CSS filepath for CSS files
Meta data of the page
Element data to build page elements
Etc...
I have an HTML template file that I parse with PHP and replace certain tags... |
I always wonder what is the best way to design your property files. I have few questions that I didn't find an answer to them
Do we place all our labels / error messages in one file?
Do we split the files, one for labels and another for errors (more logical and practical solution)
Do we make a property file per projec... |
Our team is currently developing a hybrid application. It is similar to Sigma Estimates - a GUI with tables, forms, a sidebar with a tree structure, etc. The software allows a user to work with a database in the cloud - create table structures according to records in the database.
If the connection to Internet is avail... |
I use @SuppressWarnings("unchecked") and @SuppressWarnings("null") mostly above methods to let the code compile without any warnings but I have my doubts. Found this Stackoverflow question. Jon Skeet wrote an answer to it which I find intriguing.
According to him,
Sometimes Java generics just doesn't let you do what y... |
Should I use HttpUtility.HtmlEncode or write an extension method?
Pro for using HttpUtility.HtmlEncode is that other developers can instantly see and recognise what it's doing.
Pro for using an extension method is that it's less code to write everywhere and less noise.
So I guess I'm asking obvious readability vs tidi... |
Let's consider the rule in python PEP8, coding standard for the linux kernel etc saying that a line of code are not allowed to be longer than N characters.
To this rule there is normally a few rationales:
On some terminals you can't see more than N characters on a line without wrapping.
Optimal line length for readabi... |
Let's assume you want to change what user sees on the website.
There are two ways to do that:
a) manipulate the DOM via JavaScript, but user has to download whole script, with possibility he may not need that script. More bandwidth is wasted. Also this limits what you can display.
b) rebuild the whole page on demand (i... |
I'm working on a graphics library that works a bit like the Android-type libraries and I ran into a question regarding the topic of margins and whose responsibility they should be.
It seems very common for graphics libraries to put the margin on the element itself; ie if you want to clear 10 pixels of space around an e... |
I have this random number generator, and have had it for quite some time, but despite how much I use it I don't really understand it.
public static int Random(int x)
{
x = x + seed;
x = (x << 13) ^ x;
return (x * (x * x * 15731 + 789221) + 1376312589) & 0x7fffffff;
}
It works really well for my purposes - ... |
Lately I've been working on a project that involves parsing a toy domain-specific-language. While building it out, I realized that an efficient way to handle parsing tokens would be to represent the parser as a state machine. To great success. Representing each possible state of the parser got rid of many problems I wa... |
I have a Spring application, where we make few service calls to fetch data. There is a Data Layer in between the Controller and the Service layers.
Controller (Request-Mapping) -> Data Layer -> Service Layer
If we do not get the data from the underlying service, we intend to throw an exception. My question is regardin... |
I have some (or just a little) experience in writing web application
backend with interpreted language, php, python and javascript
(node js). When writing the backend app, usually what I do is write
some code, see the result on the browser, if anything wrong fix the code,
see the result on the browser, and then add som... |
I have been working for a few weeks on a new web project and I am realizing that all I am doing is basically calculations and transformations on data, and that most of my classes do not contain any state and could perfectly be turned into static classes with static methods. Therefore I am thinking that this could be a ... |
Recently I have been reading the book, Scrum Shortcuts Without Cutting Corners by Ilan Goldstein. Goldstein mentions that when practicing scrum, you will write user stories and you will write task for those user stories that would then be assigned to one individual. The problem is when I got further into the book, Gold... |
I have a somewhat popular open-source project on Github, and I'm getting ready to do a major overhaul - completely different directory structure, substantially different versions of major components, and lots of files that simply won't exist anymore.
I don't want to create a completely new repo, because we will lose al... |
There are at least two distinct memory management models:
Java (we do it for you)
C++ (it is your responsibility)
I have two questions:
(1) Is GC language specific or compiler specific?
(2) Do most languages fall in one of these two categories? Are there other memory models in commonly used languages?
The names of ... |
I am working on a feature where I need to store some data and I am not sure what should be my best option to store this data.
I am sending data to some third party and want to show some part of that data internally in system dashboard.
Data is being calculated at run time and being sent to third party.
Since the base ... |
I just "fixed" an intermittent failure by this process:
Observe intermittent failure
Debug code; at one point near where the failure could be, pause execution, and inflict harm upon a variable (by, say, setting it to null)
Failure occurs
Fix the failure you just inflicted
Declare success
It's related to voodoo debugg... |
I'm beginning an open-source project for logging work hours. The intention is to build something similar to Git, where instead of pushing code you're pushing information about work hours and progress.
I intend to make a PHP SDK for interaction with this program (and hopefully SDKs for other languages in the future), bu... |
In the build lifecycle in maven, I encountered the validate phase described as validate the project is correct and all necessary information is available to complete a build
1. what are the check points for a project to be correct?
2. what are these necessary information that needs to be available in completing a build... |
Suppose, I have class Boss and Worker; Boss has a Worker and Worker holds a reference of Boss:
Boss.h
#include "Worker.h"
class Boss{
public:
Worker worker;
};
Worker.h
class Boss;
class Worker{
Boss* boss;
};
In C++, Worker doesn't need Boss to compile, but I am not comfortable to see the word "Boss" appear ... |
Just a basic question on IF statements in programming languages, specifically C++. Consider the following basic code example:
int i = 2;
if(i == 2 || i == 4) {
//do something
}
Because the first condition would equate to true, are CPU cycles wasted on the second condition? Sorry for the Programming 101 question, ... |
I've been searching for tons of websites for how an interpreter works, but I found none of these explain how Interpreter works internally. But I found in many places how compiler works with all the steps and descriptions.
So my question is, how does an Interpreter work?
|
I was modifying a class whose job is to load other classes from the same directory. Basically, everytime a new class is added you need to add a new CommandClass; statement to this class for it to be loaded.
I thought that it's strange and violates "Closed for modification" principle, so instead of adding another line t... |
This is a general question on a subject I've found interesting as a gamer: CPU/GPU bottlenecks and programming. If I'm not mistaken, I've come to understand that both CPU and GPU calculate stuff, but that one is better in some calculations than the other due to the difference in architecture. For example, cracking hash... |
I've recently used typescript, and I think the ability to mention or not types is great. It greatly reduces the debugging time while also giving you the advantages of an untyped language. I could imagine a python language superset with the same functionalities, I'm sure the type specifications could be used to greatly ... |
I am trying to figure out how an AMQP broker, such as RabbitMQ, can be integrated in our architecture. This should allow to easily scale horizontally in the future.
For the sake of simplicity, let me ask the question via an analogy.
Say you have:
A set of bank accounts. We assume that the the number of accounts can gr... |
UDP provides no guarantee for delivery and no protection from duplication and is connection-less protocol but why then DNS uses UDP protocol. Please make me clarify.
At what conditions we should prefer UDP over TCP protocol?
|
I found out that the package name should follow the web domain you own for this application / developer Id.
I published an app starting with com.health... (example) because I didn't know better at those times. In how far will I run into (legal) issues (if any), because I am not the owner of health.com (example).
Should... |
I have a requirement to write a POST endpoint where the payload is huge(not normal). In the order 10s of Megabytes. And this endpoint will be accessed by a lot of clients (in the order of 1000s) simultaneously.
How should I go about designing this endpoint?
The expectation is to validate the incoming requests and sen... |
Password reset option should be given only if the link has come from that specific user's inbox and not from somewhere else. How to implement url in such a way that the required information i.e. Mailbox can be obtained from the url? Facebook and Twitter like companies seem to have already implemented it. Any suggestio... |
I'm now doing my internship in a government company (in India) and I've been assigned a project to create an online forum for the company..
I'm about to use phpBB forum software to create it, which is licensed under GPL. The created forum will later be put online in the company's website.
Now my question is, does the g... |
I need to create a class which will have the following structure:
public class MyClass {
ArrayList<File> myList = new ArrayList<>();
public void addFile(File f) {
myList.add(f);
}
public void DoHeavyWork() {
for (File f: myList) {
/// ...
}
}
}
I was thinking on th... |
I've heard that it's ideal to have one assert (or expect or should, etc) per aspect of a component's behavior you're trying to test. Is this how it works? An addOne function would be tested like this, I suppose (example is written in javascript syntax):
it("returns one plus its input", function() {
assert(addOne(5) =... |
As you read in the title, for example, i wanna login to my account in StackOverflow by sending the E-mail and password through a program developed in c language, so all what i have to do is to enter the required data (E-mail, password) in my program and after refreshing the webpage in the browser, i'm directly connecte... |
Suppose we are using java or python to access the database. Then is it considered a wastage of time and unnecessary to learn the kind of data structures and objects being used inside sql?
Please answer in reference to the software industry.
Please try to tell in which cases it will be good to have knowledge of such thi... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.