instruction stringlengths 34 36.1k |
|---|
According to https://softwareengineering.stackexchange.com/a/334994/432039, I know "init()" method is a code smell, and "physically make them two separate classes" is a way to refactor the "init()".
However, I don't understand what is the meaning of "physically make them two separate classes". Is it mean move the init ... |
For example:
After I've learned about SQL injections I realized that in past projects I didn't check user inputs for SQL injections.
After I've learned about PKCE I realized that in past projects I didn't use PKCE in OAuth 2.0.
Each time I have these enlightenments, I feel bad about my past projects. My inner voice s... |
I use code like this and it seems to work fine:
void addActions(const vector<zero_arity_function>& _actions)
{
actionsMutex.lock();
for (auto entry : _actions) {
actionsToRun.push_back(entry);
}
actionsMutex.unlock();
}
And the corresponding code that the other threads runs:
void runActions()... |
We have some domain primitives for representing an Account an Amount with Currency etc.
These are in a shared library, so all our microservices can use them.
And then we started adding some convenience methods like Amount.of(String currency, BigDecimal value) and Account.fromIdentifier(String) etc.
These are really con... |
In my current workplace, I act as lead developer and architect in a team of software developers.
The general policy for merge/pull requests is that 1 person has to review and approve the request. This person must not be the author.
Sometimes code is merged which I personally would not have approved for one ore multiple... |
I want to model a system where someone is creating Quiz and he can choose who should do the quiz. When submitted the invited people have a deadline to solve the quiz and the creator and maybe some other guys have the authority to see the status of each Invitee, whether they finished it or not. (Basically it is kind of ... |
Given the two models company and person I'm noticing duplicate fields i.e. zipcode, emailaddress for each.
Yet, a short research reveals a reasonable popularity for separating those two entities into two tables (in terms of customer relation management databases [crm]).
Would one contact table with appropriate fields o... |
It's been a long time that I had an idea of a semantic constraint as compiler optimizations which allows for sophisticated high level optimization allowing you to transform the AST/CFG based on a SFG (semantic flow graph).
To give you a simple example I'll simplify the code of a reddit question which asked about two ve... |
I have to update app code running in a container on AKS to use a WorkloadIdentityCredential. I have to test code that I update in order to pass CI quality gates.
The code uses a public final class, com.azure.resourcemanager.AzureResourceManager, whose constructors are private.
The only way to get a new instance of this... |
Meta maintains all their code in a single repository and initially used Git. Due to performance issues attributed to the repo's size, they consulted Git's team, who suggested switching to a multi-repo structure. Meta declined this advice and migrated to Mercurial instead.
Given this background, I'm curious about the be... |
A follow up question to How do unit tests facilitate refactoring without introducing regressions?.
I said that integration tests test the behavior of the code, while unit tests, being tied to particular classes and methods, instead test the way it is written. Several answers & comments, if I understand them correctly, ... |
I am trying out CQRS, Event Sourcing and DDD in a project and I want to model a Reminder Service.
The context is as follows: Person A creates a Task for Person B and sets a Deadline for Person B to complete it (also it can be a recurring Task, so when he completes it the next due date would be for example in 30 days ag... |
Designing the architecture of a personal project, I've come up with the idea of using the combination of these two patterns to solve an architectural issue. In an MVC context, I need to implement various types of actions triggered by the UI. I want to abstract the controller from the execution logic, with the model bei... |
Given a service oriented architecture, for example in a blog system let's say we have services for User, Post, and Comments.
A new requirement comes that a User should be able to "Like" any other entity, and any future entity. A user can thumbs up another user, post, or comment.
A new "Likes" service is introduced to s... |
Only loosely related to the title.
In my code I often encounter functions such as this one (e.g. from a pet project – a Discord bot written in Python – but seemingly a ubiquitous and reoccurring issue), which I'm struggling to refactor in an attempt to make it more readable/maintainable (ignore the async/await, treat i... |
Lets say I have a project which is something relatively simple like a copy checker for legal text files stored in git, that multiple people contribute to via pull requests that must be reviewed before merging. I want to alert the reviewer to weasel words, slang etc.
I have split this project into 4 small tickets (proba... |
I am creating a use case diagram for an elevator control system program, and I am a little confused about using includes for sequential actions.
What I mean is that when the user calls the elevator, it is required that subsequently the call button light must turn on and the elevator must go to the called floor. After t... |
I am wondering whether it makes sense to not store informational Data inside the write model database. By informational Data I mean data that is not directly used for any decision making in the write model.
For example take a Product in a Sales context. It would have a name that can be updated. But other than that, the... |
The usual advice for using EF Core in a web application is to use a scoped DbContext per HTTP request. This is even the suggested default for web application in the Microsoft documentation. I recently encountered the argument that this is a bad idea and that you should not use DbContext as a scoped service as it will a... |
I see in arm reference manuals they give info about certain configurations such as
HCR_EL2, Hypervisor Configuration Register (HCR_EL2), and what I read in books and reference manual is that ARM64 have x0-x31 + PC + SP. So where does HCR_EL2 comes into picture?
|
I need to design a system that handles multiple types of resources, each having their own business logic and different types of actions available for those resources. The requirements are a natural fit to have a separate service for each type of resource (not necessarily microservice architecture, at least not at the b... |
I've built a small single-page web application in React and seen that it's possible to serve the app as a static site on something like S3.
Previously, I considered using Nginx, but as this is lower cost I'm thinking of using this method instead.
Are there any drawbacks to this method that I should consider?
|
I'm playing around with AST generation and exploring how it relates to a directed acyclic graph. I hit a logical snag that I don't understand.
var literal = 3; // expression 1
literal = literal+1; // expression 2
Clearly the value of literal is 4; that is, once expression 2 has been parsed. Logically, though, the ac... |
There‘s an approach in unit testing where, instead of just writing the technical details in every test method, you create a library of helper functions like
givenServiceFails (that acts on mock behavior)
whenUserDataIsRequested (acting on the production code) and
thenDataIsDisplayed (asserting mocks or production code... |
Example:
The MacOS API known as Cocoa uses Delegation to specify various behaviors within the app. A Delegate is a separate object that implements a set of methods that are called by an original object. For example an NSApplication calls the applicationWillTerminate method in the NSApplicationDelegate (which is overrid... |
We have built a library which can handle RESTful requests based on configured endpoints.
A fluent builder is being used to create endpoint definitions (configurations). These definitions are bound to a request.
When a request is being executed, the definition is being used to set the correct parameters, like HTTP head... |
I am working with a provided end point that returns a JSON response,
Property "Items" in the response changes depending on:
When there is a single value being returned then it is an object
Items:{SomeObject}
same property when there are multiple items are being returned then it is an array of objects:
Items:[{SomeObje... |
I had a discussion with my boss on DI pattern in C# and I would like to get some reviews and discussion on the following code snippets.
Key points to look into is that the instantiation of the ExternalService and ExternalServiceConfig where there's no interface for DI to register or mock.
Pattern A - Instantiate the Ex... |
I'm programming an embedded system that has a number of user configurable parameters, which are stored in flash memory. I have to store a default value for each parameter as well as the user settings. Because the STM32 I use can write 64 Bits of flash memory at a time, I chose to use one word (32 Bits) for the paramete... |
I am using the Spring Boot framework to create a RESTFUL API and I need a way to avoid the duplication of validation rules when using multiple DTOs as request/response objects for my endpoints.
Using the following example for the Entity
@Entity
public class Post
{
@Id @GeneratedValue(strategy = GenerationType.IDENT... |
I'm making a vpn service that can be controlled through admin web page.
So I have a web page that consists of front-end page and a backend API + DB.
In this admin web page, I can execute a vpn binary at my server by clicking a button or submitting a form. And also set some configurations before I start my vpn-service.
... |
Per the UML 2.5.1 specification:
DeployedTargets are shown as a perspective view of cube labeled with the name of the DeployedTarget shown prepended by a colon. System elements deployed on a DeployedTarget, and Deployments that connect them, may be drawn inside the perspective cube. Alternately, deployed system elemen... |
Are the reasons for why Microsoft states that DB contexts should not be long lived because of measurable effects (memory leak, resource hog, increased probability of data corruption, ...) or is it because of a more subjective reasons (anti pattern, hard to manage multiple instances of the same record, increased complex... |
Typically the solution for comparing if 2 relational db tables (I am using AWS Athena) are equal is to do full outer join on all the columns but adding an extra column to each dataset that acts as a marker.
select *
from
(
(select *, 't1' as t1 from table1 where ...) t1
full outer join
(select *, 't2' as t... |
As I understand it, the join() method merge/composes/combines the results from all subtasks. A simple example I saw was summing the numbers from 1 to N and the subtasks would simply sum a range of such numbers -- obtaining the final result very naturally involved summing each subtask's result to indeed get the right an... |
I personally put build stage in Dockerfile. (Using multi-stage feature in Dockerfile)
But in my company, we have dev containers where all dependencies are installed and managed. So in our product's Dockerfile, there is no build stage. Build(compile) is done on dev containers and result binary are copied to Dockerfile. ... |
When you define a class, is inheriting a logger such as log4cxx a good design?
Assume I am defining a class called MyClass.
When I want a logger, I use a pointer to an abstract logger class as a member variable of MyClass. Then during the construction of MyClass, I can pass in a pointer to a concrete logger class in th... |
I am currently analysing the project ddd-library which is really helping in learning designing a system based on DDD principles. However there is one thing I have a problem with.
In case of placing a book on hold, first the Patron Aggregate is updated (it holds now a book) and then the Book Aggregate is updated. Whethe... |
My team own two micro-services, both hosted on AWS ECS. One service uses aws redis. For second service we need to implement lock mechanism for one endpoint. For that we need to store single key in redis. I propose to use same aws redis infrastructure. One point raise as its against bounded context of first micro-servic... |
In his "Software Engineering. Principles and Practice," H. van Vliet mentions "tree impurity of a call graph." However, the term tree impurity is not used in this meaning anywhere else but refers to decision trees in machine learning. Did H. v. V. misuse the term in his book, or has the term recently lost its original ... |
I tried searching the web but can't understand the difference/boundary between hexagonal(ports and adapter) architecture and ACL Pattern.
While hexagonal architecture talks about creating ports(interfaces) and adapters(implementation), doesn't ACL also do same by adding a layer which is corruption free and isn't impact... |
I’m writing a web application with an Angular client and a Pyramid/Python server. I need to dynamically interface with an external cloud application, with two requirements:
When the end user approves an invoice in that external cloud application,
the Angular client should automatically open in the browser and show the... |
Just to provide context:
I am modeling a ticket (service management) process and specific actions are allowed in specific life cycle stages, so not in a straight sequence flow.
Therefore I encapsulated the respective task in a subprocess that now has several boundary events.
E.g. adding notes to the ticket. That can be... |
So, I recently added some validation logic to our controllers:
interface Validator<T> {
fun validate(model: T): Boolean
}
Which is used in the controller like this:
validator.validate(request) || throw Exception()
During code review my colleague was thrown off by validate || throw construct, while to me it is suc... |
I have a large R project developed in a Windows environment which I want to move to Linux, and there are lots of Windows style directory references (assigned in variables at least) which I assume I will need to translate. There are various folder tree references in the code.
Is there an easy way to do this, other than... |
I was writing a procedure that is only applicable in a particular case, but it didn't feel right to enforce it by contract or raising exceptions, because there's no problem with calling it in other contexts; it just shouldn't do anything.
Thinking about it, I decided it would be easier for future debugging if I explici... |
Most template engines have two ways to refer to other templates:
Inheritance with blocks (child template inherits from parent template and fills one or more blocks)
Includes (parent template includes child template).
Coming from vanilla PHP require/include and from component based JavaScript frameworks, I never reall... |
I have a service A that every once in a while needs to send a message to a cluster of services B1, B2 ... BN.
Then all of these services need to receive that message reliably, and send a confirmation back to A.
After A receives the confirmation from all services from cluster B, it needs to send a message to another clu... |
For example, I have a Business Intelligence (BI) microservice, it reads data from other microservices, and displays the data as a bar chart or some other styles.
My problem is, the BI microservice needs other microservices to register the display content and some rules, and the BI microservice reads and displays the da... |
I am going through various virtualization concepts, and am trying to understand their benefits.
Based on what I have read, Amazon EC2 is an example of server/hardware virtualization, and it helps us achieve high utlization of hardware. In the absence of hypervisor, we would have low utlization rate of hardware. Also, s... |
HINT: the purpose of this question is to identify downsides for the scenario described. If something is a downside, then it should be quantifiable and it should clearly have a negative impact.
Background:
I'm working in a project for which we take a yaml file with some values and use those to render Jinja2 template fil... |
I am trying to devise a simple system that, with the use of tokens, allows a specific file to be rendered in the client's browser, yet prevents the user agent from being able to download the file. Below is a simplified description of the process:
A user agent or client requests the web page from the web-page server.
T... |
I’m working on an application that requires many 3rd-party integrations. I’m using Postgres to store these API responses but am having trouble for a number of reasons.
These objects are frequently large and require me to model the relationships to fields.
Many 3rd party responses have some sort of inherited relationsh... |
I need help with the architecture pattern I should use in a NestJS project.
So I am using a command/query approach for developing my RestAPIs. Right now it's a Monolith and not a microservice architecture, but I am developing it in a way that tomorrow it will be easy to switch to Microservice.
So consider a scenario, w... |
I have a NextJS app for which I want to cache data from our backend APIs to reduce the load when we have high volumes of concurrent users scrolling through (or search) years-worth of historical data.
Data flow is unidirectional with the cache only ever being updated via our APIs. Cached data is eventually consistent. I... |
I have a "Games" API which retrieves video game data from a large database.
The /games endpoint returns some very basic information about the game, such as the title, description, etc.
More detailed information, such as the developer, is actually not given by this endpoint. Instead, a reference ID, to be used for anoth... |
This is the case:
We have one Scrum team of 7 members (developers and QA's) plus PO and SM
We have content team of 3 members that are responsible for portal ''look'' (banners, pictures, copywrite etc.)
This is the problem:
We have situations where development team is working in the sprint and we only use lorem ipsu... |
I am a student working on a personal project which is essentially a location finder that will be on a website. I have a data set of over a million addresses and I want to display the closest N locations to a given address or current location.
I would greatly appreciate some examples of the technologies/stack that an e... |
I'm modeling a system while improving my knowledge of software engineering. I am building a class diagram and a component diagram, but notice that when I tweak one, I have to alter the other. Also, I feel like I can represent the classes in a component diagram. How do you do this? Do you make them both or only one? If ... |
I have different equations to compute the same quantity. For example, val = my_func(a, b, c) but also val = my_func(x, y), where my_func represents the quantity I would like to compute: it could be Velocity or Momentum or something completely different. I have dozens of quantities to code, each with multiple equations.... |
I am not asking whether to do server-side validation or not.
My question is whether any solution or better practice exist in the software world to address this repetition of code.
|
This is quite basic question that started puzzling me recently while studying Lisp (and derivatives). I have read some Lisp books and web sites and this subject is somewhat obscured by other Lisp properties that seem to be having more meaning to the authors so they give them more attention. So I cannot find this subjec... |
We developed a generic .NET library for our line-of business applications. This is what our namespace/class structure looked like 5 years ago:
...
AcmeCorp.Tools.ExcelWriter
AcmeCorp.Tools.Code128Barcode
...
5 years later, the number of classes in the generic Tools namespace has grown (e.g. there's now a CSVWriter in ... |
We have started using a "micro service" architecture and we have multiple services. Each service owns the data and the business logic for a domain and only entity ids are shared across services.
Everything was perfect until 1 requirement came in...
On the UI, when a user is about to delete an entity, a warning listin... |
In my case I inherited a poorly engineered code, on that piece of code I have been tasked to increase the code coverage in integration tests. But instead of the usual pattern:
Create/Populate a test database with specific test data
run the test
Delete the test data or Nuke the db
Repeat step 1 until no more tests.
Th... |
I am working in a purchasing system where we take calls:
public class Call
{
public List<CallItem> CallItems { get; set; }
}
The calls can be turned into quotes, where call items become quote lines:
public class Quote
{
public List<QuoteSegment> QuoteSegments { get; set; }
}
public class QuoteSegment
{
p... |
I have a system where a user uploads a file to import some users but it's necessary to do some validations and this take some time. I would like to create a work queue with RabbitMQ and the user will upload de file and I'll send to the queue and then process it.
What is the best design to use in this case for my prod... |
I've struggled to find any discussion on this.
If you have a simple MVC page for updating a User, and you put a dropdown list on it of Country, you need to populate the dropdown list in the viewmodel. Let's call it List<Country> countries {get; set;}
If the page is posted, and there's an error like they forgot to put a... |
What are the pros/cons of having a serialization function accept a sink:
class Foo:
def toString(self, stringIOSink):
pass
def toBytes(self, byteSink):
pass
versus having the serialisation function return the result:
class Foo:
def toString(self):
# ..
return s
def toBytes(self):
# ..
... |
Continuous integration with testing is useful for making sure that you have "shippable" code checked in all the time.
However, it is really difficult to keep up a comprehensive suite of tests and often, it feels like the build is going to be buggy anyways.
How much tests should you have to feel confident in your CI pi... |
So let's say I have a view model, representing a student. The view model is corresponding to a student model, from which the data comes. What I am struggling with, is how to populate the fields in the view model. Do I simply forward reference the fields from the model (where possible) or do I have actual fields in the ... |
I entered yesterday to my new job and while browsing their repositories, I noticed they have a project for every resource of a REST API. For example, if they need to add a REST resource called "people", they proceed to create a whole new repository that contains only the endpoints of the resource "people".
Honestly I'v... |
public class LDLTrackViewModel : RailwayViewModel {
private LDLTrack _ldlTrack;
public LDLTrack LDLTrack {
get => _ldlTrack;
set { _ldlTrack = value;
OnPropertyChanged("LDLTrack");
}
}
public LDLTrackViewModel(LDLTrack ldlTrack) {
LDLTrack = ldlTrack;
... |
Assuming we have following message that will be used to update data and it just got updated to version 2.
message HelloRequest {
string name = 1; // version 1
bool is_valid = 2; // version 2
}
Now assuming we updated our apps like so:
server : version 2
client A : version 2
client B : version 1
We don't have any... |
I have a web app that connects to a MYSQL database which has some encrypted data in it. The encrypted data is encrypted using the the mysql AES_ENCRYPT function and a key.
Now, this key has been static for a while, and we're looking at methods to change the key (and ideally change the key periodically). My problem is t... |
If I write this code in a function:
void func(void)
{
int x = 0;
int y = 3724832+x;
}
It would (probably) optimize the variable y out because it isn't being used. Even if I'm wrong about this specific case, the point I'm making is that the compiler has the ability to optimize out variables.
My question is does... |
I have a small library where I am performing 1 long running operation and based on that operation,I am saving some data inside database tables.Now this is small library which does not include alot of database tables operation hence I have used Ado.net to manage data access layer.
I have created base class where I have ... |
I don't use SSL on my website currently. It's a small hobby site with no online store or anything of that nature that would need it. I've read that Google Chrome will stop loading such sites sometime in the near future. Are there going to be additional future consequences if I don't purchase a signed SSL certificate?
|
I have a question about Fluent Interface Builder.
I have a simple object like this:
public class Person
{
public string Name { get; set; }
public string Surname { get; set; }
public int Age { get; set; }
... other properties
}
and I have a simple UserBuilder class:
public class UserBuilder
{
priv... |
I am implementing a Binary Search Tree and cannot decide if it would be good practice to constrain the generic type of the tree to a comparable item, i.e. IComparable<T>. Or, to just use the default comparer, i.e. Comparer<T>.Default. To me they are functionally the same and they both provide a method to sort with.
Can... |
Here's a snippet of code:
An inlined function:
inline void rayStep(const glm::vec3 &ray, float &rayLength, const glm::vec3 &distanceFactor, glm::ivec3 ¤tVoxelCoordinates, const glm::ivec3 &raySign, const glm::ivec3 &rayPositive, glm::vec3 &positionInVoxel, const int smallestIndex) {
rayLength += distanceFacto... |
I have decided to try to create my own board game implementation. Probably going to use a REST-api to expose the contract. I'll figure out what database, communication, ... tools I'm going to use once I've got my business logic set.
Now, to achieve not being dependent on tools/frameworks in my business layer, I need to... |
Let's say a user goes to the log in page of my website and creates an account. Instead of entering their real name, they decide to write some sql code and try to gain access to my database.
I have prepared statements to prevent any harmful code from altering my database at the signup process, however if the user goe... |
Do I need unit testing for everything? I know that Unit testing is not necessary for really small tasks, but what about for bigger stuff? How do I know I need a unit test?
|
I generally try to adhere to the 80 character limit for each line of code to satisfy my colleagues, to satisfy the linting tools, and to maintain an image of professionalism when random people look at my code.
However, sometimes I have URLs that I wish to embed in the comments, and some of these URLs are very long (exc... |
Hello I am building a demo project to teach myself about clean architecture and unit testing. My setup is very similar to this github repo https://github.com/mmacneil/CleanAspNetCoreWebApi
The important parts for this question are the following 2
The Core project which should contain the business logic
The Api projec... |
Throughout the course of programming, you will end up with some comments that explain code and some comments that are removing code:
// A concise description
const a = Boolean(obj);
//b = false;
Is there a good method to quickly parse which is which?
I've played around with using 3 /'s and /** */ for descriptive com... |
I am currently building an Entity Component System (ECS) in cython in order to speed up operating on large numbers of game objects in python. In the process of building this system, I ran into the following architectural issues that I would appreciate shedding some light upon. I have read through lots of online blog po... |
In our current project we are versioning software using gitflow as process and git/gitlab.
We had some trouble managing multiple release at the same time, but nothing we couldn't survive.
Until now we had only client A and the project is very oriented to it.
But client B will join soon. Also, we want to start to build ... |
tl;dr: I work at a small company with a development team of 5-10 people, lately we have been asked to present "scope documents" for effectively all of our work before we carry out the actual work, with seemingly no regard given for the magnitude of work required.
I worry that I am often spending more time writing scop... |
I'm new to Core Data, and am not sure how to reconcile the need to inherit from NSManagedObject with the fact that my model is a Swift struct composed of structs. I chose to make my a model value type so that it would be simple to push and pop it onto an undo stack. But since a value type can't inherit, I'm unsure as t... |
There're multiple topics about bootstrapping a compiled language, languages that are compiled into machine code directly; However, I can't find good explanation about bootstrapping a transpiled language. First, The difference between a transpiler and a compiler is that the former converts a language into another, unlik... |
I'm looking for ideas on how to design a "generic" bug-tracker integration architecture for Kiwi TCMS (opensource test case management system).
Background: at the moment we support integration with several systems: Bugzilla, JIRA, GitHub and GitLab. Behaviours are:
- link existing bugs to test cases/test executions
- a... |
I’ve built a small little library that I think really aids in PHP development. It makes secure by default database transactions, makes cURL requesting anything easy (including files), and it has a bunch of methods for handling and sanitizing different data (phone numbers, emails, etc...) it’s this last part that I have... |
I am working on a product that will not be able to be updated once released. Furthermore, if the product malfunctions, the results may include death, serious bodily harm, or major financial setbacks. Therefore, my code must be correct the first time, as I will not get a second chance.
What techniques are available fo... |
In the following function IsDoubleString(),if res is true then it shouldn't call IsDoubleString(), I debugged the code but I am unable to understand that once it hit the line returns res; why does the control go inside the if(!res) condition?
Shouldn't it be directly returning the res value to the main function?
bool I... |
I saw in many sites that compare REST with GraphQL. after investigating this concern (actually my concern) that, "is it a correct comparison?", I being more confused.
Since the REST has a different definition against GraphQL, this question busies my mind that, why we'll be able to compare two different concepts togethe... |
In the Django documentation it's mentioned that Django managers are accessible only via model classes rather than model instances to enforce table and record level operations. What are table and record level operations and does they get affected if we use a model instance?I have gone through https://stackoverflow.com/q... |
We have multiple microservices communicating over MQ. As MQ messages are the interface/contract between the services, whenever we make changes to the MQ message published by a service we need to make the same adjustments on the services which consume the message.
As of now, the number of services is small enough so tha... |
We have an application which on every resource update(resource update, create, delete)creates a message and puts it on a queue. This message is picked up by a worker process, converted to a format that the receiving application (lets call it a hub) understands and sends it. The hub implements a policy of last writer wi... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.