instruction
stringlengths
34
36.1k
My app has an API endpoint GET /sessions/{id} which gets info about a session. This endpoint returns a lot of data, so we allow passing JSON in the request body to filter what fields etc. are requested. I know GET requests should not include request body, so I am trying to convert it to POST but not sure what to call t...
I’m working on a small project with two other developers. Our work is on Gitlab. Our general workflow is that we create feature branches by branching off development which get merged back into development after review by one of the other team members. Recently, the other two team members were on holiday for several wee...
To simplify the domain let's say we have a system that takes in orders from customers. There's an API endpoint that validates the input, and if valid pushes the order onto a messaging queue to be picked up by an event handler to process the orders. So a simple (.NET) API controller might look like this: [HttpPost] publ...
I read a lot of examples where I read code like this: def get_user_by_id(session, id) ... and the function that calls that function needs to create or get the DB session a pass to the function. the question is why the general design is doing that instead of creating or getting sessions inside the function? Thanks.
I have some code on Arduino (so, written in C++) that receives a String through the UART terminal, reads the String, then decides what String to print back and how many things to print depending on the data. I've used an if-else stack to decide on what to print back. Something like this: if (cmdtype == "VALCN" && c...
I'm new to "web development" so I don't know much about ways to store data. I'm trying to build a web app using Python-Django which accesses private data from multiple accounts. The data comes from a third party eCommerce site and my app is supposed to access it by making HTTP API calls to this service. This service us...
I have an inventory of products stored in Postgres. I need to be able to take a CSV file and get a list of changes—the things in the CSV file that are different to what is in the database. The CSV file has about 1.6 million rows. The naive approach is to simply take each row, retrieve that product from the database usi...
I'm developing and designing a system which runs mostly on intranet of client companies. The system consists of one main database which is MariDB, for now one web-application as system management and data output/analysis/export (which is hosted on same HW with the main DB), and multiple possible little applications tha...
I am a backend developer and I am writing a restful application. I have a question about how best to design the endpoints. I have a database table that stores values (I just provided an example) |id (int)|A (bool)| B (bool)| | 1 | 0 | 0 | | 2 | 0 | 1 | | 3 | 1 | 1 | Busi...
I have built a string to enum converter, which converts a known set of strings that it receives into enum, in order to satisfy a function pointer. Some of you may recognize some elements of this question elsewhere. This is written in Arduino, so C++. enum input {FIRMV, VALCN, RQSPC, LIDVM, LIDVC, PREVC, STPWM, CHPWM, S...
To set the stage, I am trying to do pure dependency injection for a Java Library I am creating to make it more testable. As it is a library, I want to do pure dependency injection without creating a DI container/composition root as discussed by Mark Seemann in his blog posts*. The problem I am running into is that I ha...
I am facing a common situation where I am saving some values into database from a business object. I am using a relational database and usually I only need to save a few items that are part of the object. To clarify, my business object is composed of other sub-objects, or some core variables (float, string, int). It c...
Google tells me that the ideal unit test coverage is 70 - 80% (although Google's source for that doesn't look especially credible). This old post suggests that in fact it depends on what gives you confidence to release. Which is right? If the mayor of a peaceful town with 100 residents were to hire a squad of 80 pol...
Let's say there's a class that processes text, and it gets that text from another class as a buffer. If this buffer class has multiple get methods, like readLine(), readChar(), readCharCode(), how should I choose what method to mock? Obviously, I can just look at the current implementation of the text processing class ...
I have a website which lists expenses filtered by year and allows for editing. Over the years, the expense entity evolved. Some properties were removed and some properties were added. If you go back and filter by a previous year, my website displays the expense by how it looked at the time. In my database, all the diff...
Suppose I have two abstract classes called Color and Animal And I can create classes Green/Red/Blue derived from Color and classes Dog/Cat/Pig derived from Animal at runtime using factory pattern. Then, I have a template class Hybrid: template<class A, class B> class Hybrid : public A, public B {} What I want to do is...
My project is a monorepo where the top level directory contains build infrastructure and a set of project directories for different services. Each service has its own branch of development. The branches have rc and release tags: service1-14.0-rc1 for the first service and so on. The issue is the build infrastructure th...
I want to know how rigid do we have to stick to the notion of end to end testing, please consider the following explanation: Basically, when we talk about end to end test we send a request and expect a response, in an end to end test we verify this request and response with a reference payload that we have. But, consid...
All too often, I see people people pointing out flaws in Semantic Versioning (SemVer), or pointing out that it doesn't apply to huge categories of software. (See quotes below). In particular, SemVer doesn't apply to websites without a public API. SemVer doesn't apply to stand-alone applications without a public API. S...
I'm learning PyInstaller for deploying Python applications, more specifically, applications developed with PyQt5. As far as I understand, it's possible to bundle application data (or "resources") in two ways: with PyInstaller or by using the Qt Resource System. With PyInstaller, one specifies the files to the parameter...
C++ features deterministic order of calling destructors up the call stack until the exception is handled somewhere. To my knowledge, neither Java nor (object oriented) Python provide this. In those languages, how is the following situation handled idiomatically: run the program for some time, allocating resources (mem...
I am trying to understand the difference between an Application Programming Interface and a Library and I stumbled upon this question: https://stackoverflow.com/questions/3678665/is-there-still-a-difference-between-a-library-and-an-api And according to one of the answers: A library contains re-usable chunks of code (a...
Working on the API, I understood that the behavior for one of the endpoints might be a bit counter-intuitive, but I am not sure whether this violates any RESTful rules. Based on what I have read, it doesn't directly but probably that's a bad practice anyway. I have an endpoint, say, /items for which there are two metho...
my following example seems to go into the direction Inheritance VS Composition. But that's not, what i want to ask. I see the concept Inheritance and Composition on one side and the alternative, which I will show, on the other. Let's say I have the following Base class class Base { protected final String a = "1"; ...
I'm trying to use the middleware pattern to avoid repeating same code over and over again. In my application I work with user data a lot, therefore there are a lot of checks here and there. The problem I encountered is that my middlewares only work with pure functions, that do not depend on any data. I will try to expl...
In many cases I can formulate some boolean parameter equally well positively as negatively, e.g. isOn or isOff. Which one should I pick then, in case I want the argument to have a default value? Is there a convention that an optional boolean function argument should rather default to false than true? Or the other way a...
I've several repositories. To make them testable, I add the ORM session in the constructor. class Repository: def __init__(session): self.session = session def save(object): self.session().query(object).save() class FruitRepository(Repository): def custom_method(): # ... pass Problem: I need to i...
Is there any common wisdom for managing a software project in an unfamiliar programming language? Most software projects go for safety and use some mainstream language but some opt for a niche programming language for special purposes, especially research projects. Some literature I've found on this: https://leaddev.co...
I work for a web development agency, and currently we bill clients by the hour, and provide estimates for each piece of work. Work is generally broken down into small chunks, with estimates being provided for each of these, rather than large pieces of work all at once. We’re currently talking about trying to move away ...
This question is related to Vincent Driessen's Git Flow branching model. To better describe my problem I would like to use one of Mr. Diressen's great pictures in a slightly modified way: The important point here is that there are the releases 1.3.0 and 1.4.0. The situations comes that 1.2.0 needs a fix which would re...
I came across an article about LSP https://stackify.com/solid-design-liskov-substitution-principle/ . It seems that a strategy pattern could be implemented here but I cannot see how to implement it. My idea is to let the brewCoffee be the strategy method, in which i state what kind of coffee should be brewed. The follo...
When reviewing code, I sometimes see blocks like this (I happen to be using a JavaScript since it is widely understood): if (!myVar || myVar === null || myVar === undefined) { ... } Those who know JavaScript decently well will immediately recognize that myVar === null and myVar === undefined will never be true if t...
I try to understand the difference between software development approaches like MDE, and design processes like UCD: UCD is a framework of iterative processes. The end-user is the center of the development process and is the main source of all requirements. The goal is a software product/prototype which has a high usab...
I'm currently in the process of reworking a monolithic function. My first step is finding blocks of code that can be extracted into their own "sub"-methods for ease of readability & maintainability. One of the blocks is a loop that runs over a list of entities of type A that contain a list of objects of type B which in...
I am refactoring a legacy codebase of an Angular SPA. The central entity of the app is the chat room, and there is a plethora of ways on how to enter a chat from different views all across the app. Due to our special use case, entering a chat is a multi step process with a fair amount of possible edge cases. To top it ...
I have an API with some specific resource say "cars" which have the following actions: Get all Cars Get one car Add one car for Get all cars and Get one Car, I have a REST api resouce with GET /cars and GET /cars/:car_id. However adding a new car requires two steps: Get a presigned-URL to upload the car to S3 from t...
All, We're just started on SRE journey and trying to define SLI / SLO for our application. It is an ETL application where 1. feeds (e.g. start of day, end of day data feeds) comes from various upstream and gets loaded with some transformation. 2. Once feeds get loaded there are some jobs which process the data and popu...
I‘m working on making a legacy code base more testable and made good progress with (constructor)-injecting dependencies to classes. I noticed something in all classes that access the file system: they make calls to C#'s static helper classes like System.IO.File or System.IO.Directory. To really be able to unit test the...
In a microservice architecture, it's commonly admitted that each microservice should have its own replica from another "main" microservice acting as single source of truth. This keeps microservices autonomous and loosely coupled. When the "main" microservice changes, it emits some events, so that interested microservic...
Let’s say that we want to encode recipes or dishes for x days in the form of a string. There can be an arbitrary number of days. Each day, we can have 0–3 of the following: breakfast, lunch, dinner. For each meal, there are multiple possible options ordered by preference (preferred option, fallback option etc.). For ex...
I started my first job as a dev about 3 months ago, at a very small company where I'm (currently) the only developer, and I've been setting them up with git. Their codebase is a bit all over the place, but mainly split up into three different sections. 1.) In the root directory of a web server, located on a Windows ser...
I've got these classes: enum Environment { case staging case production static func current() -> Environment { #if STAGING return .staging #elseif PROD return .production #endif } } struct HostEnvironment { private let urlStrings: [Environment: Stri...
Description This is a long shot, but I'm in dire need of advice. If you know of a more appropriate forum for this type of question please share! I'm working with a legacy OAuth system using email + password grant type (deprecated, I know: it's out of my control). I have to somehow connect this authentication service wi...
For the example shown below, in which I added the True and False values over the original document (so if something is wrong there, it's probably my fault), I understand there should be seven states to test (at a minimum) (because the cyclomatic complexity number is 7), but looking at the activity diagram, (i) how is o...
In a recent PR, a developer, whom I will call Alice, came across a lot of resistance by a coworker (Bob) because she wrote a utility code unit in a fluent style rather than in a classical style. In short, Alice had a piece of business logic (BL) similar to this (Java): Role role = ...; List<Role> otherRoles = ...; if (...
I think it's O(m*n) but someone said it's O(n). If you think it's O(n) could you provide an explanation? def convert(self, s: str, numRows: int) -> str: if numRows == 1: return s res = "" for i in range(numRows): col = i while col < len(s): res...
recently i came across an architectural diagram in my organization, where a backend service sends messages to itself using Kafka, so basically it queues the messages and reads from the queue and processes the messages. Tried to ask the rationale behind it and the only answer i got was it was done to reduce load on the ...
So, an Application Programming Interface is a way for two or more computer programs to communicate with each other. An application programming interface (API) is a way for two or more computer programs to communicate with each other. It is a type of software interface, offering a service to other pieces of software.1 ...
I have a system that uses a graph database without any ORM, mapper or tool that tracks entity changes, like EntityFramework. I'm not using domain entities, instead I have an Event that calls changes directly in Commands. Instead of having a entity like that Community{ public string Title {get;set;} ...
The UML is listed below. There are different products with different preferential strategies. After adding these products into the shopping cart, the caller needs to call the checkout() method to calculate the totalPrice and loyaltyPoints according to its specific preferential strategy. But when a new product comes wit...
I am trying to put in practice a small DDD example but I have some dubts. In my example, I have an Order and a Status. The Order can be this: Order { long Id; long IdStatus; long IdBuyer; Address Address; } Status { long Id; string Status; bool IsFirstState; bool AllowModifications; ...
Imagine having an ART (Agile Release Team in SAFe) with people with following skill groups: backend developers, mobile developers, BI developers. Having, as a product, a mobile app like Uber Eats, imagine that we want to deliver value to the users via new features like adding a screen with map showing a location of t...
I watch this YouTuber's mostly excellent videos on .NET features (let's call him Nick). He more often than not uses Benchmark.net to demonstrate the differences in performance of different approaches to programming problems. The results this tool shows for statements or full methods that typically have quite a bit of l...
I have an application that has been written in Python and it is used for generating various MIS reports for a specified month. It is now written without using the OOPs concepts or any kind of design patterns. I would like to refactor the application so that it will be maintainable and extensible. At this point, I have ...
I am creating an application using hexagonal architecture. The application uses WebSocket connections to communicate with some outside clients. Communication works in both ways. the client can send a WebSocket message which the application needs to handle and the application can also send a WebSocket message to the cli...
I am working on implementing some stock order types for a financial technology application. There are six different types of stock orders - market, limit, stop_loss, stop_loss_limit, trailing_stop, and trailing_stop_limit. These orders share a minimal subset of properties like IsBuyOrder and TimeInForce. However, they ...
I strongly believe that good user stories should articulate the problem to solve and for whom (typically stated as "As a role, in order to solve a problem, we want a suggested solution"), and that these stories should ideally provide a real, immediate and tangible value. I work as a test automation architect as part of...
My organization has a redundant setup across 2 data-centers. During normal operations both data-centers are up and handling workloads. For whatever reason, the infrastucture team has decided to operate 2 independent Kubernetes clusters, one in each DC. We've just started developing a cloud-native application that runs ...
I'm stuck with a problem, where I don't know how to model interfaces that are provided by different IPC frameworks. Let's say, there is a camera component and two arbitrary components C1 and C2. The camera has an interface for retrieving health data like temperature, errors and so on and an interface for retrieving the...
For instance, if I'm modeling a book collection and I want to be able to represent sets of books that come together (like an encyclopedia series), the sets may share a lot of properties that individual books would also have (author, publication date, title, etc.). In terms of naming the classes in an OOP context, would...
What's the recommended design for an endpoint that accepts a nested resource as the following: POST /account { "name": "Project John Doe", "description": "Description of the account...", "type": "corporate", "relation_number": "PR2022-1509-8", "contacts": [ { "firstname": "John"...
I've read several questions and I couldn't find one specifically similar to mine. I also don't think there's a design pattern for this situation as I think my system is a legacy system and don't fit the "best practices" in many parts of it. I'm rewriting a legacy feature from a 1990's system to a "new" system in .net, ...
Users are allowed to post on our website and we have started to get some spam. We have a background process that removes most of them after a few minutes, but are integrating a better solution that blocks on ingestion. This way they never make it to the site. My concern is that if we give them a big “we’ve detected spa...
We have several medium to large software projects targeting different platforms (arm32/64 and x86/amd64 on Linux and Windows) with a lot of duplicated code in them, since every project has its own split(string, delimiter), find_files(regex/pattern), and stuff like that. Because of that we're fixing identical bugs over ...
Semver specifies to update the major version on a backwards incompatible change. Would modifying the behavior for the hash function of a custom type fall under this category? I asked a couple friends, and they mostly generally agreed that it shouldn't. For using data structures like a hashmap or hashset, they behavior ...
For example, which term completes the sentence "p has 5 ____" in order to describe a situation like int *****p?
My company has a huge C++/C# software system composed of 1800 binaries. The technology range goes from old school native C++ Static Libs, C++/MFC, C++/CLI, up to .NET Framework, .NET Core 3.1, .NET 6/8/etc. Almost all possible Visual Studio project types within this technology range exist in the software. We struggle t...
I am trying to imagine a website/system where only 1 copy of a file is ever stored, but multiple users get their own custom link to the file, and it uses the CDN features. For this question we can assume we are using S3 and CloudFront or other AWS CDN features, but I am probably going to use Google Cloud Storage instea...
We have product X which has the following semver versions: 1.0.0, 1.1.0, 1.2.0, ..., 1.10.0. In version 1.5.0, we introduced a feature which changes the way the application is consumed in a big way. Eventhough the change is backwards compatible (which means a minor bump would be appropriate), we didn't realise at the t...
The most of the database management systems use B-tree as a data structure for increasing the performance. Let's imagine that we have a table users with the following columns: id (int), name (string), email (string), password (string), age (int). We want to select only ones that meet the condition: (name.contains("Bob"...
I often come across this dilemma in my own code and wondered if there is a term for this and if there is a single solution to it. Let me illustrate it with a pseudocode example of making a table from some book info: pure option make_table(bi, ab, pd): [p] t = make_table_from_book_info(bi) [p] t = add_author_bi...
I''m working on a C# library where the API provides several public interfaces and a single concrete factory class (itself an interface implementation). This factory provides implementations of the various interfaces. Other than the factory, none of the actual implementations are available to the user. As is the natur...
I'm creating a service for creating web tools. The tool is a generated web page with some JS engine. The user can interact with the JS engine through the user interface. The user interface can be either ready-made or custom. The idea of ​​using a custom user interface is dangerous. This approach creates possible securi...
I'm engineering architecture of a new web based software. I've never worked on high-scale softwares before and I'm reading a lot about it. To increase client-side speed and reduce load on servers, and also enabling server-to-client communication, I decided to use WebSockets. To process request from clients, I always re...
I have several services and each of these services has interfaces for each. I need to add a shared execution strategy here. By designating two classes with the same inheritance relationship as primary and secondary, one should be executed according to a branch. Example of the services: interface FirstService { abs...
I have a text file which is evolving and thus, difficult to manage. Hence, I am going to rewrite the code from scratch. Since, only few parts of the txt file change with a newer version, from the answers here, I understand that I should prefer a template design pattern rather than a strategy design pattern. Below is an...
I know almost nothing about threads, synchronization, ... That being said, I am working on a record handler, that hits Excel sheet to pull/push data. There exist, in my code base, a BaseRecordHandler, which use the entire spreadsheet to read from/write to. The game plan with it is as follows: create singleton instance...
Subj - how could I allow\disallow actions in my system based on the state of another external system (I have access to it's state via the shared DB table)? I can get the state of another system almost immediately, another system is like a state machine with some states like 'running', 'maintenance', 'initializing' etc....
I am using this DTO class to pass object between web application layers public class CreateProgressDTO { public int Total { get; set; } public int Created { get; set; } public decimal Progress { get; set; } } In many places I had to do the following: var createdNone = new CreateProgressDTO() { Total = ...
HTML rendering and javascript engines are very optimized, so why do they feel slow on smartphones? It seems that HTML's low performance justified the creation of mobiles "apps" which are more responsive, but also did not allow developers to just do things in HTML. It seems that websites are generally too heavy/cluttere...
I need to compare and synchronize two tree data structures. I have Tree A (the "Reference Tree") and Tree B (the "Target Tree"). I need to bring the Target Tree into compliance with the Reference Tree. I need to find differences -- additions and deletions, including those that result in new descendants or branches -- a...
I am currently making a newsletter website that will send you a email with the top ten manga for that week. Currently I have a web scraper that retrieves the top ten along with descriptions and other fun stuff. It then puts that into a pandas table which I was hoping to use along with a Heroku hosted Postgres database....
I am building a wrapper for a library that requires little complex logic. The whole project is 8 builder classes, 4 classes for doing some pre-processing, and a couple visitor classes. Essentially I am just building wrapper classes around a third party library's objects. I was curious whether in a situation like this i...
So I've got a simple object recognition app in iOS. I am trying to create an Interface-Adapter for the machine learning / computer vision like this: protocol MachineLearningInterface { func detectObject(from sampleBuffer: CMSampleBuffer) -> Observable<DetectedObjectEntity> } // Either Apple or Google class AppleMac...
I'm working on a Desktop App in C# that communicates with a Java backend hosted AWS. I want to deploy on multiple instances and use an Application Load Balancer with sticky sessions but as Far as I know it is based on cookies to route the request. So far I can only think on 2 solutions : Handle cookies on my Desktop A...
At first glance, these seem equivalent. If one has the right visibility, one can access a global variable or a class variable from anywhere in the program; There is only one, shared copy of them. So why would a software engineer choose one over the other? Considerations could assume a language like Python, with no priv...
We have divided our app into vertical slices, by feature, each of which contains domain/data/application/ui layers which has increased cohesion. However there is still some coupling because feature B might use value objects (or things associated with the value objects) from other features. For the sake of the example l...
Most of the information that I can find online is about how to do basic dependency injection in the common flows. eg one DI container where services are registered. For a project we are writing a library that comes with internal services and public services. The public services are the ones providing methods that can b...
I am thinking in a common orders and order lines example. The order has a state and depends on the state, I can do some actions or not. I guess that a good option for that it is to use the state pattern. If I am not wrong, with this pattern, I should to have one action for each possible state to change the order from o...
I'm interested in finding a text distance (or string similarity) algorithm which computes a greater distance (or lower similarity) when characters are further apart. For example, I want the distance between abc and abz to be greater than the distance between abc and abd. It would be easy to compute a text distance like...
My application contains webhook handlers that should execute many actions when the event happens. Given CUSTOMER_REGISTERED event this is what happens in pseudocode: function WebhookHandler(EVENT) { const selectedStrategy = selectStrategyBasedOn(EVENT) const result = executeStrategy(strategy); ... } function execute...
Let's say we have the following business requirements: We have a list of dishes. They have a name and a list of ingredients. The restaurant owner always wants to have a dish (and only one) marked as the "main" dish. Let's suppose we are using an OOP approach, and we have two possible designs (I'm using python but it ...
So, recently I have been looking into developing apps. I joined a school group who wanted to develop an app, problem being that I had an Android phone and my friends all had Apple phones. I know of Unity, but I was wondering if there might be a better way to develop apps for Android and Apple simultaneously. While havi...
Background: I'm splitting a monolithic multi-tenant chat bot builder application. Each customer registers an API token for a third party API which their bot will run on such as slack/telegram/discord. They then use our service to code the "brains" behind the bots functionality. I have identified a number of microservic...
I'm seeing two ways of orchestrating NServiceBus sagas. I'm not familiar with it so I'm trying to understand if they are just two alternative ways of doing the same thing or if I should follow one or the other. The scenario is a saga that is going to perform three steps - each of which is some sort of complex behavior....
Talking about gateways from the Clean Architecture, it is required to distinguish: The interfaces The implementation of these interfaces The TypeScript example: // === Interface ====================================== interface UsersGateway { retrieveSelection: (requiestParameters: UsersGateway.SelectionRetireving...
Currently I don't understand the Use case concept enough good - too much abstract definitions but no particular examples. The section Use Cases of Chapter 20 Business Rules does not including any code or at least UML example. The current question is discussing around below paragraph: A use case is an object. It has on...
I have an ERP-style system that needs to allow users to orchestrate an Entity.action() on a variety of objects that implement the Entity interface, at different datetimes. Calling action() would change the Entity state. What design pattern/architecture would be appropriate to allow users to store and manipulate a logic...
I've been using Git and GitFlow for quite a few years now, but this is still confusing me. Let's say I open branch release/1.1.1 to let the stakeholders test their application. While they're testing devs complete 2 new features and merge them on develop. Meanwhile stakeholders ask for 2 small fixes on release/1.1.1, de...
I'm trying to find a good way to implement state transitions for a job posting. This is just an experiment in trying to write better code. You can find the code and a diagram in this repo. The main problem I have is how can I write the code in such a way that there are as few as possible exceptions thrown. For example,...