instruction
stringlengths
34
36.1k
If we implement the following function: template <typename... Ts> [[noreturn]] inline bool die(std::string_view message_format = "", Ts&&... args); We can then write: if (bad_thing_happened()) die("A bad thing happened!"); or, for example things_are_ok() or die("Things are not ok, and foo is {}", foo); I know this i...
Sometimes I need to use the same use case with different details implementation. It is easy and straightforward for presenters as each use case has its own output port and therefore different implementations. BUT in the data layer, there are Gateways that have different abstract methods used in different use cases. The...
I have been using "Perf" when writing about performance of some pieces of software (in tools, pull requests, etc.) but was wondering recently if this was an appropriate practice. Can I assume software engineers, both native and non-native English speakers, would understand what "Perf" means in this context? (And just t...
So I have a project which does not have any regression test or automated unit tests. We release every week. We use forking git flow which is basically everyone forks repo and pushes their changes in their specific fork. From their fork devs push to develop branch which is pushed to pre-prod where tester tests it and th...
We have several C++ projects that use clang-format and clang-tidy and other similar tools. Currently the config files for these tools are stored in each project's Git repository. Now I'm trying to put these files into a separate repository so that they can be shared between all projects, so that all projects use the sa...
I understand that a SocketTimeoutException (I'm in Java, but I guess it's the same in just about every major language) happens after a server or client doesn't respond after a period of time, let say 10 seconds. I know it can happen if, let's say, the client sends a request to the server, and that request takes a long ...
Let's say I was to create a scraper. At some point I'll need to come up with algorithm of identifing whether or not a piece of a newly scraped text matches the one that's already in the DB. How would I check whether those 2 pieces are identical? If I decided to use a hash to compare them, it wouldn't be reliable becaus...
The idea is that for each resource we want to dispaly in a grid, there will be one endpoint for data and another for metadata. The metadata endpoint will bascially return a list of columns and their types based on the POJO being displayed. From one point of view, I can see the productivity gain with this approach. Howe...
I have one design problem for one of my projects based on location tracking. The scenario is I have multiple devices(for some business) all over the city and have GPS installed inside, the device is calling the Ping API for updating its most recent location every 10 seconds. I am managing a queue-based solution(RabbitM...
In my Java 11 / Spring Boot codebase I have enums that don't respect the convention to have all uppercase constants because when we move to frontend the data there has to be camelCase (or even random / weird case). I am not designing this from scratch, more dealing with something pre-existing. Here's an Enum example: p...
People say "don't expose primary keys from the database in your API" because its a major security leak, so I'm trying to come up with a way for: RESTful HTTP requests to reference server-side resources without requiring their DB PK example: I want to update a Widget resource with a PK ID of 293, so I want the equival...
When trying to follow a functional programming paradigm, I often find myself in a situation where I have a chain of functions that I would want to combine/compose somehow, but they all also take in a similar set of parameters. I've been trying to research best practices surrounding this kind of set up, because it's not...
I am looking into building an iOS application and using an internally built API to access data. My API has some authentication endpoints that takes in a username and password and, if the login is successful, it spits out a JWT. My question is, what are best practices for iOS logins such as this? I've been doing some re...
We have to fork a repository and keep it up to date, with adding changes here and there. The important branches are remote/1.0 and remote/1.1 The workflow currently used is to fork the repository, create our own 1.0 branch that is the same as remote/1.0. Changes are then made that are pushed to our 1.0. Now, we have to...
I have an endpoint GET home/{homeId}/laptops . Its response is : {"homeId":string,"laptops":string[]} If homeID does not exist I can return '404 Not found' OR an empty response with the homeId and the laptops array empty such as : {"homeId":'homesIdentifier',"laptops":[]} The client does not really care about the err...
So I've got a class that calculates a discount (Let's call it class "A"). It has a price fetcher class as a dependency (constructor injection) (Class "B"). The price that is returned (by class "B") is used to calculate the discount. However it is not obvious that class "B" is used to fetch a price unless you go into th...
I am well aware of a programming-to-an-interface term. That's a good thing! I understand that these allow to add decorators; or perhaps one can implement a service that works faster and by injecting it instead of the original the whole thing would work faster as a result. In all of these cases the end result remains un...
Our system needs to process PDF invoice files from generic external third parties. Using HTTP is the most obvious, but this isn't the greatest of ideas in case we need to deal with bulk uploads. Even when we push all HTTP requests on a queue behind the http controller, when thousands of PDF's are sent to the server as ...
I have a domain entity called a "Booking Window" that has a Start Date and End Date, and defines a period in which a Member can make a Booking.  The business is a mobile car wash, and Members can book a wash every 14 days. I have a means of establishing the first Booking Window - at the point of the Member signing up. ...
In many languages, the convention for naming Booleans is typically to prefix them with "is", "has" or "can". This convention seems to be applied mostly to fields and methods (e.g. Java's Scanner.hasNextInt()). Is there a convention for naming a method's Boolean arguments? I don't see the same convention being applied t...
We are building bot application that suppose to support both Slack & Teams. Both Slack & Team has a single Web hook endpoint which makes the app code tightly coupled with them and hard to make the core business logic verify-able. Hence, we thought to divide our single monolith into two sub apps. Core & Slack Adapter. C...
Well, I've been studying software architecture a lot, Clean Architecture in specific and I came across some multi meanings terms and "Use Case" is one of them. I'd read in some places that we don't have a defined connection with use cases from CA and use cases from requirements specifications in software engineering no...
So I am learning how to use the factory function in javascript/typescript. I created a to-do list project where I had to pass the instance as a parameter to the function. I wanted to ask is it a bad practice to use this approach eg const Animal = ()=>{ const legs = (noOfLegs:number)=>{ console.log(noOfLegs)...
Let's say we have an undo/redo system and we have a superclass storing an object that should later form a tree of the attributes that can be undone/redone. This would require every class that should get involved into undo/redo to extend from this one superclass, depending on how big the system grows, this could result ...
I have a outlining app that I am writing using unidirectional dataflow and some of the concepts from Redux. When the user has selects items in the outline, and clicks indent, an indent action is fired. This needs to update the state of the app via some complex rules that modify the parent property of some, if not all,...
Is there a good pattern in microservices systems for delaying the processing of a JMS message until some other task has been completed. Let's say, for example, a message is sent to a topic when a customer makes a transaction. Two microservices receive the event, one of which updates details of how much a customer has s...
Say we want to write a Java class that represents a fixed-size list. Let's call it Chunk.java (as in, it represents a chunk of data to be processed or sent somewhere). My implementation of this class can be outlined as follows: A chunk is represented internally by an ArrayList. It has a constructor that takes as argum...
I am working on a project that is structured in hexagonal architecture. It is a multi module gradle project where web layer is a separate module that depends on the domain module. Sample code related to the question: class InvoiceController(val invoiceService: InvoiceService) { @RequestMapping(..) fun getInvoice(co...
There is somebody else's project (A), a part of which (foo.h) I want to use in my project (B) with some modifications. The modifications make sense only in the context of B, so I can copy foo.h into B and track its changes using B's version control. But in the future, I may want to merge new changes made to foo.h in A ...
Given: You have a list of opportunities* that may improve the speed metrics of your website. For example Total Blocking Time (TBT) is one metric that heavily impacts the experience of a visitor. You've run lighthouse (or any other speed testing tool), which tells you "Estimated Savings" for each of these opportunitie...
I am learning Domain Driven Design currently and I'm trying to use it on an application that has a complex domain. The application is fully configurable, meaning that most the domain objects can have most of their proprieties modified by an admin doing configuration work. Although it should happen rarely and mostly whe...
I have the entity class. @Entity public class User { @Id @GeneratedValue private long id; private String name; private String lastname; @Column(unique = true) private String email; private String password; //getters and setters } I use the following class to fill it. public cl...
Context To level set, I've been working with OOP and FP for my whole career, so my experience with the imperative paradigm is limited. The team I joined is made up of very senior (20+ years xp) imperative programmers using a domain specific language - think Pascal. The team is challenged to try new things (not the focu...
So I want to inject an Application Client, say a Rest Api client, in my code. In order to create this client I need to go over the network to get it's user and password that is in a HTTP Vault. This behavior got my team divided, some saying it's an anti-pattern to go to the network before finishing injection, some othe...
If for example we have a user, project and a task service where a task is assigned to a single user and user can be part of multiple projects - how can one enforce a rule so that one cannot assign a task to a user that is not part of the project? For example, a POST request comes in to /tasks/1/assign with this data: {...
Well, we all know the main concept of TDD: write a failing test, then implement the testing component to make your test pass. I've been working on a personal project in Clean Architecture following TDD, and I'm gonna start testing some basic use cases that just CRUD some entities. These interactors classes use presente...
Problem I am currently working with a class that necessarily has a very complicated initialization function (>350 lines of code) given that many computations and attributes need to be performed and defined. I am considering using either helper functions within the __init__ function of this class in order to make the co...
I am learning about Dependency Injection and I have been recently implementing the following classes for an app that executes commands over ssh using Python. I am confused about whether I am using it in the wrong way. I am using a ConnectionFactory class to create an ssh object that I call dynamic, because it depends o...
With the introduction of the slash character to specify position-only arguments, is it recommended to put a slash in every method after the self parameter? For example: class A: def something(self, /, some_arg): Many built-in objects seem to do so (see range, str.encode, etc.). Is there some sort of advantage (may...
In polymorphism, your base class defines an interface. The inheriting classes fill in the data for that interface. The key is that the interface remains the same. Given that, if your interface is properties/attributes (not methods), is it more appropriate to override a getter, or to simply define/overwrite the attribut...
We are looking at implementing Multi-factor authentication for our application, using Time-based one-time password (TOTP) algorithm. What we want to achieve: Users should have the option to enable Multi-factor authentication for their account. Once enabled, they will be prompted for the Authorization code (which they...
I'm currently working in a firm, based on an executable, who uses different DLLs. There are several issues: Everybody builds the binaries on his own PC. The executables (*.exe and *.dll files) are not (as I call it) signed. Signed? What is that? I mean that, from the executable file, it is impossible to retrieve the ...
A play arena contain a list of Machines and Amenities playArena : guid : GUID name : string location: Location owner: string amenities: Amenities playing_machines: PlayingMachines Amenities is list of Amenity -> Array<Amenity> PlayingMachines is list of PlayingMachine -> Array<PlayingMachine> Initial ...
Imagine you're creating a completely new version control system, like Git, Mercurial, SVN etc. from scratch. Rather than identifying commits by SHA hashes, you identify them using an ordered sequence of numbers and letters, from 1, 2, 3, 4, 5 etc. If you make a branch from a commit, you call that commit 1a, and then fu...
If a class is written well, you should be able to gleam all relevant information about the class simply by looking at its header. If one sees that the constructor is marked explicit: What should one assume to be absolutely true about this class? What should one assume to be potentially true about this class. What sort...
Docs and blog posts describe what row version columns do, but rarely delve into the decision process of when it's appropriate to use them. I suspect that many developers just add them to every table without considering whether they're actually needed. This saves development effort, but it comes at a cost that I may wan...
I am fairly new to programming; I was following a tutorial that was using php 7.3.8. So I went to the documentation website of that same php version, and it says it’s no longer supported. So, I stumbled on the questions. What does that mean that is no longer supported? That it won't receive any updates? Is it safe to u...
As I am learning OOP principles, I know that it is always good practice to hide the inner workings of classes so that the end user can't access or break them. I understand why this is important. The human mind cannot comprehend overly complex code. I also hear the term "Black box" quite often. A common example I hear i...
I have a Curve class that has some CurveData inside as private member as well as getter functions for topics of interest (e.g. peaks, width and so). So the math logic of a curve is inside this class. Things to be done with this Curve are: Test its values (returned values from functions) with some thresholds. The test...
Is it possible to fetch data and update it if a time constraint has been met? Originally, my implementation was a cron job that regularly updated the data in my PostgreSQL table every minute on the minute after selecting all the rows that met the time constraint. (Meaning the job always ran at 12:00, 12:01, 12:02, etc)...
I'm currently working with a pre-existing class (not written by me) that has functions which call other functions, passing through the parameters to the helper functions. Sometimes there are layers to these functions, so that func1 calls func2 calls func3 calls func4, where a parameter of func4 is passed through all th...
How do I solve this riddle of contradicting "good practices" to properly cover my app with unit-tests? These are principles I found about writing unit-tests: Pyramid of testing says unit-tests have to be written first and there should be more unit-tests than integration tests It is useful to automatically calculate te...
Let's suppose we have this expression: (i % 1000000) * 1000 + ms where i is an always increasing number, and ms is the millisecond part of the current time ( ranging 0..999). So each time we are calling the expression above, at random intervals, while i is increasing always obtaining all unique values, the result of t...
I have a requirement to cache some static data as it is being consumed by our system. There is a static API that gives a map of records and we are fetching the corresponding record based on request. Instead of calling the static API for every request, we are planning on caching the data in an in-memory Java cache that ...
I am currently creating a software model for controlling a simple (two-way) pneumatic cylinder. In essence, this controls just a movement from point A to point B. The controller has two outputs (OnMovingToA, OnMovingToB), which can be linked to a relay, valve, etc... to move the actuator to resp. A or B. The controller...
Context I have a service class whose sole purpose is to interact with a specific API, let's say the Automotive API. The API mostly works with generic AutomativeRecord which basically represents a database record on the API backend with its fields stored as an array. AutomotiveService.cs public class AutomotiveService :...
I have a application built with nodejs. It's hosted on AWS and uses postgres as the database. The application allows for users to create bookings. When a booking is created, an email is sent to the user to notify them of the booking. The problem I'm having trouble wrapping my head around is how I'd implement recurring ...
Is it common to write test for CI/CD scripts? Background: Some CI/CD jobs/scripts have become rather complex over the years (new features, edge cases) and I believe it would help rewriting them with e.g. python instead of bash. However, since these scripts have no tests, rewriting would definitely be error-prone. There...
I want to come up with a way to make it easy to write classes that represent quantities with units, such as length, weight, etc. For example, var height = new Length(32.2, LengthUnit.M); var weight = new Weight(164.2, WeightUnit.Lb); In addition, these classes should automatically handle unit conversions and implement...
My friend is building a small open-source project with a few convenience functions. He'd like to release both JS, PHP and Python versions of the package to npm, packagist and pypi. The main part of the package is just data that can be shared, so the actual code to translate is very small. Should I recommend him to buil...
I have been using an implementation of UML statecharts in C++ similar to that defined in the book "Practical Statecharts in C/C++" by Miro Samek (https://www.state-machine.com/psicc). One of the "problems" I keep encountering in my development over and over, is how to associate an action with a transition that requires...
I have Items and Im creating an API which validates different aspects of an Item. eg: whether it has a valid height, width or depth. My request body looks like { height_check: true, width_check: true, depth_check: true } The response looks like { height_check: { valid: true, ...
I was reviewing a pull request of a programmer that works under me, and found that in testing fixes to their code, I ended up completely rewriting it. Should I push my changes and then explain what I changed, or should I scrap my changes and just try to explain to them how to fix their code? I don't want to offend them...
I'm doing a simple project that represents a CI Pipeline in a low scale. So I'm trying to model "the best way possible" to practice DDD. Basically I have the following information: PipelineSettings (A configuration file that shows me the steps the pipeline will have) PipelineSteps (A collection of classes implementing...
I have a problem where our current SDLC model is the V-model which is great for its verification/validation of all phases, but lacks the support for iterations. Spiral model on the other hand has iterations and fits, but does not focus on verification, validation and testing activities like the V-model. Is it valid to ...
I have to create a table to map some strings that are my input, to the result value that is a value that I can choose, like an id (or string). So, to make an example, I have an excel file made of a not normalized list of names, that are all the possible values that I can expect: "audi A4" "Audi A6" "audi a6" "ford foc...
Canva has Templates that are unique & can be easily modified by anyone & replaced with their own text, images, etc... I want to build something like that. I have multiple options to use but don't know which one is good or which one is fast enough to code. My options are: DOM with html-to-image for screenshot Canvas Ko...
I have a project where I am planning on using maybe 4 raspberry pis to record a bunch of different sensor info like temperature, humidity etc. I would like to be able to access this info from a webpage. For this, I am assuming it'll be easier from the website perspective to pull data from a single database that's hoste...
I am trying to understand Rabbitmq and how I can accomplish sequential message processing in certain circumstances only. For example if I have 2 queues. One for pricing an order and one for sending out an invoice. Sometimes these queues would get messages and be processed independently, but other times they are depe...
I'm interested in modernizing an existing codebase for a commercial software package written in Java, in part by moving it to Maven. The primary motivator here is to shrink our git repo, which is very large due to the build system being ANT with its dependencies checked into git. I've done a few small side projects i...
Maybe I'm overthinking about naming, but it's a problem I've encountered several times and it was really annoying every time. I have three interfaces. The first is IAssembler, which has assemble(...) method. The second is IDisassembler with disassemble(...) method, and the third is [no good name for that one] which inh...
When designing my simulator, I have gotten stuck on 2 main design choices. The simulator can be described as having X number of nodes (between 50 - 2000) that each need to independently do some processing during each time-step in their own thread. After they are all done processing, then the main thread needs to do som...
I have a Nest.js application, and lately I've been thinking about how I can ensure that data is synchronized between two sources - my database and an external database. For example - and to my question - is my database versus Stripe's database. I have plans with recurring payments, and I track how many licenses a cust...
I've got a GRPC API that I'm designing. It includes an RPC method that requires the caller follow-up with another API call. Some pseudo-code a client might write: val apiInstsance = makeAPIInstance() val questionFromMyAPI = apiInstance.computeQuestion(clientInformation) val clientResponse = doBusinessLogic(questionFr...
One thing I've long struggled with being able to grasp properly is, when designing a program in an object-oriented language, where and how should explicitly named/defined interfaces be added? In particular, I have heard at least the following statements on the matter: The "SOLID principles", of which the last three (i...
I am trying to understand what can be done with closures that would be difficult or impossible to do without closures. One use of closures I have found is to make an object's variables private, for example: function CreateEmployee() { var name; var obj = { "getName": function() { ...
Monad is a monoid in the category of endofunctors. Endofunctor is a functor that maps to itself. What does it mean? Well it means that, no matter which element in the set is taken as an input, the output value must also belong to the same set. I understand that if the input of the function is an integer, then the outpu...
For the purposes of this question it will be assumed that the conventional commits spec is used as a version driver for semantic versioning. Given a project is in active development. Releases are planned but not often enough to warrant CD. Thus a release-from-branch strategy is chosen. If a release branch were to be cr...
Outline When you build an Adapter that connects your application and the database, How big should you make this adapter? Should it contain all possible queries that could be made to the DB? Do you split it up into several adapters? By what means should split it up? Concrete example I'm imagining the following rough ...
A monad is a monoid in the category of endofuctors. Category is a set of two things: Set of elements Set of binary operations between these elements. When we talk about the category endofunctors we also have a set of two things: Set of endofuctors Function compositions as binary operations Function composition is a...
I don't know from where I got this but in my head a function returns a value and a method does not. I know that with OOP a method is a function related to a class. But I am trying to remember where I got this idea.
Abstract I'm trying to figure out a solid, scalable, clean and practical architecture for react projects. As a a playground I have a project with two Screen and a JSON server. When I try to apply a clean, one-directed architecture, I end up with a very complex Structure. (Here, a Screen stands for *a site, that is sh...
So I'm trying to understand the connection between the Requirement Types given in my Software Engineering lecture. We discussed 5 different Requirement Types: User-, System-, Functional-, Non-Functional- and Domain Requirements. Is it true to say that System Requirements are better and more precise User requirements an...
Hypothetically, consider a social photo platform - each pic gets its own url, this page contains the image, text about the image, buttons for the user to click, related pics, and some user-specific elements (maybe notifications, etc.). There are different ways of going about the frontend. In each case, elements specifi...
First some context. Working in teams which use a CI environment, many people will know the typical Gitflow release process. Without going into too much political detail, the company I currently work for has decided to "release features more often", up from a 2 week cycle where develop branch was merged upwards step-by-...
As a Scrum Master, how does one plan to minimize the impact of the sprint deliverables/to the team when a team member is leaving?
When we have a math problem such as 3 + 5 + 2, we say that it is associative. We can choose which step to pick first: 3 + (5 + 2); we know that brackets affect the order in which the operations are performed. I've learned that function composition is a binary operation and it is also associative. They say, function com...
Problem Hi, we have an API that it's pretty similar to a standard CRM. That is, we have a really big amount of resources (even our own customers can define new resources). All of these resources share the same endpoint: /resources/<resource_name>. This resource name can be any name, like customers, leads, contacts, etc...
Colloquially, type hint and annotations are used interchangeably in Python. After reading PEP 484, I was unable to disambiguate the terms "type hint" vs "type annotations" from the text. Are they synonyms? Otherwise, do "type hint" refer to the typing system and "type annotations" refer to the written text itself (e.g....
I am using a networking library I created which contains a Client class. I have a GUI which will display all these clients in a ListView with columns, such as one containing their online status. The online status property is only for the UI, so it is not present in the class in the networking library. What I am current...
I'm wondering how to choose between those "patterns" - please forgive me if I don't use the right terms - when having to deal with complex object coming from the front I want to process. Simple Beans Simple beans means the separation between data structures and logic, like this: class Post(val title: String, val conten...
Following context: in a set of metadata that contains a lot of possible fields there exists at least one field (possibly more in the future) that can be empty by intention but realistically will be relatively rarely and in most cases the field being empty represents a mistake/carelessness of an employee. Due to that fa...
At first, we have a working function name foo void foo() { bar1(9); bar2(9); } Noted that the value 9 is hard-coded. Then, we want to make a change so we can make 9 a parameter yet preserving the old foo function, so we change it to void foo() { foo_ex(9); } void foo_ex(int x) { bar1(x); bar2(x); } Cod...
When catching and wrapping an exception in PHP, assuming the new exception doesn't have a meaningful code of its own, should you also use the caught exception's code value? or the default value? In other words... Should I do this? try { do_something(); } catch (GenericOrThirdParty_CaughtException $e) { // Reus...
I'm busy working on a website – somewhat new to this – and I don't quite know where I should store static data: in the public folder as a separate json file, or within the .js file as an object. In the json file, it would look something like this: { "navLinks": [ {"title": "Home", "path": "/", "number":"one"}, ...
I currently have a database centric web app for my company. For the office staff, the whole system is based around orders. There is an order list page. Warehouse manages his part by reading, preparing and marking incoming orders as 'prepared', 'dispatched' etc.. Telephone staff takes new orders from customers using the...
It is considered the best approach that a microservice db is private to it and shared nothing approach is the best. I recently came across a cloud based system which used postgres, mongodb & elasticsearch. The per service DB is followed, to the extent that each service was running its own cluster of storage engine whic...
Edit: The question below is summarized by this question: I sent you [payment] to run computations. How can I make sure you are actually running the computations? Thanks to user253751 for this Edit: TL;DR I'm currently making an open source application that essentially creates a cluster computer over the internet. Thi...
When using composition, when should we favour wrapper methods? Let's say we have the classic car example. public class Car { private Battery battery; //wrapper method public void load(float p) { this.battery.load(p) } } public class Battery { public void load(float percentage) { } } The ...
I have got the following scenario, which I have been thinking what would be the "best" way to solve it. Request comes from the FE, which changes the status of a delivery, and that should trigger different things depending on the value of the new status. -if confirmed, send email and also create pdfs -if dispatched, cre...