instruction stringlengths 34 36.1k |
|---|
After reading What differentiates function objects from poltergeists?, according to the definition of poltergeist, I still don't understand why would "poltergeist" be a bad pattern:
A poltergeist is a short-lived object, typically stateless, which is used solely to trigger or initialize several other objects and then ... |
There is a variable that must persist between calls but otherwise only one method uses it.
As it is a method of the object, the value can be persisted as a private field of the object, or otherwise it can be persisted as a static variable within the method. The initial value is trivial and can be easily assigned in any... |
At work, we have a Web application, which makes queries to databases, and I’m asked to determine if using Web APIs could be an added value.
Personally, I’m not convinced it is.
I know Web APIs are tailored to let different systems speak a “common language”, but having one to just access databases seems overkill to me. ... |
I have a Svelte web app exclusively for internal use, so there is no main landing page or registration, as accounts need to be created by the admin. Since the main page has no function as an unauthenticated user, it will redirect to the login page. After a successful login, there is a JS redirect back to the home page,... |
The below code sample given is for Salesforce but it is close to Java and you should be able to understand easily what I am trying to ask here.
AccountController.getAccountsThatMeetSpecificCrtieria is a method invoked by front end(ex: jsp) and if this method runs into any error, Salesforce says, we have to throw specif... |
Hi I have following structure :
Client App (layer 1)
Business logic Services ( Layer 2)
Business Logic layer consists of many microservices . Access token can be created and passed from APP layer to business logic layer. Business logic layer could validate the access token and allow access to required operations.
But S... |
I am currently struggling with how to solve nested grouping of data.
The initial structure is given and my grouped structure below as well as my approach can be adjusted.
My idea was to have the array of objects grouped by multiple parameters in a nested way.
Let me show an example structure:
- City: Zurich
-- Date: 20... |
I'm currently learning how to separate frontend server and backend server. However, i'm not sure which approach should i take between the two
Frontend server obtain data from backend server and adjust pages based on result
In this approach, user connect to frontend server, then frontend server connect with backend se... |
The problem
Let's assume such scenario:
List of IoT devices (one model?)
Each list item has (among other fields) a type field
Depending on the value in the type field, device may report different values (by number and sometimes type)
And I need to save them in the database (related to reporting device, of course).
So... |
I have a single connection being used by multiple devices, and I'd like to filter the messages so that each device only reacts to messages intended for it. This can be done with an unique ID field in the messages. I have two options.
Option #1: Have each object filter the data from the connection themselves:
class MyDe... |
Let's say, in a rather big application suite with multiple more or less integrated products, data is stored across multiple databases. Some of them are SQL-ish DB clusters, some are MongoDB clusters.
Some entities (= "rows" or "documents", depending on the type of DB) are stored in several databases. Many (if not all) ... |
Some years ago, every API I developed was a REST API and I did everything to follow the best practices to make them "RESTful".
But after some time, I have my doubts if RESTful APIs that should represent a Domain are not even an anti pattern.
The most important reasons:
The HTTP Methods like POST, PUT, DELETE and GET a... |
I know there are some posts talk about primitive obsession : When is primitive obsession not a code smell?, Is "avoid the yo-yo problem" a valid reason to allow the "primitive obsession"?, but the posts mostly talk about business data fields like "ZipCode" and "Address" (I can't define what "business object" is accurat... |
I made a small utility as a PowerShell script. It worked fine, but wasn't very practical when getting other people to run it who weren't familiar with PowerShell. I modified it to add a GUI using System.Windows.Forms and then used PS2EXE to turn it into an executable. Again, this worked fine - double click the exe, do ... |
I have an end point where a user can start an update operation. I don't want to make the user wait for the result. There are two possible outcomes:
The action is succesful - nothing to do for the user.
There is an exception - this is logged (every exception is) in WatchDog and the database admin checks this.
[HttpPat... |
I'm modeling a part of Python/Qt GUI code which uses reflection to construct a collection of widgets, in a form. The code works like this:
There is a Model which has attributes of various types, including (but not limited to) Foo and Bar. These types have corresponding widget types to be used in the form (FooWidget, B... |
During my career I only used DI to insert object of certain class based on certain interface. So there was never the situation when I needed two different bindings for one interface.
So natural question arises: can't I just use Concrete Factory instance of which I will create on compile time/runtime and use all over my... |
I heard that if you maintain a program, you have to study what the code does. Another engineer said it is not necessary. Just use test cases to find out the function that does not work well, modify the code so it handles the new case, as well as the previous ones, and release it. So when fixing bugs, do you have to foc... |
While writing the constructor for class A in Python, I calculate some of the class's fields using function fun(). This function is never used outside the constructor of instances of this class.
In situations like these, I tend to write fun() so that it returns the desired values and then I assign these values in the in... |
I am working at a digital banking company i.e company that provides software for banks so that the customers of that bank can use banking services via smartphone.
But the documentation there is non-existent. I am always confused about the working of the various types of payments like:
How does transfer of fund between... |
On day 1, one person discovers a secret.
You are given an integer delay, which means that each person will share the secret with a new person every day, starting from delay days after discovering the secret. You are also given an integer forget, which means that each person will forget the secret forget days after dis... |
Working on DDD lately got me thinking about how it preforms on large scale systems.
Watching many tutorials and reading many articles makes it look fun and promising for small projects.
I have three questions for three different categories of DDD.
Lets take the famous example of eCommerce, Say Amazon.
Data Duplication
... |
As I was reading this blog post: https://go.dev/blog/loopvar-preview about scope of loop variables and as I’m trying to learn #GoLang, I asked myself the question: “okay, but is really so common pitfall in practice?”
Then I tried it with Subtest and Table testing, ...to me becomes blatant potential pitfall:
func TestHa... |
I have a question about what's the best approach to handle persistent data for web apps.
I have a web app that is authenticating through an auth service. once authenticated it makes requests to the resource server.
However, when a user logs in, they want the display settings of the web app to be consistent regardless o... |
I have Firebase connected to my web app and users can authenticate using the 'microsoft' provider. The provider only allows authenticating with the active directory tenant that I specified in my firebase project.
I also have a SQL database that I want to let the users connect to after they're logged in on my web app. I... |
I'm in a pickle following a recent executive decision by our parent company. They have elected to abstract away our SQL data warehouse, transitioning to a REST API for data retrieval. The purported aim is to streamline data access, though, as anyone previously accessing the data warehouse will now have to make web requ... |
Versions are on the form:
x.y.z.[..]
Where these letters are numbers and there are arbitrarily many of them.
The first version is 1. The next one is 2. The only time when you
branch out to the next components is when you have the following case:
You need to make a new version on top of X
X+1 is already released
Then... |
I would like to use std::chrono::time_point in some simulation software I am writing. I would like to take advantage of features like the time point arithmetic functions. However, I run into a snag. I need to define a clock to use with my time points, and the spec indicates that clocks have a now function such that ... |
Are there any algorithms that can do or suggest merges without requiring the "base" file, the most recent common ancestor of the two file versions that we want to merge?
Is a manual merge between two files still considered a 'merge'.
|
I believe this forum is the correct one for my question, based on the community guidelines but let me know if not. It seemed like the best fit.
I am performing a data modeling exercise to formulate a conceptual model of our business to support our requirements. An obvious step is discovering the entities.
My challenge ... |
I need to process a queue of videos in a scalable way. Processing includes number of tasks that can depend on each other. Some tasks are computationally expensive some not (e.g. transcribe audio, clean up, summarize, extract features from transcription, etc.).
I think to create a DAG to define tasks dependencies and th... |
I have about 60 repos containing Python packages, currently using setuptools in a setup.py (run via pip install) to manage third-party dependencies. Most of these packages need to be installed on a system at the same time, which means their dependencies all need to be compatible with eachother.
The dependency versions ... |
I have a little pet compiler project that generates bytecode interpreted by a virtual machine. The language is kind of low-level, as it allows the user to manually allocate memory and dereference any pointer as they see fit. This can of course lead to bugs which crash the interpreted program. When the VM runtime is use... |
Is there a reason to encode options like this:
{
"options":[
{
"name":"opt1",
"value":"val1",
},
{
"name":"opt2",
"value":"val2",
},
{
"name":"opt3",
"value":"val3",
}
]
}
instead of like thi... |
I'm working in a codebase at work that requires that anyone who wants to merge a PR rebase against the last master prior to merging the pull request. To further complicate things, CI (which takes hours) has to pass before the PR can be merged, so if someone merges a commit to master while CI is running, you have to reb... |
Edit: I'm copying the question but changing the example code. Apparently, I used a bad example earlier that contained an imprue getter. I'm keeping the old example code at the bottom so the first answers stay relevant.
Is storing computed values in the app runtime state always bad in OOP? Assuming that:
Computation co... |
I've just accidentally came across this answer about inlined functions and I'd like to know how this affects call stack. But I can't add comments because I don't have enough rep so I decided to ask this question.
Also recently I discovered Tail Call Optimization (TCO) and now I want to learn more about this topic. And ... |
I'm learning about graph algorithms, so to learn them better I'm beginning to write some of them using c++. For example, I created the code for implementing the Depth First Search algorithm. Here's the class structure I have:
template<class T>
class Graph
{
public:
struct Edge
{
T src, dest;
};
... |
Background
Sometimes also referred to as doubly connected edge list, the HalfEdge data structure allows programmers to efficiently and easily modify topological and geometric properties of a mesh. Examples of things you can do with them in very efficient terms:
Find all neighbours of a vertex.
Split an edge.
Split a f... |
According to Explanation on how "Tell, Don't Ask" is considered good OO, I know I should avoid get the state of an object and then decides the actions to take to that object, eg:
Bad:
public class Manager{
public void scheduleCallback(){
if(this.systemMonitor.temperature>100){
this.systemMonitor... |
This article on Medium addresses the scopes of the domain model in hexagonal architecture.
I have sketched the following generic hexagonal architecture:
On the one hand, the secondary/output adapter receives the domain model ("model" for short) and maps it to a DAO for persistence.
On the other hand, the primary/input... |
Consider I have 4 Services .
Account
Order
Items
Customer
Now a External Partner Service calls all these services , by passing an External customer id ( EXT_CUST_ID) in the request.
Our platform has a Internal customer id (INT_CUST_ID) which can be found by querying EXT_CUST_ID inside EXT_ID_MAPPING table .
As EXT_ID... |
I am reading the paper "Ethernet Goes Real-time: a Survey on Research and Technological Developments".
In this paper, it says "Flow control can be implemented on a link-by-link or end-to-end basis"
Link-to-link means flow control examines only an individual link between switches or stations.
End-to-end means flow contr... |
I've noticed this kind of architecture in hub payment systems(system where you can pay to multiple merchants at one place-thus called hub).
payment app-->payment mediator-->bank server
Bank server deducts money
Bank server responds that it deducted money to payment mediator
Now payment mediator requests for verificati... |
I am planning to design a microservice system architecture for a ticketing platform. It will be similar to "TicketMaster". Here is the flow of my architecture:
client web browser
API gateway (nginx)
Virtual waiting room (AWS Simple Queue Service)
Once the user is out of the virtual waiting room (queue), an "identity" ... |
I am hoping someone has had to do this before and can help.
I have a multi tier MVC application that I need to add WebApi, in preparation for moving to .Net Core + react and a new set of controls for displaying data.
App built on .net 4.7.2, SammyJS (SPA), knockout (will be switched to React in time), and MS SQL Server... |
I have 5 interfaces in an API component, which in its turn call an external 3d party solution provider (REST).
The goal is to make this component universal, and under the hood support multiple service providers from the same industry for example, loyalty management. In other words the API component is a facade / gatewa... |
Given a class which has certain private, constants (e.g., configuration), should these (A) be included in the declaration of the class (in the private section) or (B) should it be "hidden" with the definition (in the source file).
Option A
//MyClass.hpp
class MyClass
{
public:
int foo(int a);
private:
static co... |
In the solution I've been asked to maintain (Meteor based app), there are several responsive SVG charts. When the page is loaded, settings for each chart are stored using the following:
<input type='text' id='chartA' style='display:none' value='{{settingsChartA}}'>
Then, when the window is resized, there is no curre... |
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, but the question is about template class or containers, how about the non container class? For example, suppose I'm using a UI framework, cocos2d-x, which Label... |
Here is a passage from the Blue book:
Distributed system architectures, such as J2EE and CORBA, provide
special publishing mechanisms for SERVICES , with conventions for
their use, and they add distribution and access capabilities. But such
frameworks are not always in use on a project, and even when they
are, they are... |
I'm using python and fastapi with oauth2 flow (just for clarification as the question isn't language specific).
I'm confused on how to implement scopes in an efficient and secure way. I was thinking of using roles and associating scopes to these roles, so when an user with determined role logs in, the API issues a toke... |
I'm designing class library with background service which has
public static class ServiceCollectionExtensions
Which have few methods which will be call outside.
Now above mentioned extension will call Builder pattern which actually building a services/Adding the services.
Now my problem is I'm designing a Mass-transit... |
My code has 2 python methods defined, m1 and m2. m1 receives 6 arguments - p1,p2,p3...p6. It uses p1 in its own code, but passes p2-p6 to m2. Is there a recommended programming style here to prevent the definition of m1 from getting too verbose?
Is this a good scenario to use **kwargs in?
|
I'm making code examples of how to start a modern microservices web architecture from scratch, and I only recently learned about API gateway pattern. So far, the authentication methods I used for microservices were either duplicated in every service or centralized via an internal auth service, called inside the other s... |
I have two bounded contexts, one to handle files and another to handled bills.
I have two projects, one for each bounded contexts.
Files can be any kind of file, an image, a document in pdf or any other format and so on.
I have a many-to-many relationship between files and bills, in the way that a bill can be related w... |
I am trying to write a simulation that has multiple (20+) variables, which the user should be able to control without modifying the source code. Currently I'm stuck between two design choices: Should I use one big class or multiple smaller class? Should I use a map/dict, or a class?
Example,
class Car:
class Engine:
... |
In C# and C++, an apparent trend is in place to reduce / avoid inheritance:
C#: "Sealing types can improve performance."
https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1852
C++ "Prefer concrete types..."
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#SS-concrete
I ... |
In a spare-time project of mine, I implemented RSA public-key cryptosystem.
Because the official PKCS#1 standard specify key formats in terms of ASN.1 syntax and DER/BER coding, which is a coding with variable-length encoding of lengths, I had to design a 2-pass interface to accommodate its encoding, where
in the 1st ... |
I am working on a Go application where two concurrent maps, products and productCatalog, are accessed by numerous threads in live traffic to retrieve data at high throughput. These maps are populated with data during server startup and are periodically updated with delta changes every 30 minutes from Kafka.
products ... |
In trying to learn DDD by applying it to a new project, I've run into an obstacle.
Here's a simplified structure of my very real domain: a project has many components which have many objectives which have many contracts for carrying out said objectives.
Project A
|_Component A
|_Component B
|_Objective A
|_Contra... |
Let's say I have a blog, I use DDD approach, I need to pass an instance of PaginationParameters class to PostsRepository, is it ok to bind DI container to concrete instance of PaginationParameters with exact values (let's say page_number=1, page_size=10) passed from HTTP request?
|
I'm making an interpreter (currently in python but later I'll remake it in C++) and I wondered how I could use a C/C++ function in my language so when somebody wants to write an extension for my language ex. an OpenGL extension he can bind the functions to my language.
|
I am working on a simple client server program in C in which multiple clients will be connected to a single server.
Clients will submit operations/actions to the server and the server will process these requests. These operations may be expensive and/or long running so ideally I would like to have a thread pool on the ... |
First of all, let me clarify the terms in order to avoid any possible misunderstandings.
Language is considered to be compiled when a program written in it's source code cannot be run directly without additional steps under normal conditions. That means it's usually and normally done that way. Technically we have onlin... |
I get that IOC containers can be useful to help break dependencies and allow you to test a class in isolation. I don't wish to focus on that right now, instead, I'm trying to understand some of the other arguments for using an IOC container. There's quite a few articles out there that introduce IOC containers (and the ... |
I have a server which maintains some shares state.
The clients can send some requests and get an answer from the server.
Sometimes the server needs to give some information to the client asynchronously (without getting a request first)
To make it easier on myself I would create two TCP conntections. The first where the... |
We have a .NET 6 application that consists of a REST API running in Azure App Service, and long-running background jobs hosted in Docker containers. These jobs are triggered by messages in a message queue that is fed by the REST API.
Logs from the web app are written to Application Insights, which works well for that p... |
I have a legacy 32-bit Win32 DLL driver that interfaces with a test equipment. I possess the API header file for this driver, and I dynamically load the DLL at runtime within my C++ test application using Visual Studio 2019. My goal is to port this test application to 64-bit architecture, but there is no corresponding ... |
I’m trying to use a VPN on an unreliable network that blocks UDP and randomly kills TCP connections (by spoofing RST packets). With OpenVPN this is tough because all the tunnel traffic gets sent through a single TCP connection. When that connection gets killed, the client has to open a new connection and start a new se... |
I have a package that provides an object with quite a lot of features owned by it.
Let us say the object is an HTTPServer, and when the user initializes it by providing config and a request handler object, the server would be serving HTTP with added request observabilty, panic handling, and other in-house logics.
Now, ... |
I know there are some questions about "Introduce parameter object", eg: Is "Introduce Parameter Object" actually a good pattern?, Should we avoid custom objects as parameters?, which means this form:
public void myMethod(int parameter1,int parameter2){
}
should be refactored as:
public class ObjectForMyMethod{
pub... |
I have a Spring Boot application which is containerized. The application has become huge with lots of complications and its difficult to maintain it. So I am thinking of breaking it into microservices. I have gone through the theory for microservices and have a basic understanding about it.
First things first... I have... |
As far as I understand it, the URI specification says that URIs are strings of the format scheme:b, and the format of b is specified by scheme (and there is not a finite centralised list of what scheme nor thus the formats of b can be).
So what's the point of that? Why would you want the concept of URI to exist? Why is... |
I have a private S3 Bucket that contains a lot of folders (currently 1000 folders). The amount of folders changes (new ones are added, old ones deleted). Every customer has to register and log in to the application, which uses AWS Cognito, to access those folders over a fronted. A user can only access specific folders ... |
I have a Java project where a coverage analysis tool is being used (SonarQube). It rightly declared that code similar to this was a potential performance issue (Encode.forJava would still be called if the log level was above INFO).
public static String foo(String bar) {
log.info(Encode.forJava(bar))
...
}
The fix... |
I would like to discuss with you this way about the best way to work with git.
We are currently developing software with three people. For version management we use git. The main branch is our productive branch. In parallel, everyone works separately in his own feature branch. This branch is regularly pushed and may be... |
I am developing a game idea that has a large collection of objects/widgets (let's say 5 billion objects). They each have specific attributes as follows:
style (10 styles)
pattern (4 patterns)
color (10 colors)
type (15 types)
etc.
etc.
etc.
(The number of attribute categories has not currently been determined).
An e... |
The Decorator pattern allows behaviour to be dynamically added to an existing object, effectively "decorating" it with new behaviour. While the pattern as formalised and named seems to have been popularised by the "Design Patterns" book in 1994 by the Gang of Four, I'm curious about its origins.
In functional programmi... |
I am working on a simple interface to SharePoint via Graph API. I have created a project that references Azure.Core, Azure.Identity, Microsoft.Graph, and other dependencies required to make calls via Microsoft's Graph API. This project is our API project and other projects will reference this API project to be able to ... |
Typically, when writing unit tests I tend to need to stub out collaborators and also mock some behavior in one or more of the collaborating objects. Say if I am testing a Service that is using a Dao, I will need to inject a mocked dao in the constructor when setting up the test.
But
creating new classes at runtime usi... |
In my projects I have several third-party Python packages which I need to build from source (because there are no .whl packages published for the versions+platforms I need). Currently these packages are built in the Dockerfiles which create my development containers and deployment containers. This has a few drawbacks:
... |
I am trying to write a unit test for a helper method in my ApiRequestHandler which handles APIGatewayProxyRequestEvent . This class uses an EFS file path, which is where it writes files to. I have this stored in my codebase in public final class Constants as public static final String EfsMountPath.
Obviously, I cannot ... |
I've been struggling with refactoring my code to use a generalized design pattern for a theme I see being repeated. The biggest struggle is that each instance of this repeated code uses different types. I have a tendency to keep code generic, but I haven't been able to find a way to support this with generics, even tho... |
I'm working on a component that needs to draw chart-like structures like this:
One issue I have is when multiple values are too close with each other. Here's an illustration:
The last values for the blue, green, and purple charts are so close that one can barely decipher the 61.0 corresponding to the latest blue valu... |
I am currently working on a codebase that is full of objects that are 3000+ lines long and have at least 20 dependencies each, and I'm about to try covering them with characterization tests before I start refactoring them, but I'm not sure how to deal with the dependencies they have.
at first I thought "if I don't mock... |
In the question What is "low code"?, there are many comments against it. One example:
In my experience these tools are managed by business users until they've painted themselves into a corner. Then developers are brought in to untangle a gigantic mess of unreliable buggy garbage with gobs of unnecessary complexity.
H... |
I was reading Martin Fowlers take on Dependency Injection, and in general have been trying to discuss it a bit online to help get rid of my own misconceptions and to understand this principle better.
In this article, he talks about one of the benefits of using dependency injection, which is that it allows you to share ... |
Please advise me what pattern to use in following case:
I have a Java/Spring Boot application. There is a component with @KafkaListener method which receives Kafka Messages on CRUD of various subject notifications, grouped in a bigger logical groups/types/topics (e.g. topic "humans" notify on "students", "teachers", to... |
class ItemList {
constructor() {
this.list = [];//list holds many instances of Item Class
}
removeItem(id) {
//...search for item in this.list, remove it
}
}
class Item {
constructor(parent) {
this.id = 123456;
this.parent = parent;//ItemList
}
removeSelf() {
t... |
What is considered better practice?
Case 1:
if n == 0:
doThis()
elif n < 0:
doThat()
elif n > 0:
doSomethingElse()
Case 2:
if n == 0:
doThis()
elif n < 0:
doThat()
else:
doSomethingElse()
The first case is more explicit and (arguably) clearer.
The second case doesn't handle the incorrect case ... |
When using properties in a Python class, you have a lot of boilerplate code. Is there a best practice to hide the code for the getters and setters?
I know about @dataclass, but the problem is mainly with classes that are not data classes, where you have to scroll through the boilerplate code to get to the actual functi... |
Ive been tossing this around in my head for awhile. But I'm working on a project that consists of an Order, that has a OrderStatus. There is quite a bit of logic that revolves around the status and changing of it.
I've got my fake order class below and I'm curious on the possible ways of implementing this logic - I've ... |
According to Should interface names begin with an "I" prefix?, I should not add prefix "I" to interfaces. However, I think prefix "I" in interface may be useful sometimes. For example, if the interface have totally different names with the implementation naturally, eg: "Fruit", "Apple","Orange", then I agree it doesn't... |
I'm building an application related to donation on streams.
And I have such models as "alert" and "alert-template".
"alert" is a set of different parameters to understand when alert about donation should be displayed.
"alert-template" is a visual config for the "alert" (image, audio, positioning).
At the end, on stream... |
Currently, all REST applications I work with have a three-layered architecture:
Persistence -> Contains "entity" classes with JPA annotations / Spring Data JPA repositories
Core -> Contains "model" classes which are POJOs, along with "service" classes that perform business logic by using repositories from the persiste... |
Suppose there is a C++ source code base of millions of lines composed of several hundred *.cpp and *.h files.
There is also a driver program main.cpp that uses several header files from the above source code.
Suppose I want to scan the entire code base and
(1) pull only those files that are used by main.cpp,
and
(2) ke... |
I know that it is common for software to have parallel development in major versions, such as v1 (1.x.x), which can be completely different from v2.
Regarding Semver (Semantic Version), can I upgrade to a patch version (e.g., 1.0.1) right after launching a minor version (e.g., 1.1.0)? Let me describe a situation that I... |
I have a program which needs some constant data, in JSON-like format. However, this data only needs to be consumed by my Python program, and by making it Python code, I can include types like datetime.datetime and enums, as well as custom types and any other type I wish to use. It would also improve performance, as par... |
I'm try to improve our deliver time from start to end. I read google post about 4key metrics. I have questions that don't find answers in any post.
1- Lead time definition is "The amount of time it takes a commit to get into production". When do you push first commit ? For example I have task. I can do big part of task... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.