instruction stringlengths 34 36.1k |
|---|
I will explain my problem in the form of an example.
Suppose we want to use both databases in a transaction.
Data is edited in database 1 (for example, Postgres) and then added to database 2. Finally, we want to commit the changes (uow.commit()).
It is possible that the first database is committed and a problem occurs ... |
We are beginning to add third-party integrations that all have to do with a certain business concept. (If it helps to make things concrete, in our case it's "measurements," i.e. third-party partners that track whether customers have visited websites, downloaded apps, etc.)
Tech-wise, each of the third-party integration... |
I have a large C++ project I'm hoping to release publicly soon (it is currently an internal development at work).
We have a large auto documentation setup which uses doxygen and sphinx, however our documentation includes many images (useful as our tool deals primarily with image processing, geometries, and rendering).
... |
Background Information
We have a .Net core application that uses Hangfire (pretty version of cron) jobs to batch process different types of data.
As a bogus example, we have one job that will run every 30 minutes to query an external source to get a list of products and saves them into a local database. (for discussio... |
I'm currently trying to build a very simple application for handling OpenID Connect using the library Openiddict. This library lets me construct the access_token and the id_token and lets me set which claims/attributes to include in which token. And this is the part that I cant quite wrap my head around.
Which type of ... |
There are many packages for creating bindings of a library that's written in one language to be called from another language. Some programming languages also include such interop in the standard library, e.g. Julia can call C++ code without having to write manual bindings for it.
With more languages becoming interopera... |
I am writing a Windows Service using the Windows Background Worker Service template. Some data that I track needs to persist between application instances (i.e. after shutdown and restart).
Initially, I saved this data into the app.config.json file. However, this involved clobbering the file. Normally, this wouldn't be... |
Given a state machine that implements a certain protocol. I need multiple instances of this protocol running, so I create multiple instances of this state machine. Each instance is associated with a certain key. The state machine itself doesn't need to know the value of this key in order to do its work (state evaluatio... |
What is the recommended approach for managing platform components within our internal JFrog Artifactory? I am currently facing difficulties in defining the appropriate structure.
As an example, we are downloading the open-source Apache NiFi image and storing it locally in our Artifactory using the following URL:
https:... |
I was reading the excellent book by Axel Raushmayer, Tackling TypeScript.
In this section of Chapter 7, the author makes the interesting claim
In many programming languages, null is part of all object types. For example, whenever the type of a variable is String in Java, we can set it to null and Java won’t complain.
... |
I have a state machine that, as a side effect of going into a certain state, sends a message to a remote server. In some situations, however, I don't want the state machine to send that message, even if it ends up in that specific state. The state machine itself doesn't know when such a situation occurs because that de... |
I'm working on an app I created for myself using the MVVM architecture. On my ViewModel I have a list_items that, when changed, updates the corresponding UI element on the View. The list of items depends on the state of other UI elements. Right now I have this method on the Model:
get_list_items(arg1, arg2, arg3)
Wher... |
I've recently joined a new company and they've been experiencing some issues related to their branching strategy which causes untested code to be released inadvertently.
We have three branches of interest:
main: this is the branch we release from
develop: this is the branch that contains code that is yet to be tested ... |
I am writing integration tests via unit tests by using Xunit. (the specific testing framework is not set in stone, Xunit is being used simply because it has been used before in this project team)
The integration tests will test the workings of an API that facilitates certain operations on AD accounts. We will be given ... |
this is my code:
System.out.println("--------------------------");
if (person instanceof Student) {
Student studentPerson = (Student) person;
System.out.println("GPA: " + studentPerson.getGpa());
System.out.println("Major: " + studentPerson.getMajor());
System.out.println("Year of Graduation: " + studen... |
I’m evaluating different options for communication between C# applications. My requirements are:
Central server where clients connect
Persistent connection, server should know when clients connect/disconnect.
Server can broadcast messages to all clients
Server can send messages to individual clients
Clients can send m... |
I got a few questions about using UML state machines in software architecture:
I have to design an STM and express it as part of a UML model. There is a singelton STM Maintainer holding the instance of the STM and performing state transitions. There is also an STM User class, reading the value - the currently active s... |
From my conversation with @Steve in the question Is there any philosophical theory behind the concept of object in computer science? on Philosophy Stack Exchange:
Steve: More often than not, programmers haven't in fact been equipped to understand how things work in the real world - not even their own computers, let al... |
Event-sourcing often implies to have one row per aggregate id :
event_id
event_type
entity_type
entity_id
event_data
102
OrderCreated
Order
101
{...}
103
OrderUpdated
Order
101
{...}
This is perfectly fine, since it allows for an aggregate to be rebuilt by applying all events for a specific entity_id
But ... |
I have a class that has dependencies that I know are not going to change.
class ConversationFinder
{
public function __construct(
protected Conversation $conversationDbFinder = new Conversation,
protected ConversationMessages $conversationMessagesDbFinder = new ConversationMessages,
prote... |
I feel something is wrong with my approach handling MVP and the Repository Pattern. I'm making an album winform app just to practice MVP, crud and the Repos. Pattern.
First some code.
The model:
using System.ComponentModel.DataAnnotations;
namespace Models
{
public class Album : IAlbum
{
[Key]
... |
I have some incoming request - it's an instance of class generated from api specification - POJO with public getters/setters.
I would like to normalize some values. For example dimensions (to use metric system).
I have a service class which has method processing incoming requests. First I would like to normalize the re... |
I (unfortunately) work in a large German corporation, in a department where the codebase is up to 20 years old, written in C++ (actually more like C with the occasional classes, since most developers used to be electrical engineers).
We have a requirement to adhere to certain security standards (which ones exactly I am... |
This well-known article criticises Java on the basis that it does not allow you to write functions that do not live in a class. This flaw forces you to write classes with names that look suspiciously like verbs, such as GridCellHander or GarbageDisposalDestinationLocator. In other words, it looks like you've built a cl... |
I have a form. It contains things like grids. Users do things with these grids and what they do with them is sent to a SQL server. Clearly, the server is a volatile dependency and should be dependency injected.
Of course, it would be silly to have the form know about my business logic, so all of the business logic to d... |
In my little WinForm app, intended to practice as a hobbyist, I'm using this code to pass data from the View to its Presenter:
public event Action<object, string, string?>? SearchInAlbums;
private void Btn_SearchInAlbums_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(cmbSearc... |
I noticed a huge portion of software apps only support Windows and not Mac or Linux. I understand that there might be an API that they're using that only exists on a certain system. In this case, why don't programmers use cross-platform APIs instead, that have portable frontends that interact with non-portable backends... |
In C, such as in many POSIX structures, the structure members are prefixed with an abbreviated version of the structure such as:
struct passwd {
char *pw_name;
char *pw_passwd;
uid_t pw_uid;
gid_t pw_gid;
time_t pw_change;
char *pw_class;
char *pw_gecos;
char *pw_dir;
char *pw_shell;... |
I'm and entry-level developer straight out of college. I am the only developer at this company.
I feel the challenges I face are different to most people working with sub optimal or very poorly written code, because I am not only not part of a team, but also entry-level, and have no documentation, or tests.
I've been t... |
There is a string field x, contains value a/b/c/d
The order of a/b/c/d is changed infrequently , only once a year or several years.
What is the best approach to store this config?
Currently , it's being put in config file and there is discrepancy between prod config file and source control.
edit 1 : I didn't share my t... |
It has caught my attention that both arguments of fopen are both restrict-qualified. It's been that way since C99.
What does this achieve?
If I have:
const char *path = "foobar";
const char *mode = path + 5;
FILE *f = fopen(path, mode);
is the behavior undefined, since the mode pointer accesses
something which is als... |
Aside from modes, Antlr grammars can use "actions" which have to be written in the target language, sometimes seen used to conditionally push and pop from the mode stack.
If I were to make a parser generator, how should the lexer be stateful? Specifically, if I want to accommodate all mutations that rightfully belong i... |
I've been a software developer for 20+ years, although it's been an unusual career. I've mostly worked on either legacy projects, or small standalone, non-public-facing apps and so only a couple of times has it been mandated by my employer to include unit tests in my work.
To be honest, I struggle with the whole conce... |
I have a class file Settings.php that loads an ini file and assigns the content to a constant for global access and reducing clutter. The class file contains the logic for loading the settings and define the constant (sorry for the large sample didn't see a way to compress this:
<?php declare(strict_types=1);
namespace... |
Say you want to test an update capability across a CRUD api.
Test A updates a field, queries it, and asserts that it now has the value from the update. Knowledge about the starting value (and that it differs from the test value) comes from the way the initial data for the field is prepared: it is done by an utility com... |
Two recent failed projects in my career involved trying to implement a discount/promotional offer system for retail. For example, a retailer may want to offer discount codes in emails or newsletters, or offer special incentives to order on a holiday.
Each use-case seems simple enough to implement. For discount codes, f... |
Edit based on responses so far
I am starting with an edit so as to save future contributors from going down the same path others have.
I am only interested in contributions that stick to the exact definition of SRP I have quoted below. So no “you can think of SRP as…” type elaborations, as that takes away from the obj... |
I'm wondering how i can implement what Im calling "business policies" in my code? For discussion purposes, let's say I have two separate contexts - synchronizeUsers and Licensing.
The synchronize users bounded context is a downstream component that connects to a Open Host Service, gets a list of changes to users, persi... |
How should I design a relational schema to store graph documents that can contain plain nodes (shapes, in the example below) as well as nodes that can reference other graph documents?
To visually describe the data I'm storing, consider document A with three nodes, two of which are shapes and one is a reference to docum... |
The context, or bounded contexts, it could be defined as a logical boundary of a domain where particular terms and rules apply consistently.
There are another definitions but more or less, this could be a star point.
According to that. Supose that I want to manage the order of the clients. In this case I would have a b... |
I was looking through the prettier docs and the prettier source code. It essentially has those defined helper functions to layout the text, given an AST. It operates on the level of the whole file, on many elements next to each other. It takes the AST and outputs text, not outputting a modified AST (like ESLint does).
... |
I have an app that has an assets table like the following:
user_id
code
current_price
1
ALUP11
12.5
2
ALUP11
11.9
user_id and code are unique together and current_price is updated if the user triggers a task that fetches the values from another service. I'm also using CQRS so when this task finishes it up... |
Domain Object, while not necessarily a design pattern, can at least be considered as a design "concept", and one of its points is:
https://wiki.c2.com/?DomainObject
Domain objects should not direct their persistance. They don't know how to be persisted and even if they will be persisted. The infrastructure layer is th... |
In C and C++ we need to declare a function before its usage, if its definition comes after where it is called. (Well, there is also the "implicit declaration" rule in C, but it is rarely used.)
However, in more "modern" languages functions defined later in the same module are implicitly "declared" (or has the same effe... |
I have some doubts about the state pattern, but I think it is better to ask one question at a time, so it is easier to focus on the answer.
The state pattern establishes which actions can be performed according to the state. So, if the context is in state A, I can perform actions 1, 2, and 3, for example.
However, my d... |
I want to allow some Java objects to be translated into a string representation which matches Python or JavaScript objects.
I thought that I could tag all compatible classes with compatibilising interfaces:
public interface Pythonable {
public String toPython();
}
public interface JavaScriptable {
public Strin... |
I have a project with various bounded contexts. I have Purchases bounded context and product bounded context.
The two projects are developed by two diferent persons, so I am organazing the projects in this way:
MyProject.Products.Domain
MyProject.Products.Repository
MyProject.Products.Comun
MyProject.Products.Appli... |
This is something that I come across fairly often, and there are a couple ways to proceed, but never know which is the best way. I usually pick one way at random. I'm looking for a framework that I can apply each time I am faced with this problem.
The problem is this:
I am working on a bug. In this case, the bug is due... |
When creating the crud GET methods to get a list of items, or the details, what should I return? The whole object properties for both cases? Or just the properties that are necessary? I'm asking this because it may be related to a future api that I call to change some of the products status.
For example, imagine the fo... |
I have a Java Spring boot microservice in production which supports multi-tenancy and the tenants are isolated at database level. This microservice exposes REST APIs for communication. During a request, the tenant ID is passed as a header which is read by the filter and is put in ThreadLocal as a Tenant Context.
One of... |
I'm currently working on a Turborepo project (monorepo architecture) and I have managed t share my locales files to both back-end and front-end parts.
This means I share the exact same keys across those 2.
When coming to internationalization, I've asked myself few questions and came to these conclusions:
Server sendin... |
I have 3 classes
class Backup
end
class Database
end
Class App
end
The backup database has a reference to Database and App, like
class Backup
def getDatabase
Database.create
end
def getApp
App.create
end
end
Similarly Database has a reference to App.
Practically, If I am creating a backup object, i... |
I have two npm packages that build on top of our core software platform. Their core functionality is mostly different, except for how they serialize data. This is and will predictably stay identical for as long as these systems operate. The code for serializing said data is very short (~200ish LOC), so the dilemma I'm ... |
I am using the c language. I created one lifeline for each file. I am confused about the activation box. Many people said an activation box indicates an object is active and processing a task. In case of c language, can I say an activation box indicates a function is running?
For the example below, is my UML sequence d... |
Let's say that I have a Parent class and a Child class, Parent relies on Child to perform, say, some network request:
class Parent {
...
public init(){
const child = new Child();
const stuff = child.fetchStuff()
}
}
class Child {
public fetchStuff(){
const stuff = fetch("blah blah");
return ... |
I need to be able to track users' time spent on the app and on each page (based on URL).
I have a visits table that logs the users' page visits (by URL) and time spent.
The time spent is done using JavaScript that tracks activity on the page.
The DB table has the following structure:
id
user_id
page_url
visit_start... |
We are going to have multiple microservices and decided to use api gateway. What we couldn't decide is if we should go for a single gateway for all of them or one for each. The reason why one for each is considered is having all api routes for all services in a single gateway feels like it's creating more coupling betw... |
For example, many dating apps are limited to only certain cities of the USA. Or, they launch first in only regions and then may be unlocked across the country.
Why the restriction?
Why wouldn't you want your app to be used by as many people as possible?
|
I'm very new to DI, and must admit, am having a hard time understanding to what extent it should be used in an application.
Even in a basic project, you can have hundreds of classes that have constructors which take in one or more dependencies. Should all these types be registered by your DI container? or only the root... |
My code looks roughly like
40 def send_pubkey( s: socket ) -> None:
41 '''Transmit own public key unencrypted.'''
42 _, pub = crypto.read_keypair()
43 s.sendall(pub.save_pkcs1())
This... |
This seems to be a commonly encountered and brought up code smell, and is a common feature in multiple coding design books which I wasn't fully able to understand.
Say I have a function
def train_model(model,useSGD,initWithZeros):
if initWithZeros:
model.initWeights(method='zeros')
else:
mo... |
I'm working on an AspNetCore application, with a requirement to raise and handle certain events asynchronously using an external event queue. I'll use AWS services as examples here because that's what I'm using, but this would apply to any queue infrastructure.
Here is my design for connecting my external event queue. ... |
According to the standard ISO/IEC 25010:2011, the "quality of a system is the degree to which the system satisfies the stated and implied needs of its various stakeholders". The standard defines 8 categories of quality characteristics:
Functional Suitability
Performance efficiency
Compatibility
Usability
Reliability
S... |
While I was learning functional programming I have encounterd two for me very similar terms: immutability and persistence. Also I have read simular questions from stackoverflow, but I am still confused.
Wikipedia says:
In object-oriented and functional programming, an immutable object (unchangeable object) is an objec... |
I'm reading the book The Secret Life of Programs by Jonathan E. Steinhart. In it, he mentions in passing:
many consider the handling of whitespace in Ruby to be a replay of of a mistake in the original C language that was fixed long ago
What mistake is that?
|
I've seen a variety of discussions talking primarily about the question of the difference or not between the Repository and Data Mapper persistence system design patterns; but I think I have a decent understanding now - Data Mapper, as the name describes, simply maps objects in/out of a database, but Repository can inc... |
I am contemplating the use of the design pattern API Gateway, specifically the Backends for Frontends derivative.
We have a number of 3rd party software packages that expose an API. Over the course of the past few years I have been creating custom APIs as wrappers for the functionality of these 3rd party APIs. These fu... |
Consider a class that follows the obfuscated function call anti-pattern. I've also seen these called "stupid classes". The definition of such a class is that it only has one public method and one public constructor. As the name suggests, such classes should "just be a function". For illustration purposes, here is a suc... |
I am not sure if I have been using the term wrongly (and including it in my CV), so some inputs from the community will be appreciated.
I am not a DevOps, but a noob machine learning engineer. So I basically developed certain pipelines to perform batch processing jobs to automate stuffs like
Read raw data from a cloud... |
It's rather common knowledge that aggregate root provides an interface for every state change within that aggregate. For instance, aggregate root checks some business rules before some dependent entity is modified.
Now, according to Microsoft guideline for API design, URI /customers/1/orders/99/products should be split... |
I have an angular SPA that runs in an office add-in (word) that I need to authenticate against Azure AD using Oauth2, consume resources from multiple apis and make graph calls. I have been successful doing this in a standard web app but not with the introduction of office add-ins and using the office dialog api. Curren... |
The CppCoreGuidelines contain the following:
T.65: Use tag dispatch to provide alternative implementations of a function
[...]
Example
struct pod_tag {};
struct non_pod_tag {};
template<class T> struct copy_trait { using tag = non_pod_tag; };
template<> struct copy_trait<int> { using tag = pod_tag; };
template<clas... |
A common scenario I have is this:
I download a new codebase. In order to have me understand the code, I need to litter it with my own comments about what each section of code does.
It seems inappropriate to then push these messy comments back upstream.
So now I have a problem: my own codebase has a bunch of my own note... |
In my work, which is a UK university, we currently have no specific way of recording and tracking business logic and rules as they arise from stakeholders for our in-house software projects.
We use Agile Scrum and put things into the usual product backlog items, etc. but the logic is often clouded in multiple different... |
Context
I'm designing the software architecture of a safety critical software written in C, under DO-178C (DAL A) and with a Code Standard based on MISRA-C 2012, but no fully compliant.
It is the first time I do this, and I don't want to fall in design issues that could be avoidable in advance.
Program description:
The... |
I want to achieve user authentication and keep state with cookies between client and server.
Webapp runs with domain1, backend runs on domain2. I am having lots of trouble letting session cookies be exchanged back and forth between the web app (the browser) and the backend, because of the different domains.
I have to ... |
As a fellow SW developer in EU, I hope that you know that there is a proposal for a new law, called Cyber Resilience Act, that will, if approved, will affect all digital products on the EU market.
In the proposal there is two annexes, I and II, that contains requirements on the product and the development of the produc... |
In C#, it's possible to create a strictly sealed set of classes that inherit from a base that cannot be further extended like so:
public abstract record MyBase
{
public sealed record A: MyBase;
public sealed record B: MyBase;
public sealed record C: MyBase;
private MyBase() { }
// My base props
}
... |
I hope this isn't too off-topic/opinion-based, I'm new here.
I want to pass three elements of the same type into a function. The three elements are unique cards of a deck of cards, so they're not intrinsically connected (unlike, say, the coordinates of a point). The array or tuple will only exist for the sake of compar... |
I'm not sure if I misunderstood these codes. First Alice generate her keypair and sent the public key to Bob. Then Bob uses the parameter in the public key to generate his keypair and sent the public key back to Alice. So Alice can generate a shared secret based on Bob's public key and vise versa. Here's the question, ... |
I am fond of writing Streamlit applications (when a front-end is needed) and fastAPI backends when I just need a REST API.
I've seen many blog posts where these two are combined - with the Streamlit app basically just querying fastAPI endpoints as needed.
But I'm unclear on the benefits? If I am writing a function:
def... |
While researching the topic of Coupling, I still have a little misunderstanding about what counts as less / more Coupling. I will take as an example two options for setting delegates in Unreal Engine C++.
Example One:
We wait for an entrypoint and get the owner of our component. Hoping that this owner is not nullptr, w... |
I'm writing a script for a webapp, which I can only copy my code manually to its platform and not push it from my machine. In the code there are parts that use its API and parts that don't. I cannot split it into multiple modules as well. Everything should be on one file.
To be able to debug it on local, I need to chan... |
I have a function that looks roughly like this:
async function getValue(connection: Connection): Promise<number> {
const value = await connection.getValue();
return value < 0 ? value : 0;
}
The important thing to note about this is that Connection is some huge megaclass and mocking it would take a significant ... |
According to Why define a Java object using interface (e.g. Map) rather than implementation (HashMap), when creating objects, I should declare the most abstract type, eg : Map hashMap=new HashMap(). However, I don't think it is a good idea, because it seems suffers from the same problem as primitive obsession. Let's co... |
In this toy example some_function is... some function that takes a dict as an input and modifies it in place somehow.
def some_function(dct: dict):
"""Do something to the items in the dictionary.
Args:
dct: A dict that ... some description.
"""
I happen to know the caller of this function will oft... |
Currently, I am developing a software in C# (.NET 6) that tests devices after production. Therefore, it runs specific tests, e.g., voltage measurements, using the connected hardware. If the voltages are not in the expected range, the tested device will fail.
I implemented the voltage measurements using a generic IVoltM... |
I'm writing this library in which the user can provide custom code defining the algorithm used for finding an optimal solution. In the papers that I have read, the targeted user thinks in terms of finding the hyperplane that maximizes a measure of impurity. Since I want the user to articulate its code in a way that is ... |
I am responsible for implementing search functionality for our web application; I take search text from a user and come up with a list of products, score them, and return them to display to the user. The search itself works fine, however, the team wants to be able to guide the user's search by way of presenting filters... |
I am building a website, where the main data source is Snowflake, a cloud data warehouse.
This cannot be changed, but we can add other technologies.
There is a lot of data in Snowflake, and the calculations for each web page are quite complicated.
We believe that computing everything in real-time would not be acceptabl... |
I am thinking about how to build a language VM. I have been able to get some of the basic constructs right, including jumps to functions within the chunk of bytecode that is currently loaded.
But now I am thinking about how to handle (dynamic) calls to functions that are in other chunks of bytecode that have not yet be... |
Presume I have a function that does some precise calculation on a large amount of data, call it calculateResult(data).
This function gets very slow with increasing size of input.
Luckily, I only need the approximate result in some cases, so I write a second function that does the same calculation much faster but with a... |
I have the following interfaces to allow me to generate "drawing" of some product.
public interface IProductDrawer
{
public string Execute(ProductScope scope, ProductConfig config);
}
public interface IProductDrawer<in TConfig> : IProductDrawer where TConfig : ProductConfig
{
public string Execute(ProductScope... |
Please help with a diagram in which there are sequential requests.
The logic is the following:
Service 1 sends a PUT Trigger an export request to Service 2
If the response is 200 OK, then after 10 seconds sends a GET Retrieve an export request until the status is COMPLETED or ERROR
I don't show the 400 response.
If the... |
I was programming today and encountered something that just feels like I'm doing something wrong (maybe?). I've encountered this situation before, but I wanted to reach out and ask if there's a better way to handle this. I have a situation where I realized my function direct_data could save a lot of execution time by e... |
In software design and security, why would it not be a good idea for users to send you their passwords and it would be a better idea to delegate: use public-key auth or logging in with one of these: OpenID connect, "sign in with Google" or "Facebook", etc.
I am curious to understand more about these topics. I recently... |
I have the existing code provided below:
if (!$existing_records && !$has_required_field) {
return 'Skip Update, no records found';
} elseif (!$existing_records && $has_required_field) {
syslog(LOG_ERR, "some field is required but no regulatory records found. id=$id");
return 'Error some field is required bu... |
According to Why is Global State so Evil?, I believe we should avoid global state, so suppose I have an App that count user clicks in all pages like it:
public class GlobalState{
public int clickCount=0;
}
public class Page1{
public void onButtonPressed(){
GlobalState.clickCount++;
}
}
public class ... |
I am not a native english speaker so I have the following question related to naming I have a class that has generic filter method of type:
filter(Predicate predicate)
In the same class I have some more concrete filter methods of type:
filter(EventName eventName) or filter(Datafield datafield)
Is it acceptable to use ... |
I went through various blogs but nowhere I can find the reason of having virtual constructors in C++.
Why is virtual constructor needed and lets say if we go through the wrong way of creating virtual constructor how would our code look like and what would be the problem with it? And how does the factory method helps us... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.