instruction
stringlengths
34
36.1k
I have seen information that at least one of reasons why type placed before variable name is that it allows compiler easier evaluate size and type of variable. If so then how (what way) it eases this work?
Building on this answer here, and its comments it entails that subscribers need to know and locate the publishers in a traditional pub/sub system. It also entails that publishers need to live at least as long as the consumers. One of the most widely known pub/sub systems today is Kafka. However, in the case of Kafka, w...
I’ll try my best to explain, but for the closest context I could think of, imagine that I am building an analytics platform that allows paying users to sign up, place a tracking script on their website and track their website visitors’ data. This would mean anyone who visits their site would need to be able to make an ...
UML is generally taught as a standardized way of diagramming software, however, I've heard recently that there's an actual grammar behind it. I've searched the UML specification and haven't found much that was sufficient in terms of describing an actual grammar. Tools like PlantUML seem to have a text-based conversion...
This is just an example of an (still incomplete) real-world project written in Rust using a clean architecture: https://github.com/frederikhors/rust-clean-architecture-with-db-transactions. Goals My intent is to have an app build in 4 layers: entities: some call this layer "domain", not important for now, just the mi...
I'm thinking through adding a lazy-loading cache to my API. Currently, REST objects are filtered out (scoped) based on the user's role, and additional constraints in the system. Users of the same role may have access to different objects based on constraints made by administrators, these are accounted for in the db fil...
Consider the following python3 code: from abc import ABC, abstractmethod class Food(ABC): _food_factory_map = {} _recipes = {} @classmethod def getFood(cls, foodName): return cls._food_factory_map[foodName]() @classmethod def registerFood(cls, foodName, recipe): def callable(f...
I'm in a situation where we strive in different directions on how we should use user stories. As an example we have a Salesforce (and the user) requesting a document to be created, sent and archived and so on. The workflow is like this: SF -> Gateway 1 -> Gateway 2 -> DocGen The work is done by four different teams, de...
Domain context and requirements So let's say I have the following concepts in my domain: Company: it's just a bunch of data related to a company. Name, creation date, assigned CSA, etc. User: again, name, joining date, etc. Now the business experts come with a new requirement: we want to show a list of companies in o...
Reading this interesting paper it seems that a lot of performance loss is due to scheduling overhead in tight loops. To recap: There's a variable called "Chunksize" which determines how big of a chunk (amount of iterations) each processing unit (effectively a thread) will claim to later execute in private context. The ...
Situation Object MyObject needs to be sent to one of our downstream systems depending on the enum value of its field myField. public class MyObject { private MyEnum myField; public MyEnum getMyField() {return myField;} } For this we are using the strategy pattern implemented with lambdas, like so: public class Pro...
Based on the data structure of the AVL tree, I implemented a memory manager that does the best matching according to the size. I originally thought that the speed would be fast and the length of the memory heap would not be too large, because it was matched according to the optimal size. However, when I use the valgrin...
Say there is an user that wants to query a random element during runtime from a dynamic struct. The type of the data is unknown, but all the data is either a integer (size unknown), float, string, or vector of one of the aft-mentioned structs, and the struct implements the queryable trait, which mandates that the struc...
I want to understand what is the main difference in these two diagrams when it comes to the Model-View-Controller pattern. If there is a difference, how should I choose to construct my program? What conditions should make me choose the first design (or the second)? But I am not even entirely sure if they are different,...
I'm creating an application based on the microservice architecture and stuck on notifications microservice design. Basically it should be a service that notifies users about events happening in the app through multiple channels. Channel selection should be performed based on user preferences for particular notification...
The system I'm working on started as a small training project within the company I work for but quickly caught interest from management as a means to help to standardize the existing excel-heavy workflows. I'm one of the lead developers on the project, despite having no lead experience prior and only being in my third ...
how to support to vendor libraries. Apart from file changes, and APIs, the new version is 64 bit whereas the old is 32 bit What's the best design and implementation effort to support two version of a library. Lets call them Lib_v1, and Lib_v2. We want to reduce the amount of code base changes that call the existing 'L...
I'm building a mobile, in which the user is able to create,modify and delete entries in a database. There are multiple screen where some of the entries are displayed: (here are some examples, not exhaustive) Screen with the list of the entries Screen with details about one particular entry Screen with some statistics ...
I have an endpoint that returns whether a resource is valid or not (true or false): GET resource/{id}/valid Where the returned value is not a field of the resource and is dynamic, it does not depend on the resource alone but on other factors that can change in time, meaning that if I call it today and returns true, to...
Good software is always designed based on different modules before integration. I was wondering what rules/guidelines decide software partition into different, smaller modules during the design phase.
I have a function (written in Python) that processes a loosely structured log file. The log file would have begin-end markers for different sections, with each section describing different things (e.g., errors, assertions, warnings, property dumps, etc.). Sections could repeat for different operations or different obj...
I have a DigitalOcean droplet on which I have deployed a Docker container (Docker version: 20.10.14), but my app is sometimes slow, therefore I would like to allocate more resources to it. The droplet has 16 CPUs. When I run docker stats, I can see that my container's CPU usage averages 120-140%. When I monitor my drop...
We're designing the architecture of an embedded device (esp32). One of the tasks is that the device should connect to the internet and use a preprovisioned redeem code to register itself with our web cloud. Within the same message the device will upload a random generated password to the server which is then stored in ...
I realize this sounds similar to How is layer between MVC controller and back-end called?, but that didn't quite clarify the situation I'm facing. I have a backend system - for the sake of an example, let's say it's a company calendar system. The system has some core domain logic implemented in a service layer. There a...
I have a distributed platform which allows customers to make purchases, and the items which are purchased are stored in an inventory: Sales app -> PurchaseEvent -> Inventory app The Sales app raises the PurchaseEvent onto a message bus, which is asynchronously consumed by the Inventory app. This all works great. There'...
I have the following piece of code. Line 1 is a container (for simplicity, one can think of it as a list of elements e1, e2, ..., en). Now there is a function function_fun which takes as input an element ei and returns a list of elements. So finally we need to recursively keep processing elements from container and app...
I have a class Character who has a list of Spell objects that he can cast. abstract class Spell { name: string manaCost: number abstract cast() { ... } } class InvisibilitySpell extends Spell { ... } class FireballSpell extends Spell { ... } class Character { mana: number spells: Spell[] add...
What would make more sense, to use functions for exports/imports: // globals/helpers.js exports.fnOne = () => {} // features/user.js const {fnOne} = require() Or class-based approach with static methods? Same question goes for features development. Should I create functions within user.js and export/import them in my...
In the picture above class of the type implementation will at some point receive a class of type C1. Classes that implement Contact will at some point hold references to C1. So should the diagram be more like
I have simple wrapper class around C-style array. I don't want to use std::vector since I want to have only one array even if I do copy of the struct. With std::vector the vector is also copied. struct RawDataArray { double* data; size_t size; static RawDataArray CreateNew(size_t size){ return ...
I have the following Supabase db structure for my web app Project -> Stage -> Logbook A project can have many stages (stage has a foreign key for project) A stage can have many logs (logs have foreign keys for stage). Now, in the UI I need to be able to show logs in terms of a selected stage or selected project – I'm...
When reading through the ECMAScript specification, I noticed, it actually never mentions concepts like "pass by value" or "pass by reference". When looking at the assignment operator, this is how it is specified: An expression like let a = 4 would lead to path 1.d. Which basically just sets the value of 4 to a. But sa...
I'm building an app where I need access to quite large reports about different publicly accessible URLs, JSON objects about 200kb to 500kB in size. Each user would generate hundreds of these reports per month and I would need to store them for some months at least. First I thought I'll just write them into to my Postgr...
As an individual developer, I often find need to write a trivial (let's say, under 100 SLOC + tests + docs + build system config) library that helps me to write code of some other (large) project in a simpler and more readable way. The libraries are unrelated and often simply add some feature that was missed out in som...
Kind of a yes/no question, if so, how? If the customer is unsure of his requirements and keeps changing them, on what basis are the software testers supposed to test the software to assess its quality? Is it even possible to test the software?
I am wondering where do I need to put email delivering logic in DDD applications? I have the impression that it is in presentation, because it is showing stuff to users and the domain usually does not care about whether the data is presented through a web application, mobile application or email. Though the channel mig...
Here's an interesting scenario, consider a cache with many buckets, and resources that can be shared between buckets: Bucket Highest to lowest priority Foo A, B, C, D Bar B, C, D Baz A In the example above Foo and Bar share the resources B, C, D; Foo and Baz share A; and Bar and Baz share no resources. ...
I'm trying to understand the best practices of Github Actions when splitting a workflow into multiple jobs. First of all, is it generally a good idea to split a workflow if the steps are logically indepentent? The most classical example, let's take a project with a build, a test and a deploy step. Is it generally bette...
I have a base abstract class that have many methods, and multiple subclasses that extends it and implementing the methods. I have another type of subclass that need to wrap the subclass and extend some of its methods. Example: abstract class AbstractClass { item: Item; constructor() {} abstract setItemType() ...
I am trying to explain and understand a way to create object which cannot have "default" instances. Typically I want classes which represent, as closely as possible, the real-life concept I am attempting to model in software. What I mean specifically is, if it doesn't make sense to create a "default" something in the...
Assume I have a set of nodes of an n-ary tree, packed in a dense array in depth-first order. This tree (I'm showing links between each parent and its list of children): [A] | [B]--[E]--[F] | | [C]--[D] [G] would be arranged in an array as [A, B, C, D, E, F, G]. I'm working in a memory-constrained ...
I have around 6 years of experience in SharePoint, ASP.NET MVC, ASP.NET Core MVC & SQL Server. Now when I want to take a decision, if the project should be implemented using SharePoint/PowerApps or using SQL-Server/ASP.NET-MVC, is the complexity of the relation between the entities. The less complex the more I go with ...
I've started working on a LoB application (as a learning exercise) while trying to express business logic with use cases from Clean Architecture. First use case is customer onboarding where client can enter their company name, their email address and password. Use case should do the following with provided request: Cr...
Most useful or reasonably complex applications need to save data such as user settings or saved games or browser history. I have been working on applications and games in C or C++ but I am not sure which of several ways to access files to use. First the preferred location to store such data is queried. On Linux this wo...
Currently, I'm involved in a research project in which we are evaluating an existing web environment providing a safe online playground for children/adolescents with intellectual disabilities. Certain areas of this web application require identification of the user to allow the content to be aligned with the user's cap...
Our platform is growing in the number of events we're raising, and these different events are often related to one another: ProductCreated ProductUpdated ProductTakenOffSale ProductPutOnSale Guaranteeing order of event consumption on a single topic isn't too difficult, but when you're faced with multiple topics like th...
Consider a web-app with 5 micro-services deployed with Docker, and a MySQL container dedicated to storing data produced from other services (shared-database pattern). How should I make the connection between the MySQL container and other containers? Currently, I am converting a monolith application software into micro-...
I'm doing a running time analysis using the aggregate method and I'm a bit confused about what would be the result in this case. I have some intuition in inferring that it would be O(mlog(n)) but I'm not sure
In our team we have up to 50 repos, of which about 15 are worked with regularly. The others are rarely changed, but it happens that we bring in 1-3 additional repos per release and work with them. We release a new version about 5-6 times a year. Although we have a lot of code split up into many repos the product is bas...
When writing a program that uses a working directory, e.g., PostgreSQL data directory or download target for wget, is there an advantage of having a CLI argument (or an environment variable) for such a directory? If the program doesn’t use any other path for its business, isn’t the current working directory enough, or ...
In the Design Patterns: Elements of Reusable Object Oriented Software, the Gang of Four present the following canonical form for the Builder pattern: In Appendix B the following is mentioned regarding notation: Slanted type indicates that the class or operation is abstract An object reference representing a part-of o...
I've got a backend running on Node that executes queries on a PostgreSQL database. For these queries, table and column names are imported from a .env file, for example: const ID = process.env.ID_COL; const USERNAME = process.env.USERNAME_COL; const USERS = process.env.USERS_TABLE; ... const query = `SELECT ${USERNAME} ...
I am currently trying to design some C++ classes that encapsulate POSIX sockets and their relevant functions. I want to try and design classes that are simple, elegant, and make the best use of design patterns and inheritance. Starting from the server and client side sockets we have the following functions POSIX functi...
I have the following code in C that reads data off a char array and makes decisions on what variables should some pointers point to. char preset1[20]; char preset1Name[20]; int preset1Temp; int preset1ETemp; char preset2[20]; char preset2Name[20]; int preset2Temp; int preset2ETemp; char preset3[20]; char preset3Name[20...
I am using spring boot with mongo db (azure cosmos db) in my microservices. Currently I have an Orders collection that stores Orders. These documents have a field userId that is null when the document is created. Afterwards, a request is made from a user to assign a order to him and this field is populated. The issue i...
I want to start developing a long-life ERP system to a customer. now on paper I would chose to develop it using .NET core 6.0 with SQL Server. But one of the main drawbacks which the customer did not agree on, is the short support life cycle for .NET core framework. where each 3 years a new version of the .NET core wil...
I ran into a modelling problem while solving an assignment of mine. Say I have json string that I need to parse, process it in some way and serialize it back to json. The problem is this json contains arrays that hold different types of variables: strings, integers, booleans, decimals and formulas expressed as strings....
I am implementing the Publish-Subscribe pattern. I have class Broker and interfaces IPublisher, ISubscriber. interface IPublisher { broker: Broker; publish(channel: Channel, data: object): void; } interface ISubscriber { notify(channel: Channel, data: object): void; } class Broker { channels: Map<Chan...
Coming from languages like C++, Java or PHP I've learned that there are Value Types and Reference Types. Value Types store values directly in the variable (in a box / memory location). Whereas Reference Types store a reference to an Object in memory. This makes perfect sense and seems like a simple mental model to deal...
I'm looking for some resources on learning how to best manage our software releases in an efficient manner, as our current method slows release schedules down. My current team produces and administers industrial machines that (computer-wise) consist of at least one PC, running several custom software components that co...
None of my team's programs care about multithreading, parallelisation, async, or anything else that benefit from immutability. However, immutability is clearly in fashion at the moment and I'm starting to believe that it assists readability. We typically use C#, but I don't think that's relevant. If in a code review I ...
I am working on machine learning project. I use jupyter for quick prototying. Now I am trying to convert it into concrete python project using clean architecture. entities/ - problem.py # contain type_name can be regression or classification class Problem: type_name: str usecases/ proble...
We are often told to avoid sharing business data across service boundaries. However, I tend to see the need for a service to access data from a different service. An example of this would be IT functions needing to access employee position and corporate structure (i.e. the managerial ladder) - this information is typic...
I'm building a DDD application which is effectively a wrapper around Cognito. As such, everything that this is doing is effectively just a call onto the Cognito SDK. Where I'm getting confused is how this should work with respect to Domain Services or Repositories. I've got an Aggregate to represent a User. I then have...
From many articles and answers on DDD Repository pattern, I got the feeling that a Repository should only CURD an Entity (Aggregate Root) as a whole. Following this convention, we always need to query the database to get all required data to construct an Entity. Following is an example implementation when you want two ...
Recently I encountered an issue at work where a unit test written in C++ would crash only when being compiled with MSVC 2017 (MSVC 2019 and up are fine). I tried to debug this issue and it seems like a compiler bug causes memory corruption (e.g. the stack of a thread became corrupted at some point: the return address o...
I'm trying to design mediator micro-service which will have around 20-30 different http requests to an external vendor. My general high level thoughs are on creating a BaseService class which will implement the Template Method pattern where each inherited class will be responsible on specific call, with its own request...
I'm very new to microservice architecture. In the Monolithic app structure, it was pretty straightforward to write test cases since everything was in one app. I have a situation where I manage a microservice (built on FastAPI) that stores only the users with different types like company, admin, student etc Then there's...
Part of my current product uses GPT-4 with a prompt to extract information from plain text. As behaviour of large language models is inherently opaque and failure cases unpredictable, I was wondering how standard software engineering practices translate into working with generative language models such as GPT-4?
Who among the two is responsible for validating the software when testing it? Or is it a joint effort? On the one hand, the software developer is responsible for ensuring that the software is built to specification and functions as intended. On the other hand, the user knows how they will use the software in their part...
Suppose you have been put in charge of an already existing project. As you are starting to familiarize yourself with the repository, you notice a few technical debt issues (insufficient test coverage, conflicting standards, missing documentation, etc). As someone who is going to be working on this project and maintaini...
I don't have enough experience to understand how hard object instantiation and garbage collection really hit. So I tend to write code where I don't just spin up objects for the sake of it. However, now, where I work, hexagonal design is non negotiable, and at face value, I don't mind. It makes life rather early. public...
In some languages such as Python, the order of keyword arguments in function calls does not matter. But is there a best practice for it? For instance, suppose that a function's signature is def foo(bar, baz, qux). foo(bar=3, baz=8, qux=9) is of course the same as foo(qux=9, bar=3, baz=8). But isn't the former easier to...
I am currently trying to follow the clean architecture approach but i wonder where common things like a database connections should take place. Since i think a database connection usually will be opened once, but different tables in there are used from feature to feature in different ways, it wouldn't make much sense t...
Where should I inject the dependency when I write a class? Should it be given to __init__ or to the specific method that uses the dependent object? Take the below two pieces of code for example, to me they function exactly the same way: class TextFile: def save_text(self, text): print("Below texts saved to ...
I have a piece of code where two objects (incoming request object and a profile object) are to be checked for matching conditions. So the first method is as below where I check whether the profile object will be applied to incoming request : public Response apply(Request request) { ..// some logic Prof...
I will have multiple cellphones playing videos in an art gallery. The video content must be synced to the lights, which are synced to the real-world clock. As in, at 1:00pm the lights go out, 1:15 they turn orange 1:30 they are bright, 1:45 they begin to dim, rinse and repeat every hour. I figured I would point the pho...
say I have this code which is a chain of public methods, public_c calls public_b calls public_a def public_a(...): ... def public_b(...): ... public_a(...) def public_c(...): ... public_b(...) Should I test all 3 methods individually? Part of me thinking if I test public_c then it "sort of" als...
We have an event booking system that allows patrons to add themselves to a waiting list if an event is fully booked. When somebody cancels, the system moves the first person from the waitlist into a booked status. Currently, this is implemented as a stored procedure that locks the table to avoid someone slipping out of...
I have recently encountered this problematic method (minimal reproducible sample in C++ but this question aims to be language agnostic past the syntax): void MyObject::twice_bind_cycle() { _bind1(); _bind2(); _activate(); _unbind2(); _unbind1(); } This entire method interacts with an API as do the ...
If you can have one event with multiple "things to process" or one event per thing to process, what is considered the best practice? Bearing in mind, the former option may involve persisting the payload in a DB (because it's too big) whilst the latter may mean 1000s of more events, but I'm unsure of the real disadvanta...
I have a java class with an init method. It's different from the constructor. The constructor just initializes the variables/fields. The init method connects to a database and performs some verifications on the database + it kick starts a background thread which handles incoming requests. If you wanna think of it in ps...
The Kotlin language brings the simplification of function calls to the natural language. This article shows a nice example: Function: fun of(suit: Suit) = Card(this, suit) val card = Rank.QUEEN.of(Suit.HEARTS) Infix function: infix fun of(suit: Suit) = Card(this, suit) val card = QUEEN of HEARTS AS a newbie to ...
I have this two tables: Documents(ID, IDTypeOfDocument, BigIntReference); I have a documents table that has and ID that is an autonumeric bigint. Also I have categories, and also it has a big int as reference that is unique for category, but for two categories, I can have two documents with the same reference, one fo...
I want do develop an IP based protocol oriented to smallest possible data overhead. For example UDP adds overhead of 8 bytes header. I want zero header. I will use this protocol via 2G mobile network where every byte is paid. For example 8 bytes every second makes 252.288MB per year. With 0.1 Euro per MB that's ~25 eur...
in our company we have some APIs that return some JSON data. Before sending, for instance, data to the backend using PUT, PATCH, or POST, we need to do some kind of validation in the different clients (web, mobile apps, etc). Right now that's a ton of duplicated work, so we would like to start using JSON schemas for ou...
I am building a web application where a user logs in, and uploads a CSV file with employee data to S3. This is an example of the format of the file. id name country age 3243 John Doe USA 48 Using this data I want to provide a webpage showing simple bar charts for employee count, along with a filter for dime...
For example, keywords have a special prefix. Objective-C has @interface, @implementation, but that's for compatibility with C. It inherits all the C keywords of course, with no @. How about a language in which all keywords are prefixed with a special character? It will only save the lexer some trivial trouble, but the ...
I have an employee that has to record the time when it starts to work and the time when it finishes. This records can be associated with a proyect or not. Project could be null. The proyect has an ID and a proyect number. The employee gives the proyect number, not the ID of the proyect. So I was thinking in this code: ...
I have two microservices, one Flask (python) and one Spring (java), they currently share a database. The Flask microservice handles processing json files (~40mb) for each user (could be 100's or 1000's of users per day) and adds the processed data to a Postgres DB that is shared with the Spring microservice. The Spring...
I'm trying to understand what they really are, but I can't understand how to use them. MAJOR version when you make incompatible API changes. What is incompatible API changes? MINOR version when you add functionality/features. Examples of a new functionality or features? Sorry for the noob question.
Suppose today I'm designing a new application that will employ asymmetric cryptography to allow users to securely exchange data with one another. As far as I can tell there are no quantum-safe algorithms yet generally accepted, let alone that are ready to be used in production. (Please correct me if I'm wrong!) Thus I'...
Why is there a such thing as import in programming languages? If a package does not exist, then trying to import it would cause an error anyway. So why don't languages just auto import ALL available packages? Instead of requiring programmers to have 'redundant' import statements?
I was asked to review and handle merge request for a code base, which has been contributed by dozens of programmer with basically no regulation (or perhaps there was but nobody follows), so I set up executable regulation, making clear details like formatting, naming rules, how you should build control flow etc. Things ...
We're currently exploring CQRS in our future applications. To give a bit of a background, we use a simple CRUD-style service before something like this. Old Pattern: Controller Command/Service Model Then the validation logic is inside the model like ValidateSave(SalesOrderModel), ValidateSubmit(SalesOrderModel), Vali...
Note: I'm talking about Amplitude because it's what I use, but it's probably the same with any stats tool. Amplitude, because of its very nature, is insufficiently secured. Stats are the value you get out of Amplitude. A user makes an action, this action is sent to Amplitude and has an impact on the stats. This means t...
A Composite delegates calculations of unknown depth to a virtual method. A Chain of Responsibility passes events to an arbitrary deep line of handlers. Sounds the same to me. What am I missing?
I am working on a fairly large project written in PHP (Yii2) in which we are increasingly using cron for background tasks, such as generating caches, reports, etc. We have started to move the hourly timings by a few minutes so that they don't overlap, but I don't know if this is a good idea. Besides, I have noticed tha...
Is there a programming principle/guideline that tackles the correctness of a implementation beyond the methods signature contract of an interface? Let's say we have a repository interface with two implementations, one of them is in memory, one of them is a database The in memory one implements the interface with a list...
I've been building a traffic simulation with C++ following the Intelligent Driver Model from this article: https://towardsdatascience.com/simulating-traffic-flow-in-python-ee1eab4dd20f To sum up my implementation: The map is divided into 2D grid of Tile(s) Each Tile has a list of Road(s). For the sake of simplicity, n...