instruction
stringlengths
34
36.1k
We had an exam and the question paper asked which of the following is not a defensive programming technique. I've answered it as print statement, that a print statement is not a defensive programming technique. I went back to school after 6 years of working as a programmer and I've not used print statements anywhere in...
I already to do research on internet about data design, they all explain how to do data design with database. But how to do data design without database? example i want to do data design for embedded system without using database
I have an REST API, which has a rate limit of 1 query per IP per 5 seconds. When the user tries to call the API too often, I respond with the HTTP status code 429 Too Many Requests and a JSON message. Now the question is, should I tell my API consumer the allowed rate, or should I just return a generic message? So whic...
I am writing an API to merge two different JSON Objects. Both of these objects can have same as well different number of properties. Object 1 : { "name": "Sam", "lastName": "Hanks", "address":[ { "addressLine1": "123 St.", "addressLine2": "xyz avenue", "phone": ...
I have some deeply nested react components. Let's limit them to 3 levels of nesting and call them Parent, Children and Grandchildren. The state for the entire app is stored in a single object in the Parent component, and is managed using the useState hook. export interface Parent { children: Child[]; } export inte...
I am trying to display a specially formatted dropdown list as part of a view. I have a controller action which fetches the data for the dropdown, then needs to format it by fetching certain other related data and putting it into a comma-separated format. This method is so far only used in this controller. The question ...
Hi I have a Order this order needs to be sent to an order system. There are several oprations that can be performed. Create Modify Check-Modification (this happens on existing order) Simulate Create without creating it Delete get order The way I have modeled the resource is the following: 1. PUT /orders/{id} - C...
Design Data Intensive Applications says Batch processing systems (offline systems) Chapter 10 A batch processing system takes a large amount of input data, runs a job to pro‐ cess it, and produces some output data. Jobs often take a while (from a few minutes to several days), so there normally isn’t...
I am creating a Discord Bot in Discord.Net. So first, of course this bot is not a professional project, but I still want it to look as professional as possible. And a huge part is the storage and process of user data. Sure, I won't get data like Credit Card info, private adress or workplace. I just want a user account,...
Let's say, that we keep track of students entering the auditorium using their IDs(Key) and their check-in time(Value) in a Map. We delete the entries once they move out of the auditorium. I want to know at a given point in time who all are there in the auditorium and when did they check-in. All Imperative languages do ...
I saw some books on operating system concepts mention the producer-consumer problem in the context of synchronizing concurrent accesses to shared resources. All seem to be in shared memory architecture. Does the producer-consumer problem appear in communication between processes in distributed memory architecture? If...
Let's say I have a class that's a bit more than a pure Data object, i.e. it holds some data and some basic queries about that data. (In this case, it's a class representing a timetable) Now, I want to run certain validation checks on that Data object, and I feel like this is a responsibility separate from that of repre...
When our in-house developed application (C#, ASP.NET) is throwing an exception, it displays a stack trace that contains path information like C:\users\DEVELOPER_FULL_NAME\path\some-module.cs. So it shows the full name of the developer who compiled it. The developers are telling me, this is unavoidable. I find this har...
Description of Desired Behaviour I have the following scenario: Component A can run freely as long as it is not blocked. Any other component can block the component A from running at any time. After blocking, those components may unblock A. Component A resumes running once ALL components that once blocked it "release...
I have been looking for a better design approach and will be providing my problem statement here with a similar example. As I don't have logic already in place but have the solution in mind which I think of first trying a better approach. I have two different system-A and system-B wherein system-B is dependent on syste...
The title describes an idea of a solution to a more general problem. Here is the general problem: I am developing a program which looks roughly as follows: [read a lot of data, store in data structure X] [do complex operations on X] . The reading is easy to develop, but running it takes a lot of time. The second part n...
From a software architecture perspective, are there major issues with using Salesforce as an application's single source of truth? Context: We are building the software architecture for a high touch service. For example, imagine that our service sells very expensive life insurance. Our process looks like this: A user...
When this question has been asked before on StackOverflow in 2011 and 2015, all answers as of now suggest to use a Singleton. But that’s not right. Singletons are defined by the Gang of Four to mean two things: 1) Ensure a single instance 2) Accessible everywhere I do not want accessibility everywhere. There are ma...
I'm using Enterprise Architect and the following exercise is for educational purposes. My exercise is to draw a BPMN 2.0 business process diagram(s) about user querying data from a bus station website. The exercise states that all restrictions should be described before the actual diagram (no idea what that means). How...
In React, it's common for libraries, and app-internal utilities, to used context-based dependency injection. Some examples: function MyComponent() { const client = useApolloClient(); // Apollo const store = useStore(); // React-Redux const { me, logout } = useContext(AuthContext); // utilities // etc.. } I won...
I have 3 number arrays that I need to encode into a URL through query parameters. Example: http://localhost:3000/?r=133223333302302040&y=10000000000000000000&b=13333332002100122331 This is a React app, and each number array represents a part of the apps state. The URL in its entirety represents the underlying state of...
I have a web service that serves two purposes. On a weekly basis, it syncs records from the GIS DB to a workorder management system's database. On a continual basis, it serves up the records to a web map in the work order management system. Here is a summary of purpose #1 and purpose #2: (There are 40+ spatial vi...
Here is a piece of code. Basically, I load some source files, all of them are compiled separately, and then I link all of them. LinkedObject loadObject(std::vector<std::string>& fileNames) { std::vector<CompiledObject> objects; for(const std::string& fileName : fileNames) { std::string source = load...
Distributed systems by Coulouris says The Byzantine generals problem • In the informal statement of the Byzantine generals problem [Lamport et al. 1982], three or more generals are to agree to attack or to retreat. One, the commander, issues the order. The others, lieutenants to the commander, must decide whether to...
Consider following class: public class Foo { public Foo() {} public void Bar(int input) { Console.WriteLine("Working on input ..."); switch(input) { case 1: File.WriteAllText("PATH", "The input is 1"); break; ca...
I've a class which performs an operation (say A). I've few logic which has to happen before A happens and few during A happens and few after A has happened. interface ILaunchInterface { public void pre(); public void during(); public void after(); } class Launch implements ILaunchInterface { public vo...
I have a C# interface that represents an image-file (photo, logo, etc) that's been loaded into memory. I have different implementations (using System.Drawing, ImageMagick.NET, test stubs, etc) - a problem is that these different implementations have different preferred ways of serializing the image to a Stream to be sa...
There is a set of feasible characters, say ABCDEF. Combining some of them, I can generate some "meaningful" combinations, say CAFE. I want to gather all of them. To do that, I can just "walk through" all possible combinations, starting from length of 2, then 3, until max allowed length, say 5. Then I can check each com...
I am using a great deal of jquery. I have several "sub-pages" that are loaded into a main div by a menu click. Each of those sub pages has an associated javascript file. I have been loading the javascript file when the "sub-page" loads but that seems to cause a problem with "Uncaught SyntaxError: Identifier '$div_eve...
I trying to create a little poker Texas Holdem simulator .. In my solution have some class : Premise : I know about Fisher Yates algorithm. I will implement it later Keep in mind that the next step I would like to implement a Hands Evaluator for compare Players Hands Odds Calculator for some odds like Hand vs Han...
We're a small/medium sized company with a dozen or so software developers, developing our own in-house software for in-house use. Given that there's so few of us and there's just so much work to be done, for most part each developer handles a separate part of the system and doesn't share their work much with other deve...
I'm facing a very simple scenario that should have a simple solution, but can't seem to figure it out. I'm trying to design a RESTful app that replaces a (stateful) remote for an electrical appliance. The frontend of the app simply shows the current state of the appliance and sends a new state to the backend if the use...
I am using ActiveMQ and I have a scenario where I need to update the event for 100 consumers parallelly. I am looking for a solution where the 100 consumers receive the event parallelly (i.e there shouldn't be inconsistency like few consumers received the data and few are yet to receive the data) so that only when all ...
I want to parse a binary file and track the values and positions of certain properties within it. Reading them is not that much of a problem, since I know the rules they follow in terms of where they are in relation to each other. Most of them have their offsets written in the file, anyway. To allow editing or extendin...
We have a team of 6 developers working in multiple technology stack. Most of these developers have little experience 1 - 2 years to be precise. We are very successful on enforcing coding standards because we are using coding standards checker in our ide's . However we have a hard time getting the team to follow our ...
Let's say I have class that used inside another class and uses inside some nested fields of it. To simplify the example I'll use trivial types. In reality it's something like DataType dataType, Status const& isOnline, Session const& httpSession, FileLoaderInterface& fileLoader, Condition&& cancellationCondition. While ...
Are all sockets implemented as per the Berkeley sockets specification in all platforms or languages? What I am trying to understand is; is this the only standard for sockets implementation or there are any other specification depending on the operating systems. To be specific, I don't want the entire list of socket spe...
My head hurts I've been reading about DDD for years and I've now decided to try it in as pure a form as possible. I'm really struggling in general to define aggregates, but this specific problem is worthy of a question here. I have a system that is used by multiple clients. Clients can buy a number from me, but I need...
In both the Strategy Pattern and in Inversion of Control you can exchange parts of an object that allows scalability and easy-to-exchange parts. I am referring to this and this Both use an interface and call the function of the interface. Am I missing something?
I am not sure if I ever clearly understood standard corollary "what to solve" and "how to solve" used to point out difference between functional (declarative) and imperative programming paradigm respectively. In most of places where this difference is explained is often supplemented with example where some loop control...
I'm a bit confused by some object-oriented analysis and design (OOA&D) concepts. In OOA&D, what recommendations should be followed in order to produce a viable conceptual Domain Model? How should classes be identified in that process? I've read about a number of varying English language analysis and refining processes ...
Sidenote, just learned about Haxe which may offer some insight into this question. The basis of my question is what sorts of tradeoffs (if any) need to or must be made if you wanted to compile one language into several others. I am in particular thinking like this in terms of plugins, but you could also apply it to cro...
Suppose I have 2 classes (which don't show methods to look simpler): public interface Fruit{ } public class Orange implements Fruit{ } , and assume I can use 2 ways to initialize Orange without actual difference (means both can compile and work at the same way in my code): 1.Abstract one: Fruit obj=new Orange(); 2.C...
Let's say I'm using a MVC pattern. Here's some pseudocode: View { main() { Controller.callAPI(url); display(item, position) { // display item at position } } } Controller { callAPI(url) { app.request('GET', function(response){ Model.handleCode(response...
Say I have a sealed trait Person that requires the definition of a method work :: Unit -> Unit. I then have three case objects Accountant, Doctor, and Lawyer. I can think of two ways to implement this. The first is to override work in the case objects: sealed trait Person { def work(): Unit } case object Accountant ...
It is quite common to test JSON / XML producing methods against file-stored expected output (at least in Java world, but probably in other environments, too). For instance there's a method that produces RSS feed of new offers in the service, which has different formats (for different RSS consumers) and different option...
Distributed Systems 5ed by Coulouris says on p21-22 1.5.5 Failure handling Detecting failures: Some failures can be detected. For example, checksums can be used to detect corrupted data in a message or a file. Chapter 2 explains that it is difficult or even impossible to detect some other failures, such as a rem...
People often get excited about JuliaLang supporting Unicode function names. But it's not new at all,it's just that the Julia community decided that it was sometimes appropriate, and built tooling to make entering Unicode easy. What was the first language to allow it? Please backup answer reference to a reliable source...
Let's say we write an application that can use multiple forecasts from different sources. It does not really matter what type of data we are talking about, ofc. it can be weather forecast, stock price forecast, and so on... The main thing here, that we can have multiple time periods, for example .5h, 3h, 9h, 1d, 3d, 30...
When creating new skills/apps for a voice assistant such as Google Home or Amazon Echo, are there any established patterns for providing an extra level of security for certain actions that go beyond just a PIN or password? Here's an example: let's say your skill/app allows you to call a cab. So you'd say something like...
I have a Laravel project where the controllers (all derived from one of two base controllers) use repository and persistor classes to interface with Eloquent models. Authorization logic is implemented in policy classes but the actual check needs to be made either in the base controllers or in the repository and persist...
I am designing the software to calculate employees' hours among others. To simplify my problem let's say that I have Activity class, which has a property Type. This type could be for example "Standard work", "Overtime work","Business travel" etc. As an input I have a timesheet. I can have a lot of cases here, but let'...
How can I use Java modules in an Android app repository? In particular, what directory structure should I use? I have a project in mind for which I would like to have a GUI-independent core Java 9 module (which could be distributed independently) and an Android GUI layer on top. I created a new IntelliJ project using ...
Consider the following state machine diagram: If we have the following event sequence : Close door --> Start --> Open door --> Reset and we need to know the corresponding response sequence starting from the initial state (~Closed, ~Heat, ~Error) My answer was as follows: (Closed, ~Heat, ~Error) --> (Closed, H...
In this article, it is mentioned (emphasis mine): ...the microservice architectural style is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API. These services are built around busi...
I have an API which include a registration and login process. Both process have an authentication sub-process. This sub-process are many steps which API validate a client specific data. I have many doubts about names for authentication process. This is my approach: Registration process (It creates an account) POST /a...
I'm very new to the serverless and backend world. I've been looking at tutorials on youtube and on serverless-stack.com (which is really good btw) and they mostly seem to cover React frontend applications and use NodeJS in their AWS Lambda functions. I want to use Python for my Lambda functions. I'm unsure about how R...
I am just wondering should the presentation layer connects to the Web API layer first then WEB API layer connects to the Application layer? Let's say for ATM system which has Check Balance function, in my application service layer, I have these codes: public class BankAccountService { public decimal CheckBalanceA...
I'm working in some environment where an older version of g++ is used to compile some production code: g++ 4.3.x . This might sound outrageous to you, but in various organizational settings prioritizing stability - it is acceptable; particularly seeing how the code being compiled is C++03... Now, I want to convince my ...
I have a use case which will take in data from the front end and transform it with various parameters. Then a random effects model is run on each transformation and multiple models are built For example: Data has 5 independent variables. For each independent variable there are around 3 consecutive transformations to be...
A component in a system (called Notifier) inserts hundreds of messages ~300 (SMSs) per second in a table in MSSQL database with PENDING status by flagging a column called status with int value 0. Another component (called Dispatcher) which is a console app published on 3 servers and it runs through Windows Scheduled T...
What does it mean when you say that a method or a function should do only one thing? Can it do a few things as long as it has a cohesive name? Should we avoid routines with the word "and" in them? Please provide concrete examples. Note: please don't confuse this question with the Single Responsibility Principle which i...
I am lost when reading Design Data Intensive Applications. In a nondistributed database system, nondistributed transactions are to satisfy ACID. In a distributed data store, what are distributed transactions to satisfy? Does ACID or part of it still apply to distributed transactions? Looks like Atomicity, Isolation...
It was recommended I ask this question here as it keeps getting downvoted on Stack overflow. I am wondering What is the harm in ignoring PHP Warning: Creating default object from empty value? I don't see any value in "fixing" it if the only thing I am doing is making this warning go away. Does PHP have intentions of m...
We have project which have more than 500 unit test and run for hours through Jenkins CI pipeline. In case there is failure of single UNIT test we need to kick off the build job again. I want to run the Unit Test job in Jenkins before merging the changes to master branch as staged so that build will not break in master ...
From the .Net perspective (C#, VB, etc.) and MSSQL, I have noticed that for a set of applications (maintained by the same development team) typically have the same defined configuration for connecting to the database. <DbConnection Name="SomeConnection" UserId="SomeUser" Key="SomeKey" ConnectionTemplate="server=SomeSer...
Having multiple lists of integers, like e.g.: var p1 = new[] { 3, 9, 5, 8, 9 }; var p2 = new[] { 12, 1, 18, 27, 103, 99, 4 }; var p3 = new[] { 23, 930, 15 }; // ... I want to concatenate them with logical AND and OR operations, like e.g.: var result = p1 AND p2 OR p3 ... AND should have higher precedence than OR. The...
Note: I am not sure if the question belongs to this particular stackexchange . If it does not, please let me know and I will delete it here and post it on the relevant exchange. Though it seemed more suited to this exchange than StackOverflow. I am trying to create a REST server. My problem is to optimise a router/rout...
Suppose we have a hierarchy like the following, where each thing under it means it is composed of that type: CarCompany | CarFactory | Car | Engine | +------+-----+ | | | PartA PartB PartC For everything above, also assume each component has logic associated with it and it's no...
I am still a software engineer in training, but I have heard the following adage multiple times: Good coders don't have to deal with merge conflicts. Whenever I work on a project with others, I'm losing an annoying amount of time and effort on resolving merge conflicts. So, I began wondering how true that adage is. I...
I'm trying to determine what is the fewest number of bits I need to represent the state of a Rubik's cube. (EDIT: I am assuming the cube is a valid Rubik's cube that has not been altered and only valid rotations have been performed. I am also assuming the faces are solid, uniform colors. I am not concerned with center ...
Problem: I am using a Domain Driven Design architecture and I have a domain model called User as follows: public class User{ public User(string username){ this.Username = username; } public string Username{get;set;} } and I would like to include a GetPassword() function to the domain. ...
I am working on a simulator which simulates patients, so specific processes can be validated on "virtual" patients, before testing on real patients. The simulator is essentially a mathematical model which consists of multiple ordinary differential equations(ODE), which can be calculated using numerical method. These ma...
I understand aggregation is a "whole/part" relationship, where the "parent" class is the whole and the "child" class is the part (and this is unidirectional), and that each class exist independently (as opposed to composition). But some examples I've seen are confusing me. For instance, the path/segment relationship. I...
This seems to be a common problem and, after reading these 2 questions What is best pratice for user stories containing two roles and User stories with multiple users/roles I'm still confused. In my case, my system will have reports and 3 roles: developer team leader CTO all of them can create and read reports, but d...
I have difficulty understand Section 18.3 Fault Tolerance Services under Ch18 Replication in Coulouris' Distributed Systems. If my reading and understanding is correct (which might not), Section 18.3.1 Passive Replication describes services that have linearizability consistency but don't tolerate Byzantine failures....
In the CAP theorem, there are only three possible cases: C and A without P C and P without A A and P without C How can we have both P and C in the second case? Doesn't propagation of update from one replica to the other require a communication path between the two replicas? If network partition happens between two ...
Is it a good idea to make http patch more general and also create a new property or even a new persistent entity if it does not exist. The patch could be general and send http body for different models for example { "model": "User", "uuid": "c4daef66-4e34-4973-ad56-b11f37702a6d", "name": "Joe Bloggs", "...
I've been building an application that processes documents through different filters. I have a class (or better as an interface for creating test-doubles?) called Document. The Document class contains many fields and therefore I was thinking about using the Builder pattern for construction. Now, there are certain "spec...
From Coulouris' Distributed Systems 5ed Chapter 18 Replication 18.1 Introduction Increased availability: Users require services to be highly available. That is, the proportion of time for which a service is accessible with reasonable response times should be close to 100%. Apart from delays due to pess...
In the C++ complex library, the method norm() of a complex number actually returns the square of what I have learned is usually called the "Norm". Reference: std::norm For example, std::norm() of (3,4) is 25. To me, this looks very confusing: why did people implement something that does not correspond to the "usual" us...
I have a problem during a project of mine using Java, as usual my java classes have the structure: import ...; import ...; ... private Type0 myVariable0; private Type1 myVariable1; ... ... private Type99 myVariable99; MyConstructor() ... MyGetter0(); ... MyGetter99(); MySetters(MyType0 MyVariable0) ... MySetters(MyTyp...
I was watching Zoran Horvat's "Making Your C# Code More Object-oriented" on pluralsightpaywalled. And he says that instead of : if(obj != null) { obj.DoSomething(); } We should have a list that has either 1 or 0 no. of items of that type: list.forEach(()=> obj.doSomething()); If the list has no objects it would not p...
A super class Transaction has two subclasses TransactionA and TransactionB. A Transaction is composed of multiple events that occur in time for a specific key (a file, a person, etc.). Depending on events, some transactions have to be discarded. A concrete example with a file "key" would look like: TransactionA repres...
While assisting a student with a university project, we worked on a Java exercise provided by the university which defined a class for an address with the fields: number street city zipcode And it specified that the equals logic should return true if the number and zip code match. I was once taught that the equals met...
I'm reading OS Concepts for my undergrad OS class and came across this topic: Pthread scheduling (System and Process) Then I kept reading and came across POSIX Real-Time Scheduling that has two scheduling classes: SCHED_FIFO: first come first serve SCHED_RR: round robin Does this mean scheduling is different for r...
I'm going to start with the opposite of my question: why should events emit only to a specific context when your code is supposed to be easy to interact with? In the JS world, you can emit events such as: window.dispatchEvent( new CustomEvent('eventName', { 'detail': { 'someKey': 'someValue' ...
I am well aware of role based / activity based authorization in the context of limiting user functionality in a simple on/off manner; however, the problem gets difficult when it's not so black and white. Take for example: User A: Is a paid customer of a market data service and has unlimited requests User B: Is f...
How to exchange 1T data between multiple processes? Requirements: Data < 1TB. Memory > 1T. Multiple processes (different languages) on the same machine or different machines over network Data should be available for 1 hour for fast read Guarantee completeness of data. I am thinking using JSON or Redis or 0MQ as the s...
I'm designing a solution in .Net which will be hosted on Azure. I have a system which will allow users to specify custom characteristics for their objects which they will track over time. I am certain that I'll allow a maximum of five such properties in addition to Id, Name, and Description. In addition, I can probably...
Does "middleware" have two different meanings and therefor is unnecessarily overloaded? Horizontal: I saw some use middleware to mean something like proxy or gateway sitting between two entities at the same level. For example, https://docs.microsoft.com/en-us/aspnet/core/fundamentals/middleware/?view=aspnetcore-3.1 ...
I'm planning on the following for a use case scenario for AWS Lambda and want to make sure I'm headed in the right direction and that there's not some better/easier solution out there. The database is in AWS RDS (SQL Server), and the web application is in AWS ECS Fargate / Dockerized. The database has ~8,000 records i...
In our project, I was need to sync a piece of information between localStorage and the Redux state. Actually I subscribed to changes in a localStorage and in Redux, and if change happens in localStorage I update the state, and vice versa. Right now I've created a redux enhancer for that. My coworker, however, claims th...
I am working on parsing a file and inserting records into SQL Server DB.The database table structure will be something like this: A Users table which contains (id, name, address, destinationName,insertDate, updateDate, updatedBy). So I will be inserting the parsed data from file in to this table in a batch which occurs...
I have worked in companies that to achieve translations based on the user's localization they use a file to store those translations. However, when they try to access a translation on that file they commonly do it with "magic" strings like this: Translate("$global.name") Translate(string keyword); is a function that l...
Recently, a person here asked a basic question about how to compute in Python all permutations of elements from a list. As for most questions asked by students, I haven't provided the actual source code in my answer, but rather explained how to approach the problem, which essentially ended up in a basic presentation of...
I'm not sure if this question belongs to Stack Overflow or somewhere else. Sorry if it doesn't belong here. My question is, in an IDE, does its linter, check the whole source code every time (whenever a user update the code or periodically), or does it check only the code that has been added/removed?
I maintain a small (tiny!) .NET library. It has a few ill-defined edge cases, which I call out explicitly in the docs. Places, where the "correct" behaviour is not self-evidently well-defined, so I explicitly said For invocations like this, the method may return any of the viable outputs. Note that in all of these 'ma...
I am making a website that requires a secure area for the website owner to easily upload new content to. Because this is a relatively simple website there is no account system. I just have a URL for them to go to and enter a password (in a form with a ReCaptcha) to enter the secure area. My issue is, how do I allow acc...
I'm doing a project in PHP and I'm implementing Aggregates and Event Sourcing. In order to avoid coding up all the logic related with ES myself I've decided to use a third party library called EventSauce. I would want to avoid coupling my code, specially my domain, with an external library. However, from what I have se...