instruction
stringlengths
34
36.1k
Ive got a boot sequence that needs to check some registry values, they may or may not be present, so each check needs to be wrapped in its own try-except. I try to avoid nesting as I think it can lead to confusion, but what I ended up with was: reg_a = reg_b = True reg_a_val = reg_b_val = None try: hklm = ConnectRe...
Sequence diagrams are used to model use case scenarios i.e., main success scenarios and alternate scenarios. That's what I understand from Craig Larman's book. I understand that it depends a lot on the practitioner. I mean a practitioner may decide not to model unimportant/obvious alternate scenarios etc. Is there any ...
I am developing an application with ASP.NET Core with the ability to dynamically add new libraries that implement the necessary functions. They can be included at the start. I have already written several standard libraries myself. I wanted to use the same logger in the main application and in the pluggable libraries, ...
I have a C# system that reads thousands of messages per minute from a Kafka topic. The messages are filtered and I need to insert the filtered messages into a MSSQL table. A normal insert statement is a too slow and seems to hammer the database with thousands of inserts running at the same time. (Currently using Dapper...
So We're integrating our application with stripe and we have different products There are 2 options : Have stripe as a single source of truth, anytime we need to check the permissions of a user we call a stripe api, get the product and decide accordingly. advantage : single source of truth inconvenience: manipulate s...
I have a value object to hold a user id number as a string. This number has a unique format throughout my domain. So, it's being validated inside the object during instantiation and an exception is thrown if it's not of the correct format. The sample class is given below (all codes are in PHP): class IdentityNumber { ...
Shoutout to David Arno for teaching me about the builder design pattern via this thread! I have since used that pattern althroughout the code base to abstract out creating models from data stores, ready to use in the test cases. See the link to the other question for example on how we're using it. However, model creati...
For a mobile app, we are using the Google APIs for geolocation and geocoding. The basic use case is to find entities within a certain radius (in the range of a couple of kilometers) of each other. Often, due to people being either in high rise urban areas or city outskirts, the location accuracy gets thrown off, and th...
I am going over tutorials regarding class design; in one, a videotape can have multiple copies and each copy can be borrowed by a borrower. Please see figure A: I am trying to understand why the answer in Figure B, which considers copy as an attribute would be wrong. My only guess is that then I could only represent o...
In an event-driven microservice architecture, imagine we have three services: Customer service Order service Item service Each service raises an event with data when something happens and stores only its related transactions. For example, we want to know the customers that placed an order in the 30 min after they reg...
I want to implement gitflow but I have a question. Let's imagine I have release version 1.0.0, it works nicely so I merge it into master. We deploy and it goes to prod. Sadly we didn't notice something terrible that brings prod down so we immediately rollback to version 0.9.0 that works fine. At this point in time we s...
Prompted by Sonar, I am looking to reduce the complexity of a function (one that some might call arrow code). I am loosely familiar with some of the principles of reducing arrow code complexity (flattening, eager returns, guard statements instead of affirmative condition checks), but I doubt that this particular code ...
I'm working on a semi-complex web API, the high level design so far looks like this: |--------| |------------| |------------| | |--| | | | | core | | | | | | | | | | | |--------| | | | | | | contro...
To the best of my knowledge, user stories follow a format such as As a [role], I want to [do] such that [benefit] - (This takes 8 days to develop) Recently in the book Software Engineering by Ian Sommerville, I learned about a different story format such as below Which is broken down into What is the difference bet...
In a project I have the same imports in multiple files. For example: import os import logging import json import time import pathlib and pylint will tell me I have duplicate code. I know that there is a way to disable this message: https://stackoverflow.com/questions/29206482/pylint-duplicate-code-false-positive. Howe...
Assume I have a factory which takes in a series of bytes and outputs a pointer to a newly-created abstract message. Now, I would like to define some extensible, manageable, and clean way to "handle" those various messages without knowing the actual concrete type. To me, this sounded like a great application for the vi...
I am developing a utils data engineering package in python, and for the sake of reusability and readability, I chose the functional programming (FP) approach. Assume a key task of converting data from types a, b, c to type X. I write three functions from_a_to_x, from_b_to_x, and from_c_to_x. Is it a good practice in FP...
I'm using a PostgreSQL database and I want to create an analytics table that has a many-to-one relationship with an analytics_type table where analytics_type_id is the foreign key. The table also has a many-to-one relationship with a user table with user_id as the foreign key. The structure of the analytics table looks...
In State Machine diagrams, in some online resources, the condition is merely drawn on the arrow (the left figure below) and in others similar to right figure, where a choice node is specifically used. Which one of the following is correct UML?
I have always wondered whether public, protected, and private has security implications post compilation. Hypothetically: class Foo { public: int m_Foo; // Completely vulnerable and dangerous protected: int m_Bar; // Possible attack vector from subclasses private: int m_FooBar; // Totally secure ...
We have microservices in separate machines that currently use IP addresses in their configuration to communicate via REST APIs. There are also domain names defined for these machines. Is it a good practice to use IP address for communication or domain names should be used in case IP addresses change? What are the pros ...
I'm currently designing an interface for a container that is supposed to store references of different instances that derived from a common supertype. An analogy of it would be as following: Suppose there is fruit store where people can put different kinds of fruit. The fruit store should provide abilities to retrieve ...
We have a legacy system (app 1) that has millions of records of an object Project. It has ProjectId and OrganizationId columns along with other properties. A recently added service (app 2) gets the same object created again in its database as part of some migration. The new object will be created with slightly differe...
We're building a new feature for an online editor that the user will not edit the document, but will be able to highlight & propose edits on the document. Very similar to google documents' commenting feature, rather than a typical editor. The comments don't change the text of the document contents, but the view is diff...
I would like to devise an algorithm that given: An array of dishes with macronutrient information (proteins, fats and carbohydrates, in grams), constrained to a maximum of around 200 items. A desired macro-nutrient target (proteins, fats, carbohydrates, in grams) would output the same list of dishes, ordered by the b...
When an object creation depends on other objects, it is better to have those objects injected into the constructor of the first object's class (dependency injection). For example: Car car1 = new Car(new Body("body1"), new Motor("motor1"), ...). Instead of having them created into the class' constructors: class Car { ...
I just wonder how do you deal with this scenario. Let's say you have an application that uses configuration files that are loaded right after the application starts. Configuration files store - lets say 100 - configuration parameters. For all clients the application uses the same parameters except one (let it be one fi...
New to design patterns so my question maybe silly. I want to use strategy pattern for returning data from a databases in the same format. Nevertheless it varies the query on the underlying database that collects the data. So I am trying to implement strategy pattern. I don't use an interface but an abstract superclass ...
I have a web app that will be used locally on 2 different site. The program is a Vue web app made with node.js and express, using MySQL database. Due to limitation (no internet in site 1), there is no central server, so the web app will function similarly to a desktop app. However, there is a need to sync the data from...
On website uml-diagrams.org it is mentioned that state machine diagram is a behavior diagram which shows discrete behavior of a part of designed system through finite state transitions. To the best of my knowledge, state charts represent the states of a single object of a certain class. What is meant by part of the sys...
How do you handle migrations to your database after a long period of time? I'm using fluent migrator, and after some months or years, the number of migrations could be (and has been in previous projects) in the hundreds. This is a problem for new SaaS instances that only need to seed from the "latest" version. Currentl...
I know what we mean by cohesion and coupling in software. And generally the best practice is to achieve high cohesion with low coupling. It seems to me though that they are inter-related. I.e. you either end up with low cohesion/high coupling or high cohesion and low coupling. Can we ever end up with high cohesion and ...
My question will be mostly about Linux and contemporary X86 hardware. Clarifying the terms async event based programming: spawning fixed amount of threads and using some user space scheduling mechanism. Usually callbacks are handled in a continuation style, so the callback will be executed in the thread of the consumer...
I have an iOS application that uses the Core Data framework. I'm migrating the application from Objective-C/Swift to TypeScript + React Native. My Core Data configuration uses SQLite as a backend. The application has an existing user base who may be (quite understandably) frustrated if they lose access to all the data ...
Context: I am developing an amateur web application (with Vue.js), made up of components, and when reading about state management, the recommended solution is to use a store that gets updated by the components. Over the last 30 years, I have been reading how using global variables is bad design, and I understand that, ...
My teacher told me that in the entity-control-boundary we need to create a boundary class for each view of mock-up but I can't really understand if this is always true. For example if i have a mock up for a sign up like this Then is a class diagram like this right? Or it's better create only one boundary class called ...
I'm studying design principles, and I have a doubt in package coupling principles. I know that the 'Stable Abstraction Principle' says that a package should be as abstract as stable, and it says that we need to keep concrete packages (which are irresponsible and unstable) at an high level to make changes easier, and ab...
In the following image, regarding a CD shop that rents its music CDs. My question is regarding the correct multiplicity of X. I can think of several possibilities for X: X= 1..1 as each copy of CD can rented by one member only at one time. All copies are assumed to be rented at some point. X= 0..1 as each copy...
Hope this is the right place to post an opinion-based question like this. I'm in the process of converting an aging API monolith to a set of .NET 5/C#-based microservices and working on the code reuse strategy. Of course, this is a hot topic, and there are half a dozen or more different ways of approaching it, but what...
Considering i have a Presenter that updates a ViewModel, and potentially multiple Views updatable from this ViewModel. What would you think about this way to proceed : Somewhere we register the Views as Observers of the : ViewModel implemented as Observable. Therefore the Views will automatically be informed when they ...
I want to create an api based on Node.js and Express.js. This api should return an array of products on /products. To get these products on my node server, I need to call a third party api. However, I don't want to call the third-party API every time a client calls the API I provide, because these products only need to...
I have read the Domain Modeling Made Functional book. In the book, the author model the Order in 3 different states: Unvalidated Validated Priced The 3 states have different properties. But it's functional programming. I find it's hard to implement in Object-oriented programming. Since the 3 states only have differen...
In most build systems and development environments, there tends to be exactly one dependency tree per project - each module depends on a constant set of other modules to do its job, with the only leniency being different backwards-compatible versions of the same module. I'm currently going through several circles of he...
I'm creating a prototype mobile app that will store data locally in an sqLite database and also on the cloud (CloudKit for now). The cloud storage uses a certain way of storing the data, and sqlite uses another. my class looks like this: public class MyDataClass { public int ID; public string Name; ...
Currently reading Steve McConnell "Code complete". "General issues in using variables" chapter, "Binding time" section. He says about variable's binding time in such languages as C++ and Java, that have phases like compiling. Coding time (use of magic numbers) Compile time (use of a named constant) Load time (reading ...
I have a class, which uses a timer, to do some time-dependent things. Now, I do create the timer inside the class: class MyClass { public: Myclass(arg1, arg2, ...) :m_timer(new Timer(delay)) ... private: Timer* m_timer; ... } The timer has a few functions, like isRunning(), isExpired(), reset() However, when...
I have a C#-based system that works relatively well. It reads data from kafka, processes the data and then writes it out to MSSQL. The kafka topic has been partitioned into 10 partitions - and after 2 years, the team is considering increasing the number of partitions because the cluster is showing signs of not managing...
Why most frameworks (at least in PHP. I suppose in other languages, too) use the environment variables to set a corresponding configuration parameter and then access the value through a config object/function (e.g config('mysql.passqord') or $config->get('mysql.password') ). I won't argue on whether environment variab...
I'm having a hard time wrapping my head around the use of async/await and regular sync function calls in JavaScript. Let's say I have two functions: Function 1: async function doSomething() { const result = await doExpensiveOperation() const result2 = await doAnotherExpensiveOperation() return { result, res...
This is an example of a typical function from a project I used to work on. I have troubling grasping unit testing because if I want to test this function properly, I would have to write about 50-100 unit tests to cover most of the possible code paths to ensure all the logic works correctly, and this is just a very smal...
After my scrum certification, I had a chance to be selected as the team lead of a small project in my company. The goals is to made a choice on the new SAP the company will use. We are a team of 6 persons with cross skills. But I don't know how to handle that. The most example that I saw was how to do that for IT proje...
Let's suppose that I have two bounded contexts: A and B. In books I'm reading authors will only write "Context A maps into Microservice A". Now I'm working on a project (university assignment) in which I have one big context (A) that can (in my opinion) include a sub-context (B), as they both have the "same vision of t...
I want to build a chat application with a stateless server as backend. Users have an online and offline status. When a user connects to the server, the server marks that user as online. Now imagine a user disconnects because his battery died. The user can not notify the server he is going offline. How would a stateless...
In an Model-View-Controller (MVC) design pattern, What goes where? What code goes to model and to controller? I know (do I?) that business logic should be define in a model, but a lot of example I find on the internet only use the model to define the data. Take Microsoft's example of model for instance, it only writes ...
In Agile software development, when is a story or task considered blocked? Does the task need to be in progress? Or is the fact that a dependency is not completed, enough, for a task to be considered blocked? For example, the UI team needs an API from the backend in order to complete a task. If the UI team can work on ...
Take the following class, without [PublicAPI] attribute, ReSharper says that all public members can be made private. using System; using JetBrains.Annotations; namespace ObjMtl { // [PublicAPI] [NoReorder] public sealed class WavefrontMaterialColor { public float R; public float B; ...
I'm writing a CRUD app in Python that exposes web API. At first I wrote functions for communicating with DB and wrote tests for these functions. def crud(): # do something with db def test_crud(): crud() # check crud tables now have all required rows Then I wrote functions for API routes, which do some input...
My goal is to learn more about OOP patterns and use DRY principles. I am trying this for wrapping an os command that interacts with a database using classes: This works fine: import subprocess class Blah: command = '/usr/bin/database_exec ' def execute(self, action, user): self.action = acti...
I'm maintaining a small C library; let's call it libfoo. It has quite a few users (actually it's complicated - it's the main fork of a highly popular library which has been abandoned); and it sports a spiffy CMake-based build mechanism. My repo directory structure is: <root> | +--- src | | | + foo.h |...
Is it OK to create a variable which only purpose is to increase readability? Example: public class Example { private final HowLongCanARepositoryNameReallyBeRepository howLongCanARepositoryNameReallyBeRepository; public boolean method( final HowLongCanAMethodArgumentNameReallyBeArgument howLongCanAMethodArgumen...
The typical example, the e-commerce system. Let's say the Order is in the Sales bounded context. Every Order contains many OrderLine, which stores the ProductId. The Product is in the Product Catalog bounded context. Every Product has its own ProductId. I understand that the ProductId in Product Catalog bounded context...
I'm working on a project that has the purpose to execute tasks in intervals. The tasks and it's properties can be configured through the Configuration Website. The data is being stored in the Configuration Database. The Windows-Service loads all the data from the Configuration Database on startup and then executes the ...
This is Indirection according to Wikipedia Assign the responsibility to an intermediate object to mediate between other components or services so that they are not directly coupled. Controller seems to do this exactly, except that it is concerned with UI and Input events, while Indirection is more general. Am I wrong...
In Daily Coding Problem, Miller&Wu have the following problem : Given an array of integers, return a new array where each element in the new array is number of smaller elements to the right of that element in the original input array. Their suggested solution is (in python): import bisect def smaller_counts(lst): r...
When inter-communicating through http requests between Microservices it is quite easy to reply with error messages to users, you can just catch the error of a different Service and forward it to the user. But how does Error handling work when communicating through a message queue? For example, a user makes a request to...
There is an application of ours which has some experimental features. We want to enable it when user wants to enable. So they will change it in the UI and we are saving those to DB. So we added those settings in database as key value pairs. DB table is designed as follows. ----------------------------------------------...
As an example imagine I generate a UUID/GUID for an ID in a json file. { "25d01302-2558-4c44-bf9d-385b1cc51377": ["somevalues"] } is it ok or generally frowned upon to do something like { "25d01302-2558-4c44-bf9d-385b1cc51377": ["somevalue"], "25d013o3-2558-4c44-bf9d-385b1cc51377": ["someothervalue"] } the seco...
It seems best practice is to build the final artifact, in full, at the earliest stage. And then the stages that follow (testing, deployment) should use same artifact throughout, to protect against some sort of mismatch between what was tested, and what gets deployed. How do runtimes come to play here? My specific case ...
In our Jira board we might have 5 tickets for different API endpoints - for example: ListArticle GetArticle CreateArticle DeleteArticle When we create these new endpoints, there is some initial work that needs to take place to get our infrastructure ready for the endpoints. This only needs to be done once across all ...
So, I have the following two functions in THE SAME class: void start() { ... m_pRunnable = createRunnable( [spDiskManager = m_spDiskManager, path = m_path, &success = m_isFolderCreated]() { success = spDiskManager->createDirectory(path); }); m_spWorkThread->invokeWi...
I'm concerned with the practices on my team regarding following REST and HTTP verbs precisely. For example, when we hit a get endpoint for a resource/resources that doesn't exist, we return a 404. Shouldn't we return an empty list with a 200? I thought 404 was reserved for a URL that didn't exist. Does your organizatio...
I know that a lot of compilers use an assembler to compile to machine code, to make an executable (compiled program). Some people even made their own assemblers, or they just use an existing assembler, or they just transcompile to C, or they just use some other VM like JVM, or LLVM. What's the fastest and easiest way t...
Due to circumstances I'm now working in a small software company. We make e-mail marketing management software and serve some big customers as our national railways and a big bank. The software has been developed about 6 years ago by two guys, one who left, the other now leading architect. The problem starts with him. ...
The case is that I have a signup form for students where they can choose between different lessons in multiple rounds. Each lesson in each round has a defined available space. The total amount of space in each round is equal to the number of students which need to sign up. Students cannot pick the same lesson twice in ...
I have a code that reads a YAML file that consists of several parameters whose values are used throughout the code. For clarity, the YAML file has the following structure: PARAM_1: value_1 PARAM_2: value_2 PARAM_N: value_N These values are never changed after the YAML file is loaded into the program. When the YAML fil...
As a forewarning, this is for a school project with other school teammates, so my question is just for the sake of learning best practices. We are creating a recommendation system web app which currently consists of 3 services (react front-end, Flask server, postgres database), where the database we are using is just a...
Is there an equivalent to Banker's Algorithm but for project management? For example you have several teams with different tasks and there is a deadlock, how do you resolve and prevent these situations? (For example, team A must do task X and team B must do task Y, but to do Y team A needs to finish X and to do X team ...
Description is too long, but this is a pain point. I just want to understand whether this is also practice of Agile, if yes, how to overcome some of the issues mentioned below. Thank you. We are using agile scrum for our projects and we have 2 weeks sprints. At each sprint we are delivering "something". We have huge a...
I write a software which trades with crypto currency via big exchanges. Using the clean architecture approach I have defined some core entities, some business cases and then created an outer ring of adapters which implement my Marketplace interface. The function which retrieves the current spot price from the Kraken ex...
I'm a recovering perfectionist. According to my colleagues, I am also a good software engineer, but one of the feedback I have often received is that I tend to dive too deep too soon. Suppose I start working on a new feature that requires going into the code base of another team - I often end up trying to understand ho...
Exogenous exceptions are that kind of exception that are unavoidable because they are throwed outside of our system's pristine logic. A good practice is to throw wrapped exceptions in lower layers like the DAL. However, in my application i have a lot of filesystem access, and I came up with recursive functions, like th...
What is a good way to secure http communication between two backend services which are not hosted on the same network? One way might be to have a shared secret in both services but I feel like that is not secure. Is there a better way or an established standard?
What are the best practices when using global variables? Normally, the common answer to this is to avoid using global variables and use local variables, properties and arguments to pass data around. However, I'm working with a domain specific language that does not support these concepts. In the language I'm using, th...
I have 1-20 agents that issue requests over time with roughly ~50 in total in flight at any given time. Many of these requests are identical. The tasks are idempotent, but if two identical requests were to evaluate in parallel, the evaluation is still costly even though the final results could be stored in a thread saf...
I'm developing a system in which a ClassA object can have multiple ClassB and ClassC objects. And for store these objects in a relational DB model I create the following tables: This is a simplified example of the real system. My problem arises when I need to update ClassA objects because I need to check if the modif...
As part of a microservice-based system design, I'm struggling to decide where system configurations should reside in terms of domain ownership. For example, let's assume I'm designing a "store system" where for simplicity I want to discuss the following domains that have today 1 microservice for: Orders Inventory Now...
You have n lists, each serves as a global dictionary. Everything else is handled via IDs that represent the index in the appropriate list. Typically, this is some type of integer. However, trying to access index i in list A when it is meant for list B would result in nonsense at best or a crash at worst. While I can us...
As far as I understand, the best practice for programmatic access to the version of a Java application is to: Specify version via build system (e.g. in Gradle). Include the version string as a manifest attribute in the jar file. Access it in application source code via class java.util.jar.Manifest. Is there a good wa...
I am currently planning a movie recommendation application. Within this context, the user can fill out a form including different information (e.g. title, description, etc.). The new entry gets then saved to an external database. Amongst those fields, I also would like to include a category input where autocompletion s...
I am struggling to reconcile some good recommendations, relating to the microservice architecture and Agile and DevOps, that are mutually exclusive in my mind. On one side we have the recommendation that each microservice should have a small, two-pizza team that owns it (e.g. see "Service per team"). This is the model ...
As we know that RGB monitors requires separates signals for red, green, and blue components of the image but television monitors uses single composite signals. For this composite signal use YIQ color model. But don't understand what's the significance of Y, I, Q components? Can anybody explain just the intuition rather...
I see there are many user stories that only contain Story Acceptance Criteria Where to put the detailed requirements? Is that unnecessary?
I'm tinkering with the new streaming plugin provided with RabbitMQ, and researching how to implement event driven architectures in general. I noticed in the default configuration (maybe I have it configured wrong) if I have one app consisting of two consumers - and one producer produces 5,000 messages that both consume...
Current situation Right now I have a method like Data lookupData(Key id) { std::lock_guard<std::mutex> lock(m_mutex); auto it = m_dict.find(id); if(it == m_dict.end()) { return Data::Empty; } else { return it->second; } } Problem However I now have a situation where, i...
It is quite common to separate C++ code into cpp and hpp files and to define the hpp files as the interface of the code. Therefore, when you use the code as a library, you can expose the interface, but offer the rest as a compiled library. It also allows to separate different components of the code in a way that one co...
I'm studying use case and activity diagrams and I get confused about the difference between activity diagram and the normal flow specified in the use case specification table, aren't both of them specify the flow of our system ?
I have a method, that takes a list of students, and returns the student with the best score. Part of me wants to call it Student getBestStudent(List<Student> students), but I think that get refers to the methods, that make a relatively heavy database/service calls. Here I do just simple filtering. Another part of me wa...
We are working on a .NET desktop application written in C# and WPF, that communicates with a REST API server. The software has a layered design and consists of multiple projects. One project for the presentation and ViewModels (we follow the MVVM pattern). One project for the domain layer. The business logic like serv...
I'm currently developing message imap-based module in crm app and i'm trying to connect dots using ddd principals. I've started with three main entities, all bound under Account Aggregate: Account - Email account. Has multiple Folders. Folder - Folder in email account (ex. Inbox, Sent, Draft). Has multiple Messages. M...
I tend to create a variable whenever I need an uncircumstantially same value as to that of an earlier value more than once (the values are not happening to be the same by chance rather they actually have to be the same). I think of them as the integration variables, as their particular value may have of no importance b...