instruction stringlengths 34 36.1k |
|---|
I'm building an application that is responsible for reading data from files and displaying them in charts. The whole application is responsible for manipulating data from files, which means I have to use different parts of the same object in almost every part of my project. Charts need actual data, list of opened files... |
I have a Document class and a DocumentItem class. A document creates multiple DocumentItems.
As my project has evolved, I realized that DocumentItem needed some "deep" logic to properly display, first checking a database, then the web. My code ended up looking like this:
class DocumentItem
...
function getValue()... |
I sometimes stumble upon code similar to the following example (what this function does exactly is out of the scope of this question):
function doSomething(value) {
if (check1(value)) {
return -1;
}
else if (check2(value)) {
return value;
}
else {
return false;
}
}
As you can see, if, else if a... |
What database design would you suggest for the following example?
Example: Imagine a bus with some people inside. Every person has some attributes like name, etc. Also there are driver- and passenger-specific attributes. Every few hours the roles change - meaning, that the driver becomes a normal passenger and one of t... |
I have a function
function name(src, dest, remove) {
copy(src, dest);
if (remove) {
delete(src);
}
}
What name should I give to that function? Alternatively higher order function like this:
function name(remove) {
if (remove) {
return function(src, dest) {
copy(src, dest);
... |
While working on a project, I decided to create a database class to manage my DB connection. I started looking for the best practice to do that, which is usually either a static class or a singleton pattern class.
Answers I've found, such as:
http://javarevisited.blogspot.com/2013/03/difference-between-singleton-patter... |
I've been a proponent for training on our team since I've started with a new company. I'm dealing with two newer technologies now and my peers have given me their opinion that additional training would help everyone, including some new hires to the team. However, management hasn't bought into this idea. They say yes... |
I heard that Lua is great for configuration files, so long as you are secure about it. Lua has been used as config files by programs such as awesome and (recently) conky.
However, I also heard that using programming to configure a program is an anti-pattern.
Since Lua does not get compiled as part of the program, would... |
I have read at a few places, that Postfix is easier to evaluate & easier to convert to Code than Prefix.
I understand that if you parse a prefix expression from left to right, you might not be able to evaluate directly(as some operands might be prefix expressions as well); but if you parse the prefix expression from Ri... |
What I want to Achieve ?
I want to dump all logs in a single line which got collected during a request.
Why I am doing this?
General approach, i.e. logger.info(), dumps log in file at same time when you call function. Due to this, Logs get mixed up and can't read them sequentially as multiple threads are using same fi... |
A closure is a record storing a function, together with an
environment: A mapping associating each free variable of the function
(variables that are used locally, but defined in an enclosing scope)
with the value or reference to which the name was bound when the
closure was created. (Wikipedia)
Here is what I... |
Recently I am using a software package which seems pretty useful, but which I don't understand how it works internally.
This package contains software generated by several PhD students and lecturers of an university among several years, which reflects in code style. There are several papers related to pieces of this s... |
I've made a program to play TicTacToe against a human using a Monte Carlo Tree Search (MCTS) with UCB1 for node selection. The program will play moves until it wins but it will not make any attempts to block the other player. Is this the nature of the algorithm or have I made a mistake in implementation?
|
If you imagine a company like Amazon (or any other large e-commerce web application), that is operating an online store at massive scale and only has limited quantity of physical items in its warehouses, how can they optimize this such that there is no single bottleneck? Of course, they must have a number of databases ... |
I'm developing a server which provides a virtual block device via SCSI interface. The device is constantly bombarded by requests to read/write data blocks. Sometimes I need to lock this device (or make it read only) just to perform some device-wide operations on it - for example, a full backup.
I worry about incomplete... |
I have a console application (dotnet core, ubuntu), that looks like following:
void Main()
{
try
{
var job = new Job();
job.Start();
while(Console.ReadLine() != "quit");
}
catch(Exception e)
{
//some handling
}
}
While Job is implementation of JobAbstract class:... |
my question would be can age be considered a composite attribute? Because name is a composite attribute and it can be divided into first name, middle name and last name. And therefore can age be a composite attribute since you can divide it into years, months and then days?
|
I am trying to develop an algorithm, but I barely can describe it so I'm not sure what to look for.
I have two images img_A and img_B. img_A is the original, while img_B is an image of the same item but slightly different. Let's say one is a photo of a person, while the other is a drawing of that same person. This mean... |
Please excuse the long post. There is a question, just bear with me.
A Little Context
We have a site which is required to adapt considerably based on a variety of user settings, the group the user belongs to, where they come from and other things. We used to include the relevant bits on the model for the page, so if th... |
I'm moving from a coupled architecture to a decoupled architecture using microservices with AWS Lambda.
Here is my current architecture:
Each API Gateway route is linked to a specific Lambda, each of them has a specific task, but they all share common code.
Pain points:
- I have to deploy all the Lambda when modifyi... |
Consider the following C API:
void BeginTransaction(State *s);
void AddToTransaction(State *s, Object *value);
void CommitTransaction(State *s);
void Foo(State *s, Object *value)
{
BeginTransaction(s);
AddToTransaction(s, value);
CommitTransaction(s);
}
I created a C++ class to wrap this API:
class StateT... |
Like the author of this question from 2012 and this one from 2013, I have a 3rd party library that I need to wrap in order to properly test my application. The top answer states:
You always want to wrap third party types and methods behind an
interface. This can be tedious and painful. Sometimes you can write a
co... |
In the below tree,
typedef struct lcrsNode{
void *item;
struct lcrsNode *parent;
struct lcrsNode *firstChild;
struct lcrsNode *nextSibling;
}lcrsNode;
typedef struct Tree{
lcrsNode *root;
int size; // Number of nodes;
}Tree;
What are the advantages of maintaining parent pointer in a tree node? D... |
I'm working on a piece of software in Visual Studio. I created a PKCS#12 archive in Visual Studio to strong name sign my assemblies. I then extracted the public key from the archive using OpenSSL.
I realise that I must remove the PKCS#12 archive from the VS solution before making it publicly available but what do I do ... |
I'm in charge of switching our 10+ years old code base from SVN to Git. Currently we have one single monolithic repository containing all of our projects. We have shared libraries and multiple projects using said librairies.
I've been looking for a way to host all of our projects into seperate repositories. I have lo... |
Is it fine not have any post-condition in a test case?
For example, there is an employee information system or module and an employee can login into the system and views his/her profile and logs out.
If I write a test case for it, I can't think of any post-condition possible in this test case. Can I write it without p... |
I've been working at my job for about a year. I primarily do work in our GUI interface which uses methods from a C backend, but I generally don't have to deal with them except for return values. Our GUI is structured pretty reasonably, given our limitations.
I've been tasked with adding a function to the command line ... |
I am creating an application based on the cloud for the management of articles. I'm also a desktop developer so I never had problems with the internet absence, mainly because I was working with db locally, and then on the user's PC.
This time the app is on the cloud, then I would know if there is a way to continue work... |
Representation 1 - Multi walk tree
typedef struct multiWalkTreeNode{
struct multiWalkTreeNode * parent;
void *item;
struct multiWalkTreeNode **childPointer;
}Node;
typedef struct multiWalkTree{
Node *root;
int size; /*Number of nodes in the tree*/
}Tree;
Pictorial view:
Representation 2 - LCRS tree
typedef... |
I am not familiar with the various options you have when dealing with COM components. A legacy system in our company has published a COM API with a mixed mode dll to allow .NET components to interact with it.
It also allows the legacy system to run out-of-proc.
However, when setting up a simple windows app, it seems th... |
Let's take some blogging application.
User in this application has email, password. When a new user is registered, he should activate his account (for example, via email). But... is account activation, password, password reset tokens, etc, are domain concepts?
So I'm thinking to divide User concept into 2 parts: Accoun... |
I am currently on an angular 1.x project, and we are about to add user interactions that will cause data changes.
We already identified some flows in our app that seem like flux might resolve, so we are going to use flux.
We don't yet know flux, and the libraries that exist today seem like an overkill.
We have an id... |
Our agency is currently using and maintaining the CMS we have developed in .net MVC on SQL server.
Since the cms is highly optimized and uses various cache tables to run very fast even with thousand of pages we want to keep it the same and use it for some php websites we will do in the next months.
In this condition yo... |
My web application has a dashboard page written in angularjs that is intended to be displayed on a screen in a room as a way of monitoring the information therein.
It's a dumb screen connected up to a machine with no easy access to input devices so I want to minimise the need to interact with the browser window. This ... |
I am looking for help designing the code to create a menu displaying multiple categories. Currently, the code (classic asp) makes a call to the database and then loops through the results, so it is all inline. I am porting the code to MVC 5/C#. What I am doing now is getting all the categories from the database, pas... |
What is the recommended option to design a privilege system?
My application has some users with several roles(Admin, consulting, expert, reporter..)
Each role has some privileges (read document, write document, send mail, read mail, write mail, read book, write book...).
Is a unique privilege must give access to only a... |
I read "The Why of Y" from Richard P. Gabriel. It is an easy to read article about the Y combinator, which is quite rare. The article begins with the recursive definition of the factorial function:
(letrec ((f (lambda (n)
(if (< n 2) 1 (* n (f (- n 1)))))))
(f 10))
And explains that letrec can be def... |
I am currently initiating myself to the latest RC of Angular 2, coupled with typescript. So far, I really love it, but I however already stumbled upon a few existential concerns.
The @Component annotation, along with the class approach of typescript, are intented to encourage code and component reusability. But, there'... |
I have created a complex query that references a specific date (year and month to report on) on numerous parts of the script. What would be the best artifact to have to only change 1 line of code and have that cascade to all my script each time a new reference date is needed?
I understand that there are issues declarin... |
In C++, size_t (or, more correctly T::size_type which is "usually" size_t; i.e., a unsigned type) is used as the return value for size(), the argument to operator[], etc. (see std::vector, et. al.)
On the other hand, .NET languages use int (and, optionally, long) for the same purpose; in fact, CLS-compliant languages a... |
I have to program a generic client that uses diverse concrete clients (diverse APIs), all sharing the same interface. I have to log the response of the client.
To accomplish this (logging in background without user having to manually do it), I created these classes:
Request, Response, ClientService, Client1, Client2, C... |
I'm working on a project where we are creating some REST APIs
My question is when we are creating an API to update an entity that contains a children reference, i.e.
{
name: '...',
email: '...',
country: {
id: xxx,
name: 'xxx'
}
}
Does the update api accept a country object or just a co... |
I recently joined a software project and discovered that the current architecture relies on line numbers of input data files. For example, the data on line 248 of an input file corresponds to file ID 247.
My gut tells me that this is dangerous and bad practice, but I'm too green to be sure. The people working on the pr... |
I have an ASP.NET Web API application. It uses enums for some fixed sets of states or types. Now I need to extend enum to support more values. But it will break backwards compatibility so I need to create new version of method. Is it better to use strings for this purpose? I suppose I can easily extend a list of possib... |
I am building a simple Q&A app with PHP, HTML and JS. I have three tables: users,question and answers, each table has it's own primary key and questions and answers both have foreign key constraints. questions store users.uID to look up author, and answers store question.qIDto identify which question they belong to, an... |
We have an enterprise application. Maven build, about 20 submodules with more submodules. We have a dedicated Ops (operations) which deploys our application to 10 clusters. Installations are running different versions, about 5 customers total. Language Java. We are actively developing all parts of the application so ev... |
During prototyping a simple ddd application from public transit domain I've faced a problem with one value object - Transit Pass:
Each Customer can buy a transit Pass thatallows a passenger of the service to take either a certain number of pre-purchased trips or unlimited trips within a fixed period of time. A detaile... |
I am a software engineer of 10 years and wondered what other people have found effective in stopping a codebase from degrading over time. For example, some of the issues I have noticed are:
large technical debt
loss of knowledge from companies due to personel changes
complex upgrade and migration strategies between ... |
I have read for three days about the Model-View-Controller (MVC) and Model-View-Presenter (MVP) patterns. And there is one question that bothers me very much. Why did software designers invent MVP, when there already was an MVC?
What problems did they face, that MVC did not solve (or solved badly), but MVP can solve? W... |
I m studying DDD in a development context, and it seems that I've misunderstood something.
Actually, I was thinking that an Entity is the object that can be persisted on a storage support like a database.
But does it mean that the entity is the same thing than a row in my database ?
I mean there, can it exist objects b... |
What is the best practice for detecting piracy in a SaaS or Web based app where the user can share their login?
User is licensed to use the login on multiple devices. So how do you differentiate between that and sharing that login?
Approaches and issues
Detect simultaneous login on 2+ devices. Can be challenging to ca... |
If I have data that I will only need to update very rarely (once a month), would it be a good idea to use a JSON file instead of a database table with only 1 row?
|
Same system this site uses for example. You can vote down or up, but your votes are persistent between logins so you cannot cast duplicate vote, only change your vote to the opposite.
How would one go implement this?
Only thing that I thought of is having an extra field in database row, that would store the IDs of use... |
I am trying to learn the difference between a production system and a rule-based system because it seems to me that they are the same thing basically. I know that both refer to programs (system) that can create Artificial Intelligence Software and Expert Systems.
Can a production system be something else than a rule-ba... |
I want to create a minimal polygon which approximates the boundary of an arbitrary (semi-random) shape.
By "minimal" I mean, "as few points as possible".
The original shape (to be bounded) is in bitmap format, with simple coloring.
The complication is that the shape may have lines (i.e. long thin areas/shapes) coming o... |
Why does Swift use this function notation:
func greet(person: String, day: String) -> String {
return "Hello \(person), today is \(day)."
}
Like, I don't get why it uses the small arrow -> notation to specify return type. func identifier() -> Type instead of something more sensible, like Type identifier().
I have ... |
So I'm currently building an application that allows a user to fill out paperwork digitally, and then that information is taken in by the server and a PDF is populated and returned to the user.
The internal logic for each page is pretty similar:
Receive Request from client
Open proper PDF template from file system
Ite... |
I have a service which is an API client.
It's goal is to instantiate a concrete client you tell it (different providers), implement it's methods (createRequest and doRequest) and forward their call to the concrete client, so, it is a proxy.
But also, it needs to persist the response of clients to a database in a trans... |
Assuming I have a RESTful service and it always responds in this format:
{
"error": {
"code": ...,
"message": ...
}
}
or
{
"data": ...
}
and there is a method like POST /users/me/change-password.
What would be the correct and RESTful behavior:
Business logic / validation errors are data... |
I have a question about the object X.equals(Y).
I use Sonar and it says that I have to move the "" string literal on the left side of this string comparison: !date.equals("").
So I did that: !("").equals(date) but I don't really know if it is right or not.
|
Now I'm commenting on both on interface class and implemented class.
But sometimes, I feel it's unnecessary commenting both.
So I want to hear from Pros which is a better way? commenting on both? or only on interface class?
Example)
/**
* Google Analytics service interface
*/
interface IGoogleAnalyticsService {
... |
I've run into bit of an issue on implementing a count system in my project.
I have a system where users can like a post. Should I keep a count of it in the same table like
or should I remove the like_count column from the post table.
My concern if I have like_count column in the post table is -- frequent update of the... |
I'm building a smallish library (few kLOC) which processes stream data in C++. From the streamed data (comes in packets) the library compiles a database piece by piece and naturally has to convey that information back to the host application.
Since this is my first library I'm unsure how to proceed with the API/Interf... |
This article claims that a data class is a "code smell". The reason:
It's a normal thing when a newly created class contains only a few
public fields (and maybe even a handful of getters/setters). But the
true power of objects is that they can contain behavior types or
operations on their data.
Why is it wrong ... |
A scrum team has grown over the dezired size, which makes it difficult to organize and plan work. The team works on a component that is used on multiple projects, that every now and then needs customizations that are based on the baseline product. The reason of the team growth is that there was increase of the load of ... |
One of the things I struggle with when unit testing is deciding what behaviors to actually test. I think part of my struggle stems from how most unit testing tutorials don't use good examples of things you would actually want to test in real life. For example, the tutorial I'm looking at now has a test basically like t... |
Haskell keeps the computed values of functions. This can be done only up the the storage limit. When the storage limit is reached, how does Haskell decide which computations to keep and which to discard?
|
I've been experimenting with layered, use-case-centric architectures as described in Uncle Bob's Clean Architecture blog post. Most of the examples I've seen are simple "update the customer record" use cases, which make sense. Where I get a little lost is when it comes to creating objects.
To make things a little mor... |
I am looking for an efficient way to compare 2 images and get the changed areas as a result.
My current attempt has the following steps:
Compare each horizontal line and keep the changed line index in a list
Compare each vertical line and keep the changed line index in a list
Iterate over each changed horizontal line,... |
The code is difficult to follow but it appears to be (mostly) working well, at least with superficial testing. There might be small bugs here and there but it's very hard to tell by reading the code if they are symptomatic of deeper issues or simple fixes. Verifying overall correctness manually via code review however ... |
I have to design a Stock-Keeping Unit (SKU) for my downloaded products and I am looking for any advice on how to choose a standard.
More specifically, I would like to know:
Are there any character limitations, or could I use unicode in my sku?
Could I use Linebreaks or Tabs in my sku?
Should I bother with bar codes o... |
Based upon definitions I have read of the term deprecation, I get a general sense that deprecation is usually reserved for moving on to other methods/classes for good for reasons such as (and I borrow from Wikipedia):
The feature has been replaced by a more powerful alternative feature.
The feature contains a design f... |
I'm a novice at Object-Oriented Designing and have read some OOD books & tutorials recently. Now I'm planning to implement a video player(based on existing media api, AVFoundation or MediaPlayer etc) to practice what I've learned.
The idea is that given a video file, open it through certain media api, and then feed eac... |
I have built a Windows-only desktop application which is composed of two main executables and various configuration files.
The two applications are developed in different languages (JS and C++, respectively) and should always be in sync with versions (ie. appA-v1.0.exe would probably be incompatible with appB-v2.0.exe... |
What I mean by Internal and External API's:
Internal API: will be used by my front-end Apps (Web or Mobile).
External API: will be exposed to developers in order to integrate with my API from their systems.
Who can access my API:
My Admin Panel Web App (with multiple roles: Admins, Managers,..).
My User Web App (regis... |
That's a very vague title but I couldn't think of a better way to word it. But, just as an example, think about the direction that a character in a game is moving in. It just feels kind of wrong to be using a string and then doing things like if(character.direction == "left"). It seems to me that it leaves too much roo... |
I'm trying to implement a generic graph search algorithm in C++, as part of assignment at university, and I encountered problems when trying to implement it, mostly struggling with templates. this is the basic UML of what I'm trying to implement
Currently I have the bfs implemented, but our instructor told us we migh... |
I've just recently noticed there is an option to have static methods in interfaces. Same as with static fields of interface, there is an interesting behavior: These are not inherited.
I'm unsure it's any useful in the actual interfaces that are to be implemented. However, it enables the programmer to create interfaces ... |
I'm in the early stages of learning design-by-contract (DbC). And I think that if followed correctly, it can produce very high quality software. This gets me wondering though... why isn't it used a lot? Are there some issues in using it effectively within the typical software development process? For instance, does it ... |
All of us have some utility classes, which contain only static methods, for usage from different sources. Now, there can be two approaches which can be taken towards testing this piece of code.
Approach 1:
Have separate unit tests for utility classes. Wherever they are being called, mock out their interaction using som... |
Within IEEE Std. 12207-2008 is a description of the Software Development Life Cycle. Important for my purposes are the standards that derive from this regarding documentation. What I'm looking for is an IEEE (or ISO/IEC/IEEE) standard which describes documentation requirements for a Software Development Plan (SDP).
I'm... |
Firstly, some context.
I'm working in a project with more than 10 years of development and without any documentation. My task now is to create a comprehensive documentation for the database (it is a SQLServer database), including a dictionary with all columns of each table.
After some analysis, I found some obsolete co... |
in android, who takes care of the screens flow?
A screen closes after an operation and another screen opens. Which screen will be opened is a result of a complex logic.
I tried to do the flow in service, passing views as parameters to service methods, to let the service decide in which case will the screen close and st... |
in Gradle, when you include a library, you have to add the version number at the end, as such:
com.android.support:appcompat-v7:X.X.X
But a lot of times, understandably, the website for libraries don't tell you what the actual latest version number is on their front page, or in their "getting started" guide, and I end ... |
My company has several products on the market, developed in multiple offices in Europe and the US, which use the same common library. This common library wraps up a lot of industry-specific details, as well as adds some enhanced user controls, extension methods, math bits, etc.
Problems arise when QA comes back with a ... |
Using the Tree representation(mentioned below),
typedef enum {Running, Warning, Critical}Status;
struct TreeNode;
typedef struct List{
int childCount;
struct treeNode **childList;
}List;
typedef struct Resource{
char *resourceName;
Status resourceStatus;
}Resource;
typedef struct treeNode{
struct treeNode... |
I'm a developer still learning the complexities of a software system on a SCRUM team I joined recently.
I will be asked for a story point estimate for a piece of work that touches areas of the system that I have never worked on before. I am familiar with the technology used to build these areas, however I will need to ... |
Sometimes I discover that a commit I made two months ago had a bug. So I write a fix for the bug, but then I must choose one these ways of committing it:
I can commit the fix directly onto the main up-to-date branch (the trunk).
I can use a branch at the point of the original buggy commit, and commit the fix immediat... |
TL;DR - What criteria should you use to decide whether to 'do micro services'?
I lead a team of developers and one of them insists that we adopt a micro services approach to architecture. I was hesitant at first, because I had been coding under a rock for several years and never knew that micro services was a thing.
I ... |
I am working in WPF application and in need of a best design decision for one scenario. Basically, I am reading a .net assembly to extract the types and properties and mapping it to my own created custom classes to hold that data to make it serializable. While extracting, i required a way not to read the same type agai... |
I work on a big .NET project. It started more than 10 years ago, there is no ORM (NHibernate or EF I mean) and there is no chance to migrate to some widely used ORM (and for complex SQL queries ORM doesn't suite anyway). We use ADO.NET MS SQL provider with custom facade for datareader. We build select queries as string... |
I made some basic multi-threading tests here, and noticed that the speed increase when using the exact is bigger than I expected.
I assumed that speed would increase linearly until I hit the limit of cores, and then either stop increasing, or even slow down.
Instead speed increases linearly, and then JUMPS upward, but ... |
In my own variation of the command/query (CQRS) pattern, I define the following for a query handler:
public interface IQueryHandler<in TParameter, TResult> where TParameter : IQuery<TResult>
{
TResult Execute(TParameter query);
}
public interface IAsyncQueryHandler<in TParameter, TResult> where TParameter : IAsync... |
I'm a Scrum Master of a team that is working on developing a software & maintaining its production issues.
I'm planning to combine Scrum and Kanban. Where Scrum is for development, and Kanban is for production support, as suggested on many posts here.
I started with creating two separate boards for the product, but th... |
I'm building a RESTful API that uses JWT tokens for user authentication (issued by a login endpoint and sent in all headers afterwards), and the tokens need to be refreshed after a fixed amount of time (invoking a renew endpoint, which returns a renewed token).
It's possible that an user's API session becomes invalid b... |
1)
Below is a python function summation, that can perform sum of cubes/squares/.., similar operations.
def identity(k):
return k
def cube(k):
return pow(k, 3)
def square(k):
return pow(k,2)
def summation(n, term):
if n == 0:
return 0
else:
return term(n) + summation(n-1, term)
d... |
I recently completed a C project that uses GTK and OpenSSL. I have native binaries in linux and they run just great. However my new goal is to make as close to native as I can with a build for windows.
I've tried MinGW and it produces as a exe, however it crashes very easily, and gdb performs poorly when attempting to ... |
According to mdn's "Set" documentation, entries is provided as a convenience method
...to keep the API similar to the Map object, each entry has the same value for its key and value here, so that an array [value, value] is returned.
My question is what is the purpose of keeping the API similar in this case? i.e. whe... |
Please take a look at this AI system architecture proposal:
As you can see this is a multi-agent AI system for starcraft brood war that utilizes BWAPI AI framework, and I proposed this idea for the bot infrastructure architecture which consists of two primary neural networks where each one of these placed at specific ... |
I have a printer and SDK to work with it in Java. Printer working well with english letters and digits but doesn't print correctly special symbols like 'ä' or 'ê'.
I suppose that I need to convert string in charset used by printer. But I don't know what is the charset and has no chanse to get it now.
I run test printin... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.