instruction
stringlengths
34
36.1k
I've started working on a LoB application (as a learning exercise) while trying to express business logic with use cases from Clean Architecture. First use case is customer onboarding where client can enter their company name, their email address and password. Use case should do the following with provided request: Cr...
Most useful or reasonably complex applications need to save data such as user settings or saved games or browser history. I have been working on applications and games in C or C++ but I am not sure which of several ways to access files to use. First the preferred location to store such data is queried. On Linux this wo...
Currently, I'm involved in a research project in which we are evaluating an existing web environment providing a safe online playground for children/adolescents with intellectual disabilities. Certain areas of this web application require identification of the user to allow the content to be aligned with the user's cap...
Our platform is growing in the number of events we're raising, and these different events are often related to one another: ProductCreated ProductUpdated ProductTakenOffSale ProductPutOnSale Guaranteeing order of event consumption on a single topic isn't too difficult, but when you're faced with multiple topics like th...
Consider a web-app with 5 micro-services deployed with Docker, and a MySQL container dedicated to storing data produced from other services (shared-database pattern). How should I make the connection between the MySQL container and other containers? Currently, I am converting a monolith application software into micro-...
I'm doing a running time analysis using the aggregate method and I'm a bit confused about what would be the result in this case. I have some intuition in inferring that it would be O(mlog(n)) but I'm not sure
In our team we have up to 50 repos, of which about 15 are worked with regularly. The others are rarely changed, but it happens that we bring in 1-3 additional repos per release and work with them. We release a new version about 5-6 times a year. Although we have a lot of code split up into many repos the product is bas...
When writing a program that uses a working directory, e.g., PostgreSQL data directory or download target for wget, is there an advantage of having a CLI argument (or an environment variable) for such a directory? If the program doesn’t use any other path for its business, isn’t the current working directory enough, or ...
In the Design Patterns: Elements of Reusable Object Oriented Software, the Gang of Four present the following canonical form for the Builder pattern: In Appendix B the following is mentioned regarding notation: Slanted type indicates that the class or operation is abstract An object reference representing a part-of o...
I've got a backend running on Node that executes queries on a PostgreSQL database. For these queries, table and column names are imported from a .env file, for example: const ID = process.env.ID_COL; const USERNAME = process.env.USERNAME_COL; const USERS = process.env.USERS_TABLE; ... const query = `SELECT ${USERNAME} ...
I am currently trying to design some C++ classes that encapsulate POSIX sockets and their relevant functions. I want to try and design classes that are simple, elegant, and make the best use of design patterns and inheritance. Starting from the server and client side sockets we have the following functions POSIX functi...
I have the following code in C that reads data off a char array and makes decisions on what variables should some pointers point to. char preset1[20]; char preset1Name[20]; int preset1Temp; int preset1ETemp; char preset2[20]; char preset2Name[20]; int preset2Temp; int preset2ETemp; char preset3[20]; char preset3Name[20...
I am using spring boot with mongo db (azure cosmos db) in my microservices. Currently I have an Orders collection that stores Orders. These documents have a field userId that is null when the document is created. Afterwards, a request is made from a user to assign a order to him and this field is populated. The issue i...
I want to start developing a long-life ERP system to a customer. now on paper I would chose to develop it using .NET core 6.0 with SQL Server. But one of the main drawbacks which the customer did not agree on, is the short support life cycle for .NET core framework. where each 3 years a new version of the .NET core wil...
I ran into a modelling problem while solving an assignment of mine. Say I have json string that I need to parse, process it in some way and serialize it back to json. The problem is this json contains arrays that hold different types of variables: strings, integers, booleans, decimals and formulas expressed as strings....
I am implementing the Publish-Subscribe pattern. I have class Broker and interfaces IPublisher, ISubscriber. interface IPublisher { broker: Broker; publish(channel: Channel, data: object): void; } interface ISubscriber { notify(channel: Channel, data: object): void; } class Broker { channels: Map<Chan...
Coming from languages like C++, Java or PHP I've learned that there are Value Types and Reference Types. Value Types store values directly in the variable (in a box / memory location). Whereas Reference Types store a reference to an Object in memory. This makes perfect sense and seems like a simple mental model to deal...
I'm looking for some resources on learning how to best manage our software releases in an efficient manner, as our current method slows release schedules down. My current team produces and administers industrial machines that (computer-wise) consist of at least one PC, running several custom software components that co...
None of my team's programs care about multithreading, parallelisation, async, or anything else that benefit from immutability. However, immutability is clearly in fashion at the moment and I'm starting to believe that it assists readability. We typically use C#, but I don't think that's relevant. If in a code review I ...
I am working on machine learning project. I use jupyter for quick prototying. Now I am trying to convert it into concrete python project using clean architecture. entities/ - problem.py # contain type_name can be regression or classification class Problem: type_name: str usecases/ proble...
We are often told to avoid sharing business data across service boundaries. However, I tend to see the need for a service to access data from a different service. An example of this would be IT functions needing to access employee position and corporate structure (i.e. the managerial ladder) - this information is typic...
I'm building a DDD application which is effectively a wrapper around Cognito. As such, everything that this is doing is effectively just a call onto the Cognito SDK. Where I'm getting confused is how this should work with respect to Domain Services or Repositories. I've got an Aggregate to represent a User. I then have...
From many articles and answers on DDD Repository pattern, I got the feeling that a Repository should only CURD an Entity (Aggregate Root) as a whole. Following this convention, we always need to query the database to get all required data to construct an Entity. Following is an example implementation when you want two ...
Recently I encountered an issue at work where a unit test written in C++ would crash only when being compiled with MSVC 2017 (MSVC 2019 and up are fine). I tried to debug this issue and it seems like a compiler bug causes memory corruption (e.g. the stack of a thread became corrupted at some point: the return address o...
I'm trying to design mediator micro-service which will have around 20-30 different http requests to an external vendor. My general high level thoughs are on creating a BaseService class which will implement the Template Method pattern where each inherited class will be responsible on specific call, with its own request...
I'm very new to microservice architecture. In the Monolithic app structure, it was pretty straightforward to write test cases since everything was in one app. I have a situation where I manage a microservice (built on FastAPI) that stores only the users with different types like company, admin, student etc Then there's...
Part of my current product uses GPT-4 with a prompt to extract information from plain text. As behaviour of large language models is inherently opaque and failure cases unpredictable, I was wondering how standard software engineering practices translate into working with generative language models such as GPT-4?
Who among the two is responsible for validating the software when testing it? Or is it a joint effort? On the one hand, the software developer is responsible for ensuring that the software is built to specification and functions as intended. On the other hand, the user knows how they will use the software in their part...
Suppose you have been put in charge of an already existing project. As you are starting to familiarize yourself with the repository, you notice a few technical debt issues (insufficient test coverage, conflicting standards, missing documentation, etc). As someone who is going to be working on this project and maintaini...
I don't have enough experience to understand how hard object instantiation and garbage collection really hit. So I tend to write code where I don't just spin up objects for the sake of it. However, now, where I work, hexagonal design is non negotiable, and at face value, I don't mind. It makes life rather early. public...
In some languages such as Python, the order of keyword arguments in function calls does not matter. But is there a best practice for it? For instance, suppose that a function's signature is def foo(bar, baz, qux). foo(bar=3, baz=8, qux=9) is of course the same as foo(qux=9, bar=3, baz=8). But isn't the former easier to...
I am currently trying to follow the clean architecture approach but i wonder where common things like a database connections should take place. Since i think a database connection usually will be opened once, but different tables in there are used from feature to feature in different ways, it wouldn't make much sense t...
Where should I inject the dependency when I write a class? Should it be given to __init__ or to the specific method that uses the dependent object? Take the below two pieces of code for example, to me they function exactly the same way: class TextFile: def save_text(self, text): print("Below texts saved to ...
I have a piece of code where two objects (incoming request object and a profile object) are to be checked for matching conditions. So the first method is as below where I check whether the profile object will be applied to incoming request : public Response apply(Request request) { ..// some logic Prof...
I will have multiple cellphones playing videos in an art gallery. The video content must be synced to the lights, which are synced to the real-world clock. As in, at 1:00pm the lights go out, 1:15 they turn orange 1:30 they are bright, 1:45 they begin to dim, rinse and repeat every hour. I figured I would point the pho...
say I have this code which is a chain of public methods, public_c calls public_b calls public_a def public_a(...): ... def public_b(...): ... public_a(...) def public_c(...): ... public_b(...) Should I test all 3 methods individually? Part of me thinking if I test public_c then it "sort of" als...
We have an event booking system that allows patrons to add themselves to a waiting list if an event is fully booked. When somebody cancels, the system moves the first person from the waitlist into a booked status. Currently, this is implemented as a stored procedure that locks the table to avoid someone slipping out of...
I have recently encountered this problematic method (minimal reproducible sample in C++ but this question aims to be language agnostic past the syntax): void MyObject::twice_bind_cycle() { _bind1(); _bind2(); _activate(); _unbind2(); _unbind1(); } This entire method interacts with an API as do the ...
If you can have one event with multiple "things to process" or one event per thing to process, what is considered the best practice? Bearing in mind, the former option may involve persisting the payload in a DB (because it's too big) whilst the latter may mean 1000s of more events, but I'm unsure of the real disadvanta...
I have a java class with an init method. It's different from the constructor. The constructor just initializes the variables/fields. The init method connects to a database and performs some verifications on the database + it kick starts a background thread which handles incoming requests. If you wanna think of it in ps...
The Kotlin language brings the simplification of function calls to the natural language. This article shows a nice example: Function: fun of(suit: Suit) = Card(this, suit) val card = Rank.QUEEN.of(Suit.HEARTS) Infix function: infix fun of(suit: Suit) = Card(this, suit) val card = QUEEN of HEARTS AS a newbie to ...
I have this two tables: Documents(ID, IDTypeOfDocument, BigIntReference); I have a documents table that has and ID that is an autonumeric bigint. Also I have categories, and also it has a big int as reference that is unique for category, but for two categories, I can have two documents with the same reference, one fo...
I want do develop an IP based protocol oriented to smallest possible data overhead. For example UDP adds overhead of 8 bytes header. I want zero header. I will use this protocol via 2G mobile network where every byte is paid. For example 8 bytes every second makes 252.288MB per year. With 0.1 Euro per MB that's ~25 eur...
in our company we have some APIs that return some JSON data. Before sending, for instance, data to the backend using PUT, PATCH, or POST, we need to do some kind of validation in the different clients (web, mobile apps, etc). Right now that's a ton of duplicated work, so we would like to start using JSON schemas for ou...
I am building a web application where a user logs in, and uploads a CSV file with employee data to S3. This is an example of the format of the file. id name country age 3243 John Doe USA 48 Using this data I want to provide a webpage showing simple bar charts for employee count, along with a filter for dime...
For example, keywords have a special prefix. Objective-C has @interface, @implementation, but that's for compatibility with C. It inherits all the C keywords of course, with no @. How about a language in which all keywords are prefixed with a special character? It will only save the lexer some trivial trouble, but the ...
I have an employee that has to record the time when it starts to work and the time when it finishes. This records can be associated with a proyect or not. Project could be null. The proyect has an ID and a proyect number. The employee gives the proyect number, not the ID of the proyect. So I was thinking in this code: ...
I have two microservices, one Flask (python) and one Spring (java), they currently share a database. The Flask microservice handles processing json files (~40mb) for each user (could be 100's or 1000's of users per day) and adds the processed data to a Postgres DB that is shared with the Spring microservice. The Spring...
I'm trying to understand what they really are, but I can't understand how to use them. MAJOR version when you make incompatible API changes. What is incompatible API changes? MINOR version when you add functionality/features. Examples of a new functionality or features? Sorry for the noob question.
Suppose today I'm designing a new application that will employ asymmetric cryptography to allow users to securely exchange data with one another. As far as I can tell there are no quantum-safe algorithms yet generally accepted, let alone that are ready to be used in production. (Please correct me if I'm wrong!) Thus I'...
Why is there a such thing as import in programming languages? If a package does not exist, then trying to import it would cause an error anyway. So why don't languages just auto import ALL available packages? Instead of requiring programmers to have 'redundant' import statements?
I was asked to review and handle merge request for a code base, which has been contributed by dozens of programmer with basically no regulation (or perhaps there was but nobody follows), so I set up executable regulation, making clear details like formatting, naming rules, how you should build control flow etc. Things ...
We're currently exploring CQRS in our future applications. To give a bit of a background, we use a simple CRUD-style service before something like this. Old Pattern: Controller Command/Service Model Then the validation logic is inside the model like ValidateSave(SalesOrderModel), ValidateSubmit(SalesOrderModel), Vali...
Note: I'm talking about Amplitude because it's what I use, but it's probably the same with any stats tool. Amplitude, because of its very nature, is insufficiently secured. Stats are the value you get out of Amplitude. A user makes an action, this action is sent to Amplitude and has an impact on the stats. This means t...
A Composite delegates calculations of unknown depth to a virtual method. A Chain of Responsibility passes events to an arbitrary deep line of handlers. Sounds the same to me. What am I missing?
I am working on a fairly large project written in PHP (Yii2) in which we are increasingly using cron for background tasks, such as generating caches, reports, etc. We have started to move the hourly timings by a few minutes so that they don't overlap, but I don't know if this is a good idea. Besides, I have noticed tha...
Is there a programming principle/guideline that tackles the correctness of a implementation beyond the methods signature contract of an interface? Let's say we have a repository interface with two implementations, one of them is in memory, one of them is a database The in memory one implements the interface with a list...
I've been building a traffic simulation with C++ following the Intelligent Driver Model from this article: https://towardsdatascience.com/simulating-traffic-flow-in-python-ee1eab4dd20f To sum up my implementation: The map is divided into 2D grid of Tile(s) Each Tile has a list of Road(s). For the sake of simplicity, n...
I have been struggling with how to create an "object-oriented" cross-platform abstraction. In C++, a class requires a certain amount of coupling between its interface (i.e., public methods) and its implementation (i.e., private methods and data). There are a few design techniques/patterns that I know of to somewhat sol...
Given the following hierarchy of objects: a keyed collection of ClassA objects, where each ClassA object contains a keyed collection of ClassB objects and each ClassB object contains a keyed collection of ClassC objects. No suppose we start out with the root collection of ClassA objects (called a_objs) and we want to l...
I'm working on a game prototype: I have a Cell class which, given a mouse click on its collider, can raise an event that should be listened in two different modules: Camera and UI. The Observer pattern implementation that I generally use follows this diagram: But in this case it seems too tight and I don't see a simpl...
I am currently drawing a "C4 Containers" Architecture diagram using C4 Model. The Core Software System of System Context diagram is now exploded further into the Containers diagram (should I say it is a Zoomed-in view?). I have a few software systems that are external to this Core Software System but still part of my ...
Imagine a situation where out of 5 state implementation classes the implementation of a method only differs on 2 of them (i.e. 3/5 share the same implementation for a particular method). This situation can be handled in a couple of ways when the generic State is an abstract class rather than an interface: The abstract...
Our team has not had dev and test environments since it started 2-3 years ago. We had decided to give this (creation of dev and test environments) more priority. Current Environment One production environment with outdated software (OS, programming language, tools) - but security patches are regularly installed 5-6 de...
I am using django to develop a turn based chess variant. I just finished using django-channels to create a lobby and match 2 players together. Now, I need to make them play each other and I'm thinking about what the best way to design these interactions is. The first idea is to have each client store their own state, ...
I am working on a small suite of enterprise applications, and I am trying to determine the best way to make them more consistent and maintainable across the board. The applications are .Net Blazer Server apps in C# with SQL Server Dbs using Entity Framework Core, but the question I have is more relevant to db structuri...
I encountered the following situation: I have two modules, TokenService and Wifi which are initialized from main(). The modules themselves don't know of the existence of each other and function completely independent, yet they need access to the same global resource which in this case is the nonvolatile storage flash, ...
I am looking to see if there is a general design pattern or strategy to handle a use case I see often in our codebases. My best attempt to generalize this use case is "Map permutations of n parameters to a specific value, and look up the appropriate value when provided those parameters." Due to high cardinality of some...
What are the rules about acronym usage that are related to the business ? I always hesitate between using the acronym or not. When talking with people who work here they will understand faster when I use the acronym. On the other hand using the full name helps me when I still need to learn what the acronym means. For e...
I have a multi-threaded application. There is 1 thread that produces a resource and puts it into a queue and many (not constant amount) consumer-threads that get the resources from the queue. When there are no more resources that the first thread procudes, the first thread must terminate the queue, that is, notify all ...
Why is it necessary to have an instruction set for processors and controllers? Can't we simply convert high-level language programs, like those written in C, directly into binaries without the need for an instruction set?
I have read this article which indicates a double tuple structure, but it is unfortunately light on implementation details, which is what I am looking for. So... how are interfaces implemented in Go? Pure guesswork on my part: It cannot be a v-table in the C++ sense, because the interface is implicit - a struct doesn'...
I am learning about building a language VM with the long-term goal of writing an own language. For guidance, I am looking at this LC3 tutorial by Justin Meiners and Building a Language VM by Fletcher Haynes. (I have also previously gone through the Nand2Tetris course). In the LC3 approach, I note that the opcodes and t...
Context After creating a (bash) CLI interface that creates self-signed SSL certificates (for onion domains), the user can choose to re-use some of the data that is created in past runs. For example, a self-signed root-ca may be used for multiple services, which may be created in separate runs. Another example are onion...
There is a software (once monolith) that makes use of a long list of mappers. You can think of them as Choices field, where each item translates into different conventions. For ex, say that they are JSONs of all unit systems (weight, distance, storage, time, temperature etc) and their different standards (metric vs imp...
I just finished a discussion with colleagues regarding the use of exceptions in code. Here is the code (pseudocode) that they had written: resp = fetch(URL) if resp.status_code != 200: return False I suggested that they use the below (pseudocode): try: resp.fetch(URL) except HTTPError as e: logging.info(...
Often I want to open a new window from within some view. I see opening a window as view logic. So I don't want code in my viewmodel that creates/opens/changes Windows or anything else that interacts with view-things directly. When I've got a feature like a button that opens a Window when clicked, I do it as follows. I ...
This is just a simple code-style question. Imagine you're writing a function in language 1 that is supposed to be called from language 2. Should the function follow language 1's style guidelines or language 2's style guidelines? For example: // This file is written in language 1 // Language 1 uses `PascalCase` and lang...
I work with Computer Vision applications, mainly in Python and C++. Recently, I get involved with a customer that wants to create a UI based on React JS to visualize the results of our software in real time. I have an object detection software that will read the streaming of an IP Camera, and apply the AI model to dete...
In the python docs, I read this about the ABC (abstract base class) meta class: Use this metaclass to create an ABC. An ABC can be subclassed directly, and then acts as a mix-in class. I don't come from a strong technical background so can someone explain this to me in really simple terms? I have an ABC, which repres...
I've created a backend following a microservices architecture and now I need to implement logging. my understanding After reading some articles about this topic, I've listed below some "pretty good practices" (correct me if I'm wrong): each service logs to the standard output In a single microservice, logging must hap...
I'm doing a project to teach myself more about MongoDB and ASP.NET development and I am stuck. The project is a mockup of a JobBoard website, where Companies would post offers for potential Employees. I'm stuck near the part where I want to implement the requirements for the job. I found a very cool looking system on o...
I'm using FastAPI and in my schemas (that is, serializers) I have something like this: from pydantic import StrictStr, BaseModel class Str255(StrictStr): max_length = 255 # my schemas: class CatSchema(BaseModel): name: Str255 owner: Str255 age: int The reason I use Str255 is to apply DRY, by avoiding t...
Context I have a multi-tiered architecture that contains 2 presentation layers, one business layer and one data layer. See image below for a visualisation. Here you can see that there are two components (applications) inside the presentation layer: App 1 and App 2. Currently, I deploy all of these layers 'monolithical...
After much hard work, I've convinced my manager that some absolutely awful code needs refactoring. As with any project, they've asked me for a time estimate and I've found myself stumped. How can I estimate how long a refactoring project will take? Answers/comments have proven the following points to be relevant in my ...
In C you cannot assign arrays directly. int array[4] = {1, 2, 3, 4}; int array_prime[4] = array; // Error At first I thought this might because the C facilities were supposed to be implementable with a single or a few instructions and more complicated functionality was offloaded to standard library functions. After al...
Suppose that the following are true: You believe that unit tests should be atomic. That is, tests should always test exactly one thing. You have written a CRUD app in a general-purpose language such as C#. In particular, the app can Read and Update. Your app stores all data on a SQL server. Your language therefore nee...
I'm writing a small card game with a friend and as of the last year I worked with DDD and love every minute, So it felt natural to me to use DDD for our core domain logic of the game. Doing a little bit of research on best practices to integrate DDD with game logic, I stumbled into this question : Domain Driven Design...
Currently, my repo contains application code and what I call non-functional files, which include deployment scripts, README file, build system requirements, dependencies etc. These files are released as part of each release so that other developers could completely rebuild the environment if needed. My project follows ...
This post assumes, that dtos on the UI side (SPA) could be viewed as business objects in almost all cases - except that the business logic is missing. I'm fully aware that a dtos first responsibility is to represent data that was send over the net. In a lot of cases though these object are almost identical to business ...
In the web development application context, when someone says resolver, they talk about getting the data and modify it and then return it? What about adapters? are adapters essentially resolver connecting data to a different formats? If you talk about database adapters, what does that mean?
I am working on a huge code base (more than a million lines of code with a sophisticated architecture) written in C++ over the span of a couple of decades. The task on which I'm working at this point is understanding the use of a specific class whose functionality is unknown to almost every developer of the team. The r...
Many resources in the REST API I'm designing have a graphical representation. My fist idea was to include the image URL into the resources: Resource1: type: object properties: image: type: string format: uri Same for Resource2 etc. The problem is it's not always the same URL. Web clients want an SV...
I would like to draw a flow chart for a recursive call function whose return value is used, the real function is much more complex, but very similar on the basic idea as following: List getDigit(Integer arg) { List<Integer> result = new ArrayList<Integer>(); result.add(arg); if (arg != 0) { result.addAll...
My Domain layer contains below model: public class ApiResource { public bool Enabled { get; set; } = true; public string Name { get; set; } public string ClientId { get; set; } public IEnumerable<string> HandledScopes { get; set; } = Array.Empty<string>(); } Later, the Infrastructure layer uses EntityF...
If I understand the UML 2.5.1 spec correctly, the definitions and constraints for UMLClassDiagram and UMLComponentDiagram are identical and furthermore the set of things those diagrams may show are identical. So whether I call a diagram a class or component diagram is a matter of taste and clarity. Have I missed someth...
I've been learning C recently. I've completed a number of coding challenges on websites like codewars in C, and I always find myself wishing I had something like Python's flexible data structures. In fact, I usually end up creating a poor approximation of them. This got me thinking, first of all, do people have boilerp...
I'm designing my service layer for a GraphQL API and there are many situations in which I can't decide if code relating to a table should belong in it's own class, or the class that 'owns' the data. For example, I could have a user class which can get a users appointments, products, etc...or I could have two classes: A...
I have a testing project, in Katalon Studio, that uses data classes, called models. This is a conscious design decision. Also a conscious design decision, is the decision to separate the concern of creating models from the concern of the test(s) that uses them. For this, for the most part, I use model factories that ha...
I am writing code that will assign entities to transaction. Each transaction has a counterparty entity. Requirements The entities should be (de-)serialisable (from pydantic models into JSON and vice versa) Individual entities will be stored in a database Entities have some hierarchy, e.g. a Supermarket is a type of Co...