instruction
stringlengths
34
36.1k
I have 2 endpoints: enpoint A can only be called if endpoint B has been called before at least once. After endpoint B has been called, endpoint A can be called multiple times. endpoint B can be called multiple times without problems. Endpoint B loads certain data that must be present in the system, before we import a...
I am designing an application that works with REST API requests for dealing with information stored in a database. The user will add, edit, delete information in this client and after SAVE the information will be rolled out to the server (database) with the corresponding API request (GET, POST, PUT, DELETE) Now I have ...
Where I work, we have some integration tests which spin up a new SQL database instance in Docker, so that we can test the repository logic for write actions as well as read actions. We have a test for the "Create" method, which returns the ID of the newly created resource. Should my test assert just be that the ID of t...
In my application I'm dealing with periods. A period is defined by it's end date. A period may shrink or grow, can restart and can have a priority. This is modeled using the following struct: public struct Period { public DateTime EndDate { get; set; } public bool CanShrink { get; set; } public bool CanGrow...
I'm currently working on a farming IoT system and confused about the architecture so I wanted to get your views. I'm using a relational DB (PosgreSQL). I have multiple customers, each customer has one or more farmhouse and each farmhouse has one or more field. I have IoT devices on each field, from a few to 200 hundred...
I was asked this question in an interview of Crypto company for the role of backend developer. Please suggest me another stack-site if this is not the place to ask this question. There is a subsystem A which sends the data to another subsystem B as a file in.txt. Subsystem B then processes this file and produces an out...
In the text book software engineering by Sommerville , there is an example where he uses it to illustrate the famous type of software architecture "Client-Server Architecture", here it is : "a Client server model for a multi user, web based system for providing a film and photograph library. In this system, several se...
The result of processing an HTTP request consists of mappings. Each mapping is from an order number to an object. Is it a good practice to return this as an HTTP response whose body is a Map<String, Object>? How about a List where the object contains the order number string as an attribute. If none of these is a good p...
In one of the company's im involved with there is a problem between one manager and a programmer. They are both very good at their jobs, but there is constant clashes. I would like to get some feedback to help me sort this out. I did some research on the topic, including using my account at https://www.oreilly.com/ but...
Here is a very basic example to illustrate my point class SomeClass { publicMethod1(param1, param2) { if (param1 === "some value") { // do stuff } else { // do stuff } this.privateMethod(true); } publicMethod2(param1, param2, param3, param4) { ...
I was under the impression that Filebeat is only necessary if I wish to provide a constant, paced, fresh input to logstash. But the tutorial here starts with configuring Filebeat to send log lines to logstash.... I am confused. I am a total newbie rookie to ELK and I don't understand why Filebeat is needed if I used th...
Say I have a website/platform that allows people to submit business names in order to build a high quality business name database. You can apply this to any subject or topic, such as building a database of travel destinations, of movie titles, of quotes, etc. One of the main problems is how to guarantee accuracy and qu...
Lets say I have the following code in my GamePanel class: public GamePanel(Menu menu){ this.addMouseListener(new PlanterListener(this)) PlanterListener class: public PlanterListener(GamePanel game){ this.game=game; this.plantActive=game.getPboard().getPlantActive(); this.stage=game.getStage(); ...
Suppose someone designs an indexable iterator class, i.e. an iterator that supports __getitem__ for (non-negative) integer indexes such as the following: In [1] it = indexed_iter("abcdefghij") In [2]: next(it) Out[2]: 'a' In [3]: next(it) Out[3]: 'b' In [4]: it[1] Out[4]: ??? In [5]: it[2] Out[5]: ??? In [6]: next...
This is a bit of an invented example but I think it best illustrates my question: Say I'm creating a chess replay event API. Say I have a lot of different "events" I want to keep track of, in a specified order. Here might be some examples: A move event — this contains the previous and new square. A timer event — this...
For sure, there is a well-known topic here on SE, however, it is almost 10 years old, and answers that were excellent by then, might be obsolete now and there could be modern easier ways (but I don't claim of that, just ask) . Does anyone know, if during last 10 years, there was any significant advance, so we could hav...
I want to lead an Angular + NodeJS project. As this is my first experience, I thought about using UML diagram as both designing/architecting the project and also the project's documentation. But I am not sure if using UML diagrams is a good idea? I mean it takes longer time and many details that I don't know if is it n...
I have a class that looks something like this: class Entity { public string Id { get; set; } public List<Entity> Children { get; set; } public void DoStuff(Data data) { // stuff foreach (var child in Children) { child.DoStuff(data); } } } An...
We just started a small startup company with 4-5 guys and since now we were working by talking to each other about the requirements and maybe some hand drawn sketches about the front end of the project and how it would be look like. But we decided to extend our company and hire more frontend + backend developers and mo...
01 - BACKGROUND: I'm a typical non-programmer R user for 6+ years. Which means: i) I`m comfortable with the language most of the time and have written R packages for myself, but ii) writing C++ code (Rcpp) is not something I've done iii) R is fast enough for my purposes and data size 02 - PROBLEM STATEMENT: Few months ...
I have a data which is a std::vector of a "small collection" of items of a given type struct Bunny {};. I was vague about "small collection" because for now it's a collection of two of them, and so I'm just using the following alias using Bunnies = std::array<Bunny,2>; // probably it'd be better to make it a struct, so...
You're writing the code for an API that accepts payloads from users and, before performing the actual write/update/delete in the db must validate the input for consistency and this is done by consulting various backend services. The client basically waits for an "accepted" or "rejected" response. Obviously, you don't w...
I'm very new to writing immutable code. Would there be any fundamental issues trying to transpile arbitrary mutable code person.age = 20 into immutable code person = { ...person, age: 21 }? I am aware that it would change equality, such that "oldReferenceToPerson != newReferenceToPerson" after a change. EDIT: A comment...
All the examples across the internet try to pretend that every application is run on a single thread. There is no problem with synchronization, multithreading etc. Uncle Bob, in his "Clean Architecture" book mentions the topic but very briefly and suggests to postpone some decision as long as possible. But real applica...
I'm trying to implement a solution that stores every product from a shop, and then allows me to search them either by ID (an integer index), description (string) or barcode (string). The idea I came up with is to have a sorted list with products ID as keys and Product objects as value, this would allow me to search qui...
What's a good way of storing and referencing files of different types (csv, pdf, jpg, html), each of which needs my own custom metadata? The metadata stores details of the content and how it was created. Ideally I could add metadata to the file itself, for CSV that's going to be #comments. PDF similarly supports it's o...
I've got basic proficiency in PHP, JavaScript, html, and SQL. I also use Postman little a bit. I hope a solution to my problem can be found within those skills, but I'm willing to learn a new language if necessary. Using PHP, I've written myself a page of admin tools to be able to run my business. One feature I'd like,...
I have a set of algorithms to choose from based on their execution speed. I know that it is very hard to get an accurate measurement due to the process scheduling, the time that is actually consumed to get the measurement ... etc. I was wondering if a microcontroller ( like arduino uno) can provide better accuracy comp...
I have an n x n matrix which I need to convert into a list sorted by value. Starting with the maximum value cell at (row x1, col y1), I must immediately exclude all cells where (x >= x1, y <= y1) or (x <= x1, y >= y1). There are n x n cells, and each of them is getting compared to (n - x1) * y1 + x * (n - y1) cells. Th...
This is a question I have always wondered Is it as simple as repetitive pinging of a server in a seperate thread or is it more complicated than that? I am only talking about the app version not the browser as it is obvious that browsers have direct access to a servers database
I'm trying to understand the motivation of these two patterns. I think the listener pattern is just a pub-sub, and the use case is mainly in a distributed manner, for example, the AWS SNS is just a distributed implementation of this pattern. The whiteboard pattern is just a special case for listener pattern where it is...
Suppose I have two "modules", A, and B (I'm choosing not to use classes, because you generally can't create an instance of a module, which makes this question simpler). These modules contain methods suited for dealing with the same particular type of (arbitrary) data. Crucially, the representation/format of this data i...
I've a data streaming platform (Nifi) where I need to transfer tables of data between databases on given schedules. I want to be able to calculate in advance the optimum batch/schedule size i should use. Assume I've three databases with different number of tables, each with a specific row count and row size. The schedu...
Say I have a library function that expects a JSON-encoded object and does some things with it: function foo(bar) { const baz = JSON.parse(bar); doTheThing(baz); doTheOtherThing(baz.qux); } Now I encounter an object that is not already JSON-encoded but I want to do the same things with it. Since I don't wa...
In pseudo code: given numbers x and y, if x is greater than zero, subtract the magnitude of y from x, otherwise add the magnitude of y to x. It's ok if x goes from being positive to negative or vice versa. In python I've been doing this like so def shift_func(x: int, y: int) -> int: function = "__sub__" if x <= ...
I am trying to make an animation system that affects different types so I thought I would use generics. I have an animation controller that gets all animation objects into a collection (or at least that was the plan) then then run the animation on all the animation objects. The problem is I can't do it this way in C# a...
Intro I'm creating an app and I'm not sure if the structure of the solution is correct. I have a BaseController that uses generics. This controller is inherited by others that do not have to reimplement the code and just add functionality. The BaseController uses an IRepositoryService that has common logic to interact ...
I'm writing in C++, but this problem applies to most non-high-level languages, and possibly some high-level ones as well. I have a graph of heterogeneous nodes. The graph can be instantiated by different subsystems (e.g. it can be read from a file or generated by one out of many algorithms). I have several algorithms t...
In my Domain, I have numerous objects that are expressed by Identity alone. Specifically, several of my Subdomains exist only to represent something that has been created. For example, in a video game with combat, I have a Weapon concept. Each Weapon is Unique. A Weapon(bronze_sword) is different than a Weapon(steel_da...
So far, I've been using logging only in main() mostly. I do not log anything in my functions or classes but sometimes I feel like it would be helpful. What I would do now: def init_logger(): # set up logging to file logging.basicConfig(filename=LOG, format='%(asctime)s - %(name)s - %(leveln...
Recently I'm studying Saga pattern, but I'm struggling to imagine how it will work in real system. Standard example is making an order, which consist of reserving flight, hotel and a car. We can assume that we have following services: ordering service flights booking service hotels booking service cars booking service...
In an engineering company, there are many engineers that edit in Excel/VBA Spreadsheets to perform some engineering calculations.They all do more or less similar things: calculate, manage engineering stability, buildings, infrastructure etc.. They perform calculations based on data and formulas. Or draw a picture of un...
wanted to know if this is possible. Consider we have Branch A that is in a PR waiting to be merged. On a local branch, I pull the changes made in branch A and now they exist in my branch B. I continue to do work on branch B and now I'm ready to push. Q1: If I create a PR of branch B into Branch A, will this be reflect...
I have the following constructor in a class for a code I'm writing an assignment on for school: public Plant(int xPos, int yPos,int width,int height, int hp,String imageLocation,String audioLocation,Stage stage) The only parameter I find valuable to show in the UML diagram I'm creating is Stage. Could the other parame...
I have developed a Fantasy Draft system utilizing ASP.NET Core SignalR, along with Azure's SignalR service (for backplane/scaling stuff). Last year I utilized a poor-mans' javascript version that just polled the database every 5 seconds to check for new "picks" in the draft, or any changes that may have happened in the...
I need some advice on an IOT project I am working on. Here are some details about what I am trying to do: Use Case: Periodically receive data from the 3rd party vendor API in real time and allow users to set alerts when certain conditions are met in their data. Simple example: Send me an alert when temperature goes bel...
As an exercise in code architecture, I was writing a C++ wrapper for a window library called GLFW3. In this library, when a window's X button is pressed, you can register a callback that reacts to such event. The callback needs to look like this: void callback_name(GLFWwindow* handle); That is, it needs to be a pointe...
I'm working on a domain where we keep track of food that is stored on various locations, like the fridge or the cellar. While implementing the domain, I was wondering what the best name would be for the domain class that represents such a storage location. Until now, I've used the name StorageUnit or StorageLocation, b...
I need to document my design, in particular, the design patterns used, and would like to use the standard terminology. From Refactoring Guru, "Factory Method defines a method, which should be used for creating objects instead of direct constructor call. Subclasses can override this method to change the class of objects...
Basically, in our scenario, data has to be sent from a WordPress form to Dynamics 365. My current approach is putting it into an email body in JSON format, that is then extracted and further processed by Power Automate flow. ("Power Automate" is Microsoft's "low code" / "no code" product) Everything is working fine but...
I am cruising through a situation where I am my own backend and fronend developer. Let's say I have a basic backend API with some call /register/{area}. The {area} piece is dynamic and can change. Now I have a nice frontend application in angular that provides a selection of various area entries, Let's say they can be ...
I am trying to start using GitHub flow in my project. I like that it is simple and, more importantly, it encourages continuous delivery. However, there is one thing about this flow that I cannot understand: how do I test my changes? The 5th step of the official guide says: Once your pull request has been reviewed and ...
I'm developing a package for Laravel & Lumen in the same code base, but I encountered some problems. Well, in the beginning, I thought it could have the same code and work for both frameworks, however it had! But on the way of development it turned out; it didn’t work and I had to separate code into two branches. As yo...
I have been reading about system design and was going through this popular article - A Word on Scalability The author here says: An always-on service is said to be scalable if adding resources to facilitate redundancy does not result in a loss of performance. and then again: It requires applications and platforms to...
Context: I'm working on an embedded system with many small functional modules. The business logic within each module is made as simple as possible, but those modules generally need to gather bits of information from other places within the system to do their work. So far, to support unit testing and generally break de...
I am intending to come from the perspective of development choices, code reviews, and general testing against defined environments (Development, Test, Production, etc.). I will be using C# as the primary coding reference. What I am looking for: Is there anything with the following code change that could have been reco...
My question may sound very naïve to someone, but it is what it is. I have below scenario: Relational MySQL Database with BIGINT primary keys and foreign keys Spring boot as a backend (technology doesn't matter here) Angular as a frontend (again technology doesn't matter) This system is a large system and there are ma...
I need to write an algorithm to allocate x number of tasks to 2 processors per day. I know the following: Exact amount of time it will take to complete each task The exact amount of time available for each processor for the day I need to try and use the exact number of resources every day, or have as little extra pro...
When I want to execute some code under the condition that a variable has one of two (or more) values I can use the OR operator: if (var == x || var == y) { DoSomething(); } But I'm not sure whether I should do this directly, when var is a getXY() function, that might even include some expensive checks: // Is this ...
I have the following code public class MyCollection<T> { public void Add(T obj) { ... } public int Count { get; } } and the following unit test to check whether Add increases the Count property by one: [Fact] public void Add_ShouldIncreaseCount() { var collection = new MyCollection<int>(); var oldCoun...
Let’s say I have three files, all of which import a fairly large module. But I’ve divided them because they have different functions. Now each of the JavaScript files needs an initial statement like const a = require('./') Is this considered bad practice?
At the moment my code looks like this. I have simplified the UML so it does not contain unnecessary information. I have used abstract factory design pattern. My job is to create shapes. The problem is that these shapes are really complex to create. ShapeFactory has to know multiple different values to be able to creat...
I want to have a Python application - complete in itself - that allows the user to extend it via scripting (or a plugin model) in Python. But I want the script/plugin to have an isolated environment (within the same process) to run in. How do I do this? For concreteness - the app performs dynamic geometry visualizat...
I'm trying to write a new API that can support many devices. There will be at least 50k devices in the beginning that will connect to the server using an HTTP API on a daily basis to receive updates. The number of devices increases with time (with new installations). The devices need to contact the server once per day ...
I must store prices for various items on multiple dates. The table schema would look like this: CREATE TABLE date_wise_price ( item_code varchar, date date, price numeric(19,4) ) An alternate table schema for this could be to store prices date range-wise, which results in a smaller number of records stored...
I'm writing in C++, but this problem could apply to any other language. This post is a continuation of this question (I thought the question is different enough to fit a new post better. If I'm wrong, I'm happy to edit the old one). I have a graph of heterogeneous nodes. All the nodes derive from a base Node class that...
i am a lawyer and currently writing an essay about data access in ioT environments. I often stumble over the distinction between read access and write access. Could someone provide me with an example, preferably in an ioT, mobile app oder plattform context. (a little context for those who are interested: My argument is...
I have a given set S of strings, and a length l, and I am looking for the number of strings of length l that contains every string of S. A naive approach would be to generate every string of length l (I have a given alphabet), and for each check whether it contains every string of S. However, this is clearly very ineff...
TLDR How do you keep track of which version of which microservice is deployed in which environment? In Details Say your company has dozens of Microservices and 5 different environments (Dev, QA, Prod, ... ). Deployments of services are partially automatic and partially manually, depends on the different environments an...
I've recently joined a firm, where we are working with Progress 4GL from OpenEdge, release 11.6. As I have quite some experience in other programming environment, I'm really surprised by the extremely old-fashioned tools and technology (I started working with Delphi 4 in 1998, and this was already more modern than the ...
What's the difference between writing OO code that depends on internal state and writing a pure function that expects an argument that is a data structure of a specific type (and thus has internal data that could be different)? So function f(x) where x is a complex object that may be { foo: 'bar', biz: 'blah' } but wil...
I'm considering building a feature in a customer service application that allows users to build their own chatbots and use them to respond to customer input. I've worked with Dialogflow in the past, and I know how to build and leverage a single agent, but I want to know if it's possible to use Dialogflow in a feature t...
We have a REST API Get request which downloads a file from the server. This file needs to be updated whenever there is a latest version. Currently this is done by deleting the existing file and moving the latest file as new one. As the file is being held due to high traffic nature of service, deletion of file is not ha...
I'd like to start by saying that I'm new to DDD and I'm creating a hobby system to practice some concepts, so this question might be trivial, but not so much for me. I have the following scenario: I have a given user that should be able to add exercise to the system, so I have two models User and Exercise, and I have a...
Let's say I have a REST api endpoint that is getting a resource called a "purchasable" (an item that a user can purchase). Here is an example of what this might look like. Endpoint: GET /purchasables/253 Responds with: { "id": "253", "name": "T shirt", "price": 1234, "discounts": [ .... ] } ...
Take a simple example: string1 = "" string2 = "foo" string1 is empty or null, which is clear. But what about string2? I wouldn't call it "full". "Non-empty" or "non-null" works, but is there not a single word that unambiguously captures the meaning of "not empty" in the context of a string?
What are internal and external polymorphism? I understand what static and dynamic polymorphism means. How does static and dynamic polymorphism relate to internal and external polymorphism? These terms come up in one of the Robert C. Martins Clean code videos when he talks about design patterns and says "Template method...
I have a class class A { List<int> a; A() { this.a = []; } void add(int x) { a.append(x) } List<int> display() { return a; } } This is a simple class I want to write in a TDD approach. my question is how do you write the test for the display() since the add() need to be called to make the te...
Recently, I've been studying Clean Architecture and I have some doubts. I want to make a REST API that adheres to this architecture. To do that, I define my entities, use-cases, etc. For each endpoint, I use a different controller that calls for a use-case. My problem is that for all examples of controllers that I have...
This problem arises in the context of a web application. When we send a request from front-end to back-end, we must map the data, e.g. in post request: { something : this.something } When we receive it, we must map it to a .new() method like some_class.new(something = input['something']) Also, someone must make the .n...
I have a new site that allows you to play sounds of letters on click. Each letter produces a separate sound. I went from roughly 500kb for .wav files to around 30kb for each sound file. That's a lot to load for each sound (200 sounds so far). Can we optimize this for mobile browsers? Should I combine all sounds into a ...
I'm planning to extend an application with logging of user events. (Client application via REST-API to Symfony). What is the preferred type of databases? Currently the log data is stored in a relational database along with the rest of the data. Click events are to be stored as well. I suspect that a relational database...
In Clean Architecture, a use-case calls a presenter, based on the agreed output object. When the presenter is called, it returns a ViewModel used by the view. That is fine until you have more than two views: a CLI and a Web, for instance. If you have these two views, you need two different presenters too. But the use c...
My company is about to onboard some junior devs for the first time, and we want to limit their access to just the presentation layer. As it stands, everything is in one Git repo. The current plan is to fork the main repo, and modify it such that only presentation layer and the compiled assembles will be left. The new d...
I was watching a lecture by Bjarne Stroustrup from 2014, on "The Essence of C++". About halfway through he rather forcefully recommends not using new, delete, or pointers for class member data, but rather delegating that work entirely to container objects (i.e., from the STL) whenever possible. For example, he shows th...
A few years ago, I wrote an application that allowed users to upload a file (it's a very specific file type) to a server. It then sends instructions to the server on how to visualise the data, and the server presents the data as either a dot plot graph, or a histogram graph. The PNG is constructed on the server side, a...
I read a lot about DDD but few thing are still unclear. At this moment I have two dilemma The size of aggregates. How small could be an aggregate? For example we have: class Car { String colorId (or String colorCode) ...other fields } class Color { String code } I think in this case Color should b...
We have developed an algorithm that processes some data at runtime and is slight efficient in terms of time and computing compared with other solutions out there. Though we sure anyone can develop a similar algorithm, for now at least we have good results for the same. We will be deploying that algorithm as an SDK/libr...
I am given a binary string binary consisting of only 0's or 1's. There are two allowed operations (can be re-used any number of times): Operation 1: If the number contains the substring "00", can replace it with "10". For example, "00010" -> "10010" Operation 2: If the number contains the substring "10", can replace it...
I ran into an issue when developing where a user that did not exist, but had a correctly signed JWT, was logged in. This happened when I absentmindedly logged in using a browser while running the test server. Because I used the same makeshift credentials for the user in both databases, the login succeeded. I then switc...
In most contexts, the concept of "interpolation" seems to be related to estimating unknown states from known ones, like video frames or data points. From the Wikipedia entry on interpolation: In the mathematical field of numerical analysis, interpolation is a type of estimation, a method of constructing new data point...
Out of the 5 SOLID principles, I find LSP to be the most confusing one. The most popular description of this principle is simply "A subclass must be replaceable with it's base class without breaking the program". So if I have a base class Bird, with the method eat(), and a subclass FlyingBird with the method fly() And...
I am planning a project which has users collaboratively editing a document. To provide good latency to users, I am planning to deploy in multiple AWS regions with active-active mongodb replicas with geoproximity based routing policy in AWS Route53. This plan conflicts with another requirement where users in a region (s...
I don't think one can achieve full decoupling with micro-services. We might have a Microservice architecture in which they are fully dependent on each other. Example I have 2 services: an order service and an account service. My order service process order placements, dispatch and shipping. And my account service conta...
Background: You think the halting problem is silly. Let's solve it. Your solution? You create a program compiler which will always terminate compiled programs in an arbitrary, finite, determinate amount of time t. If the number of clock cylces/second cannot be counted on the system, then the program exits without doing...
I have gone through multiple posts but am unable to find an answer to my very basic question on classes and so asking it here, it would be great if someone could shed some light on this topic- I have a twofold question which is generic to any OOP language- 1)When a class is instantiated what are the exact steps that ta...
Let me explain what I mean there is a logical flow runs over various event notifications based on our web app, which is event-driven and it is quite common in my opinion. User clicks a button to trigger some action and a web request. The event handler here is bound to some UI action. Web app updates UI based on the re...
I've seen some topics around DaaS on the web. Some of them state that DaaS stands for Desktop as a Service, which basically is the offering of virtual desktops. In the other hand, some topics state that DaaS stands for Data as a Service, which basically means the offering of a cloud to deliver data integration, data an...
At my uni the software design teachers like to ask questions about UML diagrams, such as this: In the following class diagram, can class Bar’s bar() operation modify Bar’s b attribute? Can it modify class Foo’s a attribute? Now as far as I know, static operations may only modify a class’s static attributes. Bar’s b ...
So, in terms of systems design: given a highly scalable system being served through a single load-balanced anycast IP address, when that system receives a load in the order of (hundreds of) millions of requests per second, then how should the load balancing be designed to reliably distribute such load? Elaboration: I...