instruction stringlengths 34 36.1k |
|---|
I have an update API (PUT/PATCH) entity/{id} to update a certain entity in my DB. Let's say:
entity {
id: number, // Primary key, unique, not null
content: text,
parentId: number // Foreign key, nullable, points to another entity's Id from the same table
}
When I call this API, if the id doesn't exist in the DB,... |
I'm using flask with SQLAlchemy on a postgresql database for a mobile app I'm building. My application allows a single user to save lets say up to 5 different locations which are saved in the database.
For each of these locations, I'm serving data from a different API and each of these API calls depend on the specific ... |
I see a pattern where the get method from a repository returns an Iterable, even if the list is composed already:
def get() -> Iterable[type]:
my_list = [list]
for x in my_list:
yield x
I'm wondering what are the benefits of this pattern?
|
This is something I have been thinking about a lot recently - why do we still authenticate / connect to databases with usernames and passwords?
Hear me out.
Lets talk about production databases. I think it is a safe assumption to make, that when it comes to production databases, there should never be a situation where ... |
I have a little bit of experience with Go, that I have been trying to use as a reference point to wrap my mind around Rust via a cards game I wrote in Go that I would like to now write in Rust.
I know how I would approach this project with a language like Python or Ruby and of course Go, but I am unclear how I would ap... |
In contrast to bitcoin:
How is double-spending technically prevented in traditional banking? Do database transactions have to conform to the ACID property in order to prevent double-spending?
|
I'm an applied physics student and currently working on a simulation of the magnetic interactions of multiple protons within a protein.
Me having only little experience with programming and almost none with OOP, there is a lot of information for me to process. Especially in terms on how to design my model in a way that... |
I am implementing clean architecture in my new back-end project and getting stuck with a particular use case.
I have a CreatePhysicianUseCase what is responsible for creating a new physician user in my system. I inject my repository into it which has the following methods:
export interface CreatePhysicianRepository {
... |
I'm working on a project that has microservice based architecture.
Recently we started facing problems where a single user requests requires updating multiple microservices each having it's own dedicated database and the response needs be sent to the user only after all the microservices have updates their databases.
I... |
Problem
We have multiple microservices, like Home, Menu & Cart, exposed via Gateway. Each one has API exposed to the app. Now, each API has certain information that is needed by the successive API. Wanted to know the best way to persist this information.
Possible Solution 1
One solution that comes to mind is to give th... |
I built an asset management system (a web application) using C# ASP.NET in MVC structure. My project is built upon the ASP.NET Boilerplate template, which includes 5 layers by default. These layers are:
Core (Data) layer: Entity classes, domain services and some core helper classes.
EntityFramework (ORM) layer: Databa... |
I have the following entity relationship.
A {state: ON | OFF} => B {state: ON | OFF} => C {state: ON | OFF}
So, in this case, B is a child of A, and C is a child of B. Moreover, they all share a property called state that can be either ON or OFF and defaults to OFF.
Domain rules
A child must inherit the state of the p... |
All the examples of Clean Architecture that I see have very simple use cases, such as:
OpenAccountUseCase
DepositMoneyUseCase
However, real world applications have much more complex logic.
Let's say I have a use case which gets the youngest Student on a Course for a given year. I could have:
GetYoungestStudentOnCour... |
For this MS sample code, I have checked Program.cs, Startup.cs, and other config files, don't see how the two parameters sqlQueryService and sqlCommandService are populated. Appreciate if someone can explain.
namespace ProductCatalog.Controllers
{
[Route("api/[controller]")]
public class ProductController : Con... |
I had a debate with a work mate regarding the following code as to which one of it would be the better practice:
My code (in pseudo):
var A = <precondition either TRUE or FALSE>;
var B;
if(A)
{
// some other multi-line, complex computation based on A=TRUE
B = <value fetched from JsonElement .GetProperty("C");>
... |
What does it mean this fish object on the architecture diagram?
|
I am currently implementing a Trunk Based Development workflow utilizing Short Lived Feature Branches in a project I am working on. Recently I have realized my release strategy is less than optimal, and I'm working to move to a Branch For Release, strategy for creating new releases.
Given I am implementing Branch For R... |
I'm trying to learn to create use case diagrams and would appreciate some pointers. The sample problem is to create a use case diagram for a seller in an online magazine selling site, I only have to worry about the 1 actor. Actions include selling a magazine, viewing listed magazines, a secure login, etc. Do the action... |
C# is considered a statically-typed language. However, it contains keywords such as:
var, which infers the type at compile time, and
dynamic, which determines the type at runtime.
Is this a contradiction?
|
I have written a class that implements some BLE scanning functionality. I have also written some test code that helped me to manually verify my scanner works as intended.
Now I want to somehow preserve that test code for future use. But I find myself stumped - how would I do this? I am currently using a unit test metho... |
For my job, I work on multiple different scientific software projects, as well as general administrative tasks that go hand-in-hand with any 'office' job. Thus, any given working week could involve progressing none, or all, of those software projects.
Put simply, my problem is that I waste a lot of time (sometimes days... |
Umbrella Question
In an onion architecture, where do all the components needed to consume an external API fit in?
The following is the architecture I have so far, based off an example found here: https://github.com/CodeMazeBlog/onion-architecture-aspnetcore/
Requirements
I'm now trying to test out this architecture by... |
I'm writing a ray-tracer in C++, and while writing a constructor for the Ray class:
class Ray {
public:
Ray(const glm::vec3& origin, const glm::vec3& direction) : o{origin}, d{direction} {}
private:
...
}
my IDE helpfully put a zigzag line, saying:
This got me thinking, and I decided I wanted to be a little stricter... |
Say I have a feature in a web app where users can create a post and like it. In the frontend the user should see the number of likes a post has.
I could store the data two ways:
1. Option 1: A small table where # of likes is determined from a query
(content: text, liked_by: string[])
2. Option 2: a larger table where... |
I've been working on a personal project for some time, and I believe that I'm at that point where, if I don't embrace unit tests (and ideally TDD) now, it may be too late, so I want to make the right call. I'll try to keep things generic, so that this answer can be useful to as many people as possible.
Something releva... |
I am trying to design my database, where i have to save some response data given from an external api as a webhook.
This api will return me as well “referenceId” as an identifier, which i will use afterwards to relate with already existing record in database.
So, the question is, is it fine to design databased columns ... |
I often write front end apps with a generic MVC pattern. I use javascript but this questions is language independent and relates to OOP as a whole. I struggle to understand the SRP principle and I read many inconsistent content about it.
I am looking for a definitive answer by providing a written example of a problem I... |
So nowadays, creating js & css that works the same across different browsers is less of an issue as to what it was a few years back.
So let's say I have this Vue app that -
Has CSS reset
Include @babel/polyfil
Doesn't care if it works on Internet Explorer or not
Not using any special CSS properties
Edit -
Has browse... |
I've heard people say things like "B can't inherit from A because A is immutable and B is mutable".
My understanding of inheritance in Object-Oriented Programming is that you use it to add behaviors/methods, such as set methods.
interface A {
getX(): X
}
interface B extends A {
setX()
}
You can't remove methods... |
I'm building a web application using Laravel. I use the repository pattern as my data layer.
Imagine there's some entity like Product and a product can be assigned to a ProductCategory.
The Product has a field named category_id and that field either contains the id of a product category, or null if the product doesn't ... |
What is correct in your opinion regarding the creation and handling of models in an application let's say using MVVM, or even an MVC design pattern?
I will try to illustrate the situation I see at my company in an iOS Application,
We have a couple of tabs in our application and for each tab we create the models needed... |
I have a project in which I'm the sole contributor, there isn't a stable API yet and I'm constantly refactoring code, but I still try to denote breaking changes whenever they do happen. Recently however, the repository for this project has attracted some interest and I decided to establish some conventions to make it e... |
Long story short: I would like to create a plugin system for my microservice architectured app. so we can allow our customers to install their plugins. (something like a plugin system on wordpress|...)
Each plugin:
Receives pre/post hooks for every operation from our microservices (e.g., productWillBeCreated(),product... |
I read some very interesting discussions about decoupling microservices on this forum. One of the approaches is to ensure each service holds (parts of) the data of another context to allow it to operate without having a dependency on other services (e.g. REST call to other services).
Where does one draw the line while ... |
The following figure comes from https://spring.io/guides/topicals/spring-security-architecture
I refer to it as a "figure" rather than a "diagram" as I'm not sure if it is.
the doc/guide says
Often, each of those is a ProviderManager, and they share a parent.
which seems to indicate the 3 blue rectangles labeled Pro... |
I have an Micro-services where we get the event messages from a Kafka messaging system. The event message contains the orders information, quantity, the mode of package and delivery location. At a predetermined time, these events are pushed to the Kafka stream. A special event full delivery event is issued to signify ... |
For a frontend web app version 3.9, we have a visual change that I would constitute as a backwards compatible (as far as the API) new feature. Therefor, my SemVer instinct is to bump the minor version number.
But how do I do that when we're at 3.9?
|
I wrote a java call graph generator with tree sitter (the 3rd-party library in question)'s python binding. I am doing a thought experiment on how I might model the same application in Haskell. I am asking for help on designing the architecutre in Haskell. I have put forth a hypothesis, but if there's a better way in a ... |
I'm writing a code that extracts information about functions (prototype) and types (enum, struct, typedef) from a C source file.
This is to augment the type information about a particular function or type in my documentation.
Basically, I don't want to manually specify type information because that information can alre... |
There are many questions and responses on database triggers, however I have not found any that touch on network performance specifically, in the matter of benefits (or otherwise) of triggers.
I have this case:
Table A has rows that are data heavy (1-2 KB of JSON data). When one of the fields (status) is updated, the en... |
At my company we are revising some backend architecture. I think I have identified a use case where event streaming (for example with Apache Kafka or RabbitMQ) makes sense.
Because me (and everyone else- at my company) are pretty much noobs in that space, I'd like to validate my idea.
Business flow and prerequisites
We... |
In my company we hire engineers for various "disciplines"—iOS, Android, Web, Backend, Data, etc. Engineers follow an onboarding workbook to install what they need for their discipline. iOS engineers need to install Xcode, backend engineers need to install IntelliJ IDEA, etc. And some things are common to all discipline... |
Question inspired by a similar question in Academia.SE: Is it OK to generate parts of a research paper using a large language model such as ChatGPT?
I've always been very sceptical about AI code generation tools. My thinking is as follows:
Such tools are known to sometimes output incorrect code. Sometimes the flaws ar... |
We have a system built on microservices with 50-100 different services. Previously most servcie-to-service communication was done with direct REST API calls, but we are shifting to a event based architecture (for this question I have simplified the setup a bit)
My question is related to how to model the events between ... |
I have read many articles about repository pattern and service layer but I have still some doubts in certain arguments:
Repository should return only aggregates and I should have repositories only for aggregates and not entities, for example Product and not ProductDetails. If I would to retrieve only some properties f... |
I'm trying to make a simple Blog-application, but I'm a bit stuck on the architecture of the application.
I'd like to create a details-page with the content of the blog-post and a form for adding comment to the post.
My code looks like the following:
ViewModel
public class PostDetailsViewModel
{
[ValidateNever]
... |
I'm a huge believer in the value of Intellisense for showing you what syntax is expected and allowed (and also saving typing, though this is a secondary consideration).
When you build a web component (or use JSX or tagged templates or the like), you have code like this:
class MyElement extends HTMLElement
{
constru... |
I'm new to DDD and I trying to create an API using DDD concepts for study purposes. Today, I faced a scenario where I've to create an Application Service to expose a functionality to be cosumed from the external world. The scenario that I came across is to consult in the repository some Domain Entity informations by it... |
I am making a game of monopoly. Inside my game I have a Board class. The Board class has an array which contains 40 squares. Each square is a different class e.g. ChanceSquare, PropertySquare FineSquare.
Now inside the board class I want to do various things. Check three separate squares to see if they have the same ow... |
I'm looking for the optimised approach of designing MongoDB database collections where there are three stakeholders-
A User (who accesses a portal).
An Organization (which can have multiple Projects).
A Project (which will be inside a single Organization).
A user can be added either to an Organization, which will giv... |
The traditional (Scheme, Pascal) way to structure code is this:
declare outer function
declare inner function
body of inner function
body of outer function
The where clause in Haskell moves the inner function from the beginning to the end.
declare outer function
body outer function
where
declare inner ... |
I like programming in such a way that every component/injectable of the applications I build, has a clearly defined scope, and it's easily tested.
With years working as a Developer I've come to ensure every component I declare and implement fits one of the following categories:
Technical components: those behind the s... |
This question has probably been discussed to death, but I don't feel like I have a good answer. I work at a company where customers are on different versions of our product. When a bug is found, we determine what was the oldest release of the system that was impacted. Developers then checkout the appropriate branch for... |
We develop a SaaS solution that processes customer ERP data and provides analyses from it in a front-end. The software is a standard solution and should require as little customization as possible for the respective customer. Unfortunately, the ERP data is business-critical data (not legal protected data e.g. personal ... |
I own a laptop and a desktop. The desktop better for training neural networks, but I don't have physical access to it. The laptop is better for day-to-day work on the neural networks. Right now, my workflow is:
Make an edit on my laptop (for example, changing the value of one parameter)
Commit changes
Push to github
S... |
At some organizations I'm seeing a trend where if a bug is reported, engineers will directly rewrite the offending code without knowing the root cause. In general this will fix the bug, but in my opinion it also introduces the risk of new bugs - and it doesn't allow a team to learn collectively from the mistake that ca... |
For one of my current projects, written in Python, we would like to have two different versions: One for internal use, with all features enabled, and one for external use, with limited features. The current external and internal deployment method is to directly pull from git master whenever there are updates.
My initia... |
I have a simple 2D game which has squares, player (teal) and enemies (red).
class Game {
List<List<Square>> map;
Player player;
List<Enemy> enemies; ...
My problem is that I don't know what would be the best way to store the coordinates (int x, int y) of the enemies. Currently each enemy contains their coordina... |
I'm currently developing a bot for Discord that sends news over webhooks to multiple servers and I've decided to separate that news onto it's own microservice because the bot runs multiple instances of itself so that means this would run multiple times as well (while I could theoretically just tell it to launch on a sp... |
I have a Material class :
public class Material
{
public string Name { get; private set; }
public double Density { get; private set; }
public double SpecificHeat { get; private set; }
public double Conductivity { get; private set; }
public Material(string name, double d, double c, double l)
{
N... |
I'm working on an application that contains a central class, called Engine, made of different sub-modules (classes), where each module is responsible for a specific functionality. Those modules are private in the engine class, and the engine class itself exposes their work through some public methods. For example:
clas... |
I have a Kafka topic providing events of the following type: id(hash):[ADD|REMOVE].
These events may be generated at a high rate and are idempotent, i.e. getting 123:ADD one time and ten times in a row produces the same result: state of 123 is ADDED
Processing of each event may take a while (not hours, but seconds).
P... |
I have one microservice (in GO) that needs to read a whole table every hour, filter out some data and send it to another application.
So as an example, imagine I have the following model:
type User struct {
ID uuid.UUID
Name string
Surname string
Birthdate time.Time
}
And I need to read all the users of the ta... |
A simplified version of my code looks like this:
def process( object ):
try:
if suitedForA( object ):
try:
methodA( object )
except:
methodB( object )
else:
# we would get a bad result from methodA()
methodB( object )
... |
I have a transmitter class which contains raw data which represents physical values (double and int). These values should be taken by a receiver class to display them with logs (string) sorted according to the physical values.
Maybe I think too much but I don't know in which class I should process the data.
If I create... |
My website deals with states, which contain regions. So there will be a page called /states that lists states, and if you click on one, you get /state/{id}.
Note 1: This is not a REST endpoint, but an actual web page where you view the state info with a nice UI.
Note 2: I'm not concerned about the id's in the url. The ... |
I am trying to wrap my head around the concepts of Clean Architecture, and specifically about the responsibility of the Infrastructure layer. Its purpose is often described as "to provide functionality to access external systems", which is a bit vague when you try to think deeply about it.
Consider this example. Let's ... |
I read a talk entitled "Deep C (and C++)" by Olve Maudal and Jon Jagger. I paste the relevant code and quote below, but here is the link to the slides.
On slide 349, the presenters show this C++ code snippet which deliberately contains issues:
#include "B.hpp"
class A {
public:
A(int sz) { sz_ = sz; v = new B[sz_]... |
When modeling classes I always have stumbled on the problem that the class has a field with the same name. Look at this example:
class Name {
string meaning;
string language;
string name; //the actual name
}
As you can see, the class Name has a field name, which is the actual name. Is this good practice?... |
I have an angular based SPA, and backend resource server is written in springboot. I have integrated keycloak to provide OIDC support. Currently the app talks to auth server for login, (supplies credentials) and gets a token, which is uses further to access resource server APIs. But I don't want end users to be aware o... |
This sounds like a newbie's question, but please bear with me. I have 10+ years of commercial software development experience, and I still don't know how to do this properly.
I'm working on a pet project that's taking me months to think through all the subtleties. The actual code will be a small amount, maybe 10K LOC, ... |
See: Type inference with duck typing - does this work? Why is it not used?
And: General approach for proving decidability/undecidability
Hello, I wanted to ask a theoretical question about type system conversion. The proposition is to suggest or complete static typing for gradually typed languages (or dialects / transp... |
I was going through the source code of an existing project and totally confused about one implementation. The project is created in .Net 6 and it's a frontend MVC project. It's part of a microservice project and data is coming through an API.
Now the thing is, there is a generic class written for API access and it has ... |
CONTEXT
My project is about implementing the "conventional method for house-energy-efficiency assessment" in France (120 pages). I want to provide a strict yet easy to use API to this method. At first, the audience will be engineers that are not programmers but have basic knowledge in C# to consume such an API inside t... |
Here I'm working in Python, but it's more of a language agnostic question, unless specific language features makes it clear that an option is better than the other.
I get my raw data from a REST API, and need to do many operations with it.
tc_builds_by_agent = [
{
'agent_id': agent_id["id"],
... |
When in the refactoring step of a TDD process, if we "factor out" some common functionality from two (or more) code modules, how do we avoid that "factored out" code not being properly covered by unit tests?
Here is a toy example to illustrate what I mean. Since it is a toy example, the factored-out code is very small... |
I am going through this nice write up on thoughtworks about inheritance vs composition. I understood the authors explanation of the dual purpose of inheritance. But, I am confused on the specific details about "dimensions".
When you have a situation where either composition or inheritance will
work, consider splitting... |
Suppose there is a flow of functions in C++
step1();
step2();
step3();
step4();
step5();
and they interact by adding and modifying data on a data class D (only data, no functions). For example, step1() creates d in D, step2() modifies d, and step5() uses d.
The problem with this design is that at a given step function... |
I'm designing a web application for image analysis using AI. My API for CRUD operations is written in Django. Now I want to add the AI functionality which loads the model once on the startup, receives images, and returns the results. In the future, it would also allow for annotating data and fine-tuning the models.
Fir... |
For example, A system can accept a description of a symbol as "black-heart" or "heart-black". As far as this system is concerned, both description are valid.
Is there a computer science terminology or math concept for the existence of multiple, equivalent codes/representations of a concept/object?
|
I know that as a general rule, you shouldn't construct SQL queries dynamically because of the possibility of SQL injection.
However, it could come in quite handy to break this rule and define for example my SELECT statements like so and use it for all my tables:
public static string SelectAll<T>() => $"SELECT * FROM {t... |
I've been searching the internet and I can't find a good question to this so I believe I have a fundamental misunderstanding on what they are.
Is the only difference that in gitflow there is a release branch for your "not released yet" changes and in trunk based there isn't one?
Because for either method, you are going... |
From what I understand from this answer, it is not possible to use a typeddict and typechecking in a function. So for example, if one has a function:
def some_func(some_int: int, some_dict:Custom_typed_dict) -> str:
"""
Takes a value from dict and adds it to some_int and converts
the result into a string.
... |
I work for a supplier of software solutions, and when we want to deliver our solutions to the network of a customer, we are forced to use a myriad of tools: VPN connection over GlobalProtect, VPN connection over PulseSecure or another FortiClient, ...
Edit: it's the idea that we deliver support to our customers, while ... |
I have a UI for a tool with a fair amount of user interaction.
Imagine a sports tournament predictor where you select which team will finish 1st in the group, 2nd in the group etc., with the winners of each group progressing to the quarter finals and so on. The user's task is to predict who finishes where. The user can... |
Not 100% a coding question, more around developer productivity.
I work in Data Science, meaning a lot of my day is spent reading some data, manipulating it, making some charts, training some models, evaluating them, etc...
I'm proud to say the code we are using is very optimized (files are saved in parquet, all manipul... |
There has been a change in the project I am working on.
Until today, there was only one type of user in the system.
From the moment you logged in, you had all the information about the user.
The new change we need to make is to support several types of users.
Some types of users have information about them, and some do... |
I'm interested in understanding, conceptually (e.g., similar to how many of the concepts in networking are explained in textbooks like Tanenbaum's Computer Networks, or Kurose's Computer Networking), how a virtual private server (VPS) processes an incoming packet with data conceptually and it is mapped to my virtual in... |
I recently took on a long ago python project which has some weird code style that I can't pinpoint. e.g.
# this is a params and value package?
opts={
infile="xxx",
outfile="xxx"
}
def parses():
with open(opts['infile'], 'r') as f:
#do something here and get a parased_object
opts['infile2']=parased... |
I have three services, each of which has its own databases
User information table located in service one database.
The membership table located in the database of Service Two, which specifies which company the user belongs to.
The table of financial information that is located in the database of
Service Three.
The ch... |
I have an embedded system running on a little-endian Cortex-M3. This system is able to accept packets from the network and reply to them. Now, I would like the system to start generating files. These files will then be downloaded and inspected with tools running on regular x86 desktop computers (i.e. also little endian... |
In the simplest case, I have some code where the user may want to do one thing (a), another thing, (b), or both (a+b).
The options are reasonably complex and have their own functions, but I would like an elegant way of executing one, the other, or multiple.
I want to consider the types of the choices supplied, as I thi... |
I want to run a complex algorithm consisting of many subtasks in parallel on a number of processors. These subtasks depend on one another, so that this algorithm is characterized by a DAG (Directed Acyclic Graph) of subtasks. An arrow from A to B in the DAG means that subtask A must be completed before subtask B starts... |
We're dealing with a lot of "data analysis", basically different sorts of data mangling, aggregations and calculations using Pandas. Usually, the data is time series data.
All underlying data is stored in a SQL database.
As of now, we usually wrap all data access logic into a single "DBWrapper" class that implements me... |
I am currently seeking a solution to run sanity tests on my GitLab repos architecture. There are more than 20 repos in a GitLab group.
My idea is to create a "Health Check Repo" (HCR) that would do several health checks on all these repos. For example:
verify that for all the branches whose names respect "branch_v[num... |
I'm finding myself in a situation where I need to define common behaviour and implement it depending on the environment (minecraft server or javafx runtime). The simple graph below describes my idea.
Maybe a few more notes to get the big picture.
A user starts the gui module and makes some changes to the default setti... |
Question Background
Consider a scenario in which I have two structs. Both consist of three fields for doubles. The only difference is the names used to refer to these fields. The first struct is for non-descript Tuples and the components are to be named x, y, and z. The second struct is for RGB values and the component... |
We are doing a mobile app development and currently, we have Dev - UAT - Staging - Main branches.
We branch from the Main branch as feature/fA for feature development.
We do our development in that branch and when it is done, we create a merge request to the Dev branch. We go on with the tests and create a new merge re... |
I want to build a web application with a Single Page Application as the front end and an API as the back end. The front-end SPA will read and write data to the API.
The SPA and the API will be hosted on two different domains:
SPA: https://my-spa.com
API: https://my-api.com
The API needs to be private so only authenti... |
I have scheduling requirements where I place all my schedules in SQL db and then use the azure function every minute to read that database. When the schedule is met, I then perform a durable function for that schedule.
This causes a lot of Azure Functions to be invoked, and CPU usage also increases as this is continuou... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.