instruction
stringlengths
34
36.1k
Is every object in C++ mutable if not stated otherwise? In Python and Javascript I can't change strings, tuple, unicodes. I was wondering if there is something in C++ that is immutable or every object is mutable and I have to use const type qualifier to make it immutable.
A Tech Lead in my team said: We're going to use sonar on our (500KLoc) codebase so that everytime you do a commit, it will check the classes you've touched against the coverage goals. If you don't meet the coverage goals for your commit, the build will break. Another developer responded: No that has no value. The c...
I one failed at an algorithmic test with Codility because I tried to find a better solution, and in the end I had nothing. So it made me think if I could use an approach similar to TDD? I.e. If I can usually develop a solution gradually in similar fashion? If I were writing a sorting algorithm I could move from a stand...
Having built a RESTful API (using Laravel) for a project at work, I followed what seemed (from lots of reading) to be a the majority in terms of my approach to nested resources - by defining them in the path: https://myapi.com/clients/{clientId}/tasks rather than: https://myapi.com/tasks?client={clientId} Filtering r...
I'm working on my CS Masters thesis at a company which does user interfaces in the field of embedded devices. As part of that I am developing a library for integrating a certain device. My C++ library wraps the device drivers and integrates the device's features in the Qt framework so that it can be used with a variety...
I'm comparing two technologies in order to reach a recommendation for which one should be used by a company. Technology A's code is interpreted while technology B's code is compiled to machine code. In my comparison I state that tech B in general would have better performance since it doesn't have the additional overhe...
Suppose you were asked to design a scalable chat server with the following requirements: The main use case is: player A sees B online, A sends a message to B, B receives it. The secondary use case is: player A sees B offline, A sends a message to B. When B comes back online, B receives the message. (No push notificati...
When creating time estimates for tickets should the time taken for testers (QAs) be included in a tickets estimate? We have previously always estimated without the testers time but we are talking about always including it. It makes sense for our current sprint, the last before a release, as we need to know the total ti...
I am designing an application file format which will store chunks of user data, ranging from a few bytes to a few gigabytes - median size probably in the 10MB - 30MB range. I have the option of storing this data in a sequence of fixed-size blocks, each block having some lightweight structure to it. This structure would...
High-level languages often expose stream-based I/O abstraction to the programmer, where blocking or non-blocking streams offer select/read/write operations. (AFAIK, message-based I/O seems is usually an even higher-level abstraction built on top of streams.) But at the low level, the communication between the CPU and t...
In some MVC frameworks I've used the Model has the method and SQL in the Model so that if you call the controller, it invokes a method on the model class (say Products), and it returns the data. In ASP.NET MVC Core, from what I have seen so far, there is a separate file besides the model to do the logic. Do I use two...
I know you can configure NServiceBus to automatically retry to send messages (FLR: First Level Retries) and wait before retrying again (SLR: Second Level Retries), but, using the default configuration (5 FLR + 5 SLR) it'll take about one minute before seeing a message into the <error> queue. I understand the value of ...
I implemented some CSV reading functionality to my Java program, for which I required adding a Maven dependency. Should changes to pom.xml be part of the commit for the CSV reading functionality, or should it be a separate commit? I'm leaning towards the dependency being part of a logical unit of code, and thus should ...
It is very, very common to see code like this: for (int i = 0; i < array.Length; i++) { DoSomething(array[i]); } The above code makes certain assumptions about arrays (which apparently hold true most of the time, but not all the time). Wouldn't it be more explicit and more forward-compatible to use something like...
This question has an excellent answer by Eric Lippert describing what the stack is used for. For year's I've known - generally speaking - what the stack is and how it's used, but parts of his answers make me wonder if this stack structure is less-used today where async programming is the norm. From his answer: the st...
I am creating an object oriented design for a cab-calling app like Uber. I have some of the classes listed. I am having trouble in designing behavior between the classes. For example, I have these two classes - Customer and Driver A customer can call drivers and a driver can accept a ride request from customers. So my ...
This is the title of a user story: As APPLICATION I require a new SOAP element for OTHER_APPLICATION Lately I read a lot of entries like this in our tool of choice. Here is a write-down of the description. Obviously I had to remove a couple details, but I hope it is still understandable. A new SOAP element XXX must ...
We know some of this syntax won't compile, specifically the line where I'm explicitly referring to the class name for a variable. class Main { static String Main.s1 ="output"; //won't compile static String s2 = "output"; public static void main(String... s1) { System.out.println("output"); } }...
I'm learning Composite and Observer design patterns and I have created a FileSystem class where I define Node, Folder and File as a composite relationship. Now I want to implement Observer pattern so when there is a FileBrowser/Finder/File Explorer Observers they can get updated when I add a File to a Folder. This is m...
my company currently develops software without ever having releases. This makes all our customers live on the bleeding edge, and they know that. Now we want to do releases, and intend to regulary fork from the branch, let that branch be testing and after some weeks of testing that branch becomes the new stable. But ho...
Assuming I'm using a class from third party library that does not implement an interface, for example: class ThirdPartyLibClass { void DoThis() { ... } void DoThat() { ... } } I want to create a very thin wrapper around it, directly reflecting class' interface and delegating to the ThirdPartyLibClass. The purp...
Assume I have the following code. class D { static Integer i1 = 42; } Is it true that D has an Integer? Or is it only for instance variable that we can have a has-a relation? I also wonder about very similar, if a primitive variable also can make a has-a relation or is it strictly for classes? e.g. class D { int i1 = ...
I always see the discussion when there's an API version in the URL where to point the versionless one. I mean look at these three URLs. http://host/api/customers/1 http://host/v1/api/customers/1 http://host/v2/api/customers/1 In every blog post I read, they are talking about where to point the first URL. I would first ...
I have a question similar to this other question Why aren't design patterns added to the languages constructs? Why isn't there java.util.Singleton and then we inherit it? The boilerplate code seems to be always the same. class Singleton { private static final Singleton s = new Singleton(); public static Singl...
I find it difficult allying CQRS/ES with the "Out of tar pit" paper architecture. This architecture implies 4 layers: State (state of the application) Business Domain (purely functional) I/O Control ( all the dirty stuff for making the layers work together) In my case, the state depends heavily on a database. With t...
How does one even approach testing an abstract data type? I mean, besides the normal (supposed) way of doing unit tests, where you mock the collaborators, feed them in the class to test, together with sample data, and call the public methods, verifying that the output is the expected one, how do you ensure that the int...
I want to implement a backup solution in Python where a Backup-Server initiates backups on a number of virtual and physical servers (one server = one backup task). Disregarding the details of the actual backups tasks I am concerned with the scheduling/multiprocessing part for now. The constraints I have are: Only bac...
I'm currently working on an online app that includes many fairly new (for the company) features and they fall outside my expertise area by far, which means the edges may not be really well rounded yet. My boss wants it to be released in a somehow continuous manner, publishing features one at a time. All of these featur...
I'm using swagger to prototype a RESTful API and I got to a situation where one property is part of a resource but not always should be filled. Let's say my resource is stores. Basic endpoints would be: GET: /stores - returns a list of store GET: /stores/{storeId} - returns a single store Say store is defined along the...
Having read others posts, it already seems to me that the concept "repository" and "database" do not go well hand in hand, as they are meant to be completely separate concepts.... but I'll ask the question anyway. I currently have to import different types of data (one type of data may consist of several thousand recor...
I'm working on a Entity Component System for learning purpose. I made major changes with my design so I was wondering if I could pick a better design for my event system. The purpose of the event system (if you don't know ECS), is to allow communication between process. For example, in a video game (that's always ...
I am working on an application that is essentially a calculator, not the handheld calculator but more of a spreadsheet. It will take many inputs across different views and show the outputs all over the place. The application will be running many calculations. These calculations depend mostly on user given inputs but i...
In my web application I need to get data from Wikidata, for example to show item's details. I thought about using ajax for this, but was't sure from where I should to call it, so I asked this question. But after some thinking, why should I use ajax? I can make http request from my server side code (C#). I can put it in...
I'm currently part of a team developing a solution intended for small business. One of it's components is kind of a "dynamic business rules engine" (note the quotes) and because of it's nature we would like it to be highly configurable. My idea was to implement/use an external DSL to write the rules with a simple confi...
I am a student worker currently close to the finish line of a project I have been working on. Right now I'm implementing the .net Auto generated Api help pages. The nuget package WebApiTestClient does most of this for me. In the test calls however my manager wants certain fields to have options to choose from. So I wan...
Question When training and using an OCR algorithm for handwriting recognition, is it helpful to indicate the author of the handwriting? Use Case Have a warehouse full of documents that need to be transcribed into digital format. We'd like to feed the documents into an OCR algorithm first. If the OCR algorithm reports a...
I'm a developer that works alone, and recently, searching for what kinds of documents I still could benefit, even though I don't require anything formal, I've read that one document that still is highly recomended to write is the project vision document. I found it described as a short document (a page and a half or tw...
JavaScript maps (the data type, not the array method) seem set up to accept data (key/value pairs) but not necessarily methods. At least they're not advertised that way. However, we can put methods onto a map instance. Intriguingly, the keyword this works in such methods, and returns the map itself. For example: const ...
Do prototypical languages provide a remedy from Liskov's problem? So the way I see this is: a subclass is very tightly coupled with it's superclass and this creates subtle side effects when polymorphic types are used. So can this be remedied by prototypical languages in the sense that classes inherits from a copy of th...
I'm working on an application in the browser and I would like to make sure that my code does not conflict with code from other libraries or with possible calls added by browser manufacturers in the future. In my environment I would avoid collisions by using a unique application name and placing all my classes and code...
http://www.cs.unc.edu/~stotts/GOF/hires/pat3cfso.htm CreateMaze is the function which instantiates the objects. IMO, according to factory pattern we are not supposed to overload or modify or re-write the function which instantiates objects. But in the example, the CreateMaze function returns a Maze*. So, now if we have...
I recently started working with GitFlow model as implemented by bitbucket. And there is one thing that is not completely clear to me. We try to regularly address our technical debt by backlogging, planning, and implementing the refactoring tasks. Such refactoring branches end with pull-requests that are merged in deve...
It often makes sense to "fetch only what you need" for example if I should display only 10 rows of data then I should not fetch the entire data set because it would waste resources for a large data set. A practical example is the SQL Limit keyword. select * from users order by added limit 10 I wonder if we can connect...
I have a software for small delivery stores (pizzeria, Japanese, etc) here in Brazil running on a few dozen customers and have the possibility to expand it to many more customers after evolving it to a full POS (Point of sale) software. However, there is a critical feature we've been struggling to develop: an offlin...
I'm trying to decide who is right in the following argument: How to effectively process data in MSSQL? Which one is faster? Opinion 1: Data requests (this is especially true for complex ones) should be handled by SQL queries and the result be returned to the requesting C# code. Opinion 2: First, raw data should be requ...
We have a mobile app that accepts input into some fields, formalises them as a JSON document and then sends it to the back-end for processing. We want to agree on a schema for this document that can be validated and referenced indirectly in both the back-end and the front-end. One of the motivations is that the input c...
We have a system that is largely configurable, that can be organized in different architectures, and I'm struggling to write its requirement specification. I'll give an example Module 1 does A Module 2 does B Module 3 does C The system can be configured to have any combination or all of the three modules. How do I wr...
The deadline for a release is tomorrow, your collegue finally finished his task that's crucial for this release, project manager is standing over your shoulder and presses you to finally make a build and you notice a flaw in your collegue's code during review. Not a critical one, but something you wouldn't let go if it...
I have a class hierarchy for which I would like to separate the interface from the implementation. My solution is to have two hierarchies: a handle class hierarchy for the interface and a non-public class hierarchy for the implementation. The base handle class has a pointer-to-implementation which the derived handle cl...
So I working on a project and want to profile my code. I have been using KCachegrind to get general idea of what functions cost the most. But now I want to get the exact time spent on those particular functions. So I decided to measure them manually using clock_gettime using object oriented approach. ie. wrap clock_get...
I had an interesting discussion with a coworker that revolved around how people interpret the use of properties and methods on an interface. For example, let's say we have a blog with posts in various statuses: Working and Published. When in "Working" the author is still making changes and shouldn't be visible to reade...
I just want to check that my current understanding of Java interfaces is correct. If an interface says it must include public void increase(int amount), then does that just mean the class that implements that interface must have a matching method?
Similarities and differences between the two: Template Method Relies on inheritance. Defines the steps of an algorithm, and leaves the task of implementing them to subclasses. Factory Method Relies on inheritance. A superclass defines an interface to create an object. Subclasses decide which concrete class to instan...
So I had this idea to map my framework's folder structure to namespaces with a dynamic build process. To give you an idea how this would work here an example structure: src/ FS/ File/ open.php (function) Math/ add.php (function) test.php (function) MAGIC.php (consta...
So I know this diagram is really wrong. But I honestly don't know how to express my ideas using UML notation and it is hard to find resources to this very specific case. basically I have these questions After the customer entered his or her details, the Arrangement class will calculate the cost and the distance based...
I have a set of ORM models that are shared between the main business application and a couple minor side applications (such as an administrative web interface). I don't want to put the object's business logic for the main application inside the ORM model classes because the web interface doesn't use any of it (and it w...
A number N and a range a to b will be input by the user, with a < b < N. The program purpose is to generate random sets of positive integers that sum up to N, with each positive integers within the range a and b. For example, N = 26 a = 1 b = 10 And here are some possible output of the program: 1,1,10,1,1,1,1,10 3,2,1...
Some background: I develop web services for internal departments of a large organisation that are used in public facing websites. There is a geographic differences between myself and my colleagues in these departments so most communication is by email, phone, skype etc. My process for development is develop in test env...
I'm currently trying to refactor some rather complicated object graph to use dependency injection. I'm using C# and StructureMap, but the problem isn't really technology specific. I understand the basic principle, but drawing blanks on how would I resolve a dependency like this: public class Food { public Food(...
I've been brainstorming on a specific problem for a while and today I've thought of a solution. But am not too sure about it. Hence this question for feedback and suggestions. I'll use the simple example of a product T-Shirt. The T-Shirt has multiple options: Color: White, Black Size: Small, Medium, Large Now in the ca...
Below is an example image, if I have a point of the white dot in the middle and I want to find the nearest possible location for the blue circle (which is obviously at the location where I placed it) if all the red circles already exist. How can I find that location? Performance for me is not a major concern for this a...
Let's say I am using a RSA keypair to encrypt and decrypt a large amount of traffic over a public network. Assume all traffic is padded and the key is 2048 bits, how often would you recommend renewing the private key? Is there a mathematical solution to how much encrypted data is needed in bytes that would allow a hack...
We currently have a store/shopping cart system that uses a single database. We have products with a field for the number we have in inventory (say 100 widgets). We have a customer table. When someone adds a widget to their cart, we insert a record in a join table between the customer and the product which represents...
Suppose that there are multiple classes (let's call them Container-s) that have somewhat similar structure. They are smart containers for some other Foo-s classes. These Container-s have: [1] A single private STL container (vector, set, map) for objects of some other class Foo [2] Standard public operations to work wit...
This is probably a naive question but I'm trying to figure out the industry best practice for working with magic numbers and their corresponding display texts. For example, whether a transaction is debit or credit might be stored as a bit field in the database, but the true/false/0/1 need to be displayed as "Debit" or ...
I would like to create a multiplayer mobile game where players play together over an ad-hoc network, with no internet connection required. Players should be able to join and leave mid-game, and the game should not rely on a "host" device being online. How can I coordinate game state across multiple devices in an ad-hoc...
This is a specific question here, but I'm interested in the general "best practice" for similar situations as I'm new to Java. Suppose I have Java code that needs to open a file (see below for code). I first have a function that checks for the files existence. If the file exists, we call functions to open it and proces...
When I'm trying to create an interface for a specific program I'm generally trying to avoid throwing exceptions that depend on non-validated input. So what often happens is that I've thought of a piece of code like this (this is just an example for the sake of an example, don't mind the function it performs, example in...
Title says it all. Should I increment my API version if I add, say, an image property to each instance of my JSON-represented 'Restaurant' resource? or should API versioning change only when implementation changes?
I am currently in middle of designing a backup application in JavaFX written in pure Java (meaning without Fxml) . I am having trouble implementing the MVC pattern for the following reason. The way I understand it is that the view has to be separate from the controller which processes events and updates the model to re...
Many times I find myself null checking when fetching a value from some data hierarchy to avoid NullPointerExceptions, which I find to be prone to errors and a needs a lot of boilerplate. I've written a very simple routine which allows me to skip null checking when fetching an object... public final class NoNPE { p...
There are cases where I don't know how to use exception handling. To make it clear, let me divide exceptions into two types: exceptional cases that may happen occasionally, such as when you try to open a non-existent file. exceptions that you wouldn't expect to happen if you have written your program correctly, such a...
I've seen a few answers on this already but nothing that really applies to my particular situation. I'm going to be building a mobile application, so primarily phones, tablets etc. Probably using Amazon Web Services, and I plan on having large amount of user data among other things, like statistics, images and so on. S...
I am currently in a dilemma. I am thinking about downloading a JSON file from a GitHub repo to replace local files. The local files are stored in a folder named lang, which is stored in the project folder. The repo is stored on GitHub and can be accessed using a URL. The GitHub solution, in my opinion, would be good s...
I'm developing a Java software according to the object-oriented Layers architectural pattern. Every layer should be clearly separated from the rest, and provide a well-defined interface to use it's services (maybe more than one). A common example for these layers could be an architecture consisting of a request process...
When you are working with an external library in git, should you add it to Git or should it be in gitignore? If you put it in gitignore, you run into the problem that if someone (or you yourself on another PC) wants to work on your code, they will first have to download and link the library. If you do include it, the g...
I come from a background where using a configuration file for every, if not every, constant is the best solution for maintainability and flexibility of the program. By this I mean, every hard coded string, integer, table/array, boolean, color, formatting expression, etc. are all put in one file or class (often called t...
I have an OpenGL application that plots data in real time. I would like to have a background TCP server that will accept data from a client without blocking on a call. The data is originally an array of 2048 doubles. Once this array of data arrives, I need to place it in a circular array buffer that is read from the...
With almost every software there are errors and those must be given levels. Grave errors may simply stop your program while simple notices can be resolved with a click. I've always proceeded by giving them a certain numeric degree of importance. But is there a "general rule" between programmers on how to chose these de...
I'm building a web site and I want to use a big background image. Because of speed considerations, I thought that it would make sense to send a low-res version of the image the user first (for fast page loading and smooth user interface experience), and when the page finish loading, use JavaScript to load the higher-re...
I am currently implementing WYSIWYG editor that will be available on the web, what are the main security issues I should tackle? The editor currently works that when user is done typing, the text gets saved to folder with editor text on same domain, and the iframe gets refreshed with the contents of it. I know that wh...
Consider an alphabet of k symbols and a requirement to optimally encode a series of values of known frequency. The obvious choice for this is to use Huffman coding, which is known to be optimal for this problem. Consider now the extra requirement that when the coded values are received it will be unknown whether or n...
The moment of working on a system that gives you statistics based on some data gathered from the database has arrived in my company. How do you efficiently gather statistics from a database in such a way that does not add too much overhead in loading a page, or too much complexity in cache management? Currently, statis...
I need to implement a site with a real-time graph. I'm currently using WebSockets and chartjs.org for displaying the values. Now I'm not sure whether I should send all data points in every message or just only the new data points and save the remaining data points on a client-side ring buffer. In the current setup I ne...
Is it the number of iterations or recursive calls made? Or is it the number of times the conditional check has been applied? Ex: if there are 10 elements in an array in descending order. The time complexity will be 10 log 10(base 2). The answer is 33.2192. Here is the java implementation of the code. I have added a cou...
I have a class that models LogicalExpressions. The leaves are classes that implement an interface IEvaluable, that has a method called Evaluate which returns a boolean as the result. public class MyEvaluable : IEvaluable { public bool Evaluate(Environment env) { } } Some of these evaluable objects need t...
A classical problem: read the words from a text file and list the occurence of each unique word in the file. I solved the problem using a hash map, but how could the performance be improved? I tried reading multiple lines of that file using threads, but even that would be like a bottle neck and there are chances of r...
I have this two types open FSharpx open FSharpx.Reader type First = { Name: string Items: string list } type Second = { Name: string Numbers: int list } Using a Reader monad from the FSharpx library I can do this let map f = fun n xs -> { Name = n; Items = xs } // : Second ...
Recently I had to implement a Semaphore using a Mutex and a Conditional Variable (this combination is also known as a Monitor) for an exercise at the university: the Semaphore's decrement operation blocks until its counter is more than zero before decrementing, and the increment operation increments the counter and th...
I would consider myself an intermediate Python programmer. One of my recent challenges was creating a list of all possible solutions to a given Countdown problem. Without getting into too much detail, I have approached the problem through: first generating a list of all possible Number-Operator arrangements using RPN...
Should you format numbers in the view or in the services layer? If you are going to round a number to 2 decimal places. Does it make sense if that number is rounded in the view or in the services layer? What about if that number is a nullable type like in C#? I don't want to write if(number.HasValue) { number.ToString(...
doing an lscpu cmd this is what i get $ lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 2 On-line CPU(s) list: 0,1 Thread(s) per core: 1 Core(s) per socket: 1 Socket(s): 2 NUMA node(s): 1 Vendor ID: ...
I wrote a parser for a certain type of binary file with recursive structure. I made its API to be similar to SAX, that is: the parser accepts an object of a specific interface, this interface has several methods called as the parsing happens: startFoo(type, name), endFoo(), datum(type, name, value), badEntry(errorMsg)...
In any software development project that involves distributed systems with multiple developers, having Logical and Physical Architecture diagrams is best practice but in my experience these diagrams always start off being well maintained at the start of a project but do not get updated as the project get released and t...
In cloud computing these two terms really confuses me, block-level virtualization and file-level virtualization . As of my knowledge, in file-level virtualization compute systems are not allocated partitions and just deals with the storage systems APIs to retrieve or upload a file. Block-level virtualization is allocat...
Let's say that we have the following interface - interface IDatabase { string ConnectionString{get;set;} void ExecuteNoQuery(string sql); void ExecuteNoQuery(string[] sql); //Various other methods all requiring ConnectionString to be set } The precondition is that ConnectionString must be set/intializ...
I'm trying to wrap a RESTful API around an existing implementation of a game. Here is a possible state diagram of a simple API design that comes to mind: I'm having troubles here because the existing domain implementation does not expose a list of moves. Instead it exposes the state of the whole board. A list of moves...
In my current project I'm refactoring the code to get a DBAL. I have a class Entity that is the base class for all classes that model a database table. So there are several classes that inherit from Entity like Document, Article and so on. abstract class Entity { /** @var DatabaseRequest $dbReuest */ protected ...
I am inheriting an api decision in an SDK I am writing where I am required to fetch domain objects (entries) from the server like this: blogEntries = client.content_type('blog').entries As you can see, the setter for the content_type property here is parameterised. To implement this design my Client class has a method...
I have to write unit tests and integration tests for a project. Should all tests be put into a single tests folder? Or should unit tests and integration tests each be in a separate tests folder? Or should I even put them into separate projects? If I keep them together, are there any advantages or drawbacks with this ...