instruction
stringlengths
34
36.1k
I have a C# (WPF) application which consumes a particular 3rd party API/tool (let's call this Tool A). My colleagues and I are trying to decouple that from our application, so that it is possible to switch out Tool A in the future, replacing with another vendor's API/tool. We decided to define a set of interfaces, whic...
I know that this question has been asked before and is the same or at least almost the same but I just want to know: Is it the only method or is there any other way to do it? I have these tables: Person1 and Person2 are referenced to User: At the moment of insereting a new user, it's only posible to inset one ID_Perso...
If you have a very large monolithic database that is not partitioned or sharded, with strong relationships between the tables/data, does it still make sense to use microservices as the application layer?
So my question is more algorithm based rather than code or architectural problem. I have a problem where I am given an array of object like this: [{joinedAt: <Timestamp>, leftAt:<Timestamp> }] now consider this scenario: I have 4 people having a meeting, each have its joinedAt and leftAt value. I want to find max numbe...
So basically I guess I know the role of MVVM, but correct me if I am wrong View: Basically it whats the users sees + it takes user interaction Also View: It shouldn't know what the model is ... but it must know what is the ViewModel is ViewModel: its the Glue code that does the binding + code transformation + Interacti...
Lately I've encountered a similar problem in a few different circumstances, and every time it has required quite a bit of extra code to work around it. The problem I'm talking about is the one where one application or device needs to send something to another application or device (usually a server). The thing being se...
I'm trying to learn about microservices and best practices and came across this scenario and didn't know what was the correct way of approaching it: I have a website that can display widgets (let's say there's 3 types of widgets, widget A, B, and C) specified by a user. Each widget type has a corresponding microservice...
I am using an opencv.js Web Assembly build in the browser. The build comes with a JavaScript interface to call the WASM functions but it does not provide any memory management. For example every time I create a new matrix( mat = new cv.Mat() ), to free up the memory taken by that object, I will have to make sure to cal...
a short question: class ItemActionObject { private final Object moreParameters; private final Object otherDependencies; private final Item item; public ItemActionObject(Item item, Object moreParameters, Object otherDependencies) { this.item = item; this.moreParameters = moreParamete...
I'm a developer and my typical environment is to use is a Linux guest OS running inside VirtualBox on a Windows host. Most software companies don't allow developers to install Linux bare metal on their machines. The Windows host/Linux guest solution is a good compromise. My new workplace is different. They'll let me us...
I've been seeing a lot of this construct throughout my application: def doSomething(): try: # setup some variables try: # do something that could throw an OSError except OSError as err: # log and handle it # do some more things try: # d...
Overview Domain-driven design prescribes modelling a particular domain with classes that contain both state and behaviour. Microsoft attempt to support this methodology in modern C# applications through EF Core, which allows constituting graphs of entity objects from a database. I'm building an application where I mode...
So for e.x I have an entity Payment and a config Payment settings. class Payment { public Payment(PaymentSetting setting, ....other fields){} internal Payment() /*strictly for the ORM**/ //Other properties and behaviour } class PaymentSettings { public Timespan TransactionTimeout {get; private set...
I just have a quick question as I couldn't find any concrete answers on the web. Does having a private static inner class promote loose or tight coupling between it and the outer class in Java? Thanks for your help in advance, appreciate it!!
In Operating System Concepts: 7.5.1 Safe State A state is safe if the system can allocate resources to each process (up to its maximum) in some order and still avoid a deadlock. More formally, a system is in a safe state only if there exists a safe sequence. A sequence of processes <P 1 , P 2 , ..., P n > is a safe se...
Say we have an API that accepts a list of objects. Something like: { "family": "Does", "contact_details": [ { "name": "John", "email": "john@example.com" }, { "name": "Jane", "email": "jane@example.com" } ] } Say you then wante...
In OS books (e.g. Operating System Concepts), there are three strategies of dealing with deadlock between processes or threads: prevent, avoid, and check and recovery. Who performs the strategies? is it always an entity, different from the processes or threads being considered as candidates of deadlock? For example,...
I want to compare the performance gap between the two machines, the main consideration here is memory and CPU. For example, the theoretical calculation peak of the CPU. Theoretical CPU peak = main frequency × number of cores × CPU double-precision floating-point number operations per clock cycle. But this is the theore...
Disclaimer: I'm not sure if this is the right site as this question sits under both software engineering and security domains. Background: Assume you have a financial web application that receives sensitive requests from its users (e.g. money transfers) and you want your application to be able to process sensitive oper...
I'm building a project with C# AspNet.Mvc. I'm using Entity Framework Core. It has Poco which maps in data from DB. On Mvc project itself i've got ViewModels folder where i have models topass between controller and view. But how should i organize models on web to map from POCO entities. So far i was keeping them in the...
I'm working on a microservice system where 8 services share the same data - most notably: auth, forum, portal. Essentially, forum and portal use users from auth, and since I went with the 'AP' approach in CAP Theorem - I duplicate data from users and store it in database of forum and portal whenever it changes - thus r...
Since we live in a world where basically all your web activity is being tracked by some company or your ISP. I was wondering how to 'falsify' the data they collect. For instance by having software go to page A and performed X, Y and Z actions. if user goes to page A and performs B, F and G actions. In this case the rea...
A question from a friend: I have multiple usages for the same code, let's say a vertical HTML card. I change the title and a lot of data based on the react component. it feels unnecessary performance-wise and for readability to use "if statement" multiple times on the same page, so wondering shall I just repeat the cod...
So I'm aware there's some degree of timing-based logic in existing programming languages, like threads and the sleep() function (and derivatives thereof), as well as events / delegates. However, I was curious about the potential of a language, or at least a library / extension of an existing language, that embraces the...
In an OOP design, suppose I have some board type game that has pieces, such as chess, checkers. In you opinion, what properties should pieces of that game board have? imo, I feel like the pieces should only contain its respective rules, e.g. it can move like this, and it can do this. The issue I see with this is that, ...
Operating System Concepts discusses two implementations of a semaphore, by busy waiting in Section 5.5 and by blocking the current process in Section 5.6: Section 5.5 A semaphore S is an integer variable that, apart from initialization, is accessed only through two standard atomic operations: wait() and signal(). The ...
I want to optimize a bike-sharing redistribution system( find the best way for an agent to take bikes from a station that has more bikes than needed and relocate them to a station that needs more bikes) and I don't know what technologies to use. I have details about the path cost and the demand for each station. I woul...
I have a REST API (v1) which routes through to a Java springboot component for which I now need to introduce a number of breaking changes to add new and changed functionality (v2). I understand how I can use a version number in the URL or HTTP headers to signal whether a client is calling for v1 or v2. My question is ...
I come from a Java background, but now I'm supporting a PowerShell code base. In the PowerShell code base there are multiple modules that were written against a certain Azure environment. Now, we have another Azure environment that we need to support, and a lot of code needs to change. We don't want to fork the code...
Here are some discussions about mutex (lock) and binary semaphore from two OS books. Stalling's Operating Systems book says A concept related to the binary semaphore is the mutex . A key difference between the two is that the process that locks the mutex (sets the value to zero) must be the one to unlock it (sets t...
It's a pretty simple question really, how should one properly declare and use a global resource without violating Java's OOP principles? When I'm writing in C, I would declare a struct in global space. This could then be accessed by any function that needs its data; it could be database connection details, or socket in...
I have a program that involves two different data structures, and so I created a class that acts as a generalized data structure that either of the original two can be represented as. (Because the next part of the program ideally only handles a single kind of data structure) I implemented this generalized data structur...
Is a mutex lock always implemented as spin waiting? Can a mutex lock be implemented as block waiting? (Operating System Concepts section 5.4 only mentions the implementation by spin waiting. See below.) (For comparison, a semaphore's waiting can be implemented either by busy spinning in a loop or by being blocked. See...
I am currently doing some exercises with algorithms and I find myself in a huge problem. It seems that everybody understands this type of problem but I have a really hard time figuring it out. For exercise, we have some for loops to look at, and we need to figure out the runtime for that specific algorithm. We got a so...
I'm starting to notice this pattern throughout some of my code: try: some_func() except FirstException as err: # known possible err # log err notify_user(err) except SecondException as err: # known possible err # log err notify_user(err) except Exception as err: # unexpected err to prevent crash ...
Here are some discussions about mutex (lock) and binary semaphore from two OS books. Stalling's Operating Systems book says A concept related to the binary semaphore is the mutex . A key difference between the two is that the process that locks the mutex (sets the value to zero) must be the one to unlock it (sets t...
I'm studying state machines diagrams and was asked to come up with a diagram for a device that turns on and off when a button is pressed... but as with other modern devices nowadays, it can operate either when the battery has charge in it, or when connected to electricity, such as a cellphone device. My question is... ...
I want to synchronize one variable (Node.Value) to two separate sources. Both sources can read or write to their internalValue variable. How do I keep track of the newest value and update appropriately? I need to run this process multiple times a second. The sources are not necessarily databases. I was thinking about t...
At a previous job, we had a lot of excessive issues with versioning of our APIs, to the point where we had whole server farms for our services that were running specific versions for specific applications, split out in case the Mobile Team updated but the Web team did not (there were about 5 such front end teams so 5 s...
Context I'm developing a chess engine of my own, where if anything can be pre-initialized/pre-calculated, should be. This is because speed is the number-1 priority, and every extra second you spend calculating stuff that could've been calculated before-hand, stacks up and ultimately makes you lose a lot of important ti...
I'm doing a website that has a React frontend that calls some RESTful API and I would like to know if this is an MVP pattern. I think that the React application implements the View and the Presenter, while the backend realizes the Model of the website. I think it's not MVC because the view isn't updated by the model di...
The way of running automated tests (specifically, a large number of small, «atomic» unit and regression checks) that I am used to is to maintain a monolithic executable built on top of a test framework that aggregates the individual checks into a test tree and provides «quality of life» features like colourful or machi...
I am looking to understand the difference between the words index and offset. I have never seen "offset" in reference to lists/arrays/etc in programming. I have only seen index. To me, these mean the same thing. But how one is used heavily and one never implies they have different meanings. They might also just have hi...
A transaction has ACID properties, where "I" stands for isolation: Transactions are often executed concurrently (e.g., multiple transactions reading and writing to a table at the same time). Isolation ensures that concurrent execution of transactions leaves the database in the same state that would have been obtained ...
I'm in the process of adding a message broker (ActiveMQ Artemis) to a system currently and while I have my own notions on how I can divide up the namespace, it seems like a good time to get opinions from others on how they like to name their queues and topics. The overall topology I'm after is to support functionality ...
Please allow me to illustrate my question with a simple example. Let's suppose we have a Customer class: class Customer: def __init__(self, name, surname, email): self.name = name self.surname = surname self.email = email And we also have a Bill class that needs info from a Customer object...
Using Vue/Electron to post to rails/Postgres backend. Is there a common design pattern/approach to posting multiple audio file objects BUT in a single post request? My current process (which works, but is very slow) is to convert each audio file's binary data to text, append it to my JSON and then send it all to the se...
Stallings' Operating System book says about condition variable in Solaris, A condition variable is used to wait until a particular condition is true. Condition variables must be used in conjunction with a mutex lock. This implements a monitor of the type illustrated in Figure 6.14 . The primitives are as follow...
I have been developing for many years and have used many OOP languages over the past 30 years. I am still not sure if I have ever used polymorphism. I have searched and read but still don't understand the concept. Is it a feature of OOP or an implementation? Is it a combination of Abstraction, encapsulation, inheritanc...
I've been reading a lot on why one should use messages (w/ event sourcing/CQRS) for microservices communication and I get it. But most of the stuff I read online state that the main reason for using message brokers over direct http REST API communication is the cascade failure effect when a a service is down. Well, tha...
One senior member of my team setup a new git repository for our product we are working on, since we are migrating from SVN to git. Our product consists of different software components that are working more or less completely independent and are also completely different in terms of code. On SVN, these components were ...
I have a executable that starts up some resources, spins a bunch of worker threads and then waits in a loop for the done command. After the done command is received, it does a bunch of clean up and then exits. void run() { /* more initialization code, creation of classes, start worker threads etc. */ while (!d...
I have an application that does some document handling as part of its functionality. I would like to implement a "Drive" emulator that would allow users to navigate and manage documents as if they were on a local drive. In my mind, this would be similar to how a remote session can access a local drive. But I'm not sure...
Here is my UML Diagram: Are the "post answer" and "vote" actions an extension of browsing? Since you have to SELECT / VIEW (?) a question in order to answer or vote. Or can I simply say in my use case text that you must have selected a question as a precondition? Should I also change Browsing to search only? Diagram i...
I have yet to hear an answer from anyone as to why overloading of any type is a sound programing practice. Calling the same function name with an almost infinite number of variations on the surface and under scrutiny screams "hey this is a error looking for a chance to instantiate itself". I'll buy the object oriented...
Our budding (currently internal) API deals with building information models, originates in our main application written in c++. There is a small implementation of it in C# for easy interop with other CAD software exposing .Net APIs (mainly just a class library with de/serialization). This also covers python scripting t...
I am working with a message broker technology, to which events will be published (following an "event carried state transfer" architecture) for consumption by other applications. The vendor library uses a pattern where a message is handed to a Session object defined by the vendor's client library code, which sends it o...
Is it correct that In concurrent programming, a critical section is a sequence of statements which can't be executed by more than one processes/threads at the same time. Atomicity (as "A" in ACID for transactions in database systems) means a sequence of statements must be either executed completely or not at all. I...
My question is about clean code or best practice. I have a big formGroup and in my opinion its more difficult to map the form to an object than to send the form to the backend. best regards
Was introducing default methods to java inevitable? As far as I know multiple class inheritance was not introduced to avoid difficulties with the method signature clash in base classes. So we avoided it with classes and on the other hand we introduce this problem with default methods as we have to override default meth...
I decided to go with Firestore to our new project. The goal is I don't want our server logics and database designs are locked-in by Cloud Function and Firestore, And also long-term maintainability. While I know there will still have some degree of locked-in, My idea is to write the logic in Cloud Functions separately a...
For the designer of a language syntax, what are some reasons to choose a repeated delimiter to escape that delimiter, instead of having a separate escape character to escape that delimiter. A common example would be escaping the character ' in a string delimited by 's. Two common approaches to get the string It isn't. ...
I have 5000+ strings pet-project for CLI and it can do some optional calculations and can output results to CLI or/and to file. Some new modules don't work. Now I catch with GDB some strange segfaults and stack overflows, which I can't fix, though, I found all the places where the bugs are living. So, I see where and w...
For instance, in the case of PostgreSQL, it is entirely acceptable to use a newer client to connect to an older server; but if you do the opposite, using an older client to connect to a newer server, you would get a warning. My gut feeling is that, by off-loading the responsibility of ensuring backward-compatibility to...
Background: Our group of 10+ engineers all share a Git Repository. In the past, someone has checked in binaries that have caused the size of the repository to grow from ~10 MB to ~10GB. These unneeded binaries are slowing downloads considerably. I have found a tool/method for removing the binaries. Plan: My plan is t...
I am trying to create admin dashboard to track sales and inventory. Using React front end and Django rest backend API. Right now I am pulling sales and would like to make some charts. What's the practice here? Do I pull raw data then manipulate data in React? With some package? Do I manipulate in backend? Do I creati a...
I want to create my own little piece of hardware, (not sure what yet, but that's where the coding part comes in..) and I'm stuck at this little question. I have the parts, but not the means.
We are developing a system that runs a certain kind of simulation for our customers: Every simulation runs on it's own server. We typically have a two digit number of simulations running. A client can monitor multiple simulations. A simulation typically runs a few weeks. A new simulation requires manual deployment to...
I am writing a documentation for a programm where a function is defined and it is called three times. I call the definition of the function "function definition". But what is the correct term for the three executions of a function? I have read the term incarnation. However this name only appears, when the function is c...
I am wondering if it is good practice to name function which does the main logic "proceed" + "functionName". I would use that name if there are some checks(if-s, try-catches, etc.) in the beginning of the function and I would like to separate main logic into separate function. Example: private void function() { if...
REST APIs in virtually all languages use methods named Get to get GetById(int id). Is it ok to use this convention for repositories? Let's say I have a Professions repository for the sake of example. Is writing _professionsRepo.Get(profId)intuitive or would most programmers rather see _professionsRepo.GetById(profId) o...
First, the most obvious grouse someone has against this I can think of is the intricacies of an actual method. It's not enough to merely ensure no errors are thrown. Functions usually contain alternate paths borne of if/else constructs. For this, assume I use a declarative syntax that causes the generated/in-memory tes...
I know HATEOAS can be a bit of a heated topic. Some people like it, some people don't. That is not what I want to discuss. What I want to discuss is what technology other than HATEOAS (or some form of telling the client what can be done with an entity) can be used to prevent the client from writing the same logic that ...
I have some experience with WinForms and want to make a GUI for real-time plot of signals and also controlling hardware. I am planning to use WinForms for this and want to avoid WPF. My reasoning is that I don't need the outlook to be good looking but only functionality and performance. In WinForms I have written befor...
I have device interface classes written in c# for electronic variable loads. They are mostly for DC devices. We got a new one that does loading for both AC and DC devices. I also have an interface named IVaraibleLoad that lets me interact with them generically and group them if we are using several in parallel. From th...
Intro Hey, my question is kind of hard to explain so I apologize in advance. Question I'm trying to implement microservices for our ecommerce and I'm having issues on how to respond to a request when the actual logic and data needs to be determined by other ( 2-3 ) services. In order to make it easier to understand, I'...
Im in the process of creating a base class for typed HttpClient services (yes, I'm utilizing IHttpClientFactory). I wrote the process in such a way that for each CRUD method invoked from the service, the first thing said service does is check for and assign an access token to attach to the HttpClient header. Example: p...
I'm trying to implement microservice architecture to our application (basically an ecommerce) and one of the challenges that I can't really find a good answer for (despite being so many similar questions about) is how to: Create an entity in database Publish an event to event-bus at the same time (atomically, so basi...
I am trying to find the best way for a microservice to communicate with GraphQL Basic scenario: Client subscribed to GraphQL via Subscriptions (WebSockets) Client creates an Item using Mutation which will notify all the subscribed clients that the Item was created. There is a case when a Worker microservice would need...
I have experience building RBAC-based authorization mechanisms, and understand the theory behind ACLs (DAC?) though I've never had the need to implement them. A situation was just presented to me that I realize I have never thought about dealing with before, but absolutely should have. I believe OWASP refers to this pr...
Suppose I have an inventory management software that manages an inventory of phones of many subsidiaries of a company. A business requirement for this software is that you can't register a phone with the same IMEI (a serial number) as another. What I find difficult is where this duplicate check logic should be placed. ...
I can't find the exact tweet, but it was stated by Apple engineers that the retain and release operations are faster on Intel x86 translation than on standard Intel x86.
I have been developing a set of software drivers for the peripherals of a MCU. I need to implement those drivers in the C++ programming language. My idea was to model each driver by its own class. Interface of a driver for the Peripheral01: #include "HalCfg.h" class Periph01 { public: Periph01(HalCfg*); Periph...
I have written a small application using ASP.NET Core to create and manage collections of cards for a collectable card game. I currently have a version that successfully downloads bulk card data via API call, parses the JSON response, and loads it into local SQL Server database. I then use the local data to add the car...
I am an application developer and am building a token-based auth mechanism for my application. Essentially, the user will log in with username+password, if the credentials are valid, my code will generate a JWT (probably going with a 30-minute expiry, at least to start with). If they attempt to request authenticated re...
I'm currently reading through Structure and Interpretation of Computer Programs (SICP). During the course of that book, the lesson of "you can optimize recursive procedures by writing them as tail recursive" is drilled in to the reader again and again. In fact, I'm nearly 100 pages in and have yet to see a single for o...
I want to write algorithm that will find recommended friends for given user. I was wondering if K-nearest neighbors algorithm will work fine for that task? Firstly, I'm not sure if I understood this algorithm correctly, so please help me verify that. Lets assume I want to match people by interests and I have data that ...
I have been building a card game web app with firebase. Because firestore charges by number of reads/writes, I have only been updating the opponents of your plays when you place a card, so other players just see a card you moved pop into its new position -- one write, one read. I momentarily tested updating the other p...
I've tried everything related to filter and backdrop-filter, but nothing seems to work. I've searched online but not found a single article addressing this (which is odd). I simply want to set the background-color to be slightly darker than the current color, without knowing the color in advanced. That is, I do not wan...
This has puzzled and frustrated me for years: https://www.php.net/manual/en/class.dateinterval.php y Number of years. m Number of months. d Number of days. h Number of hours. i Number of minutes. s Number of seconds. f Number of microseconds, as a fraction of a second. Where are the ...
I'm working on an Editor-GUI (C#, WPF, Windows-Desktop) for a quite complex domain model. The domain model consists of many different node types mainly coupled in a hierarchie. Also it is possible to create links/references from one object to another (which can be 1:m). You could imagine it as a kind of syntax tree wit...
I was wondering whether there was a good established design pattern for sometimes allowing direct access from the presentation layer to one's repositories, but requiring the use of the BLL (because for certain data operations we want to impose business logic) for other methods. The reason for direct access to the repo...
I'm using event sourcing in an application and constantly find a problem for which I do not find a good solution. In this scenario we have an application for a hair stylist. We have a CustomerAggregate which performs all actions for a customer. But some times we need to find a range of specific customers, and for that ...
While going through the README file of a GitHub repository I am not a contributor of, I noticed a few minor typos and wondered if I should submit a pull request to correct them or if reviewing the request would take the maintainer too much time to be worth it. I considered the three courses of action: Correct the typo...
I have a class A and class B, both derive from the same parent class. Each object has a state machine inside it that defines it's behaviour. The behaviour is different though depending on if the object is of a class A or B. My approach to this is to differentiate what class an object is in the state machine and behave ...
I have a grid of squares, let's say 12x12. I want to split this grid into equal sections of 8 squares, which is 18 total sections. There is no requirement for sections being convex or compact, and the less uniform the better. First attempt I pick a square to start a section. First the corners, then the edges, then th...
I mainly use Python and just started learning Java. For now, I've tried using try/catch for basic file read/write as follows public String[] readFile(String fileName){ try{ // read file } catch(Exception e) { System.out.println(e); return ""; } } Is such try/catch usage good practice in Java?
Our POST API takes in an identifier (let's say deviceId) in order to compute the accuracy of the location we have stored for that device in a DB; the result of that compution is then saved in a different table. On a successful call, we return the result with a 200 code. We call a dependent service, including the device...
I'm starting the refactoring of a legacy app in favor of having a more organized structure, I chose to go with hexagonal architecture since I have lots of well-defined ports and adapters, my use cases are clear as well as the domain. One of the things I found in this legacy is the usage of lombok almost everywhere, whe...
I'm trying to design my application in line with the "onion architecture" principles, and have something like the following: HospitalController (depends on IHospitalService) \ --- HospitalService : IHospitalService (depends on IMedicalRepository) \ --- SqlMedicalRepository : IMedicalRepository My IMedi...