instruction
stringlengths
34
36.1k
I have a class that I use to define different types of plots I am performing class MyPlots(Enum): STANDARDSCALE = "standard" LOGSCALE = "log" there are default values associated with the coordinates I usually plot with, i.e., in my code I have parts like ... if self._plottype==MyPlots.STANDARDSCALE: xlimit...
I code an Object-Oriented simulation where you can have a Unit move on a Terrain. The cost of such move depends both on both Unit capabilities and Terrain features: a boat can move on water, a plane can move everywhere, a car cannot run on terrain, etc. Current implementation uses a table, but this grows complex (as te...
I'm designing a mongo database and I have a dilemma if I should go for normalization. Let's say that there is a database with images and descriptions. Many alternative descriptions can belong to one image, but only one is assigned as the main one. When I fetch a document for a given Image, I need to have only the main ...
I met 2 different approaches to handling in-app credits. If the problem is defined as: Allow a customer to purchase credits, which they're allowed to spend on different in-system items. The credits should have an expiration date. The top-arch solutions can be described as: Solution A Store the balance of credits on a c...
I have to develop an eCommerce website following DDD. I just completed Ardalis and Julie DDD pluralsight course and need to come up with bounded-context for this project. Can you please assist if I properly identify bounded contexts for this project? The requirement is as follow : The system has 3 types of users : Admi...
I would like to explain the following code to my colleagues: for options in [{Option.NO_CUTOFFS}, {}, {Option.HEURISTIC}]: ... The following sentence is kind of awkward: This loop loops on the variants of the algorithm. What verb can I use instead of "loops" so as to not repeat the subject of the sentence?
I have a class called ContentLoader. This class has one method LoadContent<T>(T model, int?loadLogicDecider1, int? loadLogicDecider2, etc). It runs through the input class looking for a properties decorated with a ContentItem Attribute. It then goes to the database and loads up the appropriate content. There is some lo...
Title sucks, I know, but I'm having trouble describing my question. Say I have a class Three_Eyed_Robot that sees the world in RGB through three eyes. Lets call them Red_Eye, Green_Eye, Blue_Eye, each of which are classes of their own that load a deep learning model for vision, then store the data they see. My question...
I have a question regarding my general understanding of global state in software engineering. When I write an app I like to decompose it into little, manageable components and functions, that are ideally self-contained, have their own local state and don't produce any side effect. But some types of those functions seem...
I have a function that uses a static variable to count how many times it got called: void func () { static int counter=0; counter++; /* some code */ } The code in the function executes differently depending on the counter. As it happens while expanding the program to have more features etc. the original i...
I understand that chat apps are a fairly well understood and architected thing. I’m looking for some best practices advice on structuring the backend, particularly as it relates to user inboxes. One thing I’ve seen is that many chat services will duplicate a message across a user’s inbox. For example, in a two person ...
Does "primitive obsession" as a poor design practice apply to development in Python? I have seen a lot of examples and discussion in the context of statically typed languages (like Java, C#), but there are also dynamically typed languages like Python. Do solutions to primitive obsession look different in Python without...
Let's assume we have a method that we want to run as fast as possible and it needs to loop on a 2D array, naturally we would do a nested for loop as such: int[][] arr = new int[3][3]; for(int i = 0; i < arr.length; i++) { for(int j = 0; j < arr[i].length; j++) { arr[i][j] = j; } ...
I have a series of record types in my C# project that I use with JSON.Net to deserialize json data. public record RadarrMetadata( IReadOnlyCollection<string> CustomFormats ); public record SonarrMetadata( IReadOnlyCollection<string> ReleaseProfiles ); public record JsonPaths( RadarrMetadata Radarr, So...
In orms, we can easily perform our desired operations in the save() method (for example, when a record is added in the likes table, the count column in the post table will increase.) This is great, but it prohibits direct manipulation of the database! No one has the right to execute a raw query (insert or update) on ...
A co-worker of mine is working on project solo but would still like to have other team members review their code upon reaching certain milestones. Unfortunately, they also want to wait until the end of the project to remove commented out code, remove unused code, and resolve compiler warnings. Some of the commented out...
I'm thinking of a designing a review system (restaurant, hotel etc) where users can drop star reviews. Typically in a such a application, you can see the average rating of an entity along with all the individual reviews of the users. Now, the average needs to be calculated. The approach would be to get all reviews, av...
In ddd there is the concept of aggregate root. The Aggregate Root is the parent Entity to all other Entities and Value Objects within the Aggregate. It seems to me that User should be the root aggregate in most system where an user is interacting with the system. I've an hard time conceptualizing an aggregate root ot...
I am working on a CLI chess game that only involves 2 human players, I decided to make it follow the MVC architecture to ensure separation of concern and to make the possibility of a GUI/web integration easier to achieve. Here is the package diagram: The view only has the View class that draws the board and the pieces...
Suppose that we have a SQL relational database for, let's say, asset management system. It uses a table of assets (1 row per one real-world object). There can be various metadata etc. To allow the user add its own notes that are not needed to be managed by the system or provide information that the system is not able t...
I am running into a conflict between two best practice principles- overloading should be used instead of long chained if/else statements models should not contain business logic I am working on a chess game and am struggling on implementing my method calculatePotentionalMoves() for all the different types of pieces O...
I am currently developing some C++ GUI application using wxWidgets (although the GUI framework doesn't really matter here) and thus far have been developing this on my own, which was working well. This project has a few other dependencies as well (OpenGL, mainly, and then a few smaller ones like GoogleTest, etc.). I am...
We have a public API. Users will call this API by passing in different Guids as the IDs for entities. In the API, the Guid will be translated to the internal ID (Int32) for that particular record in our DB. The public API calls our internal API and the internal API receives this internal ID to fetch the record from the...
Say we have these view model classes. You can imagine there's an entry in the UI for each subtype of InfoItem, and each item contains some text and an icon. abstract class InfoItem(text: String, icon: Image) class Email(..): InfoItem(..) { private email: String } class Map(..): InfoItem(..) { private addre...
I'm working in a company, where we work with a kind of plug-and-play system: An executable is put inside a central directory, and there is a Modules directory, where DLL files can be inserted, which will then automatically be used. The biggest point is: there is no link between the binaries (EXE and DLL files) and thei...
Suppose the following: Building has 0...n Rooms, Room has 0...n Seats. I am implementing a REST API which accepts data from different companies, with the caveat that the companies must be able themselves define the id (reference) of the entity. I'm generally unable to make any assumptions about those ids, other than be...
I have seen many open source projects being labelled as "not production ready" because they have not reached a major version e.g. 1.0.0 using semver. What is the significance of reaching this milestone? Is there a criteria that must be met for a piece of software to be considered a major version? Or is it arbitrarily d...
I know that we have the functionality to lock records or setting isolation level, but this is not my question. By default if dozen/hundred of users edit the same record at the exact same time what will happen - is the database having built-in locking that will reject some users or some users will have to wait a little ...
I have a Spring Boot REST API application that uses different profiles like dev, test, prod, etc It also makes a call to another API to retrieve some data like: Client ---> MYAPI ---> DOWNSTREAMAPI MyAPI is working fine and it will get data from DOWNSTREAMAPI and return it to client. However, for client e2e testing p...
My domain requires that a Resource (ubiquitous language for a singular unit of data to be moved - commonly a file or folder) can only be moved if it has been Scanned to ensure it does not contain any Threats. Resources are moved from a Lowside MountedDrive (essentially some external filesystem, as far as I know a lowsi...
Assuming that a VM runs a JIT compiler on otherwise "interpreted" code, such as a line by line interpreter or some form of bytecode/IL code and determines that it can create optimised native code for some part of what is running, what mechanism is actually used to "emit" and then call the emitted code? If I was writing...
I'm a relatively new IT Ops guy in a software (web) development company. Recently I deployed a virtual machine on OpenStack, because some developer needs it, and then I installed their application (written by our developers, not third party application) on that newly deployed server using Jenkins. So basically, what I ...
In some companies, code is merged at a rapid rate by multiple teams with minimal testing and somehow the number of bugs is kept to a minimum. In other companies, this leads to chaos and terrible situations. Root-causing leads to no useful insights and people feel they are put on the spot about a problem (chaos) that is...
Is there a standard procedure for producing some jars, having them tested downstream, and then promoting these jars to the actual release? By promotion I really mean taking already publish artefacts which are known to be good, and rereleasing them with minimal effort. The approaches I can see are, either really produce...
I am developing a NuGet package which contains shared code for various ASP.NET Core projects. I am planning to use the strategy pattern to solve the same problem in a few different ways. So there will be a few different implementations of a common interface. See - https://deviq.com/design-patterns/strategy-pattern My q...
Forgive me if this is the wrong place to ask such questions - I am still extremely new to this field and am not even sure where the most appropriate place to look for answers is. Question: Assume I have a system in 2 physical locations: A and B. A and B are connected via a site-to-site VPN. There are two groups of node...
I have a java application, which recieves compressed files as input. The application then reads the header information of said files and passes the compressed bytes to an external native library for decompression (JNI). In one of the files we recieved, there was a corrupt blob of compressed bytes within the input file ...
We have a .Net WebApi 2 we've been working on for quite some time. As we refactor code, we started thinking of what might be a better practice: a) "to get an app by userid", or b) "to get a User's app"? Currently, we have 2 controllers: UsersController and ApplicationsController. Each have a GetById where you pass in a...
In Microsoft's documentation, in the Named Clients example, they retrieve an HttpClient from the IoC container: var httpClient = _httpClientFactory.CreateClient("GitHub"); In the Typed Clients example, the service that they register as an HttpClient, GitHubService, creates its own HttpClient: public class GitHubServic...
I'm following roughly the TDD style as explained in the "Obey the Testing Goat" book: You have a functional test for your (Django, in my case) web app that tests the observable behaviour via the Selenium webdriver. And then once you write a failing functional test for the behavior you want to see, you'll then do the TD...
ViewModel has Two-way data binding with UI which means UI can access the data from ViewModel and can update the view models data. The Model has one-way data binding and is only supposed to respond back with the result that ViewModel requests. am I understanding it correctly?
In many situations we need access to meta information about Java Beans. The Java Reflection API itsself does not work for projects were performance matters so the bigger Frameworks like Spring or Micronaut made their own stuff but also Java introduced something. Currently i am aiming to write a library for serializing ...
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 ...