instruction stringlengths 34 36.1k |
|---|
Assuming I have the following (very simple) class
class Foo
{
public:
void setAB(int a, int b) { m_a = a; m_b = b; m_aIsBigger = a > b; }
int getA() const { return m_a; }
int getB() const { return m_b; }
bool isABigger() const { return m_aIsBigger; }
protected:
int m_a;
int m_b;
bool m... |
We had in our system in the past an external data provider (call it source) sending regular heartbeats to a java application (call it client). If the heartbeat failed, system shut itself down (to avoid serving stale data in a critical application). This was straightforward as both data and heartbeat used the same chann... |
I have a vector that stores multiple instances of a type T:
std::vector<T> vec;
From time to time, vec is being sorted for different purposes. Now, I need a list of pairs of objects stored in vec, but (because of the reordering of vec) simply storing the indices is not suitable. Using the list of pairs, I would like t... |
Problem:
Winform app for servicing different types of devices (approx. 10 types).
Some devices have more settings similar (or same) then the others.
Each device could also has software and hardware versions which could change the number of settings.
Every device has big number of settings divided into pages (tabs) an... |
I need to write a basic code indexer, which needs to be fast. Should I use an embedded SQLite database for this or should rather rely on a custom data structure, or even flat files as used by ctags?
Some of my requirements:
Find all references of a variable.
Go to function implementation
etc...
Any pointers to docs ... |
We have a REST web service written in C# in ASP.NET MVC/WebAPI.
When the underlying data store fails, this can lead to our service being completely unavailable, instantly. There is currently no caching of data in the service. We're exploring caching patterns, however I have a feeling that our approach isn't going to ... |
I've heard circular references are generally an issue, however I was wondering if this was true for interfaces that reference other interfaces, for example:
IQuestion{
IAnswer getCorrectAnswer();
IList<IAnswer> getAllAnswers();
}
IAnswer{
IQuestion getQuestionInResponseTo();
}
Is there any case where this... |
Caller waiting for method to return back and till it is not returning, we can say thread is waiting, right ? However, this behaviour is because that inner method is waiting for some other operation or inner method in call stack to complete and return back. I am trying to visualize the behaviour of final operation which... |
I have some questionnaire data in CSV files for different projects. I created a function that takes a specific subset of columns and calculates aggregated values. The problem is that across these different projects, the column names are different but they still need to be aggregated in the same way
The way I'm handling... |
We update the software manually every couple of weeks (by copying over files).For the database we get their backup, apply the changes and hand it back over.In the meantime when we do a bug fix it's usually to do with the database and no code change is needed, but we have to message back and forth with the client's IT p... |
I am designing a unified response object for REST services application , so that the client always expect the same structure, be it an exception is thrown, a simple status is returned, a map of keys and values or a complex DTO.
The idea is that in any of the above case , I want to wrap the response in an object that co... |
"Single item in a set depends on the whole set. Set depends on that item."
I'm creating a compiler (https://github.com/SuperJMN/Plotty). In the last stage, the Intermediate Code is converted to Machine Instructions. I have them represented with the IntermediateCode and MachineCode classes.
To do it, I'm using the Visit... |
I need to implement a Google-Calendar-like scheduling web app. One of the requirements is synchronization with other scheduling applications, like Google Calendar, Microsoft Exchange, Office 365 and IBM Lotus.
I came to the conclusion that there are basically two ways of doing this:
Implementing a full CalDav-server (... |
I've written a User class like this:
<?php
class User{
private $id;
private $username;
private $password;
private $name;
private $email;
private $key;
private $phone;
private $is_verified;
private $last_login;
private $last_ip;
private $language;
private $is_loggedIn;
... |
I've been tasked with taking a sample of survey results that are stored in CSV and to convert them to XML.
I'm still fairly new to XML, but have come up with a couple of layouts I could use and was hoping I could get some advice on what way is best to go.
1)
<survey>
<response>
<id>1</id>
<questio... |
I have a simple data method that does this:
public void Write(Foo foo)
{
db.Foos.Add(foo);
db.SaveChanges();
}
I was asked to write unit tests for this. To do so, I had to create a fake DbContext and DbSet. I'm basically just asserting that Add() was called on the DbSet, and that Save() was called on the DbContext... |
Suppose that you have to develop a program which stores the products with their features and perform some operations on them, and you decide to design a class to represent the products. Each product has 10 different features. Three of them are numeric values. The remains are string values.
In this case, do you prefer ... |
Note: I'm not sure if the way I phrase the question initially will fit 100% on this board, so please help me to focus on the main point.
Scenario: You develop an algorithm or a neural network that performs a certain task, in the case of the algorithm in many steps that use input from the previous step(s) to compute som... |
EDIT: I have an ExcelUtility.java class to get cell data from it and pass it on to the tests methods in my test class.
I am reading from 1 excel file.
The excel file has 3 worksheets.
Every worksheet has 1 unique working table inside.
I have 1 Test class.
The test class has 3 test methods.
The test class contains 3 dat... |
I have a resource, let's say image.jpg. This image(along with other resources) is compressed in a .zip file (archive.zip) under the path /favimage/image.jpg. The archive is uploaded at http://example.com/down/archive.zip.
Now I want to address this single resource (image.jpg) using a URI over the internet. Is there any... |
I apologize for the potentially misleading and ambiguous title; I've tried to generalize it as best as I can.
I am currently working on an OpenGL project in C++. I wanted to wrap a couple of OpenGL functions into higher level objects. I ran into (what I thought was a unique) problem. I couldn't decide between having a... |
I publish my own software which is middle-ware and is used by other software engineers. I recently ran into an issue with a customer who is repeatedly sending emails and demanding support via skype and phone for the software he bought.
At first I spend a lot of time helping via email and later I even helped via Skype e... |
What I was taught in the university was we don't save the results in the database, but only the raw data which need for the calculation. For a very basic example,
if:
a + b + c = z
we only save a, b and c in the database.
whenever we need z, we retrieve a, b and c from the database and calculate z at the software laye... |
I have read this: https://stackoverflow.com/questions/25450380/can-value-objects-exist-without-entities, which says yes and this: http://enterprisecraftsmanship.com/2016/01/11/entity-vs-value-object-the-ultimate-list-of-differences/, which says no ("value objects cannot live by their own"). Therefore I have a simple e... |
I use code object != null to avoid NullPointerException. Is there a good alternative to solve this as follow ?
if (someobject != null) {
someobject.doCalc();
}
This will not work for NullPointerException, when it is unknown that if the object is null or not.
|
I have a CMake multi module project made of a library and an executable. Both the root project and each sub module has its own version (major.minor.patch).
I would like to know how to handle each version:
if root project changes version, each sub module goes through the same change
if a sub module changes version, wha... |
I have an interface:
public interface MyInterface{}
And two implementations:
public class Imp1 implements MyInterface {}
public class Imp2 implements MyInterface {}
My program is a CLI. I want to have some class, which would take command-line args, parse it and create new instance of correct implementation:
public cl... |
We have 11 tables for transactional data. Now, this data may have some data integrity issues. We have prepared a set of SQL scripts to fix the data integrity issues, which customer can execute from UI but some may need inputs from end-user.
In some cases, end-users comes back to us and asks us to revert the changes, b... |
Firstly, I am aware that this question links with the topic of game development but I have decided to ask it here since it really comes down to a more general software engeneering problem.
During the past month, I have read a lot about Entity-Component-Systems and now are quite comfortable with the concept. However, th... |
I am looking for an abstraction from which to solve a class of problems similar to the following:
I have this ordered ResultSet (in this case sorted for NATION,REGION,DISTRICT,COUNTRY):
CITY' Table
| NATION | REGION | DISTRICT | COUNTRY | POPULATION |
--------------------------------------------------------
ITALIA ... |
Preface
I have an ORM library for a relational real estate database. The used framework is peewee. The library contains ~60 models, each representing a distinct table. The models represent a (pre-defined, proprietary) real estate data structure based on XML. There is one top level table called immobilie (real estate), ... |
My presentation has an Array which contain field names and their values.
More precisely, each value is an object (like "User" for example) of the Model.
I would like to know if the presentation itself should perform checking on the content of those fields or should it be done by a contained class?
|
We've got a system where we create long-running batch jobs.
The jobs are created, they then run for x amount of minutes and they are then presented to the user for review.
The RESTful verb and endpoint names are fairly straightforward for creating a job.
POST: batch-job, creates a new job.
PATCH: batch-job, updates
t... |
I'm having a bit of a moment of indecision here and I'd like some perspective on it.
I'm currently wrapping up objects from a 3rd party API (at home for my own project and at work), and I'm doing my best to adhere as closely to SOLID principles as I can. All of this is written using C#. Just to be clear here: this is ... |
I used to do Java development and with JPA, I don't really have to worry about the synchronicity between a table and the lists it owns. For those who don't understand what I mean, here's an example.
Suppose you have a Person table and an Address table. A person can have many addresses. So when you update the person's a... |
I know this has been asked a few times but I still a bit confused, People say to have a git repo per project, but I not 100% what "project" means in this context.
I am going to have a reactjs front end, asp.net core web api.
Should I be making 2 git repos for this as they are 2 different solutions or since it is used ... |
I migrated some files from one Version Control System to another. I have to prove that content are identical (between source and destination, denote 1 , 2). There are a few zips files (lets call them A B C) each of which contains hundreds of files. I am looking at best way to do CRC comparison between content in old VC... |
For example : Customer --->(customer details) SEND DETAILS --->(customer details) --->Clerk
|
I'm pushing out a new feature soon that has a lot of different UX components. The key metric that I want to track is user engagement (I have the equation for what this means for me and how to measure it). What I want to measure is the best combination of the UX components that maximizes the engagement. The problem is t... |
I'm doing TDD. Let's say I expect some method m of some class C to call some function f (to keep things really simple).
How would I design a unit test which would pick-up and therefore fail, if m were to be implemented something like:
m(func f)
{
// let's say some_internal_counter starts at 0 when object initialised.... |
I'm developing a service in node JS that will act as a middleware for a client calling a third party API.
My service will make some security and user roles checks before calling the third party.
So when I call my service it looks like this https://myservice/:param1/:thirdPartyURL
I use the param1 to make some security... |
In a typical case we include an identifier like so:
/myService/products/1234
And if I wanted to get the products for a given customer we'd do this:
/myService/customer/999/products
BUT, what if I wanted to get the products for a given customer and I don't model customers in my system? My system just store customer ID's... |
This question came to me when I was trying implement Clean Architecture using Scala, and come across this post.
In the accepted answer, @candiedorange emphasis on the separation of responsibility, and do not break "Tell, don't ask" rule.
But this is still confused me.
As far as I remembered, "Tell, don't ask" rule didn... |
A pretty critical issue came up, which is more legal than technical, but I hope to find a lower cost technical solution. There are laws in some countries (I'll leave out name) where you have to keep data on a server in that country. It is impossible to completely separate the back end software from the database. The go... |
In Clean code it's suggested that private helper functions should always exist directly below the function they're directly used within. Should I be doing this when using computed properties? It's the norm to place private instance variables at the top of a class but in the case of what is essentially a helper function... |
I try to work with the MVP Passive View pattern for the first time. I get the basics but some small things I still don't understand.
My example : Imagine a simple view containing a textbox, a button and two labels. When the user clicks the button the text inside the textbox shall be shown in both labels.
Now I have 2 p... |
An application has types Game (and other business units) and Message.
(Message is not a simple class with text, but a composition of a variable number of blocks like texts, images, and videos).
These types are also part of relational database, with tables named Games and Messages. The user should get a message when the... |
We're trying to develop a cross-platform app for desktops (Windows and Mac) using C#. The app contains a massive amount of platform dependent stuff and our team lead wants us to write all of that code in C#. The easy way to do this would be to write wrappers in C++ and just reference the libraries in the C# code and le... |
I have a scenario where:
I have a REST API to manage resources, for instance workspaces. This REST API is closed in the sense that cannot be altered.
I want to CRUD workspaces but save additional information about them, which the main REST API does not support.
So, i create another REST API, call it client API, which ... |
To give some context, I'm using python. We have the following package structure:
/package_name
/request.py # defines class Request
/response.py # defines class Response
Let also assume that we have a bidirectional dependency at class and module levels:
The method Request.run returns a Response instance.
Res... |
I am junior developer among seniors and am struggling a lot with understanding their thinking, reasoning.
I am reading Domain-Driven Design (DDD) and can't understand why we need to create so many classes. If we follow that method of designing software we end up with 20-30 classes which can be replaced with at most two... |
I can see how interfaces are very useful to force different classes to have the same functionality.
But there are also actions that are bound to a specific class (like updating an unique variable that is used to implement a method from an interface).
Should I write a new interface to implement the methods that aren't ... |
How can I best document a code design decision in my source code? Should I just add a massive comment at a point I feel is right?
Or should I just create a separate file?
This issue is important for me, because the project that I'm workign on in the future may be taken over by someone else (or perhaps I will return to ... |
I've been writing some code which makes use of the 'import' statement to include code from other parts of the project and during the course of development I've had the need to restructure some of the code to other locations in the project tree.
The problem I've encountered when doing this is those import statements bre... |
There is a kind of rule in dependency injection literature, stating that we should declare all arguments in the constructor, in order to have a constructor injection, which is better than other approaches.
At first, there is nothing wrong with that.
But I’ve come to realize that this “rule” applies only to the realm o... |
I'm looking for some opinions/advices about a particular subject. Here is the situation : I'm developing for fun, in my spare time, a programming language interpreter made in C# and I'm looking for improving its speed. I've made a Lexer (works great !), a Parser (works great !), Optimizer (works great !) and Interprete... |
Consider the following constructor:
NetworkTools::NetworkTools(QObject *parent) : QObject(parent)
{
view = new QWebEngineView();
view->setParent(parent); // Produces an error, shown below.
}
While QWebEngineView is a QWidget, it is able to be utilized without ever having to open a widget window, using:
void QW... |
Trying to figure out how to keep class methods clean, follow EF's guidance of short-lived DbContexts, and use DI in WPF. Issue I'm having is implementing transactions with DI. I'm trying to figure out what the best way of handling this:
public class Repository : IRepository
{
public Repository(MyDbContext dataCon... |
I'm working on Web Application (ASP.Net MVC) that will allow users to edit a JSON object in the browser and save it to database.
To do so, JSON object will be sent from view to server side (controller) and will be converted to entities (C# objects). At that moment, I can perform server side validation. After that, enti... |
I am trying to reverse engineer a checksum or CRC wherein an 8 bit number* gets converted to a 5 bit number for error checking. I have an incomplete list of data values and checksums, and need to figure out the algorithm so I can fill in the missing data. I've plotted it out in hex and binary and can't spot a pattern... |
I'm working on a larger solo project and right now, and I have several classes in which I do not see any reason to create an instance of.
My dice class right now, for example, stores all of its data statically and all of its methods are static too. I don't need to initialize it because when I want to roll the dice and ... |
Context
I'm about to start a new project for my company1 which architecture will comprise several elements. There are 2 mobile applications (Android and iOS), a web API (Java) and an ETL (still deciding whether I use NodeJS or Java).
The system should extract data from several OpenData repositories (web APIS), transfor... |
I preserve old software by asking copyright owners (often one author) to release the source code under an Open Source License, GPL or MIT. In many cases the source is gone, but the binaries still exist. Often they were released under some home made license 20 years ago. If I'm correct the binaries could be released und... |
I created a new Asp.Net MVC web project. I took the decision to create two different apps, the first one would be a web REST API that would provide all data for the second one, which would essentially be a MVC web application without any database interactions. It seems to me like a great way to separate business logic ... |
I've been using this term with a loose understanding as heard in the phrases "uses base python", "built on base python" that basically suggests a python project that only depends externally on Python Standard Library modules alone.
I've recently been exposed to the lingo of system python, and seeing comments like # SYS... |
I've seen a couple other posts about people trying to run untrusted user inputted code into a eval or exec statement.
My implementation checks the code before hand for any import statements, makes sure there are no builtins on the exec statement and clears all the global variables. I also put checks in place for the us... |
I'm creating a program that analyzes comments in Word documents (in terms of their textual content). However, occasionally one who wants to analyze the textual data may like to change some of the comments content. Yet I think it's better to leave word processing functionalities to the word processing program itself and... |
I am building out a parser for a well-known track & field meet management software output file (sample output).
I can parse this manually, and put items into my object model (overview below), but it's a bit time intensive, and it's going to have manual issues.
FYI, I'm using C# but I have no problem crossing boundaries... |
I don't mean to come across as glib, but I feel that the clearest way I can communicate what I want to know is through some analogies:
CPython, gcc, javac, ... -> compilers
MS Windows, OS X, Ubuntu, ... -> operating systems
PCRE, re2, ... -> regular languages and FSM
Android Layouts, iOS xib files, HTML/CSS, -> ????
... |
So I've been working with background processing and event-driven systems, namely Azure WebJobs and ServiceBus. And while there is extensive use of async/await programming, I'm always wondering if it is generally bad practice to await asynchronous operations when not at all needing the results further in the program. Mo... |
I am working on a sports scheduling algorithm with several different constraints, one (two) of them being a minimum and/or maximum wait time between games. Of the same team, that is.
So if Team Blue is scheduled at 4pm (finishes at 5pm) in Field 1, and we have a maximum wait of 3 hours and a minimum of 1, then its next... |
I'm trying to define a base class and override it's items on different inherited sub-classes. I'm following MVVM pattern to fetch records from backend. Created several stores and formulas within ViewModel.
+---------------+---------------+
| NUMBER value | |
+---------------+ GLYPH value |
| STR... |
I'm wondering how I can document **kwargs in Python using sphinx dostring style.
For example I have the following method and I want to document more details about kwargs.
def get(self, url=None, **kwargs):
"""
InsReq get (overriding)
:param url: url
:type url: str
:param kwargs: How to document th... |
I have a situation where in a class I have 2 constructors and they have very similar code. The only difference is the the call to the constructor of the super class. Where should I put this common code? I tried to use the instance block but with instance blocks I am not able to pass arguments required.
Also, the fields... |
I've been reading Robert Martin's Clean Code book where it suggests we should separate a programs startup/construction process from its run time logic.
In Java (the language the book uses) this involves moving all aspects of construction to main and designing the rest of the system assuming all objects have been constr... |
Is it possible to say that the difference between imperative programming and declarative programming is merely in the level of abstraction? I.e. where the imperative programming will say "break the eggs, put them into plate, turn the oven to 180 degrees, etc", a declarative language will only say "cook me eggs"?
|
At my new work I am dealing with a quite big C/C++ project (50k lines in multiple files). I usually "draw" what the code is doing to understand its functioning but this time I am struggling a bit because of the code's size. Is there a technique that you use to such a purpose? The common algorithm notation with 2D shape... |
I am working on a project (to use as a reference). The project uses mysql, hibernate and spring (REST) and is supposed to be a single microservice.
I have come to find out that limiting user/consumer database access to stored procedures in mysql is considered a better practice security-wise (no unintended operations, a... |
I'm currently developing an Ecommerce application and am trying to figure out how best to add a 'guest checkout' feature. The 3 main models that I am wrestling with to add this feature are Address, User, and Order. An Address needs a User, and an Order needs both an Address and a User.
For our guest checkout we don't w... |
We've created a simple 2D game, it has fields and elements on it, the player can move the elements. The game has two views: a graphical (with images), and a textual (printed to the console). But only one at the time, and the game's logic must not know about the actual view.
To solve this, I created a factory interface.... |
Struggling to handle aggregates and aggregate roots when it comes to persisting. For example, I currently have a repository for each aggregate/table, but this is causing some issues in my service class.
Current JournalService
public class JournalService
{
public JournalService(IUnitOfWork uow, IJournalRepository j... |
I have to design a Class for ATM cards with the following attributes:
Cardholder Name
Card Number
Pin
Other than getters and setters, I have a method to validate the pin of the ATM. As per the principle of encapsulation all the methods related to the ATM should be part of the ATM class.
But in case, later we need to... |
Let's say i have a table (in a large enterprise application) that has about 10 columns.
I am limiting any consumer access to the table to only be possible by calling stored procedures.
When it comes to updating a record in the table, i basically have 2 options.
One stored procedure to update all the columns of the tab... |
Right now I'm using Direct Exchanges (i.e. one queue per "topic", pretty much pushing messages directly to a queue). This works OK, but I'd like the flexibility of working with Topic Exchanges, specifically multiple consumers subscribing to topics without destroying the message (i.e. multiple queues per topic).
The com... |
I'm working on a free proyect over Github. I fork it, made some changes, did a PR and everything worked ok (PR was accepted).
Then I update my fork with upstream, did some other changes, and made another PR.
Then I realice that my PR included all the commits I pushed earlier, and every file I modify, even the ones I al... |
We are developing a system with coarse microservice architecture. We have an API that uses controllers and back-end logic with Entity-Framework repository, and several types of clients that use this API, all in dotnet, therefore, typesafe.
We need to use some sort of data transfer objects for communication between the... |
For example, suppose my app have some localization texts. My question is, should I load appropriate locale at start:
var locale=userPrefs.getLocale();
localeStringMap=getLocaleTextFromFile("locale_string_"+locale+".json");
//some other code
//.
//.
//.
var message=localeStringMap["welcome_to_use_the_app"];
or get th... |
Google describes the rules for Firebase as:
You are required to notify
your App Users by disclosing the following information:
The Google Analytics for Firebase features you have implemented.
How you and third-party vendors use first-party cookies, or other first-party identifiers, and third-party cookies and simi... |
I develop a WPF application using MVVM and I am learning how to do things best.
I have a WPF form with selectors, two list with search fields, and some other elements. Currently all is in one form and it works. But by now the VM for that form has more than 800 lines and it is not yet finished.
I want to structure this... |
Our application creates audit trails in response to system actions and user actions. Our business logic depends on these audit trails to find out which user performed what action.
Is it good practice to have business logic use audit trail data?
|
I have function that takes as arguments a number of classes of average complexity.
When writing docstring for that function, I'm running into a series of questions: Should I describe (besides what the function is doing) those classes too, or can I assume that the reader will dig up the class definition? Or should I po... |
I'm working on a system with hard real-time constraints in c++ and I need a very fast way to calculate the rolling/moving/streaming median of a set of numbers of size N=100 to 300. Normally this size would be trivial but in this case the algorithm will run about 1000/2000 times per 0.1ms
Every calculation a single valu... |
I found this question
Return magic value, throw exception or return false on failure?, however it is kind of broad. I would like a more specific answer.
Say I have a method called Connect() which connects to a remote device over an Ethernet socket. If the socket fails it throws SocketException.
So the way I see it I h... |
I'm designing a REST API that needs to allow me to send messages to members in the system.
Right now, I'm thinking about creating a /messages endpoint that I make a POST request to when I want to send a message, providing a member's ID and the message content. The problem that I see with this approach is handling the c... |
What name should I give classes which are just for configuration? For example, when using JAX-RS, every application is required to have an Application class which extends the superclass javax.ws.rs.Application like so. The Application class is just to register the list of resource classes.
public class APPLICATION_NAME... |
I've been writing web applications for almost 10 years. The ASP.net stack has been my bread and butter and although it has a lot of great things about it, I honestly never chose ASP.net. It's just a matter of what my employers and clients wanted.
Recently, I had the opportunity to prototype something I was working on... |
I do a lot of work in various languages, most of which are scripting languages such as JavaScript, Shell Scripting, PHP and so on. But I do also work a lot with Java, which is closer to a more "real" language.
C/C++ has been an interest always, but have not had much use for it. I did have a few small things in some Ja... |
I am very new to Domain-Driven Design. I have come across a part of a domain which I'm not sure if I have modeled in the best way possible.
There is a Membership entity which has a membership type.
public enum MembershipType
{
TypeA,
TypeB,
TypeC,
TypeD,
}
Each Membership can have 1 or some Businesses... |
Given that a lot of modern web applications just consume JSON data from the sever, what is the point in having a REST api at all instead of just using SQL's query language?
Nowadays people are starting to use GraphQL. From what I understand is a query language from the client to the sever, which then gets translated i... |
Today, I searched for includeOS and I found that it defines itself as a minimal unikernel.
I am wondering what is UniKernel. The wikipedia explanations are not clear enough to me.
Is unikernel an operating system incorporated with a single application for a special purpose similar to embedded systems?
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.