instruction
stringlengths
34
36.1k
In my current project, I find my self making factories, but for two very distinct reasons: Reason #1: To assist my IoC container if a particular class needs an parameter that is only known when the class is created. This might also include reading data from a config. This kind of factory contains no business logic, onl...
It is probably related to "Who should read Exception.Message if at all" and similar questions asked on this site, but I don't see how it is possible to always generate a custom message while avoiding exception messages. Also in .NET all exception messages are localized by default. Does it make sense or is it just a b...
I am dealing with a drawing app that allow the user to draw a set of Components (which are like the graph vertices) and they can be wired (like the graph edges) on each other to simulate how their connection propagate and affect each component based on their input, like a function on each node that takes all inputs, ap...
Currently, I'm designing the intended operation of a (RESTful) API which a team of developers will eventually build. I'm not concerned with implementation details, as long as inputs are correctly mapped to outputs (and data in the database won't be messed up :-)). To me it's not important whether it's built in an OOP o...
Until now for each of our applications we store application configuration in the same repository as the code that uses the configuration. We have environment specific yml files (dev, test, .., prod) that contain plain text as well as encrypted configuration values. Those get deployed for example as "Application Setting...
This presentation describes several algorithms for solving a CSP for scheduling. Say I have a few processes with some constraints: a before c c before b b after d c 50% more important than e give d at least 20% of the total running time f before and after d g after f only if b is still running run h if there is at leas...
Due to many vulnerabilities disclosures, we had to upgrade our core framework, on which large parts of our system depend. (In our case, it was Spring framework version from 4.3.16., but that is just an example, probably less important.) We fixed some of the backward compatibility issues in the new version. (Like : new...
I am currently writing a Discord bot and have reached the point of needing a refactor. With this being my first stab at JavaScript/NodeJS and making a bot in general, there are a lot of mistakes I made along the way that now need correcting. With this in mind, I have been trying to figure out all of the things that I s...
I am currently refactoring a WPF application that is built on the principles of the Repository Pattern. It uses Entity Framework as its ORM, and is Database First. Each of those entities is wrapped by Repository, the interfaces of which are then used in Unit Of Work. Those units of work are then used by ViewModels. How...
Why would we use the userinfo endpoint in OpenID Connect to get information about the user when we can simply include that information in the access token? The UserInfo Endpoint is an OAuth 2.0 Protected Resource that returns Claims about the authenticated End-User. To obtain the requested Claims about the End-User, ...
I want to express a use case diagram involving two stakeholders, where one stakeholder's use case is co-depending on an artifact, that is produced by the other stakeholder's use case. In the following (minimal simplified) example I try to express this using the associations for dependency, which also are used in use ca...
I have an API I have designed which can return data in 2 different units. To explain this I am tending to use the example of a measurement, in particular temperature. However my use case is slightly more complex, representing a tree of values with percentage values on each level, whether showing this in relation to the...
I am interested to see how a for loop / while loop would be implemented as an automaton. I am having difficulty imagining how that would work. Say the while-loop did this: var i = 0 while (i < 10) i = i + 1 Not sure what happens if that were implemented as an automaton (what the states and transitions would be, and wh...
For instance: python3 -m What is the technical term for the "-m" ? And, where can I find a list of these "modifiers" that correspond to a command? Then, how would I find out what each of these "-modifiers" do?
I have an activity with two fragments attached, Fragment/View A controlled by Presenter A and Fragment/View B controlled by Presenter B. View A is on the top half of the screen and does not change through the life of the activity. View B takes the lower half of the screen and is swapped out when navigating to another f...
Most Java EE guidelines suggest that we should define Abstract EJB services (APIs) and then define concrete implementations in order to conform with OO design principles. But at the injection point, either the EJB is Local or Remote, we are forced to provide the concrete implementation class. Eg: @EJB(jndi="java:global...
Wondering if there is anything closely resembling data-binding but for boolean values / triggers. It seems like it could be related to Binary Decision Diagrams (BDDs), but they are precomputed rather than dynamic I think. Say you have 100 or 1000 boolean variables all inter-related in a graph. And one of them changes. ...
I'm working with JavaScript and PHP right now. My JavaScript uses camelCase while my PHP uses under_score for variable/object/array naming. I often have JavaScript send data to PHP. In fact it's specially made to send to PHP. So, my question is, should I write the data being sent to PHP by JavaScript in camelCase or un...
In a Software Engineering class, we had an assignment to read Parnas' seminal paper on modularization [0]. In this paper, two approaches of dividing a software into modules are discussed: Traditional Approach: A flow chart is drawn to work out the single processing steps and the program's high-level flow. Then every p...
I need to architect a system for my company. My question is specific to logging. Part of the requirement is to log 2 kinds of data. A1. User events (Ex: UserA clicked on Button1, performed Action#21. Error occurred while performing Action#34, Successfully completed Action#51). A2. Complete API traffic(request and respo...
I am considering CQRS for building a realtime game server (not gameplay but the economy). For some reasons. Scaling, Event logging, Model changing. However in realtime game when player upgrade, for example character. I mocked the client without need any server feedback. But if he close the game immediately after upgrad...
For example, when an issue tracker offers the functionality to users to keep a prioritized backlog of tasks and used a relational database for persisting this information, what are effective ways to encode this information? Of course one could introduce an integral field priority (possibly unique) and sort entries acco...
I have an object that describes a two-dimensional Graph: class Graph { var points; // Array of points } Now I need to find some complex patterns in this graph, like (but more complex): Find two consecutive points with the biggest differences. Calculate for each point the average of the X previous points. I'm wond...
I've read that nesting Promise continuations is bad practice. For example, here. GetCustomer().then(customer => { ProcessCustomer(customer).then(processingResult => { console.log(customer); console.log(processingResult); }); }); As the 2nd function call relies on the output of the first, un...
Based on the demo or license version of my application, I am supposed to either save the data to a file (xml) at a specific location or a relational database. What should be my approach for this case in respect to class design? I assume using strategy pattern will be suitable in this case.
We currently have a big Django web application: all data is centrally managed by the webapp, via models backed by Postgres. We want to offer access to the data in a more decentralized way, and the solution that we are aiming for is to provide small uServies dealing with the different application domains. That is, from ...
I am building a web application that makes use of multiple API's (Google Maps, Weather APIs, and more). I am using Python + Flask on the backend, and Javascript (probably with React, I have not decided yet) on Front end. The application will take the results of these various API query's and then give the user a simple,...
So compile-time annotation processing is as old as the annotations themselves in Java. Yet most of the useful libraries were developed with the runtime approach in mind – at least at first. Now, however, I notice a recent rise in interest in the compile-time approach. Where until now we only had runtime annotation libr...
Should information about the permissions and roles of the client be included in JWT? Having such information in JWT token will be very helpful as everytime a valid token comes, it would be easier to extract the information about the permission about the user and there will be no need to call the database for the same....
I am pretty sure that in one month, I can create a website semi to professional with really good design, functionality and security. I have made quite a few researches and I have found websites where I can advertise my own website and sell it. However, I still have some hesitation: What risk do I take selling a website...
Is there a cleaner/ better readable way to maintain and iterate many-many mapping rather than multiple if conditions ? (One way would be to store the mapping of ReportType -> DataSet Req. in the database) For e.g if there's an application which depending upon 'reports selected', generates reports using data from requir...
While creating/assigning the JWTs to users, should we also store them in our databases? The negatives/cons of storing tokens in database would be, that all the data in the payload of the JWT token is already stored in the database, hence storing the token will storing the redundant data, also the verification of JWTs h...
The question is in the title. My guess is that the answer is "No", but I would appreciate confirmation. This page mentions as a downside of the Lesser GPL that using it permits use of the library in proprietary programs, but doesn't seem to touch the subject of use by a Lesser GPL library.
The Wikipedia article on the subject of inner classes enumerates a number of programming languages that support nested class definitions. Historically speaking, which programming language first added nested classes to its feature set?
Would it make sense for me to use a builder pattern to return data from an API? Currently I'm just creating the array structure and returning it. In more detail, I have 3 exit places for my class that should be accounted for (one of them being empty results). Basically it is just a multidimensional array in PHP like be...
I'm making an online game and it has a server handling smaller game server. We call it "MasterServer". This MasterServer listens to commands from both TCP and HTTP and answers to them using its own services. The thing is, the number of services is growing and I'm worried that it could reach a point where having then as...
Say I have class with a boolean member variable fancy: public class MyClass { private boolean fancy; } Case 1. I could the define the setter and getter as follows: // getter public boolean isFancy() { return this.fancy; } // setter public void setFancy(boolean fancy) { this.fancy = fancy; } Case 2. Alter...
I was reading on this slide show presentation about Elder Scrolls 6. The author writes: Add some different directions to swing your weapons, more tactical options, feinting, parrying, literally anything Let's define a few words here: feinting: a quick movement that you make to trick an opponent Parrying: to defend ...
I want to expand my personal projects portfolio, so I decided to make a card game. To be more precise, it's called Macau. I've read this answer on StackOverflow and tried to follow the steps from the first answer. I made a narrative in which I describe the general rules of the game and its particularities. Macao game....
Trying to change payment related stuff in current project, but still couldn't decide on architecture of small part. I hope you can share your feedbacks. Flow and state: We have payment account using which we send money (paypal, swift or iban accounts), each time user wants to (1) add/update his/her payment account, we ...
Suppose we have domain Character and Player. Character owned by Player. Player PlayerID : GUID OwnedCharacterIDs : Guid[] Character CharacterID : GUID OwnerPlayerID : GUID While my business logic required both side of references. Question is Should I have both direction reference? This will cause redundan...
I've created a rest generic service which additionally consume a websocket per resource my websocket code looks like so: initialize(hubSubRoute: string): void{ const accessToken = this.authManager.getRawAccessToken(); let hubUrl = environment.baseUrl + hubSubRoute; if (accessToken) { hubUrl += '?' ...
Say I have different types of operations which i need to perform. I have an abstract class 'BaseOperation' which has all the information common to all operations. Now i need to categorize these operations based on an attribute and then further categorize every operation in each category based on some other attribute as...
I'm interested to know how software deployment for cross platforms as well as different programming languages happen. Like, Customers is on - linux and Windows Languages - Java, .Net, Ruby and Python I wanted to understand how Ruby and Python projects/applications/modules are built and integrated with Java or .Net ap...
The situation Our system has a MySQL database with a product table whose parameters can't be modified. In order to add optional extra parameters, a developer designed a key-value pair table which looks a bit like this: +----+--------------------+----------+------------+ | Id | key | value | product_i...
Let's say I have a asp.net-mvc application and I have to check that object can be deleted before deleting it. public class ItemController : Controller { public ActionResult DeleteItem(int itemId) { // Check if any customer currently uses this item. var customersUsingThisItem = _customerService.G...
Here's our problem - we have several solutions with multiple projects using our own nuget packages. We're following GitFlow, but not SemVer. Every time we're developing bigger feature or epic we want to keep it's code up to date with our development branch (which can have some other features or bugfixes done in time of...
I have an amateur question with respect to CDDL 1.0 License. This link provides a list of all the open source software used by intellij idea. The one in relevance now for this ticket is: WADL-core that it uses which is licensed to CDDL 1.0. Now CDDL 1.0 demands that the source of the library also be distributed along...
I have designed a microservice stack with docker as backbone, about 50 services in total so far, still growing... Everything works well, happy with the design choice, but room for improvement. I notice a lot of duplicate logic in the different services for instance. Most of these duplication is related to queries to se...
Let's say, for example, you have an application with a widely shared class called User. This class exposes all information about the user, their Id, name, levels of access to each module, timezone etc. The user data are obviously widely referenced throughout the system, but for whatever reason, the system is set up so ...
I already went through several versions of the DOM and HTML specifications on the W3C's websites but I have never seen a complete overview model or meta model regarding the DOM or the HTML. Additionally I also failed to find such a model on other websites. Is there a good reason for that, for example does the DOM not f...
I have been reading on C# Performance Counters and I was wondering if I should be keeping them in my release build? I have never encountered an application that has it's own custom performance counters which leads me to think that maybe it is not a good practice. At the same time having performance counters specificall...
This is a standard confusion I've always had with the concept of story points. I've always been told that the complexity of story points should go up roughly exponentially. Essentially a task pointed at 5 should be more then 5 times as complex as a task pointed at 1. However, when tasks are assigned the discussion of ...
I'm developing a CLI based application. It has a "login" command to perform authentication: $ myapp login $ Type username: hector $ Type password: ***** $ Login success! Internally, myapp login makes a request against a HTTP API and a authentication token (JWT) is returned, so I need to keep it in the client somehow,...
Sometimes I can see method definition like: public User findUserById(int id){ } But my justification is, isn't "(int id)" already include the information of "ById"? is it better to have naming just like: public User findUser(int id){ } instead of having "ById" to repeat the already present information?
I have an asp core MVC project for a college and I would like to implement a timetabling feature. To see if I could successfully even generate a dynamic HTML timetable, I started playing around in a separate console app. Naturally, the more I played, the more classes I ended up adding, and the more complex the HTML gen...
We use quite a few external open source libraries in our projects, pulled in from Maven Central etc. I was wondering what is best practice to ensuring that you don't introduce some sort of security risk by using these dependencies. We have quite a few and it's unrealistic to re-write these libraries. I'm not sure t...
Let's say I build my code so that I inject ALL dependencies to every class and when I test, I replace those dependencies with test doubles. Let's also say that when I work on a class I run its tests to test it. Given that a regression is an unexpected failure in a part of the codebase other than that which I changed, i...
Assuming you want to build automated tests for the following (very simple, if odd) class. // Calculates the distance between neighboring values in a vector // and provides functions to return the distance from one index to the following // or to find the first occurrence of a specified distance class NeighborDistanceFi...
We need to email our customers once per year (yes it's opt-in etc). As I see it we have 2 ways to record the fact we contacted them (so we know not to contact them for another year). A log, or a 'lastContacted' field in the customers table. I don't like adding fields to the customers table - however, if we go the log r...
We have 4 classes. Field ForbiddenField inherits from Field RequiredField inherits from Field ForbiquiredField : the subject of my question I would like to define a function Validate()in ForbiquiredField, originaly defined in ForbiddenField and RequiredField. I would like to use both of functions X() defined in Forb...
Is it a bad design if we inject dependencies based on the running environment (production, testing, development, etc)? Consider the following container in Laravel as an example: $app->singleton( \App\Services\Mailer\MailerInterface::class, function($app) { if ($app->environment() === \App\Support\Environments::...
In the Rust documentation, under the structs section, they give this example of how structs need lifetimes when they contain references: struct Foo<'a> { x: &'a i32, } because We need to ensure that any reference to a Foo cannot outlive the reference to an i32 it contains. My question is: shouldn't that be impli...
Using C# as an example, extensions on IEnumerable to allow code like collection.Each(i => i.DoStuff) rather than a foreach loop are generally frowned upon, mainly because they don't follow LINQ conventions of being functional, in that the functions they take are statements rather than expressions, written to have side-...
I am writing a software specification and I got confused with the data dictionaries section. is it a full detail of the interfaces and stored models ( like of a database ) or a just a second step of analyzing the projects's models ( a more detailed text version of the models explained before ) ?
Often I came across situations like this, how to write this code in a neat and clean way. One more issue I find here is performance as I am iteration a list and then it's properties. Edit : - while the suggested How to tackle a 'branched' arrowhead anti-pattern? post address the nested if-elseif-if concern to a great e...
Functions are the first line of organization in any program.I believe writing them well improves the readability of code to some extent.I am working on metrics that describe how readable the function or class is ?. One such metric that contribute to readability is Function should do only one thing from clean coders bo...
I am looking into assembler and I am trying to understand the whole compilation process. During the linking step I use: ld -m elf_i386 -s -o hello hello.o Everything works fine, but I do not understand what the -m parameter does. In the manual it says: Emulate the emulation linker. And here it says: A linker emulat...
I have recently seen an example of what I think is a clear violation of ISP, but my colleague argued it is easier to use. This is what happened: We had Options class that had 2 fields sent as a parameter to one of the methods where both fields were in use. Then there was a new field added that was used in another meth...
I am trying to create a reusable component / Cocoa Touch Framework in Swift that would display the current weather based on the user’s location. Right now I cannot decide which approach should I take. First approach: A custom UIView that displays the weather and forecast information. And inside this UIView is the logic...
Situation Currently I'm developing a web service in which users can (generally) upload binary files. These files are stored in the file system of the host OS and some additional metadata about the file is stored in another SQL database, including its available version identifiers (a file may exist in multiple versions)...
I am working on RCP application, I'm new to this application. Spring beans are used to write business logic to save/fetch entities. But, instead of sending entities directly to client we are converting to DTOs and populating client. While saving, we again are converting DTO to entity and saving. What's the benefit of t...
I want to use PowerArgs for a console application I am writing. It offers some nice features I'd like to try. My root looks like this: public static void Main(string[] args) { try { Args.InvokeAction<MyClass>(args); } catch (Exception ex) { Console.Wri...
I have a simple class Notification, which has a few properties (title, body, op) and only getters/setters. Among all my project I'll use different kind of notifications, this is Notification objects but with different title, body, op depending of the logic of that part. I'm wondering what would be the best aproach to i...
Intro I have been weighing the pros and cons of using WebSockets vs. an Ajax call for an event which will happen every x number of seconds (in this case 5). I'll start by explaining the scenario. Business customer wants "real-time" updates to a webpage based on data living inside a database. This database resides withi...
I am working on introducing tests to an old system. Because of the amound of technical debt, we have landed on component/interface testing. The system is a servies of servers which sends messages in a custom format between each other. The idea is to create a framework where we can create a testcase to stimulate a serve...
I have a program where the domain is focused around programs. As part of the domain, I have a 'ProgramType', which is an enum formed mostly via a string from the database but also via a bit of logic. I currently have it split between three files (ProgramType, DatabaseTypeAttribute, and ProgramTypeExtensions). However, ...
I'd like to know what the difference is between hardware abstraction layer (HAL) and data abstraction layer (DAL) when speaking about embedded software. I might have the abbreviations wrong though... My understanding is that at thr HAL level you use the mcu's registers while at the DAL level you don't. I wrote a quick ...
When I have a reactive stream of some composite data object, I'm never able to reap the benefits of reactive programming below the highest level of the composite. Here's an example to illustrate the issue: Say we are building an edit form for data of type Product: Product: { name: string description: string ...
Is it better to store state in a global variable or in a coroutine, specifically in Python? I don't understand the best practice here. For example, consider a simple Flask script: from flask import Flask ... app = Flask(__name__) ### GLOBAL MEMORY ############ OPTION 1 exmple_variable = 'contents of some file or som...
There are lots of advantages to a monorepo. We also read that large companies like Google and Facebook use this tech to keep all source code in a single repo. But how do you manage to limit access of a certain team to projects they are working on when using a monorepo? For example, we have a microservice infrastructur...
In thinking about formal verification techniques, you also need to have test coverage. But as that article shows, you can easily say you have "100% test coverage", but every test doesn't have any assertions. That is the extreme. But I'm wondering if there is ever a situation where you can say that you have 100% test co...
Most UML software has two kinds of nodes for the activity diagram: Action and Activity. To me it seems that an Activity could represent something that by itsself would be represented by another activity diagram, and the actions would be seen as "atomic". Is this the correct semantic view?
For example, a class usually have class members and methods, eg: public class Cat{ private String name; private int weight; private Image image; public void printInfo(){ System.out.println("Name:"+this.name+",weight:"+this.weight); } public void draw(){ //some draw code which u...
The problem is like there are few restaurants and few delivery guys available. Each restaurant has a meal order and the delivery guys are to be assigned to the restaurant. Now there may be many criteria for assignment of the guy to a restaurant. For example, the distance between delivery guy and restaurant, the priori...
Given these nodes: a b c d e f g h And given some edges between the nodes like this: a/b/c b/c/d c/e c/d/e/f c/g f/g e/f/g a/c/h h/a/b c/a d/b/c f/g/c d/a/f g/f g/a/b/c f/a/b e/a/c (where a/b/c means one edge from a to b, and another one from b to c), so this describes a directed graph. Here is another, more compact ...
When I use Angular CLI to generate a component, the test linked uses the logic foo.spec.ts. I am reading a tutorial where the test linked uses the logic foo.test.ts. What's the difference between “foo.spec.ts” and “foo.test.ts"? Is there even one? It is just a matter of taste or is there a logic behind?
So I'm building my first application, in Python, and some issues have cropped up because of the lack of interfaces (I.e. explicit type declaration) My design involves several homebrew packages, and I've been taught to reduce coupling by using a controller class for package access. Here's an incomplete class diagram - s...
I'm developing a shop. I'm trying to figure out: where should "total_grand_price" belong to? "total_grand_price" = price of all order items - discount + shipping + taxex +- etc.... Should it be a property of Order or Invoice? What up- and downsides of having it in either? Also, could there be a case where t...
I am currently working on a player design. Without going into details I have two main layers 1. Playback services 2. User Interface. Playback services consist mainly of Player service and Browser Service. They communicate over REST API. User Interface subscribes to various services. I want to keep the services as state...
As far as my understanding for composition, the children cannot exist without the parent. But my instructor is suggesting that the following example is an aggregation, I just want another opinion. class ItemForKids { } class ItemForMen { } class ItemForWomen { } class PageContent { private: ItemForKids* ite...
In Clean Code the author gives an example of assertExpectedEqualsActual(expected, actual) vs assertEquals(expected, actual) with the former claimed to be more clear because it removes the need to remember where the arguments go and the potential misuse that comes from that. Yet, I've never seen an example of the for...
I am trying to load test a queue that works on a pub sub pattern and can't figure out how response time is to be calculate and the TPS(transactions per second). Problem statement : The pub sub pattern requires us to develop different script for the publishing user and the subscribing user. Every message that is sent to...
Currently C is considered a low level language, but back in the 70's was it considered low level? Was the term even in use then? Many popular higher level languages didn't exist until the mid 80's and beyond so I'm curious if and how the nature of low level has changed over the years.
I am new to graph data structure. Everywhere on google it is said to be list(or array ) of linked list. My question is can not it be represented as list of list(in java array list of array list) or map of list(in java HashMap with key as node and value as array list of connected node ) ? In all three mentioned approa...
The use of instanceof or getClass() is largely considered code smell. Is using a variable to indicate the type of object you're using also considered code smell? Suppose if I had an enum called WeaponType: public enum WeaponType { ReloadableWeapon // -- imagine more weapon types } and Weapon class: public abstract...
I have a question about architecture and I would like to know your opinion. Given a product formed by an API and several consumers (Android apps, iOS apps, web apps ...), where should I implement the API response data localization? In the API itself or in each consumer? When I refer to data response I mean formatting d...
I'm trying to figure out the complexities of these two functions that I've written but could not understand.def First, I thought it is supposed be O(N). But it is not clear how many times the loop run because I have no idea how many prime numbers could be found. def self.find_primes(n) primes = [] total = 0 ...
Functional languages seek to minimize accidental state (computationally-convenient but logically unnecessary data dependencies) by endorsing the most granularly modular, mathematically unambiguous constructs. Yet general-purpose register machines achieve the greatest time-/space-efficiency by maximizing data dependenc...
Where should the business logic for a project that utilizes Onion Architecture be placed? In my case, it's a C#-based project, utilizing Web API and possibly a MVC UI for the presentation. But that may not matter, since I'm just curious about this conceptually. The two diagrams below seem to be the most common ones ...