instruction
stringlengths
34
36.1k
I am using the Flyweight pattern to cache and reuse objects of the different classes. For example, I have a Shape interface class and multiple types of Shapes implementing the methods from the interface. I also have a factory class that has the cache of object types and object as key value. As you can see, there is a D...
I am currently working on implementing the Clean Architecture pattern using Entity Framework. However, I've encountered an issue related to the design of my Domain project. In this project, I need to define a "Wallets" table that should have a relationship with the "User" entity from the Identity project. Additionally,...
Lately I've been surveying the programming language landscape and one of the languages I looked at was Pharo, a modern Smalltalk. Programming using a living system that runs in a virtual machine seems like overkill to me. I also don't like the fact that programs in Smalltalk cannot be fully specified using human-readab...
When and Service Oriented Architecture (SOA) is designed, and the ESB is changed to multiple independent service busses that talk to each other (pub/sub), does the architecture cease to be SOA? Is it then a blend between Microservices and SOA? Full Microservice? SOA has "bounded contexts" it seems to me, though I usu...
I'm looking for some best practices for readability (and clean code in general) for naming modules/classes within more extensive projects. More specifically, is it reasonable to add the package's name to the module/class name? For example, which of the following two structures is preferable? |-- my_application | |-- ...
I'm trying to implement the MVVM-pattern in a new WPF-application. I'm using the MVVM Community Toolkit to reduce boilerplate code that comes with the pattern. In my application, I'd like to have a MainWindow that shows a list of records. Additionally, I'd like to have another Window that acts like an "import-wizard". ...
I am having a bit of problem trying to find the correct place for business logic. The project I am working on isn't huge, but is not small either and has a very considerable importance in my company. That said, I'd like to know how to better organize my business logic. First an example of how things are today. The meth...
Is having a separate read only and write only data store a core part of CQRS, or does it still make sense in some scenarios to do CQRS with a single data store? Asking because a coworker is using CQRS terminology in a project. Whether or not he's actually using the pattern I can't say because I'm not familiar enough wi...
The problem I noticed is that I wrote a function called filterX which removed any X from a list. Then another engineer came along and wrote a filterY function which kept only the instances of Y in the list. Then it hit me that an "air filter" keeps the "air" while a "noise filter" removes the "noise". So essentially th...
I have a simple product consisting of 3 apps - Android mobile app in Google Play, backend API and backend administration website. The API is connected to various external services but this question is specifically about Google Play's (GP) in-app billing system with in-app products. My API can manage the GP's in-app pro...
Although I love Rust's enums (and the idea of making illegal states unrepresentable), I'm struggling to represent (ironic, yes) them in databases like PostgreSQL when the variants have data associated with them. Example problem Suppose we have something like this: enum PetKind { Dog, Cat, Bird { can_fly: bo...
I've been interested in following what other successful libraries are doing with their nuget packages. Unfortunately, I can't seem to find any materials to read online and I don't even know what to search for. What I'm referring to is how a nuget package can be broken down into something like this: CompanyName Company...
When creating a web application that will allow users to upload images and mark them as private, should those images be protected by authentication and authorization mechanisms against access by other users? The answer seems like an obvious "YES". However, this does not seem to be the general practice. I have played wi...
I maintain a relational database of sorts, and occasionally a feature request requires a schema change (eg. add a new column, etc...). However, a number of "services" consume this data. It's not obvious what will break if data change happens. What are some good strategies to test for these changes and gain confidence w...
In my company, all of the projects use at least some kind of global state library like Redux and MobX. However, the actual usage is limited to storing fetched data, and it lacks any caching logic or mechanism. It's merely used to store the method for fetching data and the property for the fetched data. Personally, I fi...
I have a ASP.NET Core backend (with Azure Service Bus) and a Blazor Server frontend. The purpose of the backend and the frontend is to trigger manual and automatic pushing of single data points (hereafter called the "data pushing process") to 2 different external systems (two different, unrelated APIs, that I don't con...
For example, I know in c++, I can use myString=="abc" to check if 2 strings are equal. However, in Java, it is comparing if 2 objects are the same object. Also in other language, for example, javascript, I should use myString==="abc" instead. In my current environment, I may switch between c++ and Java frequently, and...
In Common Lisp, we have to use the let form to declare a new lexically-scoped variable. This means that the code either looks like that written in C89 (all variables declared on top of scope), or acquires unreadably deep nesting. let* is somewhat useful, but is not always applicable. Scheme 'solves' this problem by hav...
I'm designing a file sending system from a server to many remote clients, around 5000; each file has only one recipient client. Files rarely exceed 10MB. The server is published on the internet, the clients access the internet but cannot be reached from the outside. I'm evaluating two solutions. Expose a WebApi on the...
What are the performance implications of using multiple threads versus single-threaded asynchronous programming in Python 3.9? I've been working with Python for quite a while and I'm familiar with both multi-threading and asynchronous programming (async/await). Recently, I've been optimizing a network-bound application...
I create Hexagonal Architecture based software with TypeScript or C#. The heart of Hexagonal Architecture is the Domain Model. For example, for a user of application y, the domain model might look like this: // typescript export interface UserEntity { name: string; email: string; email: string; someFunction(ar...
I frequently use the concept of Active Objects (https://www.state-machine.com/active-object) combined with state machines when designing code. The key idea behind these is that only "events" are fed into (and out of) an object and state machines "react to" these events. This leads to a very different type of design f...
(updated) We have a read-only REST endpoint that performs a somewhat “expensive“ but transient request. Without client needing to poll, we need a mechanism for the server to avoid unnecessary processing whenever “similar” but not yet cached requests come it at the same time. What existing technologies & designs can rob...
I've built a matchmaking system where two of the classes look like this: I know that it actually looks like an inheritance, but in the code it doesn't extend to the PlayerInMatchmaking and the program is completed and already tested (so I prefer to not change anything). Can I write it as inheritance? If not, then what...
I am preparing a software package for internal consumption in my organization. It will be published on our internal non-public npm feed. The used technology (npm) requires me to adhere to semantic versioning by format, though I would also like to adhere to it by idea, which is what this question aims at. The content of...
I very much want my code to be const correct and I'm struggling to get the following case right. Say we have a function F that takes a data structure D and computes an auxiliary data structure D'. F does not mutate D, but the returned data structure D' holds non-const pointers to elements in D. D could be a directed gr...
This question may get closed quickly, but I'll appreciate any advice I can get and all the resources I can find online about this topic aren't quite relevant to my case. I am a Math PhD student doing an internship that requires me to do a lot of machine learning. From my background, the algorithms and statistics are re...
I'm working on the documentation of software management system. That system can be linked with an e-commerce website to get financial data directly. For example when a transaction will be made it will automatically get updated in our system. I want to ask if I need to include Database as actor in use case diagram?
I have to create a system to interview people on a few topics where they have to answer both objective and discursive questions, where questions may change between interviews. I structured the database in the following manner: Interview is a table with the user's e-mail and timestamps. Objective/Discursive Answers fie...
We have some services (consider 10, some of them already exist and some are yet to come). All of these services have a common part where they keep track of what's being changed, and these so-called "logs" are shown to users, and the persisting/searching pattern is also common in between all of them (searching might be ...
I am writing tests TDD-style for a cryptography package containing encryption and decryption methods. I test my methods with various kinds of inputs, including multiline strings, mixed case, calling encrypt on decrypt, and mixed case of keys. @Test void testConversionLower() { String originalMessage = "...
I mostly write mobile apps so this is definitely coming from that perspective, but I think it applies for most UI development. Suppose I have a UI with the following pattern: I want to have some user interaction in one part of the UI, and another part of the UI that reacts to it. For instance, the user sets their prof...
We have recently completed the development of a large system (150,000 lines of code more or less) which was developed from an HLD. Our stakeholders want to take the HLD and compare it with the source code. Is this a common practise? What is the goal of the comparison?
"In my company, we have this distributed system over Kubernetes. Some microservices are shared among all customers, and others are up to them to upgrade. This system has to interact with A LOT of customer's services (VPNs, private APIs, databases, log aggregators, etc.), and each customer can have wildly different envi...
I am wanting to enhance a system to execute various background tasks (primarily data importation). In order to provide data for support, analysis and job status generally, I had been thinking of implementing a related table to record task updates e.g. datetime message 10:00 Job started: status chang...
I've been trying to build this (principally desktop, but could eventually be turned into a cloud app) document editor program for a while and have it laid out using the broad principles of the 3-Layer (Data, Model, and UI) and MVC (Model-View-Controller) patterns, and one thing I've often run into is where to best put ...
Python, Ruby, Rust, Haskell, Kotlin, C#, C++, Perl, MATLAB, SQL, and R all call their respective array predicate checking functions any and all. Is there any record of why JavaScript's designers decided to deviate from the naming convention other languages have used for these functions since the 90's? Some Lisp-family ...
For example, I have an object: public class Obj{ public int a; public float b; public String c; } I need to find best "Obj": largest a and then largest b and then longest c: int bestIndex = 0; int bestA = 0; float bestB = 0.0f; String bestC = ""; for(int i = 0; i < objArray.length; i++){ Obj obj = objA...
I have a kubernetes deployment which is fielding expensive (but cache-able) requests, let's say a website scraping service (not really) which takes about 15 seconds to scrape a website. In my backend I also have a postgres database running which I can use to cache request data. The a typical pattern of requests to my s...
I have an existing application using Codeigniter Framework (MVC). I need to implement an integration in the software with the external cash register (e.g., making REST API calls). I need to either make a controller or a model (or both), but I don't fully understand which. The functions within the class will be doing th...
I am writing a web application for a simple, multiplayer dice game so the traffic from the client to the server is going to be pretty light and latency tolerant. The client will need real-time updates from the server so I was originally going to implement the game entirely in websockets. However, I've come across desig...
I'm tasked with developing an application which is going to track what an end user does in a session. My application doesn't handle user registration or anything related to user. The user management is a different bounded context(a separate micro service in my case.) But my application would need to identify an user fr...
I write embedded firmware using C++. A common job for firmware is to "handle" different types of "messages" (e.g., in a communication protocol). The "C" way of doing this would be a really big switch statement like so: void handleMessage(const AbstractMessage& msg) { switch (msg.id()) { case Message1::kId...
Problem statement: You are given an array of strings. Each element (string) of array is of size 2. You are supposed to find the length of shortest possible string such that every element of the array is a subsequence in that string. And we also have to return the number of such strings possible of that length. Example ...
I've been working as a test automation engineer for almost two years now. As expected, most of my job involves ensuring that the automation (primarily written in Python) is operational and reliable. However, I often find myself performing numerous tasks such as creating and maintaining test cases and test plans, debugg...
When talking about having a rich domain model successfully, in real applications, it needs to, somehow, access some abstraction of complex functionality (instead of being a row state calculator the way we see in most examples). But, is there any problem in using abstract classes with polymorphic properties to do this, ...
I have lots of code like the following. An "Entity" type that has some numerical properties. To be able to reuse the arithmetic I write the arithmetic functions against an interface. I use extension methods, which are easy to use. I use similar extension methods to convert the numerical values into formatted text to di...
In C programming, I have a set of information, and I have to ways of providing it to user: construct a data structure and provide it as an object. write a function to read them out and return them. I used 2 for part of my project - some of my users expect to have those values available at compile-time, so function-li...
Stack: ASP.NET Core + Razor + SQLite TLDR: How do I rely solely on Facebook Login for authorization? I am building an app with sole integration to Facebook for my Facebook group. Essentially it is a "bidding" platform where ultimately the buyer & seller will communicate directly outside my app. From my initial planning...
In the Netflix series Suits, Season 1, Episode 8 (Identity Crisis), the legal team, with the help of a hacker, is tasked with proving that a business magnate embezzled funds, splitting them and opening several different accounts across different overseas banks (i.e. to launder the funds via structuring). They know the...
I'm interested in integrating with an external system which uses webhooks to notify clients of events. The system is very similar to Stripe - the REST endpoints have rate limits to avoid undue polling load and instead relies on clients/users receiving webhooks to keep track of state. In the rest of this post, I'll writ...
In a multitenancy application where you create a new postgres database for each tenant, what's the best way to handle database connections on runtime? Do you open and close connection on every request or do you leave a connection open once opened, if yes, won't you exceed the number of open connections and how do you c...
I have a C-Style API with methods that return pointers to native objects, e.g. EXPORT hs::Pose3d* getJointEndPose(dh::Joint* joint); And in C#, [DllImport("Solver.dll")] public static extern IntPtr getJointEndPose(IntPtr j); To make the API a little nicer, I would like to distinguish between the types that the IntPtr...
After reading What is a" feature envy" code and why is it considered a code smell?" I know the following code is suffering from "feature envy": public class Garden{ public float width; public float height; } public class Owner{ Garden garden; public float getAddLawnCost(){ ...
I've a issue that hasn't been answered for long. Say, using a class C as the member of class B that is the member of class A (or even deeper nested). When I design some classes I often design such nested classed. I know that it often makes trouble, for example, if you forget to initialze a member of such class, the cod...
As the title says, Im thinking if it's a good practise to have classes that have Open and Close methods in the sense that they can be reused without a new instance being created again. Also, if I want to use Dependency Injection with the class and use it with IoC, then I dont think I can pass for example a "filePath" a...
I'm working on a website that, for all intents and purposes, functions as a Choose Your Own Adventure book rendered as a single page app (SPA). Starting at the left, this is the user experience: Each (virtual) page is rendered from an HTML-like templating language, making the user experience dynamic; for example, the ...
My application has to maintain a stateful object and update it periodically based on events received. I get an initial HTTP request to create this stateful object. After that the object has to be updated asynchronously(using RabbitMQ in my case). On my initial HTTP request I create a domain object. I thought I'd just c...
I am preparing to create my first .NET MAUI Blazor hybrid app. It is a relatively new technology so there aren't a ton of resources to look at, but of the ones I have found, they are all structured like so: With standard .NET MAUI apps, most people use the MVVM design pattern from what I can tell. Those look like the ...
For most apps I've built which deal with CRUD operations, I end up two very similar UI pages: one for the creation of the object, one for updating it. An example would be StackExchange's UI for creating a question and the UI for editing a question (but very similar, but slightly different). How can we minimize duplicat...
For example, for a mobile frontend, you need to get all the data for rendering at once. The interface is divided into blocks, in which there can be both blocks with a catalog (categories) and other types, for example, banners with additional information, and they are all mixed on one page. Each block has a position num...
One of the main guidelines I keep seeing for successfully building a microservice application is to use a separate database for each microservice. In diagrams these are usually depicted as physically separate databases. My question is, could a single Postgres process that manages several separate databases be an accep...
I have been told that Rust is both safer and faster than C++. If that is true, how can that be even possible? I mean, a safer language means that more code is written inside the compiler, right? More code means more instructions for the processor to process. In this case, I'm thinking about arrays. In C and C++, you ca...
I was reading the infrastructure persistence layer design documentation, and this quote has me confused: This'll probably be my biggest feedback. I'm really not a fan of repositories, mainly because they hide the important details of the underlying persistence mechanism. It's why I go for MediatR for commands, too. I ...
I'm making a piece of software that is able to recognize Magic the Gathering Cards from a picture or the actual camera. The codebase scans for rectangular shapes (cards) in an image and calculates 64bit perceptual hashes for them, which get compared to a precompiled database of approximately 40.000 hashes for all the m...
Currently I have an existing API for my AI Engine, and a python wrapper to interact with the API. So this wrapper acts like a helper class to help format and automate some of the process that is needed to call the API. There are 2 ways to interact with the API User (using Jupyter Notebook - python) => Python Wrapper =...
I work on a SaaS system which is generally a single-tenant environment. Customers (whom the SaaS instances are for) would like a way to subscribe to events, such as updates of certain data entities. For the most part, it seems like a general Pub/Sub architecture, where our system publishes the message, and the customer...
At the moment I design a RESTful API for a resource that is normally created by a cron job from existing data. Since the cron job runs only every 10 minutes it is possible that GET: /user/{id}/resource returns a 404 Not Found. In that case the client needs to create the resource with a POST request with an empty body I...
I'm learning JavaScript and just came across "use strict". It sounds like to me it should always be in play but me being a beginner I was wondering if there are scenarios/environments when we should not use "use strict" (besides super old code that doesn't support it obviously).
I'm building an HTTP API database adapter that has an authentication component. Users can authenticate using password, federated login such as OAUTH, and JWT. My initial design is something like the following: pub enum AuthType { Password, Federated, JWT, } pub struct Adapter { pub client: reqwest::Cl...
I know there have been many post about diamond problem, one of it: Why do you reduce multiple inheritance to the diamond problem?. But I'm not asking what it is or what is the solution of the problem. Also I'm not asking why multiple inheritance is bad. What I don't understand is, why is it a "problem"? Consider: struc...
I am currently reading Code Complete. And I was confused when the author in one case uses the term "detailed design", and in the other "design for construction". What is their difference? Or is it one and the same? As I understand it, when developing architectural developments, it will be necessary to "apply processes"...
AFAIK, APIs are a means by which two computers communicate with each other. What exactly is REST API? My confusion arises from this figure where a docker cli which is on the same host as the docker daemon requires REST API to communicate with each other. Isn't that weird? Why'd you need REST API to communicate in a sa...
Say I have a simple layered .NET application, with three layers: API Adapters Application The application layer needs to use some typed http clients to communicate with external APIs. This means that the typed http clients cannot be put in the Infrastructure layer, unless interfaces are provided in the application (...
I'm making a console application that returns a lot of information directly to the console. I do this with a custom logger. Actually my logger implementation is just a frontend to print (with some extras). The application is quite complex and I made it in DDD style, but one thing doesn't work for me - almost every busi...
When retreiving data with an api and saving it in a DTO, some values are nullable: null on initial class initialization but VS also warns you for this. For example, an employee: public class EmployeeModel { public Guid Id { get; set; } public int EmployeeNumber { get; set; } public string? FirstName { get; ...
I would like to represent tree structures in YAML. Each node of the tree is composed of a (key,value) pair. The key must be a string. A structure like this would be perfect: node1: child_A: child_AA: child_AB: 1.2 child_B: node2: ...except that I sometimes have nodes that have value...
I often see /-/ in API design, what is it used for? Is there any related documentation? I have tried to find it in the following documents, but did not find any relevant information: https://cloud.google.com/apis/design https://google.aip.dev/general https://learn.microsoft.com/en-us/azure/architecture/best-practices/...
Currently my code base has 3 deployments, development : where devs unit test and develop features, testing : where testers run end user verification for the features and production : the deployment available to clients. The issue we're facing is that all 3 routinely go out of sync. One solution is to allow only develop...
Can a use case use both extend and include? For example like the "Take Advanced Knowledge Quest" use case in the picture below.
Say I am trying instantiate an instance of a Table. Table here denotes a restaurant table used for eating. Say I have 3 different table types enum TableTypes { SMALL, MED, LARGE } I have some questions on the best way for the following Should I have 3 separate lists that hold available instances of 3 tabl...
Let's take an example of Order. An order can have the state new, canceled, shipped, or processing. The new order can be processed. The new order can be canceled. The processing order can be shipped. The processing order can be canceled. The canceled order cannot be processed, shipped, or new. The shipped order cannot ...
I have a huge amount of files (mostly documents like pdf ~80-90%, but also images, videos, webpages, audio etc.), somewhere around 3.8 millions of files which occupies ~7.8Tb of hard drive space on a 10Tb hdd. I have tested a lot of software from the internet (Windows and Linux) for removing duplicate files but it's ju...
My company, which specializes in logistics and transportation, delegated the majority of the backend microservices to our team. All of the microservices (which our team inherited from "past generations") appear to have inconsistent input field validation. Mobile number format validation is a good example. There would u...
I'm working with a RESTful API where a POST operation is used to create a user. A required field, which could be an email or a unique user nickname, is unique across the system. The response to this POST contains a unique id for the user, which is a deterministic hash calculated from this unique field. Therefore, the s...
I've been reading a bit through Clean Code and I came across the Single Responsibility Principle. The principle states that every class should have only one responsibility. An example taken from chatGPT gives me this: #include <iostream> #include <vector> #include <string> class Product { public: Product(std::stri...
Looking for a good reason to avoid this solution. Problem Multiple microservices/SAAS, each storing the same data that needs to be synced (example is customer contact details). 1st is an OAuth microservice. 2nd is a CRM that supports Pub/Sub pattern. 3rd new microservice possibly a 4th like marketing automation (Hubs...
I'm not sure how to manage configuration settings in a C#/.NET environment. For simplicity lets say I have 3 assemblies: My MainApplication is the project being started and containing the business logic. It references a separate Configuration library, which reads numerous configuration values from a config.xml file tha...
In the context of an object-oriented language, such as Dart, I have an abstract entity which has a single property called id (which is incrementally uniquely generated to make sure there are no-clashes). Then, classes which extend Entity can add other properties on top of the Uid, which however are not final (i.e they ...
Something like this cmp $0, %eax jl exit jumps to the exit: label if the content of register eax is less than 0. So it's kind of jl applies the < operator to the operands of cmp, but in reverse order, i.e. content-of-eax < 0. Why is it like this, historically speaking? Digital computers were born in the left-to-right ...
Do RESTful endpoints eliminate the need to SQL triggers? Triggers are supposed to execute after a certain event. Would moving to RESTful api endpoints conceptually eliminate the need for SQL triggers? The reason being, effects triggered from an event can be managed purely by well constructed RESTful endpoints. This inc...
I'm aiming to create a simple event-driven system where each microservice operates with its own database. The idea is to share database changes across microservices through events. To ensure proper event ordering, I'm considering a strategy where I use the unique ID of a database row as the event key. This way, events ...
I've seen in several REST API guidelines recommendations to use filtering in form of, e.g.: /products?filter=name eq 'Milk' or price lt 2.55 (example from: https://github.com/microsoft/api-guidelines/blob/vNext/Guidelines.md#971-filter-operations ) I tried to find a library that will help me to parse this kind of reque...
I have a small open source package and I'm trying to automate parts of the release life cycle. I am very confused about how to automate version bumps. Here's the relevant information about my version bump procedure. I'm working in Python. I define the version hardcoded as the __version__ attribute in __init__.py in th...
From my understanding, in declarative programming, programmer only need to define the end result, but not how to compute it. But for execute that said function, the function must be pre-defined by the language, that instruct the machine to compute, step by step, for user to use in the first place - hence it implementat...
I have a discussion with a colleague regarding how to model a command that immediately gets an answer to it's HTTP POST request back. In this specific case we do an API call to a 3rd party IDP API that we don't control, we'll do a HTTP post and get a response. There are two statements from him regarding this: Event St...
I'm currently working on a Spring Boot application where I need to create an endpoint similar to the one mentioned in the Confluent Cloud documentation (link). The cURL example provided in the documentation is as follows: curl -X POST -H "Content-Type: application/json" -H \ "Authorization: Basic <BASE64-encoded-key-...
I'm working with an API that uses OpenAPI for its schema documentation. However, there are certain fields in the request body that shouldn't be visible to all consumers, for example, internalProperty: bool. These properties are crucial for some internal functionalities but aren't documented in the public-facing schema....
I'm a novice in UML component diagrams. How would I draw the following situation? I have an << item >> called "DataAquisition". This item consists of a << unit >> called "driver". The driver requires an interface to the device, which is connected to the physical device. This is modeled by passing the interface through ...
I write BFF (Backend For Frontend) and it's domain is to provide user info and microservices integration. The User domain model looks like below: public class User { public required Guid Id { get; set; } public required string Name { get; set; } public required AvatarUrl AvatarUrl { get; set; } } The domai...