instruction
stringlengths
34
36.1k
How do I unit test a constant that defines an implementation detail? And should I? For instance, let's say I have the following class: class A { private Cache _cache; const int timeToLiveInCache = 30; // 30 seconds of TTL A() { _cache = new Cache(timeToLiveInCache); } } In my unit test, how can ...
I'm relatively new to programming (July 2015), and I've always wondered why it's good programming practice to hide variables as much as possible. I've run into this question mainly recently when I looked into events and delegates in C#. I searched around as to why I should use events rather than just a delegate, since...
This question was answered in "Understanding Abstract Data Types (ADTs)", and the top voted answerer (by Frank Shearar) is currently as follows: Objects are not ADTs (*) [editor's note: Links to "On Understanding Data Abstraction, Revisited" - Cook]. (So in C# String and Int32 are not ADTs.) With that out of the...
I am frequently tasked with debugging an application at my job. It is a BI Application that we deploy to businesses, which includes a test environment, and a production environment. I am wondering if there are any apps/tools/methods that people can suggest, based on these constraints: Debugger cannot be used on client...
I am about to start a new project which involves taking an excel file, parsing the data (php-excel-reader) and then using the parsed values in a HTML email. My question is pretty simple. Is it better practice to store the parsed data in a database first and then use the data however I wish? For me it makes more sense ...
Problem Description I am working on an enterprise data discovery project that is designed to scan databases for sensitive information. The basic search unit is called a classifier and covers things like 'Social Security Number', 'LastName', 'Driver's License', 'Credit Card Number', etc. Currently, each classifier is a...
In the, commonly referred to as, Git-flow model hotfixes go in their specific hotfix-* branch and small integration fixes right before release go in the release-* branch. General bugfixes from the previous version does not seem to have a place. Where should they appear? Should they be in their own bug-* branch branchin...
From this blog post describing the git-flow model, it seems that feature branches have to remain local to the user working on them and are actually deleted right before pushing to origin. This kind of makes sense, but what if other people want to checkout my feature branch to help me out for example? Should I push my b...
PROBLEM: this points to different instances at different stages of execution (as it should). But it is not always obvious which instance is that. On the other hand we could minimize the use of this, fixing its state with meaningful-name variables. EXAMPLE: // Variant A: this.someFunction(); // Variant B: var combobox...
Reading the gitflow model, it seems to me that the master branch is there only to provide a branch where to store stable versions. What does that add to just tagging develop with the stable versions?
I've been going through the RxJS tutorials http://reactivex.io/learnrx/. Almost all of the exercises involve moving from a hierarchical structure to a flat structure so I thought I'd try to do the opposite. I want to convert from a flat array to a tree structure based on a property of each array item, using the same fu...
So I am building a web-app. The app will be hosted on heroku and I using a MEAN Stack for development. The main purpose of the app is to allow users to search through data and be able to find a document they are looking for. This is for my companies internal documents as most of our employees are all over the world and...
I was just confused about the following declaration in C: char **p[5] I understand the char *p[] as an array of character pointers, but this one is puzzling me. Based on the precedence of [] over *, how can I interpret this?
I am building a community website with a NodeJS express backend and a mysql database. Now I am up to the point where I want to store profile pictures of users and pictures related to specfic questions. I googled a bit and found many ways how to handle image upload, but I still have problems to figure out how and what t...
I'm defining a DB structure, and I have a strong feeling I'm not doing it right. I have hotels that can be configured to offer some optional services (airport pickup, massage), that can in turn be booked with a room. So, each hotel picks which services it offers and the price. Currently I have the following tables (sim...
I'm learning Java multithreading programming by the book "Java Concurrency In Practice". In chapter 9.4.2 Split Data Model, I read this: From the perspective of the GUI, the Swing table model classes like TableModel and treeModel are the official repository for data to be displayed. However, these model objects are ...
I've inherited a problem from a programmer that isn't with our group anymore - a piece of our application suffers from performance issues under a particular set of circumstances. I can replicate these circumstances - however, I don't actually know what is causing this performance issue. I suspect it is a large Java o...
The original question is as follows: Consider a 12-bit two's complement fixed point representation, with 8 bits for the integer part and 4 bits for the fraction. What is the binary encoding of the decimal value 45.625? I found the binary representation for 4510 in 8 bits to be 001011012 I then split the .62510 int...
Now, it doesn't necessarily have to be Word — for ease of comparison, let's use ODT, which is based on XML — which is pretty similar to HTML. That would, to my mind, make rendering an ODT document almost like rendering an HTML website. With ODT and HTML+CSS basically being two ways of describing a page's layout, what a...
I am having a bit of trouble designing a new feature at the moment. It is part of a resource management system. I was wondering if anyone has experience doing anything similar. I'll try to explain: Resource: a Person, Place, or Thing Availability Template (AT): allows you to define a standard availability pattern for a...
The usage of quotes in Go's import statement strikes me as unnecessary. Typical Go import statements look like: import "foo/bar" import other_name "foo/bar" import ( "foo/bar" x "foo/baz/bar" ) According to this Quora post, it's for unusual paths containing weird characters. As far as I can tell: C and C++ #i...
I got a question about why we need equals if we have hashcode. My first attempt was the answer because collision. But we corrected starting point with the assumption that we have not many objects so there is no collision at all. My second attempt was the answer because of the speed. But I also got the reply that there...
I had this idea that I would achieve some good automation and separation of concerns as follows: Define an interface, IDataProvider, in a class in a DataMuncher project that needs to both consume and output data. In separate projects, have different implementations of that interface, e.g., in LunarData.csproj would be...
Imagine a client-server app that lets user upload images/documents etc. to server and then lets users who have access, retrieve and view them later on their respective mobile devices. So the flow is something like this: Creator (C) creates a message with n number of attachments. C uploads the files and message to ser...
When implementing the repository it's fairly easy for a stand alone class. Unfortunately, we are unable to use an ORM to manage our data access, so I'm trying to recreate some of the functionality manually (uggh). For example, If I have a class User the implements a generic IRepository. Additionally, I may have a cla...
I'm trying to learn about REST and having problems with the concept of HATEOAS (Hypermedia As The Engine Of Application State). What is it for? It seems to me the majority of commenters on the web think that HATEOAS should be used by a client to discover how to use a RESTful web service. And most seem to conclude tha...
Example taken from : Agile software development : principles, patterns and practices A new employee is added by the receipt of an AddEmp transaction. This transaction contains the employee's name, address, and assigned employee number. The transaction has three forms: AddEmp <EmpID> "<name>" "<address>" H <hourly-rate>...
Why does the documentation on some languages say "equivalent to" rather than "is"? For example, the Python Docs say itertools.chain(*iterables) ... Equivalent to: def chain(*iterables): # chain('ABC', 'DEF') --> A B C D E F for it in iterables: for element in it: yield element Or this C++...
I'm considering a few different possible flows for a restful api. For minimum viable product, I'm assuming a web browser as the front end. Current use case: the task of the human operator is to create an ordered collection of entities. Each entity will have some values assigned by the user. The assumption is that th...
In files that contain multiple languages (ie. template files), are there any best practises regarding indentation? I mostly use this: <div> IF FOO <div> <p>contents> </div> END FOO </div> Indent for every new block, regardless of language. This has a few disadvantages, though. In mo...
While developing the application I started to wonder - How should I design command line arguments? A lot of programs are using formula like this -argument value or /argument value. Solution which came to my mind was argument:value. I thought it is good because with no white spaces there is no way that values and argume...
If I extend software under the GPL licence, I understand that my source code must be freely available. If my source code is freely available can I legally charge a fee for using the version that I publish? My situation: I'm using data from a program in my program and have an In-App purchase for access to all the data. ...
void function(int x){ if(x<=0) return; function(x--); } This is a recursion function which is called with the value of x = 20. The Recursive call will take place in this way function(20)...function(19).......function(0) Each function call will use some memory and if the data is big it will throw Stack...
In our application users can enter custom expressions to calculate certain things. For instance they can specify an invoice and define a number of lines for cost calculation. Example for a course with $400 price $10 transaction fee and a number of free people (say because of some credit) (?numberOfParticipants? - ?cre...
Way back in the hazy origins of our platform it was decided that we were going to need some hierarchical data structures stored in the RDBMS. The relationships between nodes were stored via a 'parent_id' column that referenced another row in the same table. Although at face value this may seem slightly sensible, the re...
Imagine a humongous web aplication built using Single Page Application framework such as AngularJS. With its each route it downloads a couple of HTML template files. Each of these template files contain JS files unique to it. So, now when each of these template files download it will also pull in and download the JS fi...
I have an optimization problem and I was wondering where to start from to be able resolve it. I think it can be solved with an NP-complete algorithm but I am not sure where to start from. The problem is the following: There are N types of different colored same-size rectangles that have to be printed. For each type ...
I want to model an interaction between classes, e.g. there is a general class Hero and he can have some items. (I came up with this analogy so it is easier to understand) Some of them are e.g. potions and can modify hero's hp, regen, strength etc., and others can be equipped ( run method hero.setArmor(item) ) I want t...
Me and a couple of colleagues are having a discussion regarding the following case: In an OrderStatus table we're keeping track of all the statuses an order goes through in time, including "Pending", "Available", "Returned", etc. There's a timestamp field in the table to keep track of when each status was added. Howev...
I was having a conversation with a friend about the C# StringBuilder class, and what it's behavior was. I'll paraphrase, but my side of the conversation was something like this (I oversimplified because exactly how StringBuilder works isn't important for my question) StringBuilder is more efficient to use for extensi...
I'm currently working on a webapp where we often need to condition some server logic based on the page that is going to be returned to the user. Each page is given a 4-letter page code, and these page codes are currently listed in a class as static Strings: public class PageCodes { public static final String FOFP =...
I'm redesigning one of my programs which performs certain actions on processes of interest (known as "Monitored Processes" in my program). Some actions I always need to do on those processes are: Open process handle Get process name Close process handle And some further actions I may need to do on some or all of the...
I'm working on a project that uses RxJS to perform data transformations on varying sources of data, and I'm in the process of writing some documentation for it. I want to find an effective way to document the following: An abstract way to describe the cardinality and relationships of the data. An abstract description...
I have a very large selenium test framework I use to test a web application. It it built around a page-object pattern. This week I fixed a bug in a low level piece of the framework, but it broke many other pieces that got built on top of this bug. I didn't have a good way to find these spots without running the full te...
I'm working on a piece of functionality that simply allows a guest user to perform an action a certain number of times before requiring them to login\create account. In this instance, they can vote on photos in a gallery 5 times before the app asks them to create an account. My solution is roughly as follows. On initi...
In choosing the classes to group together into packages, we must consider the opposing forces involved in reusability and developability. Balancing these forces with the needs of the application is nontrivial. Moreover, the balance is almost always dynamic. That is, the partitioning that is appropriate today mi...
I'm developing a program for the Razer Deathadder and Firefly, I am going to create new light effects for the Firefly. I'm doing this in C# with the Colore library. Now these light effects will be created using Threads with while(true) statements but how can I check and destroy threads and then reactivate them again wh...
Not sure if it's an appropriate question, but here it goes. I know Haskell's do notation pretty well. And I realized that Scala's "for comprehension" really is just mostly the same as do notation in Haskell. Something I don't quite understand is why did the designers choose this name though? The words "for" and "yield"...
I've seen blog posts explaining how to do Git bisect, but how to you fix the bug, commit again and maintain the rest of the commit history? An actual problem I faced in my project was like this (the image is just an approximation): I had marked the top-most commit as bad and the bottom-most commit as good. Some of the...
I have two lists (sizes m and n) containing high dimensional bit-vectors. All vectors have the same number of dimensions and use Hamming distance as measure if distance. For each element in the first list I want to find the closest elements in the second list. Such a closest element may differ by several thousand bits ...
Let's say that I want to embed a scripting engine inside some other program, to allow users to create custom behaviours for objects. For example, when a particular event happens, the server would launch an embedded scripting engine and run a user-supplied response-to-event script supplied by each actor. Conceptually yo...
Based on the context, C# can generate the expression tree for a LambdaExpression from lambda expression syntax: Expression<Func<string, int>> expr1 = s => s.Length; as can VB.NET: Dim expr1 As Expression(Of Func(Of String,Integer)) = Function(s) s.Length Why can't either language compiler generate an expression tree ...
One thing that always intuitively struck me as a positive feature of C (well, actually of its implementations like gcc, clang, ...) is the fact that it does not store any hidden information next to your own variables at runtime. By this I mean that if you for example wanted a variable "x" of the type "uint16_t", you co...
I'm trying to understand the concepts of HATEOAS (Hypermedia As The Engine Of Application State) in REST. The following have been very useful: What does HATEOAS offer for discoverability and decoupling besides ability to change your URL structure more or less freely? REST APIs must be hypertext-driven (from Roy Fieldi...
I want to license my software with the Apache License 2.0. The software is only a single file of source code. I do not want to include the entire license verbatim in the code. The license appendix describes how I may apply the license to my work by reference. This is done by including text in my software, referring to ...
Me and my R&D team maintain a large codebase. We've divided our business logic into multiple packages. some of which have classes with identical names. As you can guess, the names conflict when both classes are referenced in the same Java file. For example: com.myapp.model (package) - Device (class) - ... com.myap...
Does the command pattern uses OCP ? In a command patter the invoker is only extensible by actually extending the class. If we want to add custom methods to it, we can make our own sub-class or we could modify the base class's constructor, which violates the open/closed principle. Which leads me to the question, is the ...
So I'm designing a database for a project which is going to enable beauty businesses to create a profile, clients to create a profile and for the client's to be able to book appointments and for the businesses to manage appointments and their clients. I have the following tables and fields so far(I've kept is as simple...
I'm utilising OpenCalais API to tag the articles from multiple news sources. I know which category each article belongs to (e.g. crime, politics etc). Also each article has three social tags available. How can I find out which topic is the most talked about by multiple news sources? I thought I first gather all the sav...
I have been working on few web applications/REST web services recently (Spring IoC/MVC/Data JPA etc) and they usually follow the same pattern: Controller classes --> Service classes (which have number of "utility"/business logic classes autowired) --> Spring Data Repositories. Pretty much all of them classes above are ...
So I'm a relatively new programmer, attempting to create a web application (ASP.net) to display the system information (E.G. Status of windows services, disk & resource usage and errors in event logs) of a number of remote servers for monitoring purposes (initially - I'd also like to keep the design open to the additio...
I often hear things like: Mapping the classes Mapping the objects from the database Mapping the objects Mapping the elements of a list A mapper What does a mapper and the act of mapping something actually mean?
I'm presently reading Building Maintainable Software by Joost Visser and some of the maintenance guidelines they recommend include: A) each unit/method should be short (less than 15 lines per method) and B) methods should have a low cyclomatic complexity. It suggests that both these guideline helps with testing. The ex...
Where I work we have around 10 VS projects in a solution which are identical in functionality (with some different different rules in a few methods) and share many exact methods. They share the same namespace and the classes are called with if else's individually. I believe it would be better and more succinct to have ...
What is the difference between a 3rd party lib and a plugin? How do I choose what should be pushed to these repos? plugins-release-local = Your and 3rd party plugins (releases) plugins-snapshot-local = Your and 3rd party plugins (snapshots) ext-release-local = Manually deployed 3rd party libs (releases) ext-snapshot...
I just wonder if exists a compiled language that can modify it's own machine code. I know that in most common operative systems the executable code is protected during execution time, but maybe if you're using some specific a permissive operative system, you can use a language that allow you use reflexive features over...
So here is what happened The customer gave me a list of things he wanted to have. It is a funding website. So to start a funding project he wanted to have certain fields in the "create/edit funding project" part. He gave me a document on what should get implemented. I estimated around 25 hours for it and made a price t...
I have a golang library that abstracts a network service (think IRC-alike). The network server produces events which users of my library should consume. I'm using blocking network calls internally. I want to design my API to minimise friction users of my library, so i'm trying to decide between having the user supply ...
I am currently unit testing some C code and I am faced with a problem: Within the code there are called functions that contain inline assembler code for the SPARC 8 architecture. Since I am doing the unit tests on a x86 architecture, it obviously can't be compiled. Unfortunately, testing it on the target plattform is ...
I'd like to design a REST API supporting: Login Temporary token generation The reason being there are a number of client-side REST libraries that would speed up development if used, as they take care of serialization, connection, etc. If not used, we would have to code these parts separately. I don't need REST for pe...
I started working on a project where I need to read and parse an xml file from a url. This url needs a credentials to successfully read the data from it, so I'm thinking while reading the file there will be a modal window that will accept a username and password to authenticate the source. This url is from the outsid...
I'm studying functional programming and I'm having some question concerning array population. Actually, I'm trying to rebuild the Array.prototype.map function, and here's what I've got: Array.prototype.map = function(callback) { let newArray = []; for (let item of this) { newArray.push(callback(item)); } re...
I know there are a lot of Q/As in legalese or plain English. I am wondering if anyone could provide a real life example of the text that needs to be included with the distribution of software using code with Apache License Version 2.0. For example, if an app uses Apache Commons Math, a Java library with Apache License ...
I am working on a rather big Node.JS project with several thousand lines of code. It's not a homepage, but acts more like a configurable general purpose application server. As such it brings some parts which are useful in most projects I do. The problem is that I easily lose overview in the core modules. So I did a bi...
My dilemma is about the GIT flow. Let's assume that I have an application that can be deployed differently (staging release, QA release, production release). Since the application has profiles to be executed as staging version or as production version (it doesn't depend on which branch the executable is) with the same ...
There are quite a few similar questions out there 1, 2, 3, 4, but non seems exactly the case in this question, nor do the solutions seem optimal. This is a general OOP question, assuming polymorphism, generics, and mixins are available. The actual language to be used is OOP Javascript (Typescript), but it's the same pr...
In C# or Java we find that the objects are stored on heap and their reference vars are stored on stack. But at run time where is the class definition stored to be used as a template for creating objects?
So I have this super sweet library I'm working on. Let's say I release it into the wild under GPL. In tandem I'm working on a commercial piece of software, and I'd like to use this library in it. Since I made the library in the first place (even though I made it GPL), is it safe to assume I can use it in the commerical...
Here is a concrete minimal example to formulate my question : In small ball game, you have a physics engine that moves the objects regularly: void move(set< PhysicalObject* > objets, Duration t) And that engine can use user defined behaviour when a collision happens (using a strategy class). For instance, default str...
I see in the code or sometimes people talk about it, for some JavaScript code: (function() { var something; function someFunction() { // some code here } // do something }()); That's an "Immediately Invoked Function Expression", or IIFE. I often hear people say, "yeah, do it in a closure",...
I'm re-creating a web app (Google Apps Script) that i made a couple months ago, and decided that I wanted to make it fully configurable this time around. So that I don't have to go in any change any code or settings to adapt to new changes in the data it manipulates, queries, and displays. I've also worked to make some...
I want to understand how the theoretical foundations of computation relate to real-world computers. As far as my knowledge goes, Turing machines, recursive functions, finite state machines, lambda calculus, combinatoric logic, and other models are all theoretically equivalent in how they represent computation. To me, t...
In the book The Little Lisper, you implement a minimal Scheme in 10 Chapters that is capable of interpreting any chapter in the book. To me it seems you could do the same for a 'minimal subset of a typed language' to be self-bootstrapping. I'm trying to work out what is feasible. To me the options are: Simply Typed L...
Why virtual inheritance is not used as default? Default as in by the programmer and not the language. If not, why? What are the cases where it may fail? Is there some run time overhead? Is it significant? The motivation of this question comes from Stairway to heaven pattern. Its usage is not completely transparent, be...
I partially found a solution to my question, but I'm not really satisfied with the result. My application consists of ASP.NET MVC + MS SQL Server. The case is as follows: An external application saves data periodically to the SQL Database. In one tenth of a second, 20 to 100 records can be saved. SQL should be polled ...
From what I understand, isn't XML used for layouts and to setup how an activity looks? My book says that XML files are converted into Java code but then, why not just write everything in Java?
I have a web app that has different types of object: Car, Client, Lead. Each record has a user owner and a user can do according to its permissions action only on its own records. Database is MySQL. I need to add to the system a feature where a user can share a specific record to a user(or a group of users)- probably ...
Consider the following method: public List<Guid> ReturnEmployeeIds(bool includeManagement = false) { } And the following call: var ids = ReturnEmployeeIds(true); For a developer new to the system, it'd be pretty difficult guessing what true did. First thing you'd do is hover over the method name or go to the definit...
I wonder if it's possible to combine Visual Studio Team Services and/or TFS with a GitHub repository. We think both products have their own advantages and would like to work on one repo within our company. The reason to use VSTS / TFS is the integration in Visual Studio for Work Items.
I am using the protobuf-net library for serialization/deserialization of messages. Due to the distributed nature of the application some applications will have an older version of the object that is being used to serialize messages. The cases I'm concerned with are adding new fields to the message object that some con...
We're trying to put together a workflow for Wordpress development which turns out to be pretty complicated with lots of elements. Is there a way to streamline this or filling in the gaps? We currently have 2 developers in the team - but essentially this can be however many, all working in the same way. The problems WP ...
I've been following some tutorials on how to design REST APIs, but I still have some big questions marks. All these tutorials show resources with relatively simple hierarchies, and I would like to know how the principles used in those apply to a more complex one. Furthermore, they stay at a very high/architectural leve...
Our program does these kinds of operations hundreds of times for many different variables and lists, then uses them throughout the program: variable = values[5] The list values are coming from the command line, often as words, paragraphs, rows of a table or other (it's not important). Our issue is that our program, wh...
Recently, I've tried my hand at building a notification system, but I quickly found that notifications are tricky things, especially in the context of building a general model. The diversity of what triggers them (from a clicking a button to something timing out; "actions" as I will call them), who is to be notified, a...
I just started working on an Android app that should display posts from my site and then a three-column list of some products. The three columns on the list contain the product names, a short description, and then some pricing information. The pricing info should always be up to date. I am not experienced, but I am th...
My coworkers and I are discussing this code and need a third party to settle our discussion :) Random randNum = new Random(); int[] A = Enumerable.Repeat(0, 1000).Select(i => randNum.Next(0, 100)).ToArray(); int k = randNum.Next(0, A.Length); int[] B = new int[A.Length - k]; for (int i = 0; i < B.Length; i++) { in...
I'm writing a client application that receives a JSON response from a server. In the past I've run into situations where a developer on the server side changes the JSON response in a way that causes the client application to crash. An example of this is when the client expects that a JSON field or subobject will always...
I'm in the planning/design stages of a new project, and I'm having trouble coming up with a good way to handle one of the requirements: Users must be able to create a new record and save it as "Incomplete" without filling out all required fields. This is a requirement that will apply to almost all user-editable reco...
I've been reviewing C programming and there are just a couple things bothering me. Let's take this code for example: int myArray[5] = {1, 2, 2147483648, 4, 5}; int* ptr = myArray; int i; for(i=0; i<5; i++, ptr++) printf("\n Element %d holds %d at address %p", i, myArray[i], ptr); I know that an int can hold a maxi...
I am a noob at JVM internals. Can someone explain what happens at Java interpreter level when IncompatibleClassChangeError is thrown? I am facing an issue similar to the one described here: https://bugs.openjdk.java.net/browse/JDK-4171827 but having a hard time understanding this comment(quoted from the same page): ...