instruction
stringlengths
34
36.1k
I am writing a library to allow two people to play chess for a toy project. For what is worth, it is in C++. I have deemed useful to have a class named Move, which represents a move which needs to be annotated in the history of the game. Objects of this class would provide the same information as an annotated move in a...
I find myself in a situation with the following implementation. I have a class that is exposed to users. My intention is to expose a high-level abstraction to the user rather than internal details of my library (or details they would need to handle without this library). An user can call some method named do_this_for_m...
Let's say I have an instance of a superclass and at a later stage this object needs to be converted into a subclass instance (based on additional information that are stored in the object). Is it acceptable to have a subclass constructor that takes a superclass object as an argument? Edit: A small but important detail:...
I'm reading Algorithm Design and Applications, by Michael T. Goodrich and Roberto Tamassia, published by Wiley. They teach the concept of primitive operations and how to count then in a given algorithm. Everything was clear to me until the moment they showed a recursive function (a simple recursive way to calculate the...
I really don't love the design pattern I've established here. It's kind of DI but not really, and the alternative is more constructor based DI, but I also hate it. Maybe it is because it is JS and that's just the way she goes, but I was hoping for a second opinion or a better pattern. Basically I have an app, that has ...
I have a pull request and this pr is being reviewed by co-worker. Context I'm using React and a specific component has ternary operator within component like below. const ExampleComponent = (): React.ReactElement => { return ( <div onClick={condition ? handlerA : handlerB}> <span>{condition ? textA : textB}...
I am designing a somewhat complex flow in publish subscribe pattern using AWS SNS, SQS , Microservice and Lambda functions. To break the whole flow into multiple logical & smaller sub-flows I am trying to accomplish that through publishing messages in different steps of the flow. But it seems the same microservice only...
Is it an anti-pattern to extract common configuration code as a library and reuse it across microservices? I am breaking down a monolith app into a few of microservices. What I stumbled upon is: since it is a monolith there's already one single point of e.g. security configuration (enforcing authentication on all endpo...
I have a class that is mapped using Entity Framework. This class has dozens of fields, and in the database there are millions of rows for this class. The class looks like this public class MyEntity { public string Key { get; set; } public string ImportantField1 { get; set; } public string ImportantField2 { ...
I want to know how standard I/O channels are handled in more depth. Processes have their own stdout, stderr, stdin channels where they can read/write. As far as I know, these are stored as temporary files at least on Linux, not sure about Windows, but the point is how does a process know where is another's stdin in the...
I'm the sole developer working on multiple projects on different versions of Java, plus some Microsoft Sharepoint front end projects. I REALLY need to figure out a better setup for my development environments and would like to know what others use. Please let me know if I should be posting in a different stack* communi...
I am working on removing obsolete/unused pieces of configuration from a .NET product starting with appSettings. There are multiple solutions and I've noticed that appSettings can be in a .config file in one project but which are somehow read in another project, sometimes in a separate solutions. What I'm trying to figu...
I work at a game company that has a Core Library with a bunch of ultities, extensions and systems that we typically import large chunks of into projects. Recently we have been trying to improve our process of improving our library. Essentially we gave devs freedom to write tickets themselves that they thought were impo...
In an RPC (Remote Procedure Call) design, an interaction across the network is hidden behind a synchronous API that makes the network interaction look (to the rest of the local program) like "just another local function call". The function-call sends its arguments (in some form) to the remote machine, waits for the co...
I am trying to engineer a library for the Genetic Algorithm optimization method. The main class for the GA is quite general. Here is what I have for it struct GAOptions{ size_t max_ga_steps; double weight;// -1 gives the maximum while +1 gives the minimum double cxpb; double mutpb; }; templ...
We have multiple publishers, that publish the data somewhere. For example, we have ElasticSearch publisher, AWS S3 publisher, or file publisher. Now the interface looks like this interface Publisher<T>{ void publish(T data); } now ElasticSearch or AWS S3 publisher does not require another parameters, it can get all ...
I'm working on a large C application that I've divided into sub-libraries (e.g. networking, message handling, message building, etc.) I've converged onto a pattern where functions are only allowed to return error codes, and all data must be returned via supplied pointers. This pattern has worked well because it is very...
I am writing a control app for a 6-DOF robot. This app can send scripts to the robot, which in turn executes these and thus moves around. In the app a robotprogram can be created by adding 3D coordinates called a point(class). This robotprogram is simply a Model with a List which contains all points. Also a few functio...
Having worked in complex solutions that had Unit Tests and Integration Test in the CI/CD pipeline, I recall having a tough time with tests that failed randomly (either due to random values being injected or because of the async nature of the process being tested - that from time to time resulted in some weird racing co...
In our company we have a requirement where we would like to store hundred thousands incoming records per seconds. we currently a pub-sub model for processing many records(100/sec) from many system(~1000) for listening to incoming events. now the problem is storing these records as fast as they come,(i.e. with minimum d...
Currently working on a project where the user will create a JSON file that's then read into the system. The fields of one object can be referred to in another object for relevant operations. Something like this: { employees: [ { name: "Mark", department: "Accounting", joi...
I am somehow stuck with my thoughts about an SLA definition, which I plan to determine for a REST-API running on a public cloud. Imagine having a REST-API service running on Azure which has a database as a dependency. To calculate the SLA for the infrastructure part, I would use the following calculation, regarding tha...
I assume the following is/reduces to a known problem, but I haven't been able to find it. I have a sequence of recipes with associated costs. Each recipe converts a set of resources to another set of resources. I.e. () -> (1A) cost 1 (2A) -> (1B, 1C) cost 2 (4A) -> (3B, 1C) cost 2 (1A, 1B) -> (1C) cost 1 I now want t...
I often get the argument that, if only a single team is working on the UI development, then the UI should not be developed as a set of Micro Frontends, with each one representing a subdomain. I would agree with the higher maintenance argument of such an architecture, but if one considered each Micro Frontend as an elem...
I have some doubts about RBAC which I cannot wrap my head around. So I would like to hear what you guys think. Though I understand the concept of RBAC, I cannot figure out how to apply that to my specific use case: I have a system that a company uses to audit its Franchises. So the components involved are: The actual ...
I have a micro-service based system running in kubernetes bare-metal. The key aspects are: download data from a datasource nightly and add to a database get any new data from the database, run a ML algorithm to get predictions for new data points I'm doing this using cronjobs at the moment, e.g. Cronjob 1 - python c...
Currently there's an aggregate root "Party" which for now only can be an insurance policy holder. A party can have multiple addresses, communication addresses (telephone, mail, ..), contact persons. A policy holder can also have multiple insurance policies, this is a different aggregate root. However new "personas" wil...
I'm in a situation that is the following: Company is an aggregate root and contains a list of contacts (name, phone, ..). On another aggregate root "Contract" you are able to add something called "Participants". A participant could be a company or a contact from a company. As far as I know, DDD doesn't allow to hold a ...
I have producers that take data A, produce data B and send it public interface Producer<T>{ void produce(T data); void flush(); } public class DataBaseProducer implements Producer<String>{ List<String> producedData = new ArrayList<>(); // create data public void pro...
Let's say we have an entity Customer which can have multiple email addresses. We create a ValueObject "EmailAddress", upon creation it checks if the address is valid. Is this concept valid and does it make sense? public class Customer : IAggregateRoot { public List<EmailAddress> EmailAddresses = new(); } If so, ca...
So a lot of the web says not to use public nested types unless you need the member visibility semantics (including this msdn article, even though that article hasn't been touched since 2008). For the most part, I agree with the line of logic. However, I am writing code right now that's performing deserialization of com...
is it possible to view behind the scenes of an exe file once its executed? to find the answers of a test questions? For example if someone clicks on F12 on a website the code is viewable to the user, is this also applicable to an exe file? Thank you.
Dave Thomas, the author of the Don't Repeat Yourself principle said: DRY says that every piece of system knowledge should have one authoritative, unambiguous representation. Every piece of knowledge in the development of something should have a single representation. A system's knowledge is far broader than just its ...
Model View Controller (MVC) is focussed on UI based applications. In MVC the model notifies the UI (view) when its values change and the view then decides what and if to update. I can understand this for desktop, mobile and single page web applications where there is a persistent UI. But why do some popular backend web...
We are currently in the early phases of developing several applications that differ significantly in their functionality. As part of building these applications, we have also developed a few generic BCs. Ideally these BCs should be reusable in order to minimize duplication and remove cross cutting conerns, and further ...
I've been reading about DDD a lot lately and something I can't find too much about is the following scenario: Let's say we have a Customer aggregate root and a Contract aggregate root. The reason they are both aggregate roots could be that contract could be accessed directly. A contract expects a Customer in the Create...
I am working on a relatively large project that could include +1000 iot devices, in this case probably a Raspberry Pi. So far I only experimented with ~ 20 - 30 devices but the concept should be the same. Currently thinking a lot about automatic Software Updates / Deployments on the device, when it's in the field (don'...
I was assigned a code review to one of my colleagues. I posed the following, which I wanted to share here in order to hear whether I am right or wrong. Consider the following code snippet: public void DoSomethingWithList() { var list = AnotherClass.GetList(); var itemsToRemove = list.Where(...); list.Remove(it...
Here is the pattern that I thought about for a resource accepting a single asynchronous HTTP request at a time (i.e. a request which has not yet been fulfilled when the response is sent): Create a single process: POST /resource → 202 {"monitor": "/process"} POST /resource → 409 "A request has already been accepted, re...
I have an Angular componente with two childs that requieres to share some data extracted from a http request. A service perform all the http request, and the parent component gets that data and manipulate it before it's shared to the child components. Is it ok to perfom data manipulation (maps to modify the structure o...
Given is the following dependency graph of a system with two subsystems. Calculate the CD (Component Dependency) of all components and also calculate the CCD and the ACD. See CDD here https://structure101.com/2014/03/10/why-cyclic-dependencies-explode-complexity/ This is my calculation: CCD = 5 + 2 + 2 + 2 + 8 + 1 + 1...
At my company we needed access to some variable to call a method on it, this variable is hidden about 6 layers down of different libraries code and each time it is behind a private variables (that this is so is a definite oversight, the method needed provides vital information pertaining to an exception that has occurr...
As I learned from the DDD rules, you have to change the entity through the aggregate root. However let's say we have a value object "Address". Is it allowed to do in the AR: (I've seen this in the eShopOnContainers by Microsoft public void SetAddress(Address address) {} Or do we have to do it like this in the AR: publ...
We are looking to develop an asynchronous server in C++. We are coming from C#, which has built-in support for async-await networking. However, with C++ it appears as if it is basically mandatory to use ASIO, other you're out of luck. I am wondering if there is are any other options besides ASIO if we want to make an a...
I'm building a service to send push notifications to the user. At first, I designed an Interface for the push notification adapters, something like this: interface PushNotificationAdapterInterface { /** * @throws NotificationException */ function sendNotification(string $appIdentifier, PushNotificatio...
A while ago Herb Sutter wrote The Free Lunch Is Over: A Fundamental Turn Toward Concurrency in Software which I basically interpret to mean that, in order to improve performance, software engineers are going to have to embrace concurrent, specifically multi-threaded programs. When I first read the article I thought I w...
I'm developing an API with ASP.NET, but I'm having some questions about the best way I should develop the controller layer for the products. I'm having these questions because each product will have its own service and its own purchase path, so product1 might have a step 1, step 2 and step 3 to buy and product2 might h...
I'm in the planning stages of a project involving communication between users in the browser environment and numerous devices running in a widely distributed manner. The end goal is that users using the web application will be able to send commands to the devices, the devices will receive and act upon these commands, a...
So the recommendations for using GET vs POST in a REST API that I've read on stack overflow are geared almost exclusively toward CRUD operations involving a database. However if you are simply writing the API to expose a machine learning model to serve predictions, most of the examples I've seen online use POST request...
I'm working on a CSS library that includes hundreds of selectors and rules for quick templating instead of writing regular CSS. This is used as a replacement of attr() CSS function until it works for any rule and not just content:. At first I generated a minified CSS file to load. But as there are many loops for each p...
Let's say there is a database that persists transaction data , e.g transaction items list of sale invoices , in raw format. Something like this InvoceId Item Price 1 Product-1 2.8592 1 Product-2 10.7559 1 Product-3 5.25 Data is exposed to other backend and frontend services by an API , let's call it AP...
Suppose I'm the first person write a proper Doxygen comment for a source file. Suppose also that there have been multiple contributors to the file - original author, previous maintainers, current maintainers, people who contributed a function, or just a minor one-liner bug fix. What's an appropriate way to list them (u...
I am working on a Spring Boot web application. The REST APIs are secured by JWT tokens. Currently I have only access token generated (not implemented refresh token concept). My question is related to login/logout of users in this scenario. Most of the blogs suggest that on logout, maintain a list of blacklisted tokens ...
I want to model a machine with a class machine. By the way the architecture of the project has been built, the module that defines each machine is its own directory. So in directory manufacturer/machine_111/ there is a file machine.py Class Machine(ModelX): def __init__(self): .... def do_something(self)...
I have a base class called FieldBase and I want to inherit from it to have different types like TextField and NumberField. I have a property Called Value which for the TextField is String and for the NumberField is Integer. Now I want to access the Value property in the base class and do some checks, but I cannot becau...
I am going through this OO design course: https://www.coursera.org/learn/object-oriented-design/home/welcome and starting to look at the use of CRC cards. (class responsibility collaborators). I wanted to apply this to one of my own projects to get some experience using the technique. I have previously written a sql...
I am looking for best answer to I think typical issue when, there is a frontend calling backend ( some api gateway ) and that gateway needs to get information from microservice A ( ie: its GET request ), but that microservice needs also to call other microservice B. It can lag of course. IMO its bad architecture desig...
I am working on a project where the architect decided to put an ESB (integration layer) between the Front end and back end. The driver was to make the services reusable across channels and the enterprise and to utilize the existing infrastructure (ESB). This was really achieved for a small set of the services where the...
As the title says, I've been noticing this trend that have been all along the evolution of programming languages. Each one has had a niche build tool and a dedicated package/lib repository system. Its hard for me to ignore that nearly all of them are: Downloading/uploading archives with certain files and metadata. Ext...
I think it's fair to say that they are quite similar to each other. The only difference that I know is the intent. Chain of Responsibility: Avoid coupling between the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along...
The intended effect (semantics) of the POST method is resource specific, e.g. executing a command with arguments: POST /command HTTP/1.1 {"parameter-1": "argument-1", "parameter-2": "argument-2"} The intended effect (semantics) of the PUT method is to create or replace the state of the target resource with the state ...
While this might seem more like a piece of an easy task to others, it's honestly not easy for me. At this stage, I find myself wandering how best to version my functions/methods. What does this mean? I have a function that does one thing and one thing alone. It saves Contacts to a local DB e.g RealmDb. This function is...
I have an Use Case that has an UseCaseInput (which is a parameter object of the use case) and an UseCaseOutput which is the output object, the UseCaseInput has lots of parameters in which will be used in various dependencies as parameters (repositories, adapters, etc), some Entities are going to be persisted in the dat...
In some recent projects, I found myself having some longer spike phases in which I build many cheap prototypes and explore different design decisions, long before I would consider my code of acceptable quality. Usually, when I check in my code into git or any other VCS, I refactor and clean it at the same time, so that...
We have two application A and B that I'm refactoring. They both use the same database. Those application are written using the Symfony framework and Doctrine as database layer. I've moved some of the business logic from A into a library in the same git repository and tried to decouple it from the application. This libr...
I have a service, call it serviceA, which has a relational database. This service is old and bloated, modifications to the code are very difficult. But I also can't get rid of it, it's the heart of the system. Now I want to build serviceB. ServiceB is basically an extension of serviceA's capabilities, it has exactly th...
What are your thoughts on having a service/process be both an API server and a background worker, consuming messages off a queue like SQS? I have typically kept these two separate to keep single responsibilities for each, but also it seems weird, at least in NodeJS, to have an API server bootstrap itself to be an API s...
When working with big architecture, I experienced high costs when it comes to changes of a data model that is used in multiple applications, servers, databases. So I thought about designing a server with a database, whose only job is to manage schemas of a data model. Its features should broadly and mainly be CRUD on S...
Context: Currently designing a product with a DDD mindset. Currently in a monolithic approach. However I'm refactoring a few things so I can change to a more loosely coupled monolith. We have an entity called "Risk" (which is an abstract class with N subtypes). Currently have two aggregate roots who have a list of risk...
Given a method that is widely used and has a void return type: from somepackage import download_model from somepackage import get_filename def download(name, download_path): response = download_model(name, download_path) file_name = response.filename file_path = model_download_folder + file_name if file_na...
I find myself writing a lot of boilerplate mocking code for my unit tests. I think there must be a better way. Background I am working on a project that relies on complex configuration that is stored in a database. The API accepts an id, which is then used to load the configuration. A very simple example: public class ...
(This relates to the problem domain I have previously elaborated on here - though the exact details are not that important for this question) I'm writing an analysis application for Blockchain (DeFi) smart contracts to help me learn DDD. The source of truth for data and state is in fact the blockchain. I can always go ...
Spring Boot/Java 8/MySQL here. I have a widgets table in my MySQL DB that is modeled by a JPA entity like so: @Entity @Table(name = "widgets") @Data public class Widget { @Column(name = "widget_property") private String property; // all remaining fields here... } And which has a matching, typical, repos...
Basically, here's the problem. I work remotely for a company, and I need to have a local copy of the production database to play around with it and test my work on it before pushing the code. The prod DB is around 6GB, and so downloading it and then restoring it is time-intensive, to say the least. I want to commit the...
I hope that's a proper place to ask my question. I am wondering how is best to integrate RabbitMq (or any other message broker) into my project. There are 2 options: Simply collect all messages, whatever comes from my other services and dump all into Rabbit Collect messages into intermediate service, to ensure "con...
Let's say I have an abstract class A exposing a method called getE() which returns an object of type E which is an enum. The value returned by getE() will be defined per subclass. Put differently, every object of a certain subclass of A will always return the same value if getE() is called. This is how I have implement...
I have an interface public interface MovieDataFetcher { List<Movie> fetchAll(String query); } And these concrete classes public class ImdbDataFetcher implements MovieDataFetcher { public List<Movie> fetchAll(String query) { OkHttpClient client = new OkHttpClient(); // get the json data, deseri...
I usually write my code in a test driven style. I write tests as specifications and then my code. It's great and useful. I always try to ignore implementation when testing and only test behaviour. I don't care how it gets done, just that it got done. I find this especially easy for functional programming. Now here is t...
I want to send two different json response for the same API based on a flag. I have a final response json as below for /api/v1/student/, which is created by fetching responses from few other REST apis. { "students": [{ "name": "string", "courses": [{ "courseid": "string", "c...
I'm learning about DDD and in many places it's stated that the domain model classes should have properties with private setters and explicit methods to change the model's state. I wonder the reasons of that claim. Isn't the whole idea of the C#'s property to simplify the getter and setter?
I need to work on a project where we have a "case". Within this case we need to attach different things, in a timeline. Those things can be: Status change (Open, On hold, Closed) Messages (just text) Calls (call history, "call lasted x seconds") Call rating Now I don't really have a way of storing this in a MS SQL da...
We have a REST API endpoint which creates a presigned url (/createPresignedUrl) to upload file. How that works is when API call is fired, server would create a presigned url and send that in response. Later, client would use this presigned url to submit the file to our server. Should that endpoint(/createPresignedUrl) ...
I have read this thread: Is it bad coding practice to create something in a get if it does not exist? But, my question involve a method which gets a record from a database or creates it if it doesn't exist. I have two separate methods for checking if a record exists and the second to insert if it doesn't exists. But co...
This question is mostly related to the way language implementer do implements static class initalization (pretty specialized question). It is for curiosity and also to potentially improve my code to gain few nanoseconds For most object oriented language I know (C++, C#, Java), there is a possibility to define a static ...
Let's imagine an application where users can work collaboratively on projects. There's a project listing where a user can subscribe to a project, and a coworking screen where multiple users can work on a project. So far I have identified the core domain, "coworking", and a subdomain, "collaboration project listing". Bo...
This post implies that the creators of Rust had to add the "async" keyword to make the async/await functionality backward compatible. Why do we need the async keyword? In a new language, where backward compatibility is not an issue, would there be any drawbacks to eliminating "async"? An alternative might be to have th...
I have been trying to figure out if I can create a class or struct with a property that is of the same class or struct. An example would be struct Number { var Value: Int = 0 var Rate: Number() //Default value for rate would be 0 } Effectively this would be a recursive line of code but I don't want it to exe...
So, I'm working on developing my first Angular project with/for a friend of mine and I have a design question before I really get started with things. I'm going to be storing persistent data on AWS DynamoDB (login credentials, whatever else), and my question is: Would I be wise to develop my own REST API to interact wi...
Why do they always say you can only change one aggregate per transaction? Decoupling? Is it a rule you can break or is it more of a strict thing? Does it also matter if we are in a monolith vs microservices?
I'm learning DDD so apologies if the question is too naive. Assume an application that manages user publications developed following DDD and using a RestAPI for external interaction (for whatever front-end layer for instance). Looking at the Publication model we would have behaviors like ApplyLike, RemoveLike, Comment ...
Asked this originally here, and didn't receive any answer so far, hence posting here too. Let's say company A acquired company B in a certain region. This means, A and B were competitors in that region, and now A will be the only player. Resulting, customers from company B will need to be migrated to company A customer...
I am having an .Net Core Solution consisting of 3 Projects: The Site (Asp.Net Core MVC WebApp) The API (Asp.Net Core API) The "Common" library for shared functionality. The Common library contains all the business logic in form of Services. These Services are used by both web projects (registered inside their Startup...
Scenario: Our CLI-script downloads data Therefore, amongst other things such as pre/postprocessing, it calls a function from another (internal) python package (which is maintained by another group) The internal python package finally executes a request to an (internal) web server In order to test the download-data fu...
After reading, Does it ever make sense NOT to condense one to one relationships?, I wanted to take the question further with regards to contemporary design of entities, front-end code and controllers. The top answer is great, but one thing not addressed is how a code-first approach and modern websites may, if at all, i...
My very large team is following trunk based development with many short lived features branches, trunk, and a release branch for when we create release artifacts. This is a team that keeps the release branch around while a release is ‘live’ in case we need to go back and patch the previous release. In other words, our ...
I am currently working on a project using Flask to make REST apis, blablabla. But, working with request validation tools that we use, I am thinking of whether it would be necessary to validate the responses of the controllers. I read a bit about Design by contracts and I saw how it was done in Eiffel programming langua...
So basically the ISP states we should break big interfaces with members that are not cohesive with each other to smaller and more cohesive interfaces, which is very close (if not the same) to what is stated in the SRP. Assume we have a Printer class that implements the IPrinter interface and assume for a moment the pre...
In a debate with our solution architect, there were 2 proposed solutions to handle (illustrated below on the figure) In the first, the API Gateway manages Authentication, Authorization and Accounting (and whatever required state management) , thus playing its role as security gateway, then calls the business service (...
Assume we had a User class which should hold references for all different kinds of request, let's say at the moment we only have 2 :RequestA and RequestB, both inherit from the base class Request. Now we are told to create a class representing the new kind of request in our business. We then create a RequestC class tha...
Considering example below, one observe that for reference type argument is successfully understood as nullable parameter. For value type conversion to T?/Nullable<T> fails. T Method<T> ( T? t ) { // Error CS1503 Argument 1: cannot convert from '<null>' to 'float' float f1 = Method<float> (null); // ⇑⇑ float <fl...