instruction stringlengths 34 36.1k |
|---|
Programming languages traditionally have blocks that specifically cater to controlling iteration.
There is the simple while-loop:
while (i < 3) {...};
Then there is the more complicated for-loop:
for (i = 0; i < 3; i++) {...};
There are others, but these examples are sufficient to illustrate a point, which is that a ... |
I was working on a unit test that has a mock object looking something like:
public class TestMock
{
static {
Doodad a = new Doodad(0);
Doodad b = new Doodad(1);
Doodad c = new Doodad(2);
Foobar x = new Foobar('x');
Foobar y = new Foobar('y');
Foobar z = new Foobar(... |
This is a follow up/related question to a previous question I asked regarding Interface Segregation. I'll build up on the same example, providing a bit more context.
In the game I'm developing, a card is structured in the following manner:
A card must have a primary ability
A card may have an "ally" ability. If it doe... |
I'm currently working as Fullstack developer, our frontend is being built in React.
Our current process involves:
The client / product owner describes a feature to the UI / UX designer.
The designer creates a nice template in Figma, or any other UI tool like-so
The design is given to us the developers to implement
The... |
I've written an implementation of the UCT1 Monte Carlo Tree Search algorithm for selecting moves in a two-player game. In the future, I'd like to expand this implementation to use more advanced tree search techniques like RAVE to be able to search more efficiently. I'm trying to figure out how to write unit tests for t... |
for example:
const arr = [1,2,3,4];
const coordinate = [arr[0] + 2, arr[0] + 1];
here arr[0] is written out twice, when the code is executed would it literally go and find same value twice or would it remember it?
Does it matter that arr[0] in example above is used in the same expression? What if I would use arr[0] i... |
I'm not sure how to best ask this, as it's the first time I have to tackle such stuff. It might be that it's a common problem and I'm just using the wrong keywords to search. Basically, imagine a microservice needs (as part of its data) the ID of some objects managed by another microservice. For example, Users and Orde... |
Consider a microservice architecture composed of a number of asynchronously communicating workers. Each worker deals with an isolated task and may have its own specialized database. Now consider that the services are meant to work on a common task by starting to do their specific computation and, once finished, contrib... |
I am looking for a better approach to add multiple products to my db.
(things I have tried)
Example 1
[table
Products - ProductId pk(
ProductId,ItemCode,Price,ProductType)..]
[table 2
Frame - ProductId pk(
ProductId,FrameType,FrameSize,Glass,Mat,Spacer)..]
[table 3
PrintRoom - ProductId pk(
ProductId,Material,ImageSize... |
What's the difference between an API and a protocol?
To use a specific example: Is Coinbase's choice to refer to its WebSocket client specification as an "API" appropriate? It seems that many companies in their space followed their naming trend. For example, FTX calls this client specification their WebSocket API. This... |
Let's say I have a REST API that needs to return the width of an object, but that width may either be a specific value or a range of values. What would be the best practice for designing the API to handle this?
For example:
"width": 35.5
"width": {
"minimum": 34.2,
"maximum": 36.8
}
Would it be best to simply spe... |
I am trying to understand layered architectures and apply some DDD fundamentals to improve my architecture. I am finding that determining "what" an application service actually is, what its bounds are and what questions it should answer is really hard. Similarly for domain services.
Overall, I can't quite comprehend th... |
I have a C4 container diagram of a system, in which most of the components communicate with MQTT. The MQTT container is SOUP. Is it necessary that I draw the MQTT container or can I simply draw direct relations between containers and state on those, that it works via MQTT? Is there a specific recommandation? If yes, wh... |
I've come to a bit of an impasse with the best way to implement a DDD problem, and am hoping for some advice from those with more experience, please.
I have a RecipeCollection, which has a collection of type Recipe (as you might expect). The abbreviated code looks like this:
public class RecipeCollection : IEntity<Reci... |
I want to understand how does Spring Boot and Postgresql DB handle the concurrent requests for updating a value in DB. Consider this example of facebook likes, if there are multiple instances of application running and each of them are getting multiple requests concurrently for a like on post, currently the like is onl... |
I find myself in a situation where I have two roles, "Admin" and a "Organizer". The "Admin" accesses the AdminUserController to update users, while the "Organizer" accesses the UserController to do so. This is important since the user indexing and input validation is different in both cases: the organizer only indexes ... |
Context
I'm giving a try at my first backend API which aim to follow some Domain Driven Architecture concepts that I've learned from an implementation in Go in a Udemy course.
The problem is that I don't clearly see the role of the Service.
In the course I've followed, there's a users-api microservice and an oauth-api.... |
I am reading about DDD and in the examples it is common to see how the domain gets the data from database, do the business logic and then persist the data. For example to update a field:
class MyDomainClass()
{
//Dependency injection of the repository
public MyDomainClass(IRepository paramRepository)
{
... |
Repositories in ddd should give the illusion of an in memory
collection.
and
A Repository is essentially a facade for persistence that uses
Collection style semantics (Add, Update, Remove) to supply access to
data/objects
I've read contradicting examples on what repositories are supposed to be:
abstract class Order... |
I have an issue where I have multiple databases from previous projects that I would like to combine into one large database. These databases are stored in .sql files. The issue is that I only need specific columns and information and I'd like to filter out any columns that aren't the ones I need. Some of the databases ... |
In domain driven design
A repository is a collection like "interface" that hides data source access. It furnish add, remove and retrieval method just like a collection would. It does it using domain language.
The application layer uses the repositories by thinking about them as collection, by retrieving from it or ad... |
I'm studying Clean Architecture with python and got into this "problem" of choosing where to implement a rule (that I considered a Business Rule, maybe I'm wrong)
I have 2 Entities
@dataclass
class A:
bs: List[B]
id: Optional[str]
# ...
def add_b(self, b):
exists = next((x for x in self.bs if x... |
I've been using the publish-subscribe pattern for a while for communicating devices and it works really well, making it easy to add extra services without touching the rest. I'm thinking of using it inside an application (think of a monolith or a GUI application).
The basic idea is: every component can subscribe to any... |
I'm working on an accounting service. I have to generate invoice for a user and upload it to the file storage. So my service would have to use a service from file storage team. File storage service and Accounting service are on the same layer level. File storage is a generic subdomain, while accounting is a core domain... |
I'm trying to design a monolithic application following DDD and clean code. Lets say I have Users, User Types, Products, Product Types and Purchases. I want to implement using different modules.
At the moment I'm thinking in Users, including the user types, Products, the same including the service types, and Purchases.... |
I am trying to understand the advantages of service discovery compared to load-balancing within the context of a microservice mesh where many instances/nodes/VMs/containers of many web services are all calling each other in a complicated web-pattern. And my understanding of the situation is this:
Service discovery -- ... |
We have a feature like "new command-line query tool" and stories like:
As a user, I can do X
As a user, I can do Y
As a user, I can do Z
Where/how do I detail "create the test harness application"? The stories focus us on what is needed but whichever one we do first, the developer will have some setup overhead.
Would... |
Note: This is a contrived example I came up with to illustrate what I'm after as simply as possible.
I have an HTML report with a single dropdown box at the top that lets the user select (or filter) the data that will be returned. However, the dropdown box doesn't contain a single type. It contains multiple types, th... |
OSS API Gateways typically come bundled with built-in load-balancing capabilities. We see this with Netflix Zuul and Kong.
In a service-oriented architecture, where many microservices are talking to many others, is the idea that each service has its own API Gateway, with its own load balancer that can serve traffic to ... |
I am working on a project and created multiple lambda functions and now I am thinking about whether I made the correct decision to go this route.
Reasons I chose lambda:
The App will have spiky traffic and almost no traffic at some times, so it is cost-effective
It seemed like it would be less stressful to update part... |
I may be overthinking it, but are controllers and resolvers the same thing in web applications? Coming from the MERN stack, everyone used to call these request processing functions "controllers," but in PERN+GQL, everyone calls them "resolvers." By my understanding, they are the same thing.
MERN - MongoDB, Express, Re... |
At the moment I'm spending more time planning out a commit than actually writing code when adding a new feature. Less than two hours would be lucky, and sometimes I'd spend a good part of the day without writing any code. This is making me unhappy, since I don't feel I'm productive enough (I'm living with my parents, a... |
I have just recently joined a new company and one of the classes used to log information has not been written properly. So I have been asked to add new functionality to the logger.
Rather than amending the Logger class I want to follow the O in SOLID and extend the class by creating a derived class and adding functiona... |
I am building a small application that supports a research project. My goal is to make the code to be painlessly executable and readable on as many operating systems as long as possible.
My reasoning is that 2-3-5-10 years down the line I will work on a completely different research project, but my software may have to... |
I am a full stack developer who's been learning about Domain-Driven Design in the past couple of days, so I have some question since I have trouble finding place for this pattern in my applications.
I think of front-end as this reactive programming "experience" focused on UI/UX, and of back-end as a transactional, perf... |
We are revisiting how we do observability at my organisation, and I'm reading about Service Level Indicators (SLIs) as a way of measuring how our systems are performing. But what I'm struggling to get my head around is how this differs from Key Performance Indicators (KPIs) that I've heard others speak about?
They sou... |
I went through different ideas about storing AES key for encrypting database columns, I learnt that there are the possible solutions:
put the key in the database
find a Key Management Service to help you keep the key
Below is my suggestion:
prompt the user to input the key everytime he/she uses the database, it is a... |
I need to implement the following scenarios at the server:
User sent too many answers in a given amount of time, for example, it can't submit more than 3 posts within an hour.
User sent answer with the same text already, to prevent spamming.
My question is what is the correct way to implement client/server communicat... |
After my team went all-out on the microservice paradigm with an emphasis on message passing, I'm having trouble defining and keeping track of all the events in the system.
I've read some guides on the event-driven architecture, and while I get that the messages themselves should be as simple as possible, it still leave... |
Is it a bad approach to add domain logic inside typeorm entities if following the domain model pattern to organize business logic.
import { Entity, PrimaryGeneratedColumn, Column } from "typeorm"
@Entity()
export class User {
@PrimaryGeneratedColumn()
id: number
@Column()
firstName: string
@Colum... |
I am building an API that (I am deliberately simplifying the schema below to only focus on what is questionable):
I have a table that roughly looks like this:
CREATE TABLE IF NOT EXISTS some_table
(
id INTEGER GENERATED ALWAYS AS IDENTITY NOT NULL PRIMARY KEY,
user... |
I was reading the documentation about how to use Entity Core in a DDD way. This is the documentation.
It is said that I can configure EF to can map an internal private field to a private field, the backing field.
The code is this:
public class Order : Entity
{
// Using private fields, allowed since EF Core 1.1
... |
I think my problem is very common but I couldn't phrase it correctly in the title.
I have a Django API that returns some information about companies (like address, partners, situation, etc) given its unique identifier. I would like to run tests on it because it is very unstable given that it depends on a lot of data th... |
I'm designing an algorithm that matches entries based on some notion of "proximity" (for the sake of discussion, assume we're matching floats). Furthermore:
The input is a scalar and a vector, and the output should the "closest" element of the vector to the scalar.
I'm considering three matching techniques: Forward, B... |
There're certain things in code that can't be conditional. Two very common examples:
static types
dependencies.
You can't naturally enable/disable a feature that implies a new dependency or a new type with a condition (a feature flag).
How do the proponents of trunk-based development tackle such cases?
package.json
... |
I have a program that runs on command-line, let's call it myprogram 1.0.1. It's published on GitHub.
Now I discovered that name already exist for a well-know software, so I want to change the name from myprogram to myprog. This, of course, will break the old usage of command since the user now must type myprog and not ... |
We are a small team contributing to our startup project, on a daily basis the code changes and multiple PR are raised daily. The general issue we face while reviewing these PRs is the code formatting changes due to different IDE or the same IDE with different code formatting configurations.
Is there a possible solution... |
I am writing a Spring Boot REST API using JPA, so I have my application layers consisting of
controllers
services
repositories
entities
models for request, response, DTOs
This question is mainly around entities which often have relationships among themselves.
For example, a @OneToMany relationship to map to database ... |
So I was sending code for review and approvals for some changes I made recently. that includes a class as below:
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class UnKnownClientException extends CustomException {
public UnKnownClientException (String message, Throwable throwable) {
super... |
I have a doubt about what would be the right OOP approach for implementing classes that do similar stuff with different parameters.
To provide a simple example, I would use two polynomial classes, please, don't give an answer specific to polynomials, e.g., saying that one could just create the generic class polynomial,... |
I am currently working on a small web-app stored in a monorepo and using PSQL as database (hosted on GCP). It's my first time working for a web app and I have to create a lot of tables manually such as using this script to create the positions tables:
CREATE TABLE PUBLIC.positions
(
position_id INTEGER NOT NULL... |
I'm trying to understand CQRS, DDD by writing a small pet project which is somewhat similar to this great repo.
I've come across Transactional Outbox pattern and as imo it was correctly pointed out in this article it looks hard to scale this approach to even thousands active users when using document oriented databases... |
My company develops many relatively small projects that a lot of times do the same things and have a similar structure. (e.g. read/write to a databse, data pre processing, building a query etc.). This creates a natural urge to create libraries and frameworks that either implement some of the repetitive logic and/or for... |
Say I want to implement a mathematical tool or simulator for mechanical joints.
There are different types of joints (revolute, prismatic, etc).
Which have different properties (degrees of freedom, constraints in a 2d planar system, constraints in a 3d spatial system, etc).
I can think of multiple ways to implement this... |
I am building a bank management system using the microservices architecture. I have many microservices but I am going to talk about two. I have customer account service and transaction service. Let's say a customer wants to perform a transaction(deposit/withdraw/transfer) should I define my api in transaction service ... |
I'm looking for some advice on a system I'm designing, at its core it will allow users to create/join/manage groups of users.
I thought it would be a good idea to try and apply some DDD principles, which has led me to create following domain models, I'm currently treating a Group as the aggregate root.
public class Gro... |
I have an abstract class that represents chess pieces, it has an abstract method isMoveValid(Square futurePosition, PieceColor color) which checks if the piece moving to that square is valid or not, if the move is valid but there is an opponent piece on that square then the piece is trying to capture not just move.
I b... |
I was reading a bit about garbage collectors and I am wondering if the garbage collector of a program scans the entire heap memory or what is allocated to it? If it reads the entire system memory, does it mean it is reading memory locations that are used by other applications? I understand that this does not make much ... |
I have a class that I use to define different types of plots I am performing
class MyPlots(Enum):
STANDARDSCALE = "standard"
LOGSCALE = "log"
there are default values associated with the coordinates I usually plot with, i.e., in my code I have parts like
...
if self._plottype==MyPlots.STANDARDSCALE:
xlimit... |
I code an Object-Oriented simulation where you can have a Unit move on a Terrain. The cost of such move depends both on both Unit capabilities and Terrain features: a boat can move on water, a plane can move everywhere, a car cannot run on terrain, etc.
Current implementation uses a table, but this grows complex (as te... |
I'm designing a mongo database and I have a dilemma if I should go for normalization.
Let's say that there is a database with images and descriptions. Many alternative descriptions can belong to one image, but only one is assigned as the main one. When I fetch a document for a given Image, I need to have only the main ... |
I met 2 different approaches to handling in-app credits.
If the problem is defined as:
Allow a customer to purchase credits, which they're allowed to spend on different in-system items. The credits should have an expiration date.
The top-arch solutions can be described as:
Solution A
Store the balance of credits on a c... |
I have to develop an eCommerce website following DDD.
I just completed Ardalis and Julie DDD pluralsight course and need to come up with bounded-context for this project.
Can you please assist if I properly identify bounded contexts for this project?
The requirement is as follow :
The system has 3 types of users : Admi... |
I would like to explain the following code to my colleagues:
for options in [{Option.NO_CUTOFFS}, {}, {Option.HEURISTIC}]:
...
The following sentence is kind of awkward:
This loop loops on the variants of the algorithm.
What verb can I use instead of "loops" so as to not repeat the subject of the sentence?
|
I have a class called ContentLoader. This class has one method LoadContent<T>(T model, int?loadLogicDecider1, int? loadLogicDecider2, etc). It runs through the input class looking for a properties decorated with a ContentItem Attribute. It then goes to the database and loads up the appropriate content. There is some lo... |
Title sucks, I know, but I'm having trouble describing my question.
Say I have a class Three_Eyed_Robot that sees the world in RGB through three eyes. Lets call them Red_Eye, Green_Eye, Blue_Eye, each of which are classes of their own that load a deep learning model for vision, then store the data they see.
My question... |
I have a question regarding my general understanding of global state in software engineering.
When I write an app I like to decompose it into little, manageable components and functions, that are ideally self-contained, have their own local state and don't produce any side effect.
But some types of those functions seem... |
I have a function that uses a static variable to count how many times it got called:
void func ()
{
static int counter=0;
counter++;
/* some code */
}
The code in the function executes differently depending on the counter.
As it happens while expanding the program to have more features etc. the original i... |
I understand that chat apps are a fairly well understood and architected thing. I’m looking for some best practices advice on structuring the backend, particularly as it relates to user inboxes.
One thing I’ve seen is that many chat services will duplicate a message across a user’s inbox. For example, in a two person ... |
Does "primitive obsession" as a poor design practice apply to development in Python? I have seen a lot of examples and discussion in the context of statically typed languages (like Java, C#), but there are also dynamically typed languages like Python. Do solutions to primitive obsession look different in Python without... |
Let's assume we have a method that we want to run as fast as possible and it needs to loop on a 2D array, naturally we would do a nested for loop as such:
int[][] arr = new int[3][3];
for(int i = 0; i < arr.length; i++) {
for(int j = 0; j < arr[i].length; j++) {
arr[i][j] = j;
}
... |
I have a series of record types in my C# project that I use with JSON.Net to deserialize json data.
public record RadarrMetadata(
IReadOnlyCollection<string> CustomFormats
);
public record SonarrMetadata(
IReadOnlyCollection<string> ReleaseProfiles
);
public record JsonPaths(
RadarrMetadata Radarr,
So... |
In orms, we can easily perform our desired operations in the save() method (for example, when a record is added in the likes table, the count column in the post table will increase.)
This is great, but
it prohibits direct manipulation of the database!
No one has the right to execute a raw query (insert or update) on ... |
A co-worker of mine is working on project solo but would still like to have other team members review their code upon reaching certain milestones. Unfortunately, they also want to wait until the end of the project to remove commented out code, remove unused code, and resolve compiler warnings. Some of the commented out... |
I'm thinking of a designing a review system (restaurant, hotel etc) where users can drop star reviews. Typically in a such a application, you can see the average rating of an entity along with all the individual reviews of the users.
Now, the average needs to be calculated. The approach would be to get all reviews, av... |
In ddd there is the concept of aggregate root.
The Aggregate Root is the parent Entity to all other Entities and Value Objects within the Aggregate.
It seems to me that User should be the root aggregate in most system where an user is interacting with the system. I've an hard time conceptualizing an aggregate root ot... |
I am working on a CLI chess game that only involves 2 human players, I decided to make it follow the MVC architecture to ensure separation of concern and to make the possibility of a GUI/web integration easier to achieve.
Here is the package diagram:
The view only has the View class that draws the board and the pieces... |
Suppose that we have a SQL relational database for, let's say, asset management system. It uses a table of assets (1 row per one real-world object). There can be various metadata etc. To allow the user add its own notes that are not needed to be managed by the system or provide information that the system is not able t... |
I am running into a conflict between two best practice principles-
overloading should be used instead of long chained if/else statements
models should not contain business logic
I am working on a chess game and am struggling on implementing my method calculatePotentionalMoves() for all the different types of pieces
O... |
I am currently developing some C++ GUI application using wxWidgets (although the GUI framework doesn't really matter here) and thus far have been developing this on my own, which was working well. This project has a few other dependencies as well (OpenGL, mainly, and then a few smaller ones like GoogleTest, etc.).
I am... |
We have a public API. Users will call this API by passing in different Guids as the IDs for entities.
In the API, the Guid will be translated to the internal ID (Int32) for that particular record in our DB.
The public API calls our internal API and the internal API receives this internal ID to fetch the record from the... |
Say we have these view model classes. You can imagine there's an entry in the UI for each subtype of InfoItem, and each item contains some text and an icon.
abstract class InfoItem(text: String, icon: Image)
class Email(..): InfoItem(..) {
private email: String
}
class Map(..): InfoItem(..) {
private addre... |
I'm working in a company, where we work with a kind of plug-and-play system:
An executable is put inside a central directory, and there is a Modules directory, where DLL files can be inserted, which will then automatically be used.
The biggest point is: there is no link between the binaries (EXE and DLL files) and thei... |
Suppose the following:
Building has 0...n Rooms, Room has 0...n Seats.
I am implementing a REST API which accepts data from different companies, with the caveat that the companies must be able themselves define the id (reference) of the entity. I'm generally unable to make any assumptions about those ids, other than be... |
I have seen many open source projects being labelled as "not production ready" because they have not reached a major version e.g. 1.0.0 using semver.
What is the significance of reaching this milestone? Is there a criteria that must be met for a piece of software to be considered a major version? Or is it arbitrarily d... |
I know that we have the functionality to lock records or setting isolation level, but this is not my question.
By default if dozen/hundred of users edit the same record at the exact same time what will happen - is the database having built-in locking that will reject some users or some users will have to wait a little ... |
I have a Spring Boot REST API application that uses different profiles like dev, test, prod, etc
It also makes a call to another API to retrieve some data like:
Client ---> MYAPI ---> DOWNSTREAMAPI
MyAPI is working fine and it will get data from DOWNSTREAMAPI and return it to client.
However, for client e2e testing p... |
My domain requires that a Resource (ubiquitous language for a singular unit of data to be moved - commonly a file or folder) can only be moved if it has been Scanned to ensure it does not contain any Threats. Resources are moved from a Lowside MountedDrive (essentially some external filesystem, as far as I know a lowsi... |
Assuming that a VM runs a JIT compiler on otherwise "interpreted" code, such as a line by line interpreter or some form of bytecode/IL code and determines that it can create optimised native code for some part of what is running, what mechanism is actually used to "emit" and then call the emitted code?
If I was writing... |
I'm a relatively new IT Ops guy in a software (web) development company. Recently I deployed a virtual machine on OpenStack, because some developer needs it, and then I installed their application (written by our developers, not third party application) on that newly deployed server using Jenkins.
So basically, what I ... |
In some companies, code is merged at a rapid rate by multiple teams with minimal testing and somehow the number of bugs is kept to a minimum.
In other companies, this leads to chaos and terrible situations. Root-causing leads to no useful insights and people feel they are put on the spot about a problem (chaos) that is... |
Is there a standard procedure for producing some jars, having them tested downstream, and then promoting these jars to the actual release? By promotion I really mean taking already publish artefacts which are known to be good, and rereleasing them with minimal effort.
The approaches I can see are, either really produce... |
I am developing a NuGet package which contains shared code for various ASP.NET Core projects. I am planning to use the strategy pattern to solve the same problem in a few different ways. So there will be a few different implementations of a common interface. See - https://deviq.com/design-patterns/strategy-pattern
My q... |
Forgive me if this is the wrong place to ask such questions - I am still extremely new to this field and am not even sure where the most appropriate place to look for answers is.
Question:
Assume I have a system in 2 physical locations: A and B. A and B are connected via a site-to-site VPN.
There are two groups of node... |
I have a java application, which recieves compressed files as input. The application then reads the header information of said files and passes the compressed bytes to an external native library for decompression (JNI). In one of the files we recieved, there was a corrupt blob of compressed bytes within the input file ... |
We have a .Net WebApi 2 we've been working on for quite some time. As we refactor code, we started thinking of what might be a better practice: a) "to get an app by userid", or b) "to get a User's app"?
Currently, we have 2 controllers: UsersController and ApplicationsController. Each have a GetById where you pass in a... |
In Microsoft's documentation, in the Named Clients example, they retrieve an HttpClient from the IoC container:
var httpClient = _httpClientFactory.CreateClient("GitHub");
In the Typed Clients example, the service that they register as an HttpClient, GitHubService, creates its own HttpClient:
public class GitHubServic... |
I'm following roughly the TDD style as explained in the "Obey the Testing Goat" book: You have a functional test for your (Django, in my case) web app that tests the observable behaviour via the Selenium webdriver. And then once you write a failing functional test for the behavior you want to see, you'll then do the TD... |
ViewModel has Two-way data binding with UI which means UI can access the data from ViewModel and can update the view models data.
The Model has one-way data binding and is only supposed to respond back with the result that ViewModel requests.
am I understanding it correctly?
|
In many situations we need access to meta information about Java Beans. The Java Reflection API itsself does not work for projects were performance matters so the bigger Frameworks like Spring or Micronaut made their own stuff but also Java introduced something.
Currently i am aiming to write a library for serializing ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.