instruction stringlengths 34 36.1k |
|---|
I'm developing an application (Java) in a modular architecture. I have two approaches in mind and I'm not sure which one will be "better code" in case of maintenance and conventions.
I have two main modules that I want to wire them up:
CORE - backend stuff
UI - frontend stuff
I can think of two approaches:
APPROACH ... |
I've recently been learning go and the versioning system seems rather odd to me. Most languages / dependency management systems that I'm familiar with (like rust and cargo) have an explicit way to specify a package or module version built into whatever configuration file they use (Cargo.toml).
I understand that go does... |
I'm trying to design a workflow engine using a DDD approach.
Context
(B1) Assign items to a workflow
Invariant: depending on their types, items can only start the workflow on specific steps.
(B2) Attach/detach items to other items
Invariant: all items (container and elements) must be on the same step.
(B3) Trans... |
I refer to this fantastic answer to an earlier question I had.
My question is, say you have an endpoint GET /tasks and that endpoint accepts query params to get certain groupings of data like:
GET /tasks?createdDate=01-01-2022&completedDate=30-01-2022
GET /tasks?isOpen=true&priority=high
etc.
As a consumer of this AP... |
We have a suite of integration tests that take about 2 hours to complete.
Currently our flow is that each feature branch runs the integration tests, and only if the branch is updated from master and the tests completed, it can be merged to master. So naturally, it happens quite a lot that you start the tests when your ... |
I need to start testing a Web API, for now I'm going to start with unit tests and I can't figure out the right way to do it. Here is what I have in mind doing:
The API consists on a list of endpoints that authenticated users can access. My intention is, for each endpoint, write a unit test that checks:
Status code is ... |
I have a requirement where we need to collect N different events and store them for analysis. I am having trouble coming up with a general architecture for this.
FINAL REQUIREMENTS
The end goal of the system is to store the raw events as they appear in the Kafka Queue for downstream processing.
Let's say I have three d... |
Hope this is the right StackExchange community to ask this question.
I am building a (Python) project that will have a list if URLs to hit. They have to be hit serially, and part of response of one API will be input to the next one. I say "part of" because which part of the response is to be fed to the next input will ... |
I am designing a system for a company which provides multiple services to users, all of which generate a document. The documents all have a validity period. Some of the services can be grouped, and their documents have the same length of validity. None of the services have the same parameters, except for the general on... |
I'm learning to make games with OOP and there's something I don't understand. What I can see is that the more I add methods to a class, the less it becomes reusable and flexible. For example, if we have a Player class which we can make jump:
class Player {
Vec2 position;
Vec2 velocity;
update() {
velocity *=... |
I am currently using tracy to profile a program I am writing. Tracy as a tool seems quite awesome, but it has one issue.
You need to markup your code when profiling. This has the negative consequence of obfuscating readability by introducing code that is unrelated to the functionality of the functions being profiled.
O... |
Problem summary:
In an application with wrapper methods over SQLAlchemy add() and query() methods, can integration tests that use the add() method wrapper use the query() method wrapper to validate that database table attributes and relationships are properly saved?
Detailed problem description:
We have a python applic... |
So I've a class that is some kind of wrapper of a state machine for a multipart upload and it's database writes/reads. Everytime something is uploaded via REST basically the following happens
MyMultipartUpload mpu = multipartUploadFactory.create(...);
mpu.load(request.mpuID); //sets mutex lock
if (mpu.state != MpuState... |
I'm mostly interested in C and C++, but I think this question can also apply to other languages.
My question is, if an unamed object or value is generated from the evaluation of an expression or function, can it be cached if that same expression or function is later called, and the compiler recognizes that the result i... |
Might be a silly question or something I might have just messed up in my head but here we go...
I saw a code example of someone using getPos() in their own class to retrieve the current position of an object instead of for example using myObj.x and myObj.y. That made me think about the use of public variables or genera... |
I'm coding an enum strategy pattern where one of the strategies makes use of an ScheduledExecutor:
class ControllerImpl {
//...
boolean applyStrat(StratParam param) {
getStrat().apply(param);
}
//...
private enum Strats {
NOOP (NoopStrategyImpl.class),
REAL (RealtimeStrategyI... |
I recently attended a C++ talk on SOLID principles and the presenter provided std::string as an example that violates SRP. I wasn't quite able to comprehend why that was the case. From what I understand, std::string isn't a paragon for STL data structures, unlike std::vector etc., since it duplicates some free function... |
I have a simple lambda that is basically x => "Error: "+x+".".
I was just wondering if this was worth a test. It's really just a one-liner, so there's not much that can go wrong.
Should I write a test?
|
Imagine a system for loan applications where loans can be in one of three states: PENDING, APPROVED, REJECTED.
Over time, people create code, UIs, internal reports, etc. that assume there are only 3 states. It's unlikely a single person knows all of the places where this assumption is made.
An idea I had is to create c... |
For the project I'm working on I was thinking to create a Java Module for each layer of my system:
servlet-presentation defines the implementation of the presentation layer. It is composed by Java Servlets that call the layer below and by JSPs that represent the view (Also JS, CSS...)
business represents the service c... |
I'm trying to group the components of my system by funtionality. This is the analysis class diagram of my system model.
A service class that involves a Post entity might necessarily interact sometimes with Section, User, or also (to a lesser degree) PostVote. This also applies with the repository classes of each entit... |
I'm studying DDD and trying to plan how we'll migrate from our monolith to a microservice architecture. At the moment I'm trying to work through two possibilities
The first is where the shopper is an aggregate with its own microservice. There's CRUD operations against these users and their data is replicated to other m... |
I am in this situation where I have to review pull requests (PRs) from one of my colleagues, who has a very broad knowledge and years of experience, she is well respected and we all know that the quality of her results are very good.
However, from time to time, her PRs are just to complex for what we want to achieve, i... |
I am a front end developer with 2 years experience, I am new to agile and I am having difficulty doing estimates to for user stories since I don't have any design for it? I am not sure how can I give estimate without even seeing a wire-frame and just by user story definition? We are following scrum as I have been told.... |
I wondered what is the "correct" or "intended" interpretation of MVVM?
I worked mainly with WPF but I guess it is still relevant to all platforms embracing MVVM architectural pattern.
1. ViewModel as application
Model is representation of data+logic for retrieving the data
ViewModel is all the application logic and i... |
I have an API that will be exposed on the internet publicly, the primary use of this API will be initially by a ReactJs front end but in the future we'd be looking to open this up to other clients that exist externally and require access to be able to call our API endpoints.
The ReactJs frontend will support a logged i... |
My team is working on building a bunch of automated tests for our project. Each automated test targets a "customization" our client ordered to modify an existing website.
The current flow is:
checkout development
git pull
checkout -b unique-customization-test-branch
magic code stuffs
git commit && git push
create pull... |
I am currently reading Clean Code by Robert C. Martin and in Chapter 8: Boundaries one can find this paragraph:
We wanted to tell the transmitter something like this:
Key the transmitter on the provided frequency and emit an analog representation of the data coming from this stream
We had no Idea how that would be... |
Given an app that manages appointment bookings, I'm separately storing purchases, bookings made, or cancellations (some of them non-refundable) and am required to show the sum of these, based on different conditions, in the form of one number.
Right now the application will fetch the entire dataset and recalculate this... |
I have read in an article DIP in the Wild that
"When Robert Martin first discussed the DIP, he equated it a first-class combination of the Open Closed Principle and the Liskov Substitution Principle".
As all of them are in scope of SOLID Principles, doesn't that mean that we have some redundancy within SOLID if one of ... |
We want our developers to be able to diagnose production issues in staging. For the sake of this, we are planning to make an exact replica of production into staging. We are thinking however, if we scrub the non-encrypted data, that it could no longer represent issues that may be present in production.
What is the best... |
Refer to the highest upvoted answer here for why you should make an IPizza interface with a IPizza.Prepare() method.
This is highly upvoted, But I think the answer is flawed. Sure a pizza can be prepared, but so can literally anything. Interfaces are only a guarantee of behaviors, not a guarantee of type, proven here:
... |
We are trying to redesign our microservice architecture-based application to support multiple tenants. We have a simple queue service that will be utilized by other services to queue any asynchronous jobs. On the other side individual microservices will poll the queue service to fetch/pick any asynchronous jobs that th... |
I have a class where I want to chain certain operations. The class look something like this
class MyClass<T> {
create<X>(fn: (_: T) => X): MyClass<X> {
...
doCreate(fn);
return this as unknown as MyClass<X>;
}
update<O>(x: (_: T) => O): MyClass<O> {
...
doUpdate(x);
r... |
I am trying something out in Springboot and stuck with a weird issue where I want to send some data from my frontend (react app) to backend (SpringBoot) and make that request non replay able by users (users should not be able to capture the request and make the request again and again).
Problem: I am writing some sampl... |
Take this constructed example:
def fetch_person(person_id, country_code=None):
if is_fully_qualified(person_id):
return person_source_1.fetch_person(person_id)
else:
return person_source_2.fetch_person(person_id, country_code)
If the function caller supplies the right kind of person_id the coun... |
I have three entities inside one bounded context:
Company
Department
Agent
A few business requirements:
A company has a list of departments, and a list of available phone numbers.
A department has one phone number, and this phone number must be part of the company's list of available phone numbers.
An agent can assi... |
I have a class like this. (My actual class is different. I am using this to explain the problem). This class instance is shared between 2 threads.
However those 2 threads (thread1 and thread2), call the methods addToList1 and addToList2 respectively. We can safely assume that thread1 does not call addToList2 vice vers... |
I've been building a library (NuGet package as I'm in the C# world here) & I want to add logging so the consumer of the library can optionally provide some logger to the library. However, there are many logging libraries out there with different interfaces, so I'm not sure the best way to go about it.
I'm leaning towar... |
I think I am struggling to model a relationship between 2 entities. I am trying to do so in a way that promotes DDD and captures business semantics. The following is my business context:
I am developing a memberships microservice. It is a service that is used to create organizations to which you can then invite members... |
Is using templates for specifying capacities of containers a good use or misue of the templates? Eg.
template <unsigned int Length>
class String {
public:
String();
String(String& other);
String& operator=(String& rhs);
~String();
void Append(String& other);
private:
unsigned int length = Leng... |
I am trying to convince others that the following first code snippet is bad practice and the second snippet is best practice.
Bad practice:
// There is only one implementation of Adapter
public function setAdapter(Adapter $adapter)
{
$this->adapter = $adapter;
}
public function persist(Entity $entity): void
{
i... |
I'm working on a codebase with very little testing. The code is 90% an ETL pipeline with functions like
def sort_data(df: pd.DataFrame, column: str = 'date') -> pd.DataFrame:
return df.sort_values(by=column).reset_index(drop=True)
or
def validate_no_duplicate_index(df: pd.DataFrame) -> pd.DataFrame:
assert df.in... |
I have read many articles online but each one of them fail to give even a basic example on how an Object Oriented Database is stored and represented. For example each of the articles say that they are not tables, but are objects and then provide an ER Diagram with arrows pointing between them, for example, wikipedia. R... |
What we often see is that software companies create an internal API which is then consumed by their own user interface. And we were trying to find the benefits of those, other than it's easy/easier to switch to another technology for user interface. Mostly these API's are custom made for that specific UI and isn't gene... |
When writing tests for TDD is it good (or bad) practice to write multiple test for the same requirement ? If it's good how many times should it be repeated? If it's bad is it it the QA engineers work to do so?
E.g. Testing a calculator that adds 2 numbers.
# import stuff here
def test_Cal(self):
self.assertEqual(... |
We've got a few CSV file templates with different set of headers. In each CSV template there's at least one unique header and each template is meant for a different entity in the system.
Right now, when the user wants to upload a CSV file, the user choses which type of a CSV it is from a dropdown, so that on the backen... |
I had a discussion with a colleague of mine today regarding versioning of a REST Api.
We currently have an API with support for versinong by providing the correct version in the URL.
So for instance:
https://ourapi.com/api/v1/something (where v1 would be version 1)
Now we want to make a few contract changes to one of o... |
I have a method that accepts one or more optional arguments and I'd like to log them, following the best practice of lazy interpolation of log values:
def frobnicate(a: str, b: int, c: typing.Optional[float] = None):
# note: c = None actually means absence of data, it's not a placeholder for a default value
myl... |
Note: I'm new to using paid APIs (like Stripe, GPT-3, Twilio, ...).
When you are using a paid 3rd-party API, you are essentially betting on them keeping reasonable prices in the future, right?
So in case you'd want to switch the API provider, potentially the work to switch could be huge if their endpoint design is diff... |
Say we have a data grid of car models in our application. In the data grid, many fields were displayed, such as the brand, the model name and the year of production. However there are many more fields of these car model entities stored in the repository (database).
In another place of the application, there is a drop-d... |
we have a private nuget repo setup available for all department developers, each developers can contribute and deploy their own reusable library which gets uploaded for the entire dev team to use after few reviews.
We have a standard policy that all Libraries should be developed .Net6.
Issue here is, the developers use... |
The application I am working on is written in TypeScript and I need to manipulate DateTime. I always avoid doing date/time calculations manually, because they have a lot of edge-cases. The Date class in JavaScript is, let's say, a funny implementation in my opinion. I would much prefer to use the immutable dates in the... |
I have a requirement from a bank where they need to store data in a tamper proof way but at the same time they need to purge it after 7 years.
The current process is they receive a letter and file it.
After 7 years they shred it.
The first part of the requirement can be achieved via a blockchain or an immutable databas... |
I have a technical application that interacts with different hardware components: measurement devices, sensors, custom hardware. These use dedicated interfaces like USB, serial ports, TCP/IP communication and others. Most of these devices' implementations wrap a request/response pattern: Send something to the device an... |
I'm developing an application (Java & JavaFX) that writes/reads data (a file). The problem is I don't want to restrict user to run only one instance (of my app) at a time, as I really can't think of reliable way of doing that so it works on both Windows and Linuxes (e.g. server), heard of sockets and files - both are d... |
It recently came to my attention that its best practice to avoid database calls in constructors. I feel like this means you end up repeating unnecessary code, thus the code is less DRY?
For example, this approach means the list of available courses is available in the Semester object and the db call exists once.
public... |
Let's say I have a single resource of employee that belongs to user:
{
"id": 1,
"name": "John Doe",
"userId: 1
}
When making a GET request to /employees/1, I'm using a JWT which contains the userId.
Any user can fetch this record regardless of their userId (as long as they're authenticated), however, I want to i... |
I have a web applications (angular) which is connected to backend using websockets. The role of web app is to display data from multiple sources (which are updated constantly by some Scala Spark apps) in dashboards;
because the backend is deployed on multiple instances (3x centOs), the frontend will send the request to... |
I need to add extra data to a list endpoint. Basically it is the list I want to return and an extra data. Like below
{
"results": [...],
"extra_data": {
"field": "value"
}
}
Is it okay to return this result from list endpoint or a detail endpoint?
|
We have a robust set of micro-services available.
For simplicity, let us call the services
S1
S2
S3
S4
S5
For simplicity, think of the flow to be this.
S1 -> performs step1 (start step)
S2 -> performs step2
S2 -> performs step3
S3 -> performs step4
S4 -> performs step5
S5 -> performs step6 (final step)
Now, for track... |
I'm reading Clean Code
In Chapter 6, Objects and data structure
First talk about Data Abstraction:
Hiding implementation is not just a matter of putting a layer of functions between the variables. Hiding implementation is about abstractions! A class does not simply push its variables out through getters and setters. R... |
A colleague of mine did this UML component diagram to represent both the required/provided interfaces and the internal structure of the subsystems that compose the system we're working on:
(The subsystems are called "User Management", "Votes Management", "Post Management", etc...)
This diagram is for a System Design D... |
I am currently exploring adding unit tests to my Django REST Framework project. I totally understand adding unit tests for other components of the app like models. However, I'm stuck at testing views. I understand using Client is for adding integration testing while using APIRequestFactory is for adding unit tests.
I'm... |
For my project, I am required to complete a software requirement and systems requirement for a program I am developing which needs to be fairly detailed. However I am struggling to differentiate between the two on what kind of information is contained in each section. My program is related to artificial intelligence i... |
I am being challenged (or confused) by this problem:
I have a List<CustomObject> in which each element has around 20 fields/attributes. In this list I might have sort of duplicate items. Four particular fields may be different, if the others match I would regard them to be equal enough and I want to merge them into a s... |
Problem
I need to build a profit/loss graph for a mobile app. The api from which I can get the historical price data only allows me to retrieve 1 item at a time. If the user has 500 items that would create an api failure since I can only make 50 req./min.
What is the best way to calculate this? Let's say the user buys:... |
I am working on a Django based project that is version controlled with SVN. My main objective is porting it from Python2.7 to Python3.9. Whilst I port the project, my team brought some updates, now I want to get these updates and port them to Python3.9 as well.
Our issue here is, how will we manage 2.7 and 3.9 codes in... |
Lets say we have DTO class with 15 properties. Usually DTOs like these are mapped from other objects. But sometimes some DTOs may use values from multiple objects. In these cases, should we “Map” or “Create” an object?
In our project we currently have these scenarios handled by constructors, in some places by static Cr... |
Is there any performance detriment to assigning variables vs using them inline. I'm guessing this WOULD be worse if a method was returning primitive and I was 'boxing' it (e.g. method returning int, and me storing to Integer). What about something like the below?
String foo = buildFoo();
String bar = buildBar(foo);
ret... |
Assume an application architecture with three layers (presentation, domain, data access - though presentation is irrelevant to this question) that follows dependency inversion:
The domain layer specifies domain models and repository interfaces
The data access layer has a reference to the domain layer, implements repos... |
I've recently joined a startup that has, in my opinion, a strange (and inefficient) way to access their database.
Their implementation consists of multiple REST APIs that are exposed to multiple clients, these APIs, according to them, were made with a micro-services architecture in mind, that's ok.
My problem is with t... |
I am having a problem currently where product managers are raising improvements as bugs. Also, they expect us testers to catch them early. Our company doesn't have any requirement document and as QA we collect the information by brainstorming and talking to product managers. Recently the QA had a meeting with the manag... |
Very recently a discussion came up regarding the usage of different buildspec.yaml files, one for branch builds and the other for deployment builds and I was wondering, since after some research I wasn't able to find the best practices on this topic from AWS, what is the approach I should follow when it comes to this t... |
My team is communicating proposals for the interaction of several processes as a flowchart. I've been drafting a codebase architecture we can use as a starting point. There are two ways intended behaviour can change, each of which poses maintainability issues:
What each edge does. Edges are in general bidirectional, a... |
I've come in to a project where it's a best practice for an Init method for all tests in a class to contain mocked happy path functionality. This should allow most methods to pass without exceptions. I'm guessing the benefit is removal of code duplication and that other test methods not directly related to this code ex... |
In trying to separate interface from implementation, I ran into a circular dependency problem.
There is a best practice in the world of Java: consume interfaces instead of concrete classes. That is, instead of declaring variables of type ArrayList<int>, use the type List<int> instead. That way the migration from Array... |
I would like to add integration testing/automated acceptance testing for a mobile app calling a registration API from the backend. I will register a sample user on the test feature then delete the user on tearDown. Something like this:
test('registration test'){
RegistrationRobot registrationRobot = RegistrationRobo... |
We want to create an API to communicate witha device we currently sell.
The API should be available for several platforms like C / C++ / .NET / Python and available for Windows and Linux.
The idea is to have on single source of truth. A C API and the others are just wrappers around that C API.
However as i am not the g... |
In the company I am working for, we have been told to keep server requests to a minimum. There are probably reasons for this specific to the company, but it made me wonder.
Let's say I am building a basic web application with a standard Nginx/Apache server, would it be better in general to write server requests that tr... |
I'm newbie in Java and I have question. Pass a value to a class via a constructor or a method?
public class HelloWorld{
public static void main(String []args){
TextModifyFirstVersion textmodifyFirstVersion = new TextModifyFirstVersion("test");
textmodifyFirstVersion.modify();
TextM... |
We have two applications, each of them separated with its own backend and frontend.
The first application is the user-facing one. They register on the site and as soon as they want to execute a critical action they should be redirected to the frontend of the second application that will ask for the users personal data.... |
In our team we have a recurrent problem that we are not able to solve. As long as the team grows, we tend to accumulated PRs at the end of the sprint / release and these become a bottleneck to advance in our daily tasks, and at the same time, at the end of the sprint we have to let our work to review PRs.
Our goal is t... |
So I came upon this time complexity result and I was confused about it, it said that :
O(nlogn) + O(logn) =O(log(n+1))
Why is that the case? Shouldn't the result be O(nlogn)?
|
I've had this idea because I've recently had to upgrade a large enterprise project (due to security vulnerabilities) that was completed and not touched for years before I joined, and both the backend (Spring) and frontend (Angular) were so out of date that I'm not sure it's possible to upgrade it since there was no doc... |
I have been looking at different solutions for large scale chatting solutions. I feel as if I understand 90 % of it but am turning to this forum to tie the knot.
I imagine running a bunch of message servers behind a load balancer, keeping long lived connections to the client (wss or xmpp). The amount of servers can sca... |
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/422
The HyperText Transfer Protocol (HTTP) 422 Unprocessable Entity response status code indicates that the server understands the content type of the request entity, and the syntax of the request entity is correct, but it was unable to process the contained ins... |
I have a few basic questions on how to implement an API for a basic e-commerce system.
The relevant entities are Customer, Puffle, and Review. Each Puffle can have zero or more Reviews. Each Review is authored by a Customer.
Currently, I have the following relevant endpoints:
/catalog which returns all Puffles with th... |
I will explain with an hypothetical example.
Suppose that my domain is Cars. Everyone around the software, talks about cars. Car is the aggregate root of aggregate roots. For example, CAR table has 150+ columns in database (irrelevant for this question, but for you to imagine).
So, there is class in the system called C... |
There are many posts about the benefits of static code analysis tools. However, in which scenarios would you recommend NOT using (or significantly limit) them? For example, do you also run them on tests?
I use mypy and pylint and usually find them very helpful. However, in a few cases I spent more time working around t... |
Let's say I have a system to which I can upload documents via an API. There are three services:
the UploadService - responsible for providing a HTTP endpoint
the StorageService - responsible for storing uploaded documents
the FileCabinet - responsible for managing a file cabinet (e.g. categories, hierarchy, etc.)
I'm... |
Can an effective code review be performed without first understanding the intent behind the code?
|
How does the 2 differ in terms of actual usage?
In DDD, we use a repository to get Aggregate Roots and persist them.
We forget about the implementations and focus on the domain and so it doesn't matter where we are taking the data from.
That being said, why does ACL exists?
Usual examples of ACL is when getting data fr... |
I have a single *.h file. This file contains a single (more to come) function declaration.
Now the implementation of that file is very complex.
the corresponding *.cpp contains several function definitions that are used by that publicly visible function.
I would like to keep the "main" *.cpp file of that function as cl... |
I'm curious if there are any obvious pitfalls to the following:
I have a database table that, because it is storing many objects of various subclasses, I'm using a JSON field to hold the non-overlapping properties. (i.e., the common properties like id, creation_date, parent_id, type are all separate "normal" fields, an... |
I have this list of Notes:
public static List<Note> _notes = new List<Note> { new Note { Id = new Guid("00000000-0000-0000-0000-000000000001"), CategoryId = "1", OwnerId = new Guid("00000000-0000-0000-0000-000000000001"), Title = "First Note", Description = "First Note Description" },
new Note { Id = new Guid("... |
if The ISA acts as an interface between the hardware and the software why we have firmware?
What exactly is firmware and how it works.
|
I'm just wrapping my head around the topic and building a simple neural network from scratch as I go. I'm trying out different data types to hold weights, values and biases as well as different activation functions and back propagation techniques.
While I have some success with treating the input/output layers as binar... |
This is Arduino code, but since it uses C syntax, and it's not Arduino-specific, I thought I'd ask here. I have a few values defined so:
#define PID_RPM 0x0C
Typically it's used as a hex number. But in one spot, I need to print the last 2 chars ("0C") as literal 2 ASCII chars "0C". Right now I do it with a switch and ... |
class Foo {
abstract doStuff() {}
}
class Bar extends Foo {
doStuff() { ... }
}
class Baz extends Foo {
doStuff() { ... }
}
From a functional perspective doStuff does exactly the same thing, however if it should be done to bar or baz then the implementation is completely different.
I try to separate data... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.