instruction
stringlengths
34
36.1k
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 ...
I have this project I want to do, using Angular 5/6 for frontend and Codeigniter 3 for backend. The problem is that I don't know how to combine the two, and all the tutorials I looked were using AngularJS which is version 1 whereas i'm using version 6, and it didn't really work. I am looking for something like JavaScr...
I have been implementing a proof of concept application using Uncle Bob's Clean Architecture and I have run into a bit of a problem. Uncle Bob's architecture calls for the explicit separation of request and responses using interfaces. This is not a problem in most cases (e.g. when implementing a UI using the MVP patter...
Projects like webkit, Linux kernel and many others take over ten minutes if not hours for a full build. What's the practical development cycle for these large projects? Specifically, how does a developer fix and test an identified bug? Can you give some concrete examples?
I'm at a bit of crossroads here and I wanted to ask the opinion of the community. I am creating a chat application for our company. Now, like every chat application out there, the messages are saved on a server that allows the client, at a later point, to access older messages. What I am lost at is using HTTP and WebS...
In a boolean system, say you have a while loop going on. Then you might have this: if (just_did_x) { do_something() } To prevent it calling do_something() more than once, you might do: if (just_did_x) { do_something() just_did_x = false } But the problem with that is, you might reference that boolean in multipl...
I am trying to start a documentation about a class library that is already finished/developed. The purpose of the documentation is to be used by other developers in order to understand what kind of methods are included in this class library and how to use them. More specifically documentation like Javadoc tool that pr...
I'm working on a system that integrates with several third party services via APIs. Those services require authentication. Usually, the services are implemented as REST APIs using HTTP. My system assumes that the requests made to the third party services are stateless. However, some of them are starting to provide WebS...
I'm writing a CSV parsing library in C and am considering whether to express error codes as return values or as parameters passed by reference. For example, here are the signatures for the function that counts the number of columns in a CSV file, using both designs: // Method one // Return value: number of columns size...
Following this question, the solution to resolve data binding is to use DFS and Topological Sorting. I am not really sure exactly what that means. Here is an animation that roughly demonstrates what I am considering. Say we have a data binding model like this: ● ↓ ● → ● → ● → ● ● ← ● ↑...
I want to create a desktop application. The application must be able to accept database transactions even if internet connection is lost, but as soon as internet connection is available the application should start synchronization data to the web server automatically. What would be a good architectural approach to this...
I have given the following architecture: Layers: Bootstrapper MyApp.Start IoC-Container etc. UI Layer MyApp.Gui Views ViewModels Business Layer MyApp.Core DataGenerator DataGeneratorRequest DataGeneratorResponse MyApp.Core.Interfaces IDataGenerator IDataGeneratorRequest IDataGeneratorResponse There is a metho...
For the following UML Class diagram, I have a reference data type Nurse, and I am using it in Hospital Class, is it needed all the time to describe the reference data types in UML Class diagram? Is this diagram created correctly? Also, is it needed for the methods that don't return anything to mention: void?
How can I show a Java HashMap data type in UML Class Diagram (or C# dictionary)? I.E. This class: public class Test { private Map<String, String> map; private Map<String, int> map1; public Test(){ this.map = new HashMap<String, String>(); this.map1 = new HashMap<String, int>(); } ...
When the @Override annotation was introduced in Java 1.5, which feels like back in the days when the dinosaurs roamed the Earth, it was a good idea at the time because, amongst other advantages, it made your code self-documenting and it ensured you've spelt the method correctly. Now it's 2018 and almost everyone writes...
I have a scenario in which thousands of IoT devices -- each fitted with a sim card -- are geographically distributed and shall be controlled individually. Therefore each IoT device has a WebSocket client with which it can connect to a central system. Since there might be a lot of communication, the IoT devices connect ...
If I am sending a POST request to update some object in a DB, such as : User{ id: 20, name: "Jack", UserAssociations:[{ id: 100, association: object1 },{....}] ........ } Where I am sending a parent object along with an array of child objects to a RES...
I have a maven project in GitHub that I wish to work with using eclipse. I want to keep the GitHub repository clear of any eclipse project artifacts such as the .project file. Is there a way to do the following (or alternative that accomplishes the same): Have two GitHub projects -- one being the pure maven project Th...
So I don't know if this is good or bad code design so I thought I better ask. I frequently create methods that do data processing involving classes and I often do a lot of checks in the methods to make sure I don't get null references or other errors before hand. For a very basic example: // fields and properties priva...
I'm big a fan of static type checking. It prevents you from making stupid mistakes like this: // java code Adult a = new Adult(); a.setAge("Roger"); //static type checker would complain a.setName(42); //and here too But it doesn't prevent you from making stupid mistakes like this: Adult a = new Adult(); // obviously ...
I am trying to write a Hash Table in Java based on some Princeton article about it. The most commonly used method for hashing integers is called modular hashing: we choose the array size M to be prime, and, for any positive integer key k, compute the remainder when dividing k by M. This function is very easy to ...
How can I achieve a workflow in GitHub such that when you create a card in todo column of a project, a branch will be created which you can start working on? When you PR the branch and merge, it will be automatically dragged into done column. I've used VSTS before; I'd like to have something similar to that workflow.
Situation: I am implementing DDD in my first project and I would like to clarify how to correctly implement strategy pattern (in my case check if API token is active). This is a business rule of ApiToken instance but there could be various implementations of this strategy so I would like to delegate this logic to exter...
After reading rules of Clean Code, one of them is to use default constructor when using transferring data from one collection to other. For example i have : Dictionary<string, string> dict = new Dictionary<string,string>(); So what is best for performance? I know that LINQ is not effective, but is always better way to...
I have the following question. I have an abstract class that manages graphic elements. Let's call it GraphicHost. Something like that: class GraphicHost { class GraphicHostState { List<Sprite> sprites; List<Text> texts; } GraphicHostState state; public void setState(GraphicHostState s);...
I don't think the title describes the situation exactly. I apologize for the poor description. I'm trying to write a software system, in C++, that will have a heavy job (scanning the file system for a particular file or for infections, or just copying/moving a file from one place to another). This system has an intera...
I am doing a Java Spring-Boot backend project and I am implementing a controller-facade-service pattern on my structure. So is it best to put all my error handling on the facade layer, while the service just throws the errors occured, and the controller just receives the response entity produced by the facade? I imag...
I am using Azure Storage Blobs to persist certain models per tenant. While processing items for each tenant these models have to be pulled to memory, used for certain operation, updated and pushed back to blob storage. With time the size of models seem to increase and thus overall latency grows higher and performance d...
I don't know if this is a legitimate architecture that I've been playing with. It consists of nodejs servers for services and to create web app front ends. And it is using async messaging (Redis) to communicate between services. And socket.io to implement full duplex comms between server and web apps. So far in my e...
By using the qualified association element of UML Class Diagram, we can create HashMap as the datatype of one of our class attributes (see here). In my case, I have to use HashMap with different key datatype (String and int) if the audience would be only with Java developers I would provide UML Class diagram as below: ...
In my experience, most errors in an application are bugs: Syntax Error Range Error (number out of bounds) Reference Error (undefined variable used) Type Error Custom Assertions These should be caught before an application is in production. If they aren't caught, then typically the application will crash. Other types ...
Lets say I have some react components on domain-a.com. From domain-b.com, an applications calls an API endpoint on domain-a.com. This end point returns the .js of the above mentioned react components (bundled). These are then executed on domain-b.com. The react components render a UI and call some end points on domain...
Let's suppose we have a class whose state has to be saved and later restored, and we resorted to the Memento pattern for that. What if the state includes resources that have to be explicitly released (like file handles, OpenGL textures, etc)? Should I make them part of the saved state? This requires handling memento ...
Quite often you need to define a getter returning a reference to a member, and a corresponding setter. They usually look somewhat like this : class Foo { Type member; public: const Type& getVar() const { return member; } void setVar(const Type & value) { member = value; } } However, sometimes you have to m...
I have a requirement to validate a data field (a reference number for payments) in our finance system by connecting to one of our vendor's API services. The finance system does not have the connectivity to internet but can connect to the local network and the other servers, that have the connectivity to internet\cloud ...
Imagine I have updated a user interface label with a value. Since this is a label, end user cannot update the value directly and can only be changed through code. Lets say the value is X. X could be a result of a calculation or retrieved from db. So now the label text is X. If I need this X value for another method, I...
I've seen several questions on this website explaining that enums should be kept in the database when there is one (this one for example). However, I feel like my case is different and there are extra elements to take in consideration. The application I'm working on provides a user interface for people to customize "sc...
There are tons of courses and tutorials about specific technologies and programming languages such as: JS, HTML, Python, etc. However, the field of system analysis lacks the same attention that technologies enjoy. Is there unified methods for system analysis/modeling? What if I need to model an accounting system for a...
Background: I work for a small company which does not have a set of established best practices for designing software. I was hired to work on a project which gathers data from a stream, does some processing and aggregation and writes it to the database. It should eventually help replace an old system which is basically...
I have been reading a lot about microservices and have been trying to logically split my system design up accordingly. For the most part, my system will have a central database whereby I will have some triggers on important entity tables that will create an audit of all changes to the data. This trigger will write a lo...
Our project have a lot of layers, Entities Repositories UnitOfWorks Domain Services (Business Logic) Validation Infrastructure Application Services etc.. We are only writing unit tests for Business Logic layer and mocking other parts. Is it possible and reasonable to do TDD in this case? (All Business Logic cl...
When asking for positive number inputs on html, is it valid to allow + on the textbox? Like +42? Surely the + sign gets removed during server-side processing. But will allowing + be fine on the html textbox? It might be valid because + denotes a positive sign. It might be invalid because + is a special symbol. What i...
I have a wxWidgets application. This is the first, main module. The second module is an openGL engine. It's a model-view-(controller) structure, where application is the view (and the controller), while the engine is the model. . This is the problem that I need to solve: I need to take input from the application, and...
I have a few tables that are generic. One of them allows a user to comment on something, and the other one allows a user to favorite something. Initially, I had thought that to make it possible to favorite and comment on anything, I could have another table named something like CommentSet and FavoriteSet, that would be...
Recently I was reviewing my team leader pull request in our Web API hosted by Kestrel. There was a place in our code which is sort of hot path and we are processing frequently over hundred of items sequentially on each request. So I suggested him to process this items in parallel instead of sequentially to speed up the...
I've asked a question about Scaling Matrix Multiplication by CPU Cores on StackOverflow and it seems that merely adding more CPU cores to this problem won't reduce the time to do Matrix Multiplications dramatically. Now I'm wondering if scalable architectures are the answer for large-scale matrix multiplications OR a s...
I read in the Python time complexity page: A deque (double-ended queue) is represented internally as a doubly linked list. (Well, a list of arrays rather than objects, for greater efficiency.) Both ends are accessible, but even looking at the middle is slow, and adding to or removing from the middle is slower still. ...
I know this topic has been covered quite a lot but I can't find an answer to my specific situation. Currently, I'm using .gitignore to exclude sensitive content and keeping it (config files, etc) seperately. As my codebase expands into more and more projects, this is becoming quite difficult to manage and I also have ...
I recently started working on an existing project written in C++ Builder. The application consists of a MainModule that loads lots of modules (DLLs). The MainModule itself is a DLL (there is a small loader (.exe) that starts the MainModule). The MainModule should not crash if a problem appears in any of the loaded m...
Checking my Sendgrid account I've noticed many drops due to "Known bad domain". Those bad domains often seem to have been caused due to user mistake. ***@gmal.com ***@gmail.com.br ***@hotmal.com I was thinking of silently fixing a select few before saving them to the database. Is this common practice or are there reas...
My events are stored in MySQL and I'm reaching a point where I have tens of millions of rows and things are starting to get sluggish when pulling an aggregate I have read about "table partitioning" and was wondering if it was a good option for storing my aggregate events, since an aggregate is just a stream of events, ...
Context We are building an application that acts like a hub for messages coming in from multiple Producers and it assigns to Consumers based on certain criteria. Need is to have the design highly scalable, but at the sametime, core functionality of message-to-interaction co-relation shouldn't be broken. Main entities i...
What are the consequences (pros and cons) of using a single structure as the argument, instead of a list of parameters. Some of the advantages I see are: create multiple default parameters. Need not reply on the order of the parameters. In case of a refactoring, need not change the signature of the method. Some disad...
I'm working on a large codebase whose core modules are in C and extension modules are in C++. We have a coding convention for C code but I'm being told that we need to enforce the same coding convention for C++ modules. As a personal preference I dislike using an ANSI-C style declaring variabile at the beginning of the...
I'm writing something that handles length units, say, metres and feet. I don't want to accidentally convert between them (trying to avoid something like the Mars Climate Orbiter crash). I'd like to use the type system for this, so that the compiler will catch these kind of errors, and only be able to convert between th...
I was completing an infosec report and came across this. Does the APP support end-user authentication? Federated, Certified, other? I wanted to have some clarification on the terms. From what I understand End-user authentication means having user auth capabilities Federated means that the authentication system can ...
Our "unit of work" class has a method which takes a class type and creates a repository: public IRepository<TEntity> GetRepository<TEntity>() where TEntity : class { var repoItem = _repositoryList.FirstOrDefault(cv => cv.GetType().IsGenericType && cv.GetType().GetGenericArguments()[0] == typeof(TEnt...
I don't really write large projects. I'm not maintaining a huge database or dealing with millions of lines of code. My code is primarily "scripting" type stuff - things to test mathematical functions, or to simulate something - "scientific programming". The longest programs I've worked on up to this point are a couple ...
We are kicking off a new project following Scrum procedures and we realized that at the beginning of the project we have to prepare a lot of things that are not user related (so they are not user stories): Create project skeleton Create continuous integration system Set up policies and procedures Create and structure ...
I was wondering what the best practice is for creating multiple different data structure which can all contain references to the same objects. As an example, consider a video game with many entities. For iterating through the entities, one would probably want to use an array or list of entities so that they can be loca...
I have been developing Cloud Broker system so I have Users. Users can register with phone number and code. How should I design the User class? Class User { public string User_Name{get;private set;} } Or Class User { public string User_Name{get;private;} public string Phone_Number{get;private;} } So should I: Add...
I don't want to include the entirety of my language, but I think the relevant part is: <expr> ::= <logical> | <comparison> | <constant> | <addition> | <subtraction> | <multiplication> | <division> <logical> ::= <expr> "AND" <expr> | <expr> "OR" <expr> ...
I'm going to attempt to build a data-driven menu for my web-app. The goal is to be able to serve different menu options to different users from an API. The hope is that the server could return a JSON object that defines the menu. The challenge I'm facing is how to define what the menu options do. let menu = { "set...
For reasons unknown to me, forking repositories is not allowed in gitlab in our company. The idea was to allow the developer to fork and create a merge request which will then be approved and post approval the code will be pushed to the main repository. Now since we do not have the forking option available, I was think...
In general a character is represented in 1 byte i.e. 8 bits . This is I believe true for all text editors even for databases like oracle. 1 byte can represent 2^8 = 256 Characters. My question is when character can be represented in 1 byte why java takes 2 bytes to represent character ? What is the reasoning behind it....
I am looking for an elegant way to get and put values in nested, untyped maps in Java. For instance assuming I have a map structure as follows: Map m = { "a": { "aa" : { "aaa": "hello", "aab": "world" }, "ab" : { ... } }, "b": {...
I have a desktop app that generates numerous csv files. The application always runs on PCs that have been configured for the English (United Kingdom) region/format, but it's feasible that files might get sent to people using PCs with non-UK regional settings. I'm therefore curious to know what would happen if someone ...
I'm a developer in an agile team, and we try to use Scrum. So I'll put here a hypothetical problem to illustrate the situation. We have a very old app, using some messy and bad maintainability JQuery code. We also have parts of the app using React, and those parts are way easier to update/maintain. Besides that, the co...
My understanding is that the main feature Cassandra has to offer is linear performance at any scale; meaning that if I know 1 C* node can handle 500 queries or commands per second from my app, then I also can rest assured that 100 C* nodes added to the same cluster will be able to handle 500 * 100 = 50K queries or comm...
I'm trying to take a QVariant (in this case from a QProperty generated on a class) and based on the type, return a QWidget that allows for it to be edited appropriately. a signature for the conversion function might look like this: template<typename T> QWidget * createWidget(const QString& label, const T& value, QWidg...
Basically, I want to know how to simulate while and if if I'm handling the control flow myself through an array of instructions. The while loop can be simulated by if, as seen with assembly branching with je and such. But the question is, can a if statement be simulated somehow, perhaps by simulating a program counter ...
A common use of the adapter pattern is to support functionality that isn't actually supported in an underlying class. For example, if I use an API to interact with a Samsung Smart TV, I might want to add functionality not available through the API. To do this necessitates the use of a wrapper object that interacts with...
This is more of a subjective question and i don't expect a perfect anwser. I have different behavior/rules in my system. for example : I have a behavior in my system that allows users to register to the same course multiple time. This behavior is configurable on the course side you can decide whether or not you allow u...
I am currently working on a project that generates videos from templates (a template being a collection of JSON files and assets). It seems natural to have a Template class that contains all the info of how this specific template is structured (e.g. which parts are personaliseable, what assets are required etc...). The...
First, this question is not really about binary search as I neither have sorted data, nor any sortable data at all. :-) W.r.t the "unsortable" claim see below; but I think the title term "unsortable" is important here, because, afaikt, any sorting would require visiting all "nodes", which is exactly what I strife to a...