instruction
stringlengths
34
36.1k
I heard somebody say their language has a convention where the names of functions which mutate state must end with an exclamation point. I'm trying to write more functional code and I like the idea of somehow marking functions according to their side effect status i.e. none, inward side effects, outward side effects (I...
Currently in our business we use Team Services in the cloud with a single self hosted build agent which runs locally on a server in our office. As we are expanding and taking on more work there is an increase in the number of queued builds. As a result we are considering adding additional build agents to cope with the ...
I've been reading the 3rd edition of [Algorithms][1] by Cormen, Leiserson, Rivest and Stein. For DFS and BFS their algorithm loops through all the vertices first and colors them white. 1) If the color attribute were part of the node/vertex you would have to traverse the graph before you traverse the graph. And if you c...
I am discussing the architecture for a new project with some colleagues. The project is relatively small and can be considered as a 'normal' crud web application. Everybody has come up with an architecture where they are comfortable with. For example the onion architecture and the Domain Driven Architecture. Some progr...
In most languages I've used it's common practice to replace the reserved word class with clazz when you have a variable that refers to a class. This has become a sort of de facto convention, to the point where if I see klass it surprises me. Is there any "replacement word" that's even close to as popular for the inter...
I've recently read a number of (layman's) articles on quantum mechanics and quantum computing, and keep seeing examples along the lines of "Quantum computing can crack passwords quickly by trying all combinations at once". The example goes on to show that rather than passing in an N-bit value, an N-qubit value is pass...
Suppose I want to create a portable OS, that needs a USB flash drive only to work. and i wrote my boatloader in the first sector to be loaded by the BIOS, from here on, what can I do to load my OS kernel, which is located somewhere in a USB drive?
My understanding from reading threads like this one is that the point of ems is to define all measurements in your webpage, by the base font size, which can be set by your browser. For example, in Chrome you can do this by going settings -> show advanced settings -> web content -> font size: very large. I might do thi...
This question is inspired by a question about final in java. In C/C++, should I use const whenever possible? I know there is already a related question about using const in parameters. Unfortunately that question and it's answers don't fully answer my question, because it's only about function parameters, but I would ...
I understand how you create flowcharts or data flow diagrams for simple linear based programming. But how do you design a flowchart for event based programming, like a game that runs on Unity3D? How would you structure it?
How, if at all, is Message Passing Interface (MPI) related to the general concept of "message passing"? Admittedly, the question does sound ridiculous. Surely, "Message Passing Interface" is an interface for message passing, right? Nonetheless, it's not actually clear to me if MPI is somehow related to the general con...
I was reading through design philosophy of java and this line struck me: "The VM checks whether the signature of the Java code is valid and would refuse to interpret if any change of the code is detected." how does the vm ensure that bytecode hasn't been changed? java design philosophy
Hi I'm working on a c# MVC code first project. I've started the project and have created the Models, database frontend etc. Now my attention has come to writing something that can read an excel document and import the data into my database. This is a bit of a fiddly task, to say the least - so I did start making a unit...
I'm doing an project where I'm using a microservice architecture. All the services within this architecture communicate with each other using an AMQP broker (RabbitMQ). When something happens in a service, it publishes an message to RabbitMQ and the services interested in this message can process it whenever they are r...
I'm working on a simple class to get a token from an API. As simple as it is, it has different aspects. A connection to the API is needed for this to work at least the first time. Credentials are stored in the code (security is not the subject). A token should not be fetched from the API more than once every 9 hours,...
We're building a website to manage our company asset, and apply Agile/Scrum to this project. We started with the Product backlog as in attachment. We planned to start the first Sprint but the team concern about system requirement - things outside PB such as hardware/software architect, database design, security, user r...
I sometimes hear about making web-site fully API based, meaning that even in browser the page is constructed based on API endpoint and practically nothing else. One of the benefits I see in this is that when you will make smartphone application you already have API that works and tested. And in case you need to change ...
Say, I have a function, RegisterUser() which takes in an user's registration details such as their username, name and password and registers them if there is no invalid data. For such functions, it is important to report all errors at once, instead of stopping at the very first test at which validation fails. An except...
I'm working on the design of a compiler for a language in which I have to use curly brace for two different purposes. I am currently stuck in writing a non-ambiguous grammar but I realized that some other language have the same behaviour. That is why I'm trying to understand how a part JS/Ecmascript grammar is built. ...
I am looking for advice on handling states in a WPF MVVM environment. As an example, assume we have A TreeView (or some other ItemsControl) with some items and a button that is enabled when an item is selected. My ViewModel contains a property SelectedItem that is bound to the SelectedItem of the TreeView. When the ...
I have this piece of code if (!expr1) { codeblock1; } elseif (expr2) { codeblock2; codeblock1; } It is pissing the hell out of me because I am trying to refactor it in such a way that there is no repetitive code, but I keep getting different results. if (!expr1 || expr2) { if (expr2) { codeblo...
I am developing an iOS app and I am moving to a VIPER-like architecture. It looks like this: View--ViewModel--Router--ViewModel--View The difference from the VIPER is that I have have one global Router instead of many Wireframes (it is motivated by the app functionality: almost everything can be opened from anywhere). ...
I have heard both "fundamental types" and "primitive types" being used. Is there a difference in what the two phrases are referring to?
In many languages, the syntax function_name(arg1, arg2, ...) is used to call a function. When we want to call the function without any arguments, we must do function_name(). I find it strange that a compiler or interpreter would require () in order to actually detect it as a function call. If something is known to be c...
It's time to improve my workflow. I never had the responsibility of setting up the infrastructure, managing git, versions or releases. For me it was simple push/pull most of the time and I think, the workflow wasn't state of the art. I'd like to change it and as there are so many ways, I'd like you to help me, finding ...
With hierarchical state machines, and their UML state chart counterparts, all the references I've found so far suggest that an active state must be a leaf state. I've looked at Samek, and papers that implement HFSMs in C++. Most suggest any transition to a composite (read parent) state must be followed by successive in...
Let's say I have the following entities that can be accessed at the following URIs (using the standard pluralization): /things/:id and /otherthings/:id I want to expose for performance reasons, an api that will response with the following structure: { "things": [], "otherthings": [] } The call is so that my clie...
I have simple POCO classes, like this: public class Book { public string BookId { get; set; } public string Name { get; set; } //etc... } I want to get all those classes and generate another classes, which called viewmodels, for example, the output would be: public class BookViewModel { [HiddenInput(Di...
This is a Gitflow process question. In all the documentation (and diagrams) I've read about Gitflow, they always indicate that once a feature is completed it is merged back into the develop branch. But the one thing that I never find defined anywhere is what the definition of "a finished feature"? Is testing (Quality A...
I'd heard about Design by Contract a long time ago and always was confused by this question. The approach uses real-world client-supplier analogy to describe caller-callee relationships. It stays, that if a client ensures preconditions before calling a supplier, the supplier will get the benefits by avoiding preconditi...
I'm hoping for a sanity check in my design thinking. I'm working with a small team on a website based on a MongoDB database. There are several collections in the DB -- for example, one representing persons, and one representing polls. Persons vote in polls, and their votes are recorded in a votes array in each poll, as...
The project I am working on for about a year now was used to create a new mysqli connection to the database each time there was a Query to the database. In order to quickfix this problem at places where this strategy had some serious performance issues I created a global $connection variable that deliveres a PDO instan...
I'm working on a small example application to learn the concepts of CQRS and event sourcing. I have a Basket aggregate and a Product aggregate which should work independently. Here's some pseudo code to show the implementation Basket { BasketId; OrderLines; Address; } // basket events BasketCreated { BasketId; } ItemA...
I'm taking the Computer Architecture course in my undergraduate study. I see that in loop unrolling, one of the constraints is the number of available registers. Since the number of registers depends on the architecture, is a generic pre-compiled binary targeted for the worst case (least number of available registers)?...
I've been tasked to query 2 large csv files which are roughly 1 GB in size each. The files contain related data, so file one may contain a list of order numbers, Order Dates, etc and the file may contain the order lines, stock codes, quantity, etc. Other Restrictions: No Access to a database - so I can't just bulk ins...
I am new to the software design lifecycle and the various processes that it consists of. I was taught/told recently that units should not be included in the SDD because the software cannot "test" those requirements because units do not mean anything in the software domain. An example of this could be.. "..shall...occur...
We are moving towards developing a web app in a micro-services architecture. We thought about running the services behind a API gateway that will handle authentication and will proxy the requests to the appropriate services. We have encountered a problem while setting up the development environment. How can we develop ...
We're developing a big application with a vast GUI and complex business layer. Without going into too much detail, the application is currently implemented in a rich native client, but functionality is roughly seperated into core business logic related parts and the (also complex) GUI which is based on an MVC paradigm....
I'm wondering what's best practice in next use case: I'have a view that displays data for 3 resources User, Company, and CompanyType (chosen in select, can be added dinamicaly so it's not enum). What is the best way to retrieve data: 1)Call API 3 times to get data: /user/id/, /user/id/company, /company-types 2)Or creat...
If I have pure functional programming language with* very very smart optimization* proccess, is it possible to reason about memory usage, just by looking at type signature? add :: Int -> [Int] -> [Int] F. E. If the answer to my question would be yes, function add would allocate exactly (1+n+y)*sizeof(Int). The reason...
I am currently sketching out a project I am doing at my job, where I will have a self hosted WebAPI, connected to a serial device, where the app I am creating will configure that device. No, it is not a Raspberry PI :) So instead of having a database as a data source for the API, I would make calls to the serial device...
I am designing a process of transforming a JSON object to HTML/CSS. It consists of: Identifying special components Extracting the special components Parsing the styles Parsing the layout etc... I am currently working with a promise chain: Promise.resolve(true) .then(copyBluePrint) .then(transformJsx) .the...
Generally game audio engines use a rather simple system for rendering audio: 1. position an audio source in space 2. apply effects on the audio clip depending on the area the object is in 3. shift volume / phase / pan depending on the angle and distance to the listener But in real life audio propogates in waves through...
I would like to know if one of the two following equivalent grammars (since they can produce the same rules) is preferred (and why). For instance the second grammar is more concise but is it a good thing that in the second form the rule b can produce εor such rules should be avoided. G1: a => X b Y | X Y b => c b ...
Background I often write software for systems that are responsible for testing manufactured products. For every product that gets tested, we have to generate a report for the test-results. The way that we do it now is that we create a .txt file with the test-results and write that file into some folder on our network d...
A colleague has challenged me with an interesting question. To be honest I have no idea how to deal with it. Suppose the following: Every 5 minutes you get a new file with one hundred thousand new records. You need to store the records in a database table within these 5 minutes. First, I'd stream that file beca...
I am writing a unit test with mocks and I am concerned about over specifying the test. The idea being that if the implementation changes in a compatible way the test shouldn't fail since that makes the test fragile and inconvenient. For example, if the implementation calls mock.add("foo") followed by mock.add("bar") or...
We have handheld scanners in a big warehouse, and there are printers scattered around the warehouse. When certain events happen on the scanner I need to Print a Crystal report to a printer. The scanner sends everything through a web service. Currently I have the web service printing the document and it is working (kind...
Today at work a colleague was looking at a piece of module I had written a month ago as a reference implementation. I had written a WCF service which a Windows service was consuming. I have a single operation exposed as below. [ServiceContract] public interface IMyService { [OperationContract] void PerformASpec...
Background: We have less than a gigabyte of documents stored in a database. In most cases there are multiple versions of a document with the same name. The versions need to be preserved. I've been asked to write a utility to extract these in a way that someone else could easily use. Most likely I'll be writing the util...
I recently started to work in a startup that been around for almost 6 years now. Our main code base is in Node.js, which means that it has been used here since the early days and therefore there is a fair share of "legacy code" running. There are some issues, but right now I'm struggling with a specific one: how to dea...
In this question, I'll use a ruby example, but I think it is a general question. According to the most popular Ruby's test framework (RSpec), mocking any instance of a class (allow_any_instance_of) is a design smell. Actually, I don't agree with this statement. So, I would like to know how would be the "best way/corr...
In recent years all we have heard over and over about MVC, MVP and MVVM. By developing an application in VB.NET we are implicitly using the MVP pattern (with windows forms). However, along at least two decades, millions of developers used versions of VB from VB1 to VB6 not having a minimal clue about MVC, MVP, MVVP (th...
From Kelvin Murphy's review on Algorithms (4th Edition) by Sedgewick and Wayne For data structures, it is obviously natural to use classes, but they also adopt this approach for many algorithms, esp. graph processing ones. This allows the algo to do pre-processing and to store internal state, and then to provid...
XOR is not solvable by using a single perceptron with standard scalar product and unit step function. This article suggests using 3 perceptron to make a network: http://toritris.weebly.com/perceptron-5-xor-how--why-neurons-work-together.html I'm trying to run the 3-perceptron network this way but it doesn't produce cor...
I'm working with JEE standard. I have the following layers: JPA (Eclipse Link), Data Access, Business Logic, and JSF (Primefaces). Primefaces uses MVC design pattern, so the the presentation layer contains the ManagedBeans (controllers). When I create an object from an user request, must I contruct the object in the Ma...
Sedgewick's Algorithm 4ed says Several fundamental data types involve collections of objects. Specifically, the set of values is a collection of objects, and the operations revolve around adding, removing, or examining objects in the collection. In this section, we consider three such data types, known as the ...
I have a web application implementing the MVC pattern where I have controller classes whose methods each map to an HTTP request. I also have a service layer with a bunch of service classes, with each service class typically containing operations specific to a particular domain entity. For simple logic (like CRUD), one ...
I'm working on a project that requires a TCP connection between a client and server. The current protocol encodes the data into hex and then sends it. However, hex increases the length of the payload which isn't really optimal from a networking point of view. Hex follows a pretty predictable pattern with repeating char...
Say I use a predefined serialization format X for certain data. Should I indicate the application in a custom filename extension or not? It is quite common pk3 is a zip archive XSL, SVG and many others are XML files Some files are INI files It is practical to denote the purpose of the file, but I am unhappy to inven...
I try to read up on the history of testing and I found an entry that I am having problems researching online. Googeling for Triangle Problems results in geometry hits. I found an entry on a website. 1973 - Triangle problem (Gruenberger) - In his paper Program Testing: the Historical Perspective - based on the talk hel...
Whereas there seems to be a lot of information on the Internet about what the presenter both is and does, there doesn't seem to be a whole lot that specifically describes where to put it in a multi-layered architecture. My guess would have been the business layer, but very recently I read something that said the busin...
I have a for loop where I must skip the first element in a zero-based array. Which of these shows my intentions more clearly? for($i=1 ; $i < count(array) ; $i++){ array[$i]; } or for($i=0+1 ; $i < count(array) ; $i++){ array[$i]; }
There's a well-known dynamic programming problem that goes by the name of the "gold mine." You have a n x n grid, each cell of which contains a certain value of coins. You begin at the bottom left and can only move right, up, or diagonally up and right. The goal of your algorithm is to determine the path through the...
I am trying to solve two situations here related to making POST requests and handling responses. Making a request and having request timed out due to no server response, as well as assuming that in this case nothing has been written in a database hosted on the server. Making a request and having request timed out, but...
Nowadays I have been practising Java EE. There are may annotations which simplify configuration of servlet container. Such as: @WebServlet @WebInitParam @ServletSecurity etc. You can do the same thing in deployment descriptor: Web.xml Personally, I prefer annotations. My questions are: can I use annotations fo...
I have written a parser using Python Ply library. While doing tests with an input file I have noticed a strange behaviour : sometimes the input is correctly parsed with no error and sometimes, there are parsing errors (and the parser doesn't follow the same rules and consequently finds syntax errors). How can this ha...
I am trying to write Stack code using the two techniques i.e Design by Contract vs Defensive Programming but I am not sure if I am doing right or not.I am not throwing any kind of exception or error in design by contract assuming all the inputs will be correct.
I'm going through some sort of phase where I over analyze and second guess every single decision I make when attempting to write software that has preventing me from getting anything done. I recently came across a need to store a"complex" C# object in a SQLite database. To boil down the object into a minimal example le...
I am working on my first sizable C++ program; a 2-D mario platformer remake. I currently have an animation class that encapsulates all of the functionality of my animations for all the bad-guys called Animation. Then, I wanted to create the animation class for mario, let's call it MarioAnimation. Mario has an ability,...
I was reading about finalize() method that it may be invoked automatically when an object is eligible for garbage collection.Now this uncertain.But what happens if we call it explicitly.Does it necessarily do a cleanup or is it just a normal Java call?
For a general purpose hash table that aims for both high performance and correctness, when, if ever, does it make sense to assume that hash equality implies logical equality? To lay some ground rules for the question, assume either that all inputs are non-malicious or that a cryptographic quality hash function is used...
If we have a code snippet like: public class Finalizer{ static List list = new ArrayList(); public void finalize( ){ System.out.println("hello"); } } What is so special about static here that affects the call to finalize ( ). Is it because that static members have lifecycle of whole program so a v...
I want to do movie ticket booking and event ticket booking. In that how to avoid duplicate booking in short cuncurrency. I have five seats remaining in my event. Two user comes both will see 5 seats but only one can book it. How can I achieve this? Please help me solve this issue.
I am working on an algorithm whose specs says that it accepts 32 bit input (long type). My actual data is 14 bytes e.g 11:12:12:04:DD I have created sub arrays like subarray1[4]={'1','1',':',1} // 32 bits Can I pass this subarray to my algorithm? Actually when I print subarray as string then it gives garbage value. Bu...
There's currently a huge growth in larger companies offering new languages and / or frameworks for us to use to create websites, apps or software and I'm interested to know for what reason do people think this is? There's always been a few big players (Java, C++, Perl Php, VB, C#, Ruby etc) but a chunk of those were cr...
I'm having trouble in figuring out why the output for theses two lines is different .. public static void main(String[] args) { System.out.println("6.0+1="+6.0+1); System.out.println("6.0+1="+(6.0+1)); } The output 6.0+1=6.01 6.0+1=7.0
I am trying to implement VIPER architecture on iOS in Swift. The problem I have is how to set up the object graph. Please ignore the Router and the Entity as it is not relevant to my problem. That leaves us with the Interactor, Presenter, and the View. Interactor - business logic, has state, does work, accepts commands...
To my knowledge multi-threading is just an illusion since CPU schedules time for each of the process. So when scrapping at a particular time, only one content from the website will be scrapped and it will also lead to so much of difficulty since all of the process are urging for the same resource so there might be a pr...
Suppose you are selling a web app. There is no data or operation that involves more than 1 customer. Each customer is totally separate. How would you prefer to make the deployments? 1) Deploy one instance for each customer, meaning you are running and managing many small apps on different servers/virtual machines/on th...
I have an event handler. It receives an event and needs to do some work on it. That work is split between common work - things that have to be done for all types of event handler - and specific work - things that only need to be done for a specific app. There seem to be two approaches to implementing this design. I cou...
I am creating a software for B2B which targets all kinds of large size companies. It will integrate with existing softwares of companies (CRM and ERP systems). I want to expose my API via REST. However, I wonder that do I need to SOAP web services too since it may not be used by companies? I mean how is the ecosystem ...
I have a service which sends a set of queries to the server in a single call and acts on the decisions from the server. I will first introduce what I already have and the questions will follow. public class Item { int id; int version; String description; } public class RequestObject { Item key; ...
I recently made an esoteric programming language, and I want to know how to test and see if the language is Turing-Complete. Most places I looked said it needed infinite loops and infinite data storage. Is that all? Also, do I need to simulate a Turing Machine for proof, or is there an easier way? It is called NOR and ...
To simplify the use case, let's say I have a mobile app available for Android and iOS, similar to Instagram, where users can upload photos that can be commented, liked or disliked by other users. When a user comments, likes or dislikes a photo you uploaded, you would get a real time notification on your phone telling ...
Following is a java solution of the classic question of rotating a nxn matrix in place clockwise by 90 degrees. public void rotate(int[][] matrix, int n) { for (int layer = 0; layer < n / 2; ++layer) { int first = layer; int last = n - 1 - layer; for(int i = first; i < last; ++i) { int offset = i - first; // save top ...
I have decided to start building a SAAS app. I wish to keep hosting costs low initially, whilst still providing a good user experience. Here are the components that will make up my app: Front End Reverse Proxy (Nginx) Auth Service Web API Worker Service A (processes data imports) Worker Service B (makes batches of ex...
I am working on developing an HTML canvas application, where I need to be able to do my own UI event processing. That's where the stem of this question comes from, but I'd really like to understand how the whole process works. I've managed to find out that typically events will capture or tunnel town, and then bubble b...
We had a situation in which a senior developer decided to change some code thinking it would be for the best, which it is, but we still had some problems during that period. Some functionalities broke (no unit tests), but the changes did make sense. What I'm looking for now is to avoid this happening again and also imp...
The setup Let us consider a variant of the classical multithreaded programming problem: the producer/consumer problem. We have some finite number of resources (for simplicity, let there be just a single resource). The producer thread continuously creates new resource units, until the resource buffer is full (in our cas...
so I made a simple game where boxes fall from the top of the screen and you have the dodge them from the bottom of the screen. When a box falls to the bottom of the screen without hitting you get a point. The part I'm struggling with is how to change the score variable. For now, I have two for loops looping through a d...
I hope someone can answer these. I have a WinForms project with +/- 8 forms. I have an SQLite database and a class that handles the queries to this database. I would like to use the passive View pattern so that the View has no link to the Model. Is a form a View?/ Can a form be a View? Which derives from a IFormView c...
I'm working on a project where I have to trigger my windows desktop app to fetch the database for new rows once a user on the internal network send new requests. I have managed to hack this around through several ways: A timer on the C# desktop app with half a second interval. The PHP webapp creates an XML file w...
I can type ⅓, ⅔ and ½ but can I type 3/3 and 2/2 using unicode? I know that from a mathematical point of view the fractions 2/2 = 3/3 = 1 but I am typing a list where I want to indicate that you have reached the final step (third step out of three steps) and entering "1", after ⅓ and ⅔, would confuse most readers, incl...
I cant for the life of me figure out why this returns 0 rather than 5. i keeps getting incremented before it hits the last return statement, however it always returns 0, from the first call in the stack. I would think that since the most recent call on the stack hits the return in the block i == 5 first it would return...
I'm trying to keep up-to-date with the latest-greatest from Angular2, in part by carefully reading the official online documentation. Is there a way to be notified or at least to figure out relatively painlessly whether, when and where that documentation has changed? With Angular2 being so new, the documentation is und...
Looking into Dependency Injection in JavaScript, as with Angular, I decided that true DI was overkill for my medium sized project, so I worked on a simpler way to organize my project and implement Inversion of Control. I felt interfaces aren't really worth the extra syntax since JavaScript has so few data types to dea...
We have a large project that performs a lot of modelling and calculations. This code is being broken down into smaller, more manageable chunks, by shifting particular calculations into their own classes. To try and keep the inputs and outputs constrained to the appropriate calculation method, two public nested property...
In a GUI application (to organize images), I use the Observer Pattern (or anything similar to model-view-(view)controller) to inform other components about changes. Assuming three components A, B, C which show different aspects of some objects, I can trigger "batch actions" which affect many objects in A and B. Each c...
The client sends a query (a few hundred characters) to the web service. This query can be split into 20 to 150 subqueries with a simple regex. Those subqueries can then be computed independently and take each up to 5 seconds. Thus we'd like to have those subqueries run in parallel in order for the original query to ret...