instruction stringlengths 34 36.1k |
|---|
The C++ "standard" method for serializing and deserializing a data type is to use streams with the insertion (<<) and extraction (>>) operators. This has some flaws, but it does neatly allow you to use the same semantics to write anything to/read anything from a stream simply by overloading the operators.
However, I s... |
Normally, when a static value is used multiple times in a Ruby context, you'd define it as a constant. However, in some cases, the context is a block for some DSL at the top level of a source file (not within a module or class). I've run into this in various situations, but recently it's been ActiveAdmin:
ActiveAdmin.r... |
At the core of my business (say, an online store) is a Postgres database that stores products and transactions. During day-to-day operations, the load on the database is not heavy.
However, there is now a need to implement dashboards, compute more metrics, generate reports and so on. Computing these statistics puts a ... |
I'm a software developer and new to data engineering, so this may be a newbie question, but I'm wondering why data integrity checks (for instance, dbt tests) are ran on the data warehouse, rather than on the data sources themselves.
For example, I have an app that runs on MongoDB. Let's say I want to do reporting on th... |
When I did a small project in school about writing a document for Online Auction System in OOAD (Object-oriented analysis and design) courses, I had trouble with multiple Auction viewing use cases that have similar functions.
My auction has 3 states, pre-approve (wait to approve by admin), open, closed. The bidder need... |
I am watching a tutorial about ECommerce Website with .Net Core - and the project is of type Web Assembly Blazor and I checked the .NET CORE Hosted, so the project spited to Client, Server and Sheared.
And the Cart model is consists of CartId, ProductId and UserId.
public class CartItem
{
public int Car... |
One major reason for using composition over inheritance is, that inheritance leads to higher coupling. How is that?
In both cases members are exposed to the subclass (in case of inheritance) or wrapper class (in the case of composition).
Compare the following modifications for the base class for inheritance (AnimalInhe... |
GIST:
PUT is idempotent PUT is used for updating/creating a resource.
POST isn't idempotent. POST is used for creating a resource.
So, I'm wondering what should I use in this case and why?
I want to send firebase cloud message notification (FCM). Should I use PUT or POST request? What'd happen if I use PUT or POST? Bel... |
For background, the question is to prepare some training material, which should also should explain a bit why the things are the way they are.
I tried to get some idea of how C began based on this tutorial.
However, this does not give the answer and already has more in the language than I expected.
I learned at univers... |
I am currently implementing a library in Rust that implements a proprietary serial protocol.
The protocol specifies several enum values, that mostly are returned by the hardware as u8s (bytes), but not any value that such a byte can take is a valid enum value, e.g.:
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Ord... |
Let's say that I have a class called Mission. This class is intended to represent a mission requested by a professor working in a faculty. Mission has a private enum field representing whether the mission is PLANNED, IN_PROGRESS, COMPLETED, CANCELED, ABORTED, etc.
There are some things that the specs require to be doab... |
I took out the request for a paper, thank you for spending so much time on this.
hopefully this edit is better.
I use the word "complexity" meaning "cyclomatic complexity" so if you want me to put that all in there i will. I am specifically looking for an academic paper also, and I think that's relevant to engineering... |
Consider the domain entity, Order, which can be persisted by the OrderRepository. Orders maintain state that is stored in the database. However, it does not expose all of it directly. That is, parts of its private state is not accessible in the repository, when it should be mapped to database records. How does one go a... |
Recently I've come to discover that I've inherited one of the internal auxilliary programs used. I've made a few minor fixes and features to improve it in the past, but now I've been given a major feature that requires significant overhaul in order to implement.
This code has a recurring issue with overzealous try/catc... |
I'm trying to understand how Auth flows work within VueJS/Express Server to a protected API.
I have a situation where I need to call an API that is protected by JWT. To get this JWT, a client ID and secret is sent to an auth server which returns a token which is then passed in the header when calling the protected API,... |
I need to pass exactly event (not a lasting state) over communication connection that can provide boolean or integer value, possible to set, clear and observe by both sides. It is OPC UA framework but I do not have access to OPC UA "methods", only to variables.
It initially looks simple: we can have the boolean that is... |
I don't know the name of this pattern but what is the purpose of such methods:
AddOrUpdate
GetOrAdd
instead of single-operation ones?
|
According to Why define a Java object using interface (e.g. Map) rather than implementation (HashMap), I know I should declare the most abstract type possible, so for example:
public interface Fruit{
}
public class Orange extends Fruit{
}
when declaring Orange, I should write "Fruit obj=new Orange();" instead of "Ora... |
I'm working on a module that handles colormaps and I want to make the mapping of pixel to colors as efficient as possible. It is a performance critical section of our app. Our current solution works like this:
I have a normalized double value x (range [0, 1]) per pixel that denotes the position inside the colormap. The... |
I am interested to know if there is an existing algorithm to start a multiplayer game, for example, poker. What steps do we need to take when the player enters the "matchmaking phase"?
I expect something like:
Player N enter the matchmaking room.
The player is saved in a database in "Waiting" status.
Every 10 seconds,... |
In my new job, I'm getting a hard time understanding how they want to model things... they are using Domain Driven Design. For example, I come across this kind of code:
$userRepo = new UserRepository($this->userModel);
$virtualClassRepo = VirtualClassRepository::fromModels($this->virtualClassModel);
$user = $userRepo... |
In my current Java project, there is such style of integration test:
@Test
@Transactional
public void testBusinessTransaction() throws Exception {
//...complicate set up code and execution code
assertEquals(expected, actual);
}
Question:
is using the @Test in combination with @Transactional suitable at all, e... |
We're building an application that needs to log into a website using built-in credentials. It's not optimal to say the least, but we're stuck with "knowing" the username and password beforehand (hence stick them into the application somehow) and can not rely on runtime user information.
So I went through this stack ove... |
I have a Post domain model object with the title, body, and author attributes. It is persisted in a datatable with the id, title, body and author_id columns. I have left the ID fields out from its domain object because these fields seem like a persistence concern, not something that my domain object needs to be aware o... |
I noticed how our codebase contains multiple versions of the same method, which unmarshalls the inbound byte-stream into java objects and that the only difference between the current and previous version is the one variable change. There are roughly 17 versions, which are all chosen based on one big switch case. Simila... |
I'm writing a Python CSS-selector library that allows one to write these kinds of expressions in Python as a pet project. The goal of the library is to represent selectors in a flat, intuitive and interesting way; all valid syntax defined by the Selectors Level 4 Draft must be supported, in one way or another.
# lorem|... |
I’m currently trying DDD with establishments’ opening hours:
OpeningHours is an aggregate root; it ensures its openings don’t overlap
an Establishment can be set many opening hours (like summer’s, winter’s…)
an establishment’s opening hours can change on specified dates. Such a change would be coded as an OpeningHours... |
Imagine that you have a large monorepo code base running as a monolith application. This application is backed by a database. Some of the data in the database is sensitive, so you want to restrict access to it to decrease the risk of developers mis handling it. Essentially, you only want to allow specific chunks of cod... |
A few years ago, I wrote a simple web application in PHP without a database. Until now, it was running on a basic Apache server. I'm not a professional developer; I'm more on the system side.
I haven't had the chance to work on contracts with DevOps infrastructures yet. To better understand containers' operation and be... |
I have a situation like the following:
int fds[2];
pipe(fds);
// Write lots of stuff into fds[1]
close(fds[1]);
do_stuff(fds[0]);
// Should I close fds[0] here or at the end of do_stuff?
Which one is better to do?
|
I have a replicaset with two pods in an onpremise kubernetes. Is it possible to setup an active standby setup so only one pod receive requests and the second one stay in standby mode and takes requests only if first one is down? I don't find anything on the web on how to setup this.
If we can do active passive pattern ... |
Since March I switched jobs and became the Tech Lead of two teams that work on a shared codebase and a separate codebase for "region" specific implementations.
This team works using NestJS, which encourages a sort of Onion Architecture / Hexagonal Architecture + DDD. At first, I saw this as an overengineered approach, ... |
I am developing a website somewhat like leetcode, however, it will be for website testing using Selenium WebDriver.My service will provide different websites, along with various tasks that describe what to test for on the provided websites. The users will write selenium scripts, which my backend will compile and execut... |
Let's assume i app have with basic flow:
Client send request to server
Server do some business logic
Server puts message into some message queue
Server returns success to the client
microservice A reads the message from message queue and process it - be it some email
microservice that generates and sends email to the... |
I am contacting you today regarding a recent problem with circular dependencies. It's about a Spring boot application that accepts data via a Rest API and then forwards it to an internal Spring service. When a new vehicle is to be created, then first a CarDto is submitted via Rest. The controller uses a car mapper (Map... |
On GitHub, when an issue in small project calimero mentions an issue in big project godzilla, a backlink message appears on the issue in godzilla. For example, suppose a hard-to-fix bug in godzilla affects many dependent projects, which all implement a workaround while referring to the godzilla issue in their PRs. Th... |
Suppose an application records a version marker on some data.
For example a database application might record UPDATE_TS as a datetime when a record was updated.
It could just be an integer version counter but the important point is it's guaranteed to change for each version and (for all practical purposes) never repeat... |
We deploy microservices in Kubernetes environment.
For providing a solution to a business use-case using microservices,
Is the idea of service registration and service discovery not an anti pattern? where the scenario of starting microservice depends on the availability of other microservice
For example, using API comp... |
I often write code to implement the dispatching and handling of "messages." My requirements are usually:
I should be able to add new types of messages AND/OR new types of handlers without affecting the existing messages or handlers (i.e., loose coupling).
Every handler can choose which subset of messages to "handle" ... |
I'm writing a math library and I've encountered trouble with floating point imprecision. I want to know if there are any standard workarounds that are used often. I have doubts about my current method and my lack of knowledge and terminology when it comes to these floating point errors emphasizes the doubt.
Specificall... |
Suppose, I have a tensor tfDataSet as follows:
data3d = [
[[7.042 9.118 0. 1. 1. 1. 1. 1. 0. 0. 1. ]
[5.781 5.488 7.47 0. 0. 0. 0. 1. 1. 0. 0. ]
[5.399 5.166 6.452 0. 0. 0. 0. 0. 1. 0. 0. ]
[5.373 4.852 6.069 0. 0. 0. ... |
According to Why is Clean Code suggesting avoiding protected variables?, I should avoid protected variables because of the reason : "closely related concepts should not be separated into different files", that means, for example, if all Animal must have an _id field:
public class Animal{
protected String _id;
p... |
I have two different options in mind:
def foo():
try:
# do something interesting
except:
# report error here
return bar
bar = foo()
or
def foo():
# do something
return bar
try:
bar = foo()
except:
# report error here
Is there a preferred way to do this? If so, is th... |
I have a Spring service that acts as an adapter for another service in my company. The service receives a request to generate push notifications for a given user and needs to call the other service for each device token associated with the user. The request payload to my service and the payload required by the other se... |
I found this Python code implementing Double Metaphone, and it basically has a bunch of if statements handling each letter, though I'm not exactly sure the decisions that went into each branch yet. But the output are two hashes of consonants it seems.
result = doublemetaphone('Jose')
self.assertEquals(result, ('HS', ''... |
Folks,
I am wondering if there is any dis/advantage to using json objects as message keys.
Assume I have 2 event streams coupled with 2 tables in a source system. Each of those tables have its own business keys;
Product table has product_number and base_product_id as business key in the source system (key: product_num... |
In a Java open source project built with Maven, is there a standard way to declare code style settings (such as indentation settings and import order)? I would like that people who import the project in major IDEs (such as Eclipse and IntelliJ IDEA) are able to get their editor configured to follow those settings with ... |
Our coding standards for C include various prefixes for data types, constants, static/global variables, and pointers. These prefixes were originally introduced for code review purposes, but with the convenience of modern IDEs, which provide type information through highlighting, we are questioning whether it is still a... |
I've recently created a library that needs a non-text (but platform agnostic) resource to be used. I basically tell CMake, if this is an install interface, it's in the "${CMAKE_INSTALL_INCLUDEDIR}/resources" directory, otherwise it's in the "${CMAKE_CURRENT_SOURCE_DIR}/../resources" directory. Then I generate a heade... |
I have an event class that holds details of a volunteering "Event" class. There is an "EXCO" Class that can create and edit details of said Events. There is also a "Volunteer user" class is allowed to register for such events.
My initial approach to this was to have a "Event DataBase" Class that holds an array of Event... |
Let's say I have a table for storing users. In this table, I have data like id, name, address, bank account and birthdate. Also, I have two domains in my codebase; in one of them, I need a user entity with id, bank account and address; in the other domain, I need a user entity but only with name and birthdate. The firs... |
Over and over I am faced with a similar problem: I have to perform two actions that are mostly unrelated, except that they need to share a mutex lock, at least for a moment. For example:
void action() {
doStuff();
cleanup();
}
//Somewhere far away:
std::mutex p;
void doStuff() {
std::unique_lock lock(p);
... |
In legacy code bases, some APIs might be encapsulated by different developers with separate classes many times. Example:
public void calculate(int baseIncome) {
revenueCalculator.calculate(baseIncome,company);
}
and the RevenueCalculator looks like this:
public class RevenueCalculator {
public void calcualte(int b... |
A recurring pattern which I see in my code is chaining together a lot of functions. This is the result of a large number of processing steps needed for a given task. This could be e.g. a data processing and visualization or my most recent example:
For some financial analysis I want to read in a couple of pdfs which are... |
Suppose we are building a REST API with ASP.NET Core. Suppose there are 3 projects in our solution:
The ASP.NET Core Web API project.
A class library project for the businnes layer.
A class library project for the data persistence, using EF Core.
The first one contains all the controllers and actions, dtos, etc. It w... |
I've started working on a C# codebase. There are three services which run the same set of steps of three kinds of objects, each returning IResult:
public IResult FooService(Foo foo) { ... }
public IResult BarService(Bar bar) { ... }
public IResult BazService(Baz baz) { ... }
Foo, Bar, and Baz share common properties,... |
I am writing an application that receives different kinds of messages from an external device. The messages are of different types and they are received from the device in the form of a string.
For each message type, there exists a DTO object representing the parsed message, and a parser class which parses the string m... |
These days, I see people always extolling the benefits of using Static Site Generators (SSG) for building static sites. Why would I not just write the HTML/CSS myself? What's the advantage of using an SSG, such as Gatsby?
|
We currently have an architectural setup as described below. Our plan is to conduct a load test, but we face a challenge due to the high cost of real switches. We have two options: either build the architecture directly or create a simulation. However, our tasks must pass through a cloud server that only recognizes rea... |
Lets say I have students and classes which are 2 entities. A student can take many classes and a class can have many students. This would be a many to many relationship.
To solve this with an RDBMS my understanding is that one would create a joining table, so the tables would be:
student table
student_id | student_nam... |
We develop an online booking system and it may be embedded in customer websites in an iframe. It is very simple to use, you just include a JavaScript file on the page and call the initialisation method in a script.
In the instructions for website developers (or website admins if they know what they're doing) we indicat... |
I have Controller that basically publishes different Event based on some input criteria, simplified version of the logic is here:
[HttpPost]
public async Task<ActionResult> Create(CreateRequestDto request)
{
IRegistrationEvent createAppEvent;
switch (request.Kind)
{
case RegistrationKind.Client:
... |
There is a back end application with a few development teams working on it. The application is a monolith. Before releasing any new features they need to be system tested on the last application's version(to avoid bugs). That said, the current process is teams taking turns, doing manual testing and then releasing. This... |
Courtesy link:
What Are The Specific Meanings Of The Terms: Functions, Methods, Procedures, and Subroutines?
What's the difference between a function and a method?
In the linked question:
function, procedure
These are often used interchangeably, but in some languages there's a distinction. In Pascal, a function is a ... |
I have found another similar question, but the answer there talks mainly about C/C++, and does not mention about the division operator. So, in C/C++ and Java, dividing an integer by an integer returns an integer. On the other hand, in Python, a single slash will return a floating point while a double slash will return ... |
Recently, I was charged with making about 9000 Selenium tests start running in CI/CD nightly. These tests had built up over about 8 years and had up until then been run in an ad hoc way. It was important that failures in the CI/CD be genuine failures, which meant that you could run the test as many times as you liked a... |
About formatting
Here are two scenarios in which the details of the formatting are described.
How should in the clean code way, this be formatted
Scenario 1: Dependent functions of dependent functions
function main () {
firstFunction();
secondFunction();
thirdFunction();
}
function firstFunction () {
fourthFu... |
I have a budget entity in my domain which can be closed by the user if the budget is open. This means if the budget opens today and closes in seven days, in between this time I can close it, not before (I'd have to delete it), not after (can't do any action).
This time constraint raised a doubt: should I add a validati... |
Using Moq framework, it is not allowed to mock a class in C# which is sealed. Same goes for many other frameworks as well. But why is it not allowed?
|
In a web application with a frontend and a backend part, how exactly is the cancellation token mechanism implemented over HTTP? HTTP is a stateless protocol and it does not allow "sharing" any data between the parties. So, how can the frontend create objects which then somehow "monitored" by the backend?
|
I am currently developing an application in Python that has a match making functionality to form sports teams of 4 and group them by skill. The following has been implemented and works.
E.g.
Form full matches of four level 5 players until there are non left
If there are some left, form a match with the remaining leve... |
I have a base class "People" which two other classes inherit from: Employee and Student. The Student class includes a GPA (type double) and the Employee class does not. I have an ArrayList of People, containing both Employees and Students. I want to sort the Students by GPA in descending order, but I'm struggling to ma... |
I have to design a part of a system in responsible for creating tickets for attractions and then sell them. Basically there are
three different parts:
Product: to create the tickets for sale for each attraction.
Prices: to assign prices according to some criterias.
Qutoas: to manage the available quotas.
I have to ta... |
I have just started my first position as a software engineer after finishing my degree, and, as warned, software is much different in industry than in academia. The startup that hired me does not have such robust documentation due to the pace of the work, and that is a piece that I would like to take on, and I want to ... |
I'm building an API that allows people to search for books (just for simplicity). There is an endpoint that takes a query string and returns the top 10 matched results. For example:
/api/v1/book/find?title=Ha
It will return
Hangover
Hammer of the Gods
Harry Potter and The Sorcerer's Stone
Harry Potter and The Chamber ... |
I am new to React and web development generally so please try to understand if the question seems dumb.
So, I am currently making a simple e-commerce app and I was thinking of using state management either using redux or react context.
However, I also thought if I have a database, why would I need global state manageme... |
this is a robotics team with some questions.
Here's our current setup, using GitLab:
Currently, we have a main branch as well as a separate branch for each of our programmers. When they want to start working, they pull main and merge local main into their local personal branch (personal meaning the branch that has thei... |
Attribute references and instantiation
In this link, that is part of the official Python documentation, I have found the following information:
Class objects support two kinds of operations: attribute references and instantiation.
Attribute references use the standard syntax used for all attribute references in Python... |
Bit of context: I'm an Economics major that somehow ended up developing an API that's becoming a whole software project, so please bear with me.
So, after I got asked to add logs I noticed I should have a development and a production environment so my logs don't get dirtied by my tests. After reading a bit I added a .e... |
This is more a curiosity/query-for-information than anything; apologies if it's thus a little malformed:
This is relevant to a useful API-querying library that can be shared across multiple teams within the company.
Consider the scenario wherein all configuration is propagated via environment variables. Anything that n... |
I'm writing a validator class to validate certain request objects against a known format. Rule declarations and the validator will both be written entirely in Python, and I don't need to store the structures in the DB or go across the wire in JSON or anything of that type. I'm considering using the builtin function any... |
I would like to write a program that essentially handles text data and metadata of files locally on a machine's filesystem. There is no need for any network activity. I am working with large quantities of sound files in complex directory structures.
Information that the program should be able to quickly access include:... |
I have a proprietary protocol that describes the exchange of messages of two participants (applications) via a messaging broker (mqtt). A participant is of type A or B. Each type is allowed to send and receive a specific set of messages. The protocol defines a strict sequence in which the messages are allowed to be exc... |
In my project I have several "basic" interfaces whose behavior is fixed, i.e. the default implementation will always be good for every puropse. So I defined them as concrete classes with data members, Configurable, Named, DataUser etc., e.g.:
class Configurable {
public:
void SetParameter(int i) { _prop = i; }
int ... |
In my company, we use a separate cron server to run mission-critical background jobs that run on a single ec2 instance: the whole platform is then vulnerable to anything going wrong on this instance.
We want to change the design of the system.
Based on that, I need to modify the system in order to make it more reliable... |
I really don't like media queries in CSS - they have limitations, and on top of that they make the code a lot more confusing.
In addition, the restrictions are so strong that when using CSS preprocessors, it is impossible to use, for example, @extend from SCSS inside a media query:
@media (max-width: 768px) {
#ele... |
Currently, I'm working on a graduation project about designing a Document Management System (DMS) that incorporates some functionalities as follows:
It won't use folders to organize documents; instead, they will be stored in a flat structure.
Document organization heavily relies on assigning suitable metadata.
Searchi... |
Let's use PHP here for examples and illustraion purposes but the question is language and framework agnostic.
Many experts say Service Locator (anti)pattern should be avoided and recommend using Dependency Injection instead.
Then we can find 3 ways of injection:
constructor injection
setter injection
field (property) ... |
Say I have a complex entity (class) called Quote.
We have one representation that has just 3-4 fields used to hold minimal amount of data to identify a quote. Is there any convention to call an entity that does the latter? We were considering QuoteGet (data to "get" a quote), QuoteDef, QuoteDefinition or QuoteReference... |
In the book "Inside Microsoft® SQL Server® 2008: T-SQL Programming" the behaviour of a sql query is explained. The following picture is taken from the book. I have some questions about the explanation.
How is a sql query processed when there are indexes, that is, would this behavior change?
My doubt is because I am a... |
I am writing a recursive function. Some of the parameter data is different for each recursive call but some of the data only need to have one copy existing at any one time during the recursive call. For example a variable to keep track of the recursion depth when iterating/recursing on a recursive data structure (octre... |
At present moment, my desktop application operates purely on file names. That is, it parses file names and then reasons about the data contained therein. However, in the future, I see that there is a great possibility that I will bring in libraries which are capable of parsing file data, to improve my application for u... |
We have a server that receives queries. We use the command pattern for this, e.g.
q := NewQuery(database)
q.Execute(request1)
q.Execute(request2)
The queries read a "model" from the database
type database interface {
ReadModel(id string) *Model
}
Problem #1: The model is stored raw. But when executing the query,... |
I would like to add functionality to an existing .NET 6, WinForms app (currently migrating to .NET 8 if that is of any relevance), to periodically upload user usage metrics, in addition to providing capability for users to 'push' log files etc to a server where we can access them immediately, rather than users exportin... |
I'm using argparse.ArgumentParser extensively; however, it comes with a lot of boilerplate to set up, and this is especially noticeable when you've got more than a few common arguments that probably exist between functionally different, but effectively the "same" update scripts.
In detail, I am writing a common update_... |
I have a custom repository for each entity/module (I'm working with NestJS). I know that this is a lot of repeated code and I may refactor it in order to use a generic repository later, but currently I'm focused on making a simple working MVP.
My current doubt is: I have some entity specific scenarios to get data. eg. ... |
I am writing my first application using DDD (in Node with TS) and I started writing all the domain first -- before starting the repositories/DB and then the application, while writing unit tests for each entity. As my domain developed, I started to have more doubts about my business logic. I'll give examples below.
One... |
We have a layered application with (basically): WebAPI, App Services, Domain and Repository layers.
This fits for most situations, but now we face a slightly different challenge on where we need to build a query based on what we retrieve from the database.
Usually, when we use the repository, we know what query to use.... |
Recently I've had an argument with a teammate that I wanted to have a reverted commit on the master branch from where releases are made as a standalone commit and not merged with future changes.
My point of view was that I wanted explicitly show that I reverted another's teammates work and then on top of that I introd... |
I've began studying how the .NET Code Analysis works. It seems that it can be either enabled via a NuGet package or a property in the SDK-style *.csproj files. Also, starting in .NET 5, it is enabled by default.
I'm surprised to discover that most of the rules are disabled by default. I can understand that some of them... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.