instruction
stringlengths
34
36.1k
Many place that i have read about static method they said please shouldn't use static method for access to database and should use dependency injection for inject other service and use that service to write other logic.But problem it happen when i inject AService in BService and inject AService in CService many month...
I'm working on implementing my first clean architecture and CQRS application, I've stumbled across a bit of logic that's leaving me a bit stumped. I'm working on integrating authorization and authentication into my application, but I'm having some trouble trying to figure out how to architect a portion of my applicatio...
In the C++, there are 6 bitwise operators: Symbol Operator & bitwise AND | bitwise inclusive OR ^ bitwise XOR (eXclusive OR) << left shift >> right shift ~ bitwise NOT (one's complement) (unary) In Qt, I have seen |, ~, and & used fairly often in functions: file->open(QIODevice::Wri...
So say I have a controller Method // GET: TimeEntries [HttpGet("[action]")] public IEnumerable<TimeEntryDTO> GetLast(int value) { return dal.GetLast(value); } And a data access layer method of (using AutoMapper to convert TimeEntry to TimeEntryDTO) public IEnumerable<TimeEntryDTO> GetLa...
I'm doing this in python, in case that changes anything. I'm trying to make a lamp/bit go 1-0-1-0 until the user says "okay" the "okay" should indicate that the user has found the lamp/Bit IRL. Now i'm struggling to find a way to ask the user a question, (because it stops the program cycle), when I also want the lamp b...
I am new to C# and have a difficulty with the code structure. My application has: GUI with button Show my Ethernet IP. When user clicks this button PC's IP address is displayed. Class ModbusTCPSlaveMachine. Within this class I create TCPListenter and supply it with PC's Ethernet IP address. In both cases I get local ...
I was following a tutorial on the normal forms of SQL databases, and I got confused landing on this example : https://www.tutorialspoint.com/sql/third-normal-form.htm. From CREATE TABLE CUSTOMERS( CUST_ID INT NOT NULL, CUST_NAME VARCHAR (20) NOT NULL, DOB DATE, STREET ...
In a program I'm working on, I need to do a substantial amount of real-time reflection in order to maintain a list of known "attributes" throughout the program structure (for use by a sort of "virtual programming assistant"). I came up with kind of a "cheaty" way of doing this (which I'm frankly kind of proud of), whic...
What is the best way to Mock a return type if we don't care about the actual state of the object. For example, I am Mocking a method whose return type is: IEnumerable<Document> Now, I can add relevant Nuget package and add necessary namespace so the type Document is defined, however I actually don't need to test anythi...
I have a use case for which I need to build a data processing pipeline Customer contact leads data coming from different data sources like csv, data base, api has to be first mapped to a universal schema fields. There could be ~100k rows coming each day that need to be processed. Then some of the fields have to be cl...
Domain Driven Design states that you should have a domain model, which reflects the ubiquitious language used by the domain experts. When using ORMs and many to many relationships I am use to doing this: public class Student { public Student() { this.Courses = new HashSet<Course>(); } public ...
In a long running Windows Service I have a custom thread pool manager that has a loop which continuously looks through a couple lists for idle threads. Given multiple uses of the same predicate, is there any benefit to saving off the lambda as a Func? How might the recommendation change based on the count of threads th...
This is purely a design philosophy question in the context of C++. Is it a okay design philosophy to start a thread from within a constructor? I have a library whose sole responsibility is to asynchronously handle some requests by exposed APIs. For this to work it has to start a thread internally. I have MyClass which ...
Our team had recently a big struggle of deciding whether it is a good practice or not for the .NET Core class libraries to register their own implementations by the fact of providing a IServiceCollection extension methods like AddMyServices(). My point was that it is good to do this because: Top level application does...
Is it a pattern or antipattern to inject a dependency that is a tree of dependencies? For example: public class ClassExample { private IContainer _container; public ClassExample(IContainer container) { _container = container; } } public interface IContainer { IDependencyA DependencyA { get...
I have programmed using the architecture below, where "client, order, piece" are just data classes, have no methods, and "managers" are the manipulators of that data, the "ClothingStore" is a wrapper where there is no logic, only calls the methods of the managers and return what they return, so the "ClothingStore" woul...
Burn down and burn up charts are used in agile projects to visualize the progress of a sprint. The same type of chart could also be applied to entire projects, not only to a single sprint. Thus they could be used in 'traditional' waterfall or v model projects as well, however I could not find evidence for that. Is ther...
Uncle Bob says in 'The Clean Coder', chapter 5 'Test Driven Development': You are not allowed to write any production code unless it is to make a failing unit test pass. You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failures. You are not allowed to write...
Generally, constructors in an interface are considered as being an anti-pattern. Some languages even don't allow that. Then I don't understand how we're supposed to deal with polymorphic immutable objects in the some particular IOC contexts... Say we have to instantiate a polymorphic object, its class implementing our ...
I have a "tracker" class. This class tracks objects from a given input image. But in addition to this, there is another parameter that corresponds to a value used in generating the image. The tracker may want to suggest a new value for this parameter to get better results on the next iteration. It would be suggestin...
On a typical web app, we commonly have to deal the LOADING/SUCCESS/ERROR problem - which is that: When I make a backend request I want to display a loading cursor, perhaps disable some buttons. When the request finishes successfully, I want to display the data. When the request finishes with an error - I want to di...
In my C# project, I have a domain class named 'User'. this class will contain user's id, firstname, last name, DoB, home address, phone, etc. And we also have a typical REST web api (i.e. api/users) to read/create/update/delete user. When we create a method (in class UsersController) to return a single user's details, ...
I need to send a json response. I use the jackson library to convert the class to json. I have a core java class to which I need to add some more fields to create my json response. I came with two ideas. To extend the core java class. To have an another class with the core class object as constructor. Concerns over ...
What is a good strategy for Q/A Engineers peer reviewing Unit tests as part of the software development life cycle? I think that there are, indeed, things that I should check regarding the unit test made by the devs (like making sure that critical part are well tested). So, what should I be looking for in those peers r...
Suppose we have the following classes: As you see, it's an implementation of the State Pattern. Basically, the Order class proxies the pay() and cancel() method calls to it's concrete OrderState instance. After executing their part of business logic, the PendingOrderState and PaidOrderState call setState on the Order ...
Assume that a Python package (available via PyPI) is too difficult for novice users to utilize. Specifically, typing python2 path_to_package/start_GUI.py in the command line, which opens a TKinter GUI, is too hard for many users. Instead, users would like to simply double-click on the file start_GUI.py, irrespective of...
I bought three boxes of tea bags with different flavors (A, B, C). I wish to mix them in such a way that - there is never two consecutive bags of the same flavor (ABCCAB is avoided) ; - the mixing is the "most" random, i.e. avoid patterns such as ABCABCABC... or ABABAB...BCBCBC...CACACA. Is there a known algorithm for ...
I had a conversation with a recruiter recently. As a contract engineer, I've worked several jobs over the years and it's been ages since I saw a formal specification. Confluence pages, yes. Jira items, yes. Agile and Kanban documents, yes. I made the statement that specifications are discredited because, like war ...
I'm trying my hand at multi-thread C programming and decided to start with a simple ncurses program to move a character across the terminal screen and change direction based on user input (think classic snake game). I decided that I needed to create a separate thread to handle moving the character across the screen, w...
Here are the requirements: (not the real case, just very simplied version) There is some sort of promotion which lasts for a week. The selected users who may benefit from the promotion is fixed at the beginning. Everyday, each selected user gets some bonus(say some credit points) from the system. I'm thinking about i...
I'm developing a database with a price list table for my workplace. I came with two major options, and would like to have your opinion :) It's rather simple, containing: Id, description and price On one hand, it's now working with each price on new row and having an extra field start_date, and is the way I've found o...
I have a system that checks the status of a large number of entities on schedule every minute. For each entity, there would be a JSON file which has fields indicating the statuses for different attributes. The system dumps these JSON files on a network share. Each run of the schedule that runs every minute generates a ...
I am new to TDD/unit testing. I am going to write a complex scheduling algorithm in Java. As this module is a core part of our application and there are number of scenarios in it, I want to write unit-test cases for every case. To compute this schedule, I need to interact with 25-30 entities and each entity, on averag...
I wrote a binary calculator & binary teaching program in the Rust programming language. I was taking an iterative approach in that I decided to first get a basic "learn binary" game started. This game displays a hex or decimal number to the console and requires the player to enter the number in binary 1s and 0s as a me...
I encountered a situation where the dev team suggested that they will push bug fixes to our dev environment rather than to the test environment, and they asked QA to test there first. I am not sure if this is a good practice, I always thought it is better to test in the test environment, but maybe there are circumstanc...
Let's say I have User resource which has Address sub-resource (let's forget about why this is a resource instead of attribute). To get a user's address, I can do GET /users/{id}/address Now I want to have an API which returns all the addresses regardless of their owners. I can do GET /addresses. This feels a little bit...
I got the following code snippet: public Task DistributeAsync(BankAccount account, decimal amount) { lock (account) { return repository.AddLoanAsync(account, amount).ContinueWith(task => { if (!task.Result) { throw new LoanException(); } ...
I have a problem in formulating LL(K) grammar for this postfix expression problem, given (4 3 / 2 * 4 5 / +) as an input must output 52/12
Given is a design of a video game in which a player has several possibilities to adjust his character: Game designers realized it's senseless to be a fire-elemental and water-elemental at the same time. Is it possible to create such a character with the current design? If yes, is it possible to avoid that without remo...
I'm coding a game and I have a design issue in which I have a superclass which all items in the game inherit from. The game is grid based, and the items can be placed at different parts of the grid. The grid has a dictionary of grid positions -> BaseItem. The problem is, the derived items all do very different things. ...
TL;DR: My goal is to create some framework with which I could discover/test all possible internal states of my application so that I would approach with confidence for example engineering software for medical devices, airplanes etc... Let me first explain some context... I was watching interesting video on example mapp...
A common algorithm used in N-body gravitational calculations with large numbers of bodies (stars in a galaxy, galaxies in the universe, etc.) is the Barnes-Hut algorithm, which assembles particles into an octree for approximate bulk calculations of gravitational forces between distant areas. The complexity of this alg...
I am starting a new service that would be an abstraction on top of git repositories. Basically, a user would sign up and Add Project (GitHub/GitLab/BitBucket repository). The tricky part for me is how do I verify that the person has appropriate permissions on the repository they're adding? I was thinking of a method to...
I wrote a Music Player and Library in Java for GNU/Linux and Windows. My build process is currently in ANT, but I intend to migrate away from that to something more modern after the next release. I've heard good things about gradle, but if there's something more suitable you'd like to recommend, I'm open to that. The...
I am wondering if it is possible to create a regular language from a irregular language if we add or remove finite number of words from it? say L is irregular, can we add or remove finite number of words to create a regular language? i might be mistaken, but since all regular languages are finite - if we add a finite a...
Good Pythonic style is much looser than Java's uptight restrictiveness: In Java, good style means private on methods wherever possible, all fields encapsulated, type declarations, defined interfaces including abstract methods. All this is now doable in Python, but good style allows and encourages public members, d...
I am creating an application where users can create forms with many fields of text, numeric, date and select types. The model will have a forms table referenced by responses table; It also have the fields table with 'name', 'field_type' - it points to forms too; The filled data will point to responses and to fields, b...
This is kinda like a concrete version of the question Coming up with tokens for a lexer. I'm writing a lexer for a small subset of HTML. I'm wondering what should I do when the input stream ends and I'm in a state where I've successfully recognized a token, but I know that it will be a syntax error. I emphasise "I know...
This expands on "Deadlock in Single threaded application" on StackOverflow. That question was not really conclusive and I think it better belongs here. By the definition of a deadlock, is it technically possible to produce a deadlock by using just a single thread? This is the definition of a deadlock according to Wikip...
Almost every blog post I've encountered around generic auth handling using JWTs in a React/Redux/Saga application does the same thing, which is to store the JWT in local storage, in the action/saga. For example: Example A (redux-saga): function* authorize({ payload: { login, password } }) { const options = { bo...
I need to make an Employee Payroll application and the client specifically stated that the application will run on their computer locally and will not be hosted anywhere in the internet. I can code in Javascript, C# and in Python. I was thinking of using Electron for my front-end so that I don't have to worry about c...
I have introduced sprint into our team and after a rocky start, we are starting to get some rhythm. One of the opinions of the dev team is they still want to be able to work on bugs and enhancements requests that are "easy" to do as this makes our customers (internal to our organisation) happy. After all, that's the en...
I have an array that holds valuable data related to what I stored in a setup / onboarding process: $imported_headers = [ 'headers_2', 'headers_3' ]; Given the fact that these elements are from the same category but their [each element's] content varies by a lot at times and each of them only holds references that all...
In our agile-scrum process, for each epic we are creating , we are creating automatically one user story that is related to that epic. From that user story, we are creating automatically too, 4 subtasks: one design task one technical analysis task one product task one QA task. The technical analysis task should ex...
We have a bug process that is currently being worked. We have 3 levels of bug: P1 bug: Bugs that prevents users from working. They must be solved on the spot. P2 bug: Bugs that are impacting but users can work P3 bug: Bugs that are not impacting and where users can work. P1 is mandatory and must be dealt on the spot...
I'm developing a set of classes designed to communicate with external APIs, and I'm running into trouble with how to properly structure everything for proper loose coupling and unit testing. Currently, each API we need to talk to has a distinct class, which implements an interface a bit like this: public interface IApi...
I am from OO background just started learning FP paradigm. Came across quote by Michael Feathers - "OO makes code understandable by encapsulating moving parts. FP makes code understandable by minimizing moving parts" What exactly he meant by "moving parts" ? My guess is that by moving parts he meant "state mutation" be...
This is a question about terminology. If I say "I'm a developer, and the team I'm a part of does foo" then you'd understand my position. If I'm a scrum master (who is a scrum master for two teams), I might say "one of the teams that I am a scrum master of", but I was wondering whether there was a way to say that in a l...
Background information I have a database that will be used by two different web applications. Solution A (user driven web application) resides on the public internet and will write / update / delete records to the db. Solution / Service B (not user but process driven) resides behind the FW and will only read the data...
We are discussing at the company the migration of some on premises services to cloud alternatives. Is it market practice to backup servers on AWS, or repositories on GitLab.com, or files on Google Drive? Personally I'm pretty confident on these big companies, I'm pretty sure that their backups will outlive mine 10 out ...
I am using protobuf definitions to define message types. Structure looks like message1 { } message2 { bytes msg1 = 1 } So message2 has a field which is a byte array representation of message1. I am: Creating a msg1 struct instance Serializing it Encrypting byte array obtained in step2 Compute digital signature on...
I have Customer, Order, and Product Aggregate Roots... When the order is created, it takes in a Customer and a List<Sales.Items>. It looks something like: public class Order { public static Order Create(Customer customer, List<Sales.Item> items) { // Creates the order return newOrder; } } T...
Broadly speaking how many downstream calls would be acceptable for a synchronous Microservice interaction, from say a gateway API down to a a few supporting services? We are seeing big swings in response time with 4-6 calls - some pass-through proxies. Is this expected? Obviously the fallacies of distributed computing...
The common argument for stability in a sorting algorithm typically involves an example where a list is sorted by two criteria. For example: 1,4,5,7,2,6,8,9,15,65,24,27 sort by evenness/oddness and then by value 2,4,6,8,24,1,5,7,9,15,27,65 The claim is that by choosing a stable sorting algorithm, you can sort this list...
Discussing about a CQRS implementation with my team we don’t agree on a point concerning the Query side. On the Commad side we have actual command clases; a CommandDispatcher that schedules commands, defines a Unit of Work scope and dispatches commands to handlers; handlers that contain the business logic and do CRUD o...
I am on a project for which I have to spawn many different processes, all in different executables, and there will be some shared memory segments and some semaphores to synchronize them. I use an "initializer" process to open some POSIX semaphores and allocate some shared memory segments. I can not decide which is the ...
I have a basic GameController with a finite state machine to handle game logic. I'm adding game modes and coming across problems cleanly implementing them. The core functionality of the game stays the same--Physics, input handling, level creation--but I have many places where I need an if/else block because functional...
I'm building a service where I need to filter activities from different products. The actual data itself lies in another key value store. As the service needs to support filtering on the activities as well was planning to use mysql for the filtering usecase alone. As the activities from different products can be differ...
One of the scrum tests contains the question about the definition best describing "Done" when multiple development teams perform a work on a same product. A proper answer states that those development teams must have such a definition of "Done" that can make their combined work potentially releasable. What is not clea...
If an ETL tool is being used to move data from an OLTP database into a "business intelligence reporting" database, is there any standard way of automatically testing that the data in the reporting database is accurate and correct? NOTE: I'm not interested in testing the functionality of the ETL tool itself only that th...
I'm having trouble keeping my user stories for basic operations from sounding ... basic. For example, suppose I'm building a CRM to keep track of clients: C: As a user, I want to create a client, so I can ... keep track of my clients? R: As a user, I want to view my clients and their properties, so I can ... know what...
Let's say we have this method: string Add(int a, int b) { var sum = _calculator.Add(a,b); var response = _formatter.Format(sum); return response; } Now I want to unit-test this method. Assume of course the code is not actually that trivial, _calculator and _formatter might be external services, there's som...
I have been repeatedly told that explicit type conversions are an indicator of bad code and they should be avoided. Now in all honesty I have been annoyed a bit by these claims due to the nature of my work which seems to require a lot of primitive type conversion. So I want to know if there is a better way to structure...
I've been learning about proxy classes in c++. I really don't see the advantages of using proxy classes, as they're not any better at concealing information than private members are. What advantages and/or disadvantages do proxy classes offer compared to normal private members? Note: I am using the "proxy" definition f...
Let's say I have a REST API, that has the ability to provide field mask (i.e. the API can return M out of N attributes where M is a subset of N). If a statically typed client (example: one that's written in Java) requests data from this API, is there a way to "gracefully" handle nullability issues. If out of N fields, ...
Let's say your company sells software that comes with customizable text, and your team's job is to customize it. The client engagement includes a contract in which the client specifies all of the text resources and where your team guarantees a complete test cycle. Somewhere in the code there is logic that looks like th...
Basically, I have a remote hosted server somewhere https://nnn.com And then I have the NNN Desktop Client. The Desktop Client shows information X. I change information X from the remote hosted server. How can I make it so that the displayed information X in Desktop Client is automatically updated? At first I thought t...
This question concerns the C# language, but I expect it to cover other languages such as Java or TypeScript. Microsoft recommends best practices on using asynchronous calls in .NET. Among these recommendations, let's pick two: change the signature of the async methods so that they return Task or Task<> (in TypeScript,...
In an effort to save this question, I have re-written it. The original question was regarding how to associate aggregate roots. I have re-factored the code slightly but believe this may couple the code too tightly. Do I introduce too tight of coupling by passing aggregate roots around? For example: class Order { pu...
Components involved: Mobile Client Microservices API Gateway Each microservice is a Flask application exposing a RESTful API. When a request is made by the mobile client, it is sent to the API Gateway. One of the most important tasks of the system is to perform the furniture selection and furniture placement algorit...
Some test frameworks, notably DejaGnu and py.test, have an "XFAIL" flag/status for a test which says that this test is expected to fail. If the test succeeds, it's marked as "XPASS" (unexpected pass). Isn't this just a redundant overcomplication? It seems much easier and comprehensible to just use an assert that would ...
Say I have this reasonable contrived situation: public class Toast { public bool Toasted { get; set; } public int MinutesToHeat { get; set;} } public class Toaster { private Heating _heating; public Toaster(Heating heating) { _heating = heating; ...
When we determine names for the variables, there are two important issues that the people mention: The variable names must be explanatory. For the sake of this, their names can be long.` The variable names summarize main purpose briefly; they cannot be long. Long names decreases understandability.` Which one of these...
I'm trying to decide which is the best architecture for a turn-based multiplayer game where the players can be either humans or AI and the UI is optional, for instance because the game can just be used to make the AIs fight against each other. Let's take the simplest possible game out there, tic-tac-toe, and I used a c...
ls and objects functions are both from the base package and are exactly the same as discussed here. I've seen other examples of duplicated functions (in the tidyverse and base if I remember correctly). To me, having this type of functions juste make the code less clear by introducing more and more functions. I don't se...
Reading the final chapter 6 of the paper "The Many Faces of Publish/Subscribe" I stumbled across: Decoupling is a desirable property because it enforces scalability at the abstraction level, by allowing participants to operate independently of one another. At the implementation level however, scalability remains a sen...
We are creating several websites, the main content will be the same across each of them but there will be some differences (e.g. extra button, extra texts, different styling) what is the best way to manage this in git. there will end up being around 30 sites and we want a way to be able to easily change something acros...
Here's my setup: Entity Framework Backend Large WPF project that has a main window with 3-4 user controls on it, each of which has 3-4 user controls on it (and so on, in some cases) What I currently have: public class MySettings { public string Property1 { get; set; } public string Property2 { get; set; } pu...
I've been using git for a while, but still do not understand how to deal with feature branches. When you develop in a feature branch in a strictly local manner everything makes sense. You commit, merge upstream, rebase on master and finally push everything. Things change with feature branch being pushed to a remote ear...
Do we have pattern, which is opposite to Template Method? I mean, in base class we define parts of algorithm and abstract method which implements algorithm. Then in derived class, in that abstract method, we can mix those parts as we want.
I'm adding admin dashboard to a website that doesn't use HTTPS. For now only that (admin) section requires user authentication. If I use encrypted + salted password and check the client IP address to allow only couple of IP-s to be logged in, will it be not secure enough? Can the attackers imitate the client IP addres...
I have two Microservices A and B. B Microservice has a large set of an entity called User. A Microservice stores the User entity in its own DB if User is configured by an agent. There is no flag available in Microservice B's DB to find if the User is configured. I want to find all the list of all unconfigured user ...
I have an Angular application with a table, and I'm considering having the console application take the name of C# programs that the user can run. I was thinking of passing the name or code of the console application to a ASP.NET WebAPI controller that will run the console application. However, I'm not sure if it's...
Generally in procedural/imperative languages, it's best practice to place variable declarations as close to usage as possible. This seems a little hazy in lisp, considering more code is used if there are separate lets. Given an example function using two lets: (defun draw-box (new-image corners) (let ((h-len (- (alas...
My question is in the header. I would like to know is there architectural solution that enables to perform nested transactions on the business model. Let me to explain - the standard flow for web service is validate input data process request persist results write response However, there are cases when i Can not vali...
In Laravel (for the record I'm using v5.6) there is an option to queue emails for background processing. I have a scheduled job to send out daily email alerts to users. Currently the job drops the emails (mailables) in the Laravel database queue and I use the Mailgun driver for sending out emails. My question is Mailgu...
Is it better for an API when it provides additional methods that check if something exists before adding? For example: if (!userManager.HasPermission(user, "somePermission") userManager.AddPermission(user, "somePermission"); versus userManager.AddPermisionIfDoesntExist(user, "somePermission"); If you use this HasP...
I'm trying to redesign a provisioning application that administrates other application through their REST API. The application is quite simple, we have groups, we have users and roles and we have a list of software to provision. We are giving access to some software to groups and we are applying different strategies to...
I am currently working on a project where I need to manipulate a tree-like data structure, which I implemented with a composite pattern. I want to be able to do different actions on this data structure, so I implemented a visitor pattern. I was starting to see some code duplication in between my visitors, so I decide...
I want to implement two methods: AddPlayers and AddPlayer. Is it better when AddPlayers calls AddPlayer or AddPlayer calls AddPlayers with a single item array? Is there a significant difference in performance and IL output? // AddPlayers contains the logic void AddPlayer(Player player) { return AddPlayers(new [] { ...