instruction
stringlengths
34
36.1k
Suppose I have file a.txt, b.txt and c.txt: a.txt: Hello, I like cake. b.txt: Hello, I like turtles. c.txt: go away, I don't like you I suspect the difference between a.txt and b.txt is quantifiable. For example, one could say that characters 15-18 are deleted, and the string turtles is inserted. Now, I would like t...
In a microservice architecture, it is common for an API Gateway to perform API Composition (providing CQRS is not used) for queries to multiple services to combine data to make it ready for a front end client. There are options for non-query distributed calls though, one of which would be to call one of the services fr...
New Web Dev here. Recently I got into DOM manipulation with JS, everything was sweet with one-page websites, but then I tried with projects with many html files and that's when I got confused. It's a static website, each page has different elements so my first thought was "Ok so, one JS file per page, right?" And I thi...
I have a table in an SQL database for storing information about some business object that looks something like this (details changed so as not to give away what company I work for): CREATE TABLE product ( id SERIAL PRIMARY KEY, name TEXT NOT NULL, price MONEY NOT NULL, ... -- Some other stuff ); This ...
Let's say I'm making a library database with books and authors, and I want to model the domain with interfaces, should I also specify the relations in the interfaces? For example, if I have the following interfaces: public interface IAuthor { public string Name { get; } } public interface IBook { public string ...
TLDR; How can I utilize Firebase Auth in my iOS application and sync the Firebase ID with a user in my API? I am in the process of designing an iOS application that reads from a Rails API. When first coming up with the design, I wanted to use a pre-baked auth system so that I didn't have to design my own. Firebase prov...
I am currently developing an iOS application where there are options on the screen to edit and delete a list. Only the user who created this list can edit or delete it. I am struggling to determine the best practice for hiding these options if the list does not belong to the individual that created it. Please keep in m...
I was reading about composition over inheritance and came across a question about solving the Circle-Ellipse Problem in Object-Oriented Programming. This kind of problem is often used as an example of the limitations of OOP. I am from a C++ and Java, therefore heavily OOP, background, but I have struggled with trying t...
According to the MDN the http protocol has the 402 status code: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses And is used for methods that require payment. Also RFC 2616 states: This code is reserved for future use. In my case I want to perform an api for doctor appointment system th...
Just curious on how to better explain this with the right terminology. For instance in React, this would kind of be like breaking down a large component into multiple smaller components. But that is specific to React. Is there a software engineering term for just separating out code into separate files? Like having a f...
I need some help with design logic, illustrated by an example. My question below. public class ChangeSet { } public class NodeChangeSet : ChangeSet { } public abstract class Base { protected abstract Action<ChangeSet> Do { get; } } public class Node:Base { private void doIt(NodeChangeSet change) { } protect...
I am dealing with an old .net code base which has a PrivilegeChecker static class with hundreds of static methods, each of which takes in some user id and some other params, and then fetches some info from db to determine whether the provided user has the privilege to do the thing. If not, then it throws an exception. ...
Suppose I have the following struct: struct Dimension { void setDimension(Vector2i dim); Vector2i getDimension() const; bool canShowInformation(); } And this struct uses the Dimension struct: struct ApplicationState { Dimension dim; State currentState; //Delegate everything to Dimension struct...
I noticed that my Member initializer list is not really readable. My main.cpp files looks like this: #include "Application.hpp" using Pathfinding::Core::Application; int main() { Application app; app.run(); return 0; } Constructor of Application class looks like this: Application::Application() ...
An app has a feature that's much like any calendar application (like the Outlook calendar for example). Consequently, I need to do a lot of date logic. I wrote a class with date calculation methods that are useful in any scenario. You can choose in what resolution of time you want to view the calendar, like a whole mo...
I am filled with questions pertaining to the situations where a desktop-application hangs, possibly for minutes. I've got this complicated game-engine written in c++. Several times during development, I've accidentally found an infinite loop during testing and the program causes the entire system to hang, usually for a...
Looking at sharding techniques, you basically have hash-based or range-based versions. Hash based is more random, range-based is more heuristic based. Say you initially have 2 shards (separate database instances), then you outgrow it and would require 3 shards. What do you do, now your hash stuff won't work anymore, yo...
Scenario : For some (comment) text field the server application is internally throwing errors when the field contains contains some specific characters. Where should the removal of characters be implemented? in the client application or server? I have tried to look at my old system engineering text book for a similar s...
I am new to UI development and am currently reading how to style a form in a responsive way. By googling I found this tutorial https://www.w3schools.com/howto/howto_css_responsive_form.asp (I know the reputation of w3schools isn't good but that was the only search result actually addressing my question). Code from the ...
So, in the hexagonal architecture layer, the application layer has incoming ports (use cases) that are called from incoming adapters, implemented by services, that use outcoming ports that are implemented by outgoing adapters. Is it really different than the layered architecture? Other than calling outcoming adapters a...
I'm working to create a library in python that myself and a few colleagues will use. I'm struggling to conceptually understand how to best organize some code that feels like it doesn't cleanly fit into a class. None my ideas seem all that clean. Right now I have several functions that all take the same input and they a...
For a localized service or application, whenever one is checking in code with new strings, it implies that localization for those strings is needed. Now, I need to ensure that there are no unlocalized strings in the code OR how can I easily find out which strings are not localized. Here are some thoughts on my question...
So for my Masterthesis i have to decompose a set of monolithic industrial applications into microservices. The aim is to decompose the monoliths in to services that are as much reusable as possible. I have not found any research that tackles this Problem. Can someone guide me in the right direction on how to solve this...
We have a lot of business logic in Excel files and we would like them to integrate in a web application (a Node.js web application). We don't want to rebuild the logic in a programming language. Instead, we would like to insert data into the Excel files we have, and read the calculation results from the same Excel file...
Can the file format gif be extended to support audio as well? I was looking into gifs that support audio and the main gif sites with "audio gifs" are just looping videos. The problem is how memory inefficient videos are. Would it be possible to extend the gif file format to also support videos? Are there any good resou...
I want to run a batch process, processing all the media I'm storing behind a CDN, on S3. I could access S3 directly with my servers S3 credentials, or go via my CDN, thoughts? Using the CDN would be faster, right? But would is the CDN only supposed to be used by external users?
I've been trying to understand when to mock and when not to mock, however I'm not able to come up with a consistent guideline and I'm hoping to get some input on the subject. Let's look at the following toy example: class ServiceMixer: def __init__(...): self._expensive_rpc_service = ExpensiveRPCService(...) ...
I need to implement RBAC in a project I'm working on, and I'm fairly new to the concept. I am trying to figure out the best way to implement it. The most common approach seems to be to create roles and permissions and link them together through the code, I have explored a couple of libraries to do it such as CASL and a...
Let's suppose that I have a model named Collection. I can create a collection, this collection have two important fields: shared_with_company, shared_list. currently I have an endpoint: /collections and this endpoint returns something like it: { shared_with_company:{collections: ..., count: 5} shared_...
I have a function with a sensitive operation: function doSomeThingSensitive() { customers = getAllCustomers() for each customer in customers if customer is from Europe Give them a 1000 euro giveaway coupon } I want to dry run this function in order to calculate how many sensitive operations...
In a class diagram, how do I know what methods to add? I’m not sure what the connection is between methods and other (i.e. Activity and User Case) diagrams. My guess is that methods can come from Sequence Diagrams, but then I’m not sure how sequence diagrams relate to the Activity and User Case diagrams. I’m trying to ...
We follow git flow, see https://nvie.com/posts/a-successful-git-branching-model/ Lets imagine the following situation: We have a current version 2.0.8 on our prod environment. After a while, several bugs appearing that need to be fixed (no hotfixes, because they are not critical but more urgent than new features). But ...
In his book "Implementing Domain-Driven Design" Vaughn Vernon suggests to reference aggregate roots only by ID. I see the following advantages of this approach: It is clear where the consistency boundary, so the aggregate root, ends Accidential modifications of related objects can not happen You're not running so easi...
I come from a background in ASP.NET MVC 5 on .NET 4.8. I've been trying to wrap my head around the new razor pages, and can't seem to get routing to work, or understand it, even. I don't want to use the @page directive, because I want more flexibility over how things are routed. (I've also found it doesn't even work as...
There is a saying about the most challenging aspects of software development is "Cache invalidation and naming things". This question is about the former of the two. Though the nature of the problem seems something that should be common, I did not find much reading on google. I'm working on an editor for production pla...
I have a search function. This function takes 4 different parameters that can be either a list of strings or a string. For each parameter, if it's a string I convert it to a list of strings. def search(name: Union[str, List[str], group: Union[str, List[str], ...): if isinstance(name, str): name = [name] ...
I know this question might sound stupid to many, but - in terms of rigorous IEEE definitions - can we say that GitHub allows some kind of Software Life Cycle or some management paradigm in particular? For example, can the Issues section look Agile somehow? Or how would you define its structure in terms of Software Engi...
I want to know the best Practice is about having multiple dto’s for different use cases. Let’s say we have an api with a set of controllers to handle requests coming from a administration backend and another set of controllers used for an mobile app. Behind the controllers we are running an onion architecture with medi...
New to writing REST APIs. Had a question about versioning. Let's say that we have a service with the following methods: Search <- Given some data, it will perform a search Billing <- Given a time-range, it will provide usage information on the Search API. EnhanceIndex <- Client can send data to increase the search ind...
I have a big function that does several things, including some database operations, and calling another smaller function. Something like: BigFunction() { DB.SomeTable.AddRow(newRow); SmallFunction(); DB.OtherTable.AddRow(otherRow); } SmallFunction(); { DB.SmallTable.AddRow(smallRow); } Small...
I use java and I have structure with a class that contains id, title and perhaps some children of the same class. So I decided to use the composite pattern. I need to have a method getChildren() that gives me subtree from the whole. I can not put this method in my interface because it is specific to the aggregator cla...
I'm working on a project that does things depend on how much time has elapsed. Specifically for testing purposes, I need to call a method twice a second. The basic idea of the test is something like this: Class c; // Call the do_something() method 2x/second for 5 seconds for( int num_second = 0; num_second < 5; num_...
This is my specific situation: I am following DDD and Event sourcing to implement my application (using C#). I have a Domain layer that contains Aggregates' implementation. I write unit tests for this layer to cover my business logic. Consider Employee aggregate that contains a field which is named PartyId. I have a sp...
We are a mid sized moving and shipping company that is transitioning our custom applications to microservices. Our business was originally based on shipping, but we found some niche areas in moving/relocation of employees and groups of employees (offices/companies). There were also a few acquisitions over the past de...
I frequently encounter recommendations to specifically keep to ASCII characters in field and function names in documentation, even though non-ASCII (modern Unicode) generally works perfectly. An example is the recent Python 3.10 documentation. I've been a bad boy in the past and have successfully used non-ASCII charact...
I'm currently designing a DDD system, and it is a reference implementation. The reference is a big ball of mud. I'm finding myself spending a fair amount of time determining aggregate roots and the relationships to other aggregates. Have you ever tried making everything an aggregate root and then refactoring to small a...
in the clear architecture, what uncle bob suggested. I have a lot of questions about how to correctly distribute the responsibility. it seems that there is no relationship between controller and presenter. the controller's job is to take the input and trigger the use case and the presenter's job is to take the output ...
So I have this distributed game im working on(for some time now). A part of the world is considered a Chunk object. This object is composed of many other objects/components that are necessary and a part of the Chunk. In order the clear up the Chunk object which has the responsibility of a smaller area of an infinite wo...
I have searched on the Internet on how do operating systems have different window layouts, but I have found nothing. Windows has one style, Mac OS has another, and Linux has a different style as well. How are they able to have a different layout for the window. Below are two examples of window layouts. They are able to...
I'm learning databases and I'm designing an ERD based on simple banking processes. I'm not sure if my design of the entity relationship diagram is correct. Thought Process A customer can open 1 : N accounts, and n accounts can be opened by a single customer N : 1. A bank can offer a customer n loans, and a loan can be...
I want to calculate how many sprints I have between two dates, for example : April 1,2020 and June 4,2020. The number of weeks between the two dates is : 9 weeks and 1 day. My Sprints are 2 weeks long. Does this mean there are 4½ sprints between those 2 dates ? I'd really appreciate your help, thank you!
Consider application where users rates products (e.g. 1-5 stars). Through passage of time, there might be millions of records. One can create desired indexes and/or keep sum and count of all ratings to easily get overall average score of particular product or seller. The problem I am trying to tackle is how to efficien...
It's very common to see this use of repository in projects using clean architecture: interface Hero { } interface HeroRepository { findById(id: number): Hero; } class FetchHeroUseCase { constructor(private heroRepository: HeroRepository) { } execute(id: number) { return this.heroRepository....
I am building an Angular web application with a RESTful backend. I plan on using semantic versioning to differentiate between different releases. I've already read a bit about how to implement semantic versioning for web applications but I'm still not sure whether I should use two separate semantic versions, one for th...
Goal Allow single web service instance to serve different tenants on a per request basis. Design In order to allow a single web service instance to handle requests for multiple tenants there exists a tenant context service which maps a JWT to database credentials (simplified for the purpose of this question). These cr...
At our company, we have multiple products which share authentication settings. In particular, we use Spring LDAP, but since our use case and configuration is more complex, we would like to use multiple LDAP authentication providers, reconfigure them on-the-fly and have a fallback in case the primary LDAP is dead. Here'...
I am making a JS library that creates graphs and charts using canvas. I have hosted it on GitHub as a public repository. So after looking at some other related questions, I have figured out two solutions to keep active releases separate. Method 1: The master branch is named dev. All work happens in this branch Once...
Given [ ["hahaha", "hehehe", "hihihi", "huhuhu"], ["hehe","hehehe","hihi","hihihi"], ["huhuhu","juju","jejejjo"], ["zxcvzxcv","zevaerva","53qgaSD","zvxzr","hahaha"] ] find subsets of elements in each array , eg take the first one ["hahaha", "hehehe", "hihihi", "huhuhu"], that make it uniquely identifiable in all of ...
I have recently given Haskell another go, mostly because I heard about the book Haskell from first principles and so far I'm having a blast. My background is that of a mathematician mostly working in Algebra, so I usually understand the categorical aspects decently, but I could not quite grasp the following specific cl...
I've been coding in python for about 6 years now. I am proficient enough to understand a good amount of the language features. When I look into source code for a number of libraries such as pandas or requests I'm able to understand a good deal of what is going on. I've worked with python long enough to develop a real f...
I'm building a reporting tool with three core layers: Extract data from a database Transform this data to compute business metrics Display these metrics in a report (a heavily formatted Excel export in this case) My challenge is that there seems to be some irreducible complexity in the task, and I'm finding it very c...
I'm aware that there are 4 ways to violate Liskov Substitution from here. But I'm not sure what these violations would like in practice. Can you show examples of code that breaks the principle for each of the 4 ways? Preconditions cannot be strengthened in a subtype. Postconditions cannot be weakened in a subtype. Inv...
I've been reading a book about C#. What does the word 'set' mean in the following excerpt? Pattern matching with the switch statement: Like the if statement, the switch statement supports pattern matching in C# 7.0 and later. The case values no longer need to be literal values; they can be patterns. Let's see an exam...
I am looking for an advice (or an example) on how to organize logging streams in my cloud app (C#). In my app there are logging events related to the application infrastructure level and I want to write them to a file (or STDOUT). I use Serilog and I will enrich those events with custom metadata like environment parame...
I am trying to assess secure ways to implement a session handover between an app and a website in the same company ecosystem. The Setup Mobile Application A and Website B use the same company OpenID Connect (OIDC) provider to login their users independently from each other with completely separate session handling. Sin...
I have a yml configuration file that list multiple application. Each application can contain multiple configuration. And of course each configuration can contain multiple mode apps: - name: foo group: - group_1 configs: - name: config_1 options: [a, b, c] solution: solution path ...
I'm writing code to clean and process a large number of transcript text files. My code will be re-used in the future to process additional files which do not yet exist. Future files will take on the same general format as existing files, and will be collected/produced using the same procedures as were used to make the ...
I have an endpoint API for a POST request in a multi-tenant application, let's say it is for a Payment, where we have to store these fields: tenant_id (this is the account owner) amount date payer_id -- the user that makes the payment user_id -- another user that has to be attached to this payment category_id -- a ca...
Let's say I have a User class described as follows: record User ( Guid Id, string Username, string Password ) { /* some methods */ }; Let's say Usernames and Passwords need at the very least 8 characters before being considered valid. Should the domain be concerned with validating that? Or the application lay...
I have one large class that computes ~50 different metrics (each metric has no side effects). My code is similar to this: class ReportingMetrics: def __init__(self, data:pd.DataFrame, config:dict): self.data = data ... # Common data validation, etc... def calculate_metric1(self)->pd.Series: ...
I'm learning rust and curious to know the purpose that we can allocate memory sizes to data types. I'm not clear yet how this could be an advantage. It can definitely save up some memory space but I ran into a similar thread that stated memory is the least of the concern.
I have a codebase where some classes contain both "essential" business logic, and "incidental" complexity. I am considering a refactor where I leverage inheritance to improve the readability and maintainability of the code. However, it's not clear if the base class should be the one containing the non-core logic (and i...
I am familiar with and see the benefits of Subresource Integrity (SRI). I understand that with SRI, once you've added a script reference with the correct integrity attribute, if the remote script is subsequently compromised, then the SRI Hash will not match the remote asset and the remote script will not download. That...
Currently working on a project where we have multiple services that all need to consume the same authorization service when their endpoints are hit. Right now we have the authorization boilerplate code copied into all of our services, but we're looking for a way to make things more reusable. The idea we're considering ...
I have inherited a large C++ codebase implementing various Windows desktop applications, services and libraries using Windows MFC. There are no automated tests. We need to decouple the UI and retain a large part of the domain logic written in C++. My understanding is I can implement high-level use cases in C++ and expo...
Given a set of interfaces, objects implementing those interfaces, and functions that use those objects, what methods exist to model mutations performed by the functions? For example, given: A Pet interface that includes a feed() method Cat, Dog, and Hamster objects that implement the Pet interface Functions that take ...
I am making a renderer as a hobby, one thing I thought to try is making the low levelAPI be dynamically swappable, i.e. you could have an opengl or vulkan backend and switch between the two without needing to recompile or even relaunch the application. To achieve this I am making 2 binaries, one is the executable, the ...
I am currently working on redesigning a microservice application. Our application is supposed to serve multiple clients and due to compliance we have to persist the data in separate datastores. We have isolated the services to be deployed for each client. there are some functionalities that are common for all the clien...
I got a bit strange 'future ready' scenario. And I'm not sure if I got it right in regards to C# adapter design pattern. The scenario is that to be future ready, 'to use the adapter pattern' to easily switch from underlaying frameworks. As for example here I use an instruction to move a robot arm vendorXYZ by 10cm left...
I am coming from the Google C++ guidelines, specifically the section on Static and Global variables. It advises against having global variables of types that aren't trivially destructible. I'm unsure if file-scope global variables fall in this category. Specifically, I have an example of this in a small C++ file (.cpp,...
I’m considering following sentence in a document: Lastly, a xxx algorithm is performed to improve the convergence speed (speed it takes for the individuals in the population to get closer to the desired solution of a high fitness value). However, I am not sure about the meaning of “convergence” and if “convergence sp...
I am building an API which, amongst other things, needs to handle users. I am building it with C# 10 and .NET 6. In order to receive/return data in the API end points, I am using records. So for example, this could be an end point which returns all users: [HttpGet] public IActionsResult ListUsers() { // The '.AsDto...
I wish to develop an application that can generate code based on an user input. Long story short: a user gives a formal description of a Resource (can be viewed as a REST resource) and based on this description I wish to generate an entire codebase that contains CRUD operations on that given resource. I am currently ha...
Protected visibility in languages like C++, Java or PHP is a strange beast: it makes fields and methods accessible in subclasses, but not in code completely outside the class. It strikes me as somewhat arbitrary to allow subclasses to access a class member, but not any other code: either kind of code is equally ‘foreig...
In an 8bit mcu, I wrote a piece of code of a state machine using a function pointer static void (*state)(void);. Inside the same compilation (let's say sm.c) unit I implement all the available states. static void state_foo(void) { //execute code //check results and change state //state = new_state } static...
I've bought a samsung galaxy s21 ultra about a year ago. Today i was looking at the specs again and i noticed that the Samsung Exynos 2100 processor consists out of 1 single CPU core of 2.9 GHz, three cores of 2.8 Ghz and 4 cores of 2.2 ghz. On the Samsung Exynos 2100 info page I read that the 2.8GHz Triple-core (Corte...
What are the generic patterns and best practices for resetting state of a database, storage, external service, etc, in Acceptance Tests? I'm struggling with spaghetti, living in acceptance tests. It connects to the remote DB, executes SQL, Rebuilds buckets through AWS S3 API, reaches into a payment provider API to del...
In our company we had a discussion whether formatting data in a certain locale is the responsibility of the frontend application or of the API that provides data to it. Which of the following scenarios would be best practice? Scenario 1 The API returns data (DateTimes, decimals, etc.) in their original data type (i.e....
I am designing a blog in domain driven design. I don't know how I should define models: Post and Comment. My database: A user can see a post and related comments. So I think that Post model can be the aggregate root and the model Post should contain a list of related comments. On the other hand, an admin can see a lis...
I work for an engineering firm which builds most of our physics models in Excel with VBA. For myself and many other younger mechanical engineers in the company, this is not a good solution - we grew up with Python and Matlab and are more comfortable in those languages. I've developed a script in Python to approximate t...
I'm writing boolean methods that do a data quality check and then performs logic. such as isRecordValidAndIsUserPrivilaged. these methods checks the record validity, and then checks the user's access )I can split each of these into 2 child methods to make the code more readable). I get that this is not following SRP, b...
I know that the C++ standard library includes the ordered and the unordered map (std::map and std::unordered_map) containers, but why is there no hashmap available on C++? I was asked this questions on one of my coding interviews and I did not have an answer. Even google did not give me a satisfactory answer and just g...
I'm writing an application based on a RESTful API located in a server (written in Python). An Android app will access the API endpoints to get, post, put or delete data. The usual. The server has a getUser endpoint: <app base URL>/users/<user email> If no user has that e-mail, then a response with http error code 404 ...
I'm trying to implement a web service API client using the guidlines i've found in this article: https://www.oreilly.com/library/view/designing-evolvable-web/9781449337919/ch09.html As it comes to my understanding, article suggests to implement different API endpoints as Link classes, which know how to construct reques...
I have to build a micro service for my company, the backend is an Oracle database, but the micro service must consume five (5) stored procedures that already exist in the database (as shown in the screenshot). The database architecture can't change. My question is: must I build only one (1) micro service that consumes ...
I am writing some code that enables / disables a certain kind of hardware function. To enable it on, I have to call some methods, and to disable it, some others. Of course I want this code to be clean, so I try to keep the use of if/else to a minimum. See Elegant ways to handle if(if else) else and Clarification of "av...
I heard about Reactive User Interfaces in a React course. I would like to understand the concept, but was unable to find reliable sources. Best I could find is that they are some sort of declarative UI representation, and I would like to confirm if that really is the case. Can someone give me an explanation of this ter...
I'm writing a class that acts as the interface to a server. The interface exposes a way to send messages to the server and pass messages back to the client through a callback. Implementations should convert messages into the appropriate format for the server and handle the sending logic. Essentially the API might look ...
I had a discussion at work about whether to unit test a private static object we're using as data for a public component. const data = { 45: { name: 'John' }, 2: { name: 'Patricia' }, 27: { name: 'Rei' }, } The list goes on with dozens of items and in the real production example it has many more fields. In general,...
I have a button element on index.html that invokes a function signIn: <button onclick="signIn()">Sign-in</button> I have a few basic options on where this function can be defined: index.html contained directly in a script tag. signin.js a separate file, included on index.html a la the script tag and its src attribute...