instruction
stringlengths
34
36.1k
I've been leaning towards the idea of Consumer-Driven Contracts in order to allow separate API consumers evolve on their own. To approach this concept initially I'm tempted to dip my toes in slightly by creating separate API paths for specific consumers (ex. GET api/SuperCresMobileApp/puppets/olly, GET api/BigPaternerI...
I'm trying to set up a test framework for (SQL) datasets that get updated daily. I want to write assertions that involve comparisons between two tables–for example, the sum of column visitors in the customer table, grouped by day, should be within 5% of the total in the transactions table (but might not line up precise...
What are some architectural solutions that can mimic eventing for systems (Java) that are too old to implement eventing solutions, such as conventional Queue/Topic based JMS messaging? I have a system that is REST capable and needs to interface with other systems, but having it send messages would be the most ideal sol...
I am wondering if there is a specific term for when multiple representations are data equivalent. Meaning that you can transfer the data from one representation to the other without any loss of data. Like an in-memory object model that can be read from data files with the guarantee that if you deserialize and then ser...
I am a theoretical physicist starting my Ph.D. shortly. As a side project, I would like to create a scientific computing website in the field of General Relativity. It should be an interactive database that allows one to explore various exact solutions of the Einstein equations. I have some background in web developing...
If a method takes an object of class A as parameter and analyzes its properties somehow, performs calculations etc. to verify this object, is it okay for class A to have a boolean valid field? After the method of class B completes verification of this object it sets the boolean flag accordingly. The verification proces...
I was playing with bitwise operations and a question about counting true bits of any positive integer value, so I solved the problem with bit shifting, so I just thought if there would be some way to get shifted or unshifted bits from the bitwise operation, Code would be more optimized. So I checked the PHP documentati...
Sorry if I'm not explaining the question well in the title, I'm not sure of the correct lingo. Let me give you an example instead. So this is a normal HTML file. <span>Welcome to the site!</span> I would like to make it a bit more dynamic by perhaps having in the JS. <script> $scope.welcome = "Welcome to the site!"; <...
This may be a naive question, but I wonder when and why (non-research) developers would directly edit a binary file. It seems like the only good reason to use one is to create a kludge when you need to fix and redistribute an unencrypted binary, and can't access the original source code or data storage. But in all othe...
I like the idea of Optional in Java which we can use to say that the object may or may not be available. I am now learning JavaScript and when trying to find an equivalent, came only across optional-js. No other major frameworks seem to be implementing that. This caused me to wonder, is such a usage not needed in Java...
Say your native language is Hebrew, and you're working in a programming language like Python 3, which lets you put Hebrew in source code. Good for you! You've got a dict: d = {'a': 1} and you want to replace that a with some Hebrew. So you replace that single character: d = {'א': 1} Uh oh. Just by replacing one chara...
I'm working on a networked game. I have tried to design the various components (client, server, engine) to only about things within their domain. For example, the server should only be concerned with handling packets and connections, not about entities within the game engine, or handling hardware events on the client-s...
I was looking at Map and SortedMap documentation from Java 7 and I have realized that SortedMap, which extends Map overrides entrySet(), keySet() and values(). AFAIK, interfaces cannot implement a method in Java prior to Java 8. So what was the reason for overriding these methods?
A lot of languages feature something like Haskell's Maybe monad these days. I was wondering about its historic origin. Wikipedia has no problem explaining what a monad, or specifically the Maybe monad is, but the page's history section is very rough. An uncited date is the 1980ies with Opal, but the only real reference...
I see a lot of DB migration tools that have up/down functions that deploy/revert DB schema changes. I have never seen a migration tool where you simply define the schema and it modifies your current DB schema to match the new definition. Benefits: Simplicity, no need to manage a bunch of ups/downs Easily couple your s...
A counterpart to memory leak, but involving CPU time instead - the program's CPU usage slowly climbing to 100% and then the whole system slowing down - without memory footprint changing. An example where this could happen - a program aggregating old data, polling the queue for samples in given interval; while the datab...
For the sake of an example, let's say I'm using Picasa, Flickr and 500px APIs, and that each of the services has limitations on these simplified parameters: overall account space individual file size I have a database table called external_services where I store the details about those services, my developer access t...
I have used Git at my past two companies for version control. It seems from what I've heard that about 90% of companies use Git over other version control systems. One of the biggest selling points of Git is that it is decentralized, i.e. all repositories are equal; there is no central repository/ source of truth. This...
If I have something like this: var1 = input("Enter a number lower than or equal to 100") var2 = input("Enter a number greater than or equal to 1.") if var1 > 100 or var2 < 1: print("Wrong.") How do I figure out whether it was var1 or var2 which caused the program to print wrong, without using another if statement ...
I have a client that's requested a detailed Scope of Work/Statement of Work. Upon looking into it, it seems they want timelines, costs, features, the whole nine. In order to do a detailed SOW, one basically has to have the whole system planned out ahead of time. Yet, the customer is not happy with any development appr...
This is more of an open ended question regarding design best practice. Say I have two classes; one is a Vehicle, and the other is an InformationSource (for maintenance/repair information). An information source will be used for many different vehicles, and a vehicle may have multiple different information sources (for ...
I am slightly confused when to use which because futures are allowed to fail. If futures are allowed to fail, then to me, that sounds like a Try[] in itself. And if the Try[] is wrapped inside a Future, then what is the difference with a regular Future[]?
Here's the situation: I'm making a proxy (for the moment running on my laptop) which deals with HTTP(S) requests from incoming clients (for the moment only one client, i.e. my Chrome browser on my laptop). It works without troubles, but it is a best effort proxy, i.e. it does not give priority to some types of traffic ...
Is an API always returning 200 OK, an issue?
I have a C# application where I'd like to present information that is accumulated in memory from an embedded system in the form of an HTML page in a near real-time manner. As a proof of concept I've implemented an HttpListener within the application and that works well for serving the data but at the moment for testin...
I am making a sport events scheduler to calculate possible schedules out of initial data and configurations. There are three main domains: players, courts and timeslots. My question regards the latter. The initial idea was that a timeslot would be just an abstract representation of a period of time, and giving it more ...
I am trying to infer the differences between two projects, however so far it has been really painful, because one of the parties has done auto-formatting on the code. Basically, this makes a merging tool like meld find many differences because the spacing in one of the projects has changed. Is there another way to com...
I'm looking at this piece of code and whilst it works, it feels wrong to me. I'm wondering if I am looking at an anti-pattern? The code starts with two promises, getAccounts and getTransactions. On one of the promises there is a catch block that handles and error but returns a resolved promise with an object that looks...
Im starting to write my own template engine for Java. It will be primarily intended to Spring Framework. I usually use Freemarker, but I know template engines such as Java Server Pages, or Thymeleaf. Im doing it only for fun purposes and to develop my programming skills. I have a few assumptions to my template engine, ...
The problem is similar to this question, but not a duplicate. What I'm looking for is a better solution than my current one. I'm building a web application for a department in my university, and due to how college works, things need to be archived every semester. By archive, I mean marked as not 'current' so that anyth...
I am currently using Firebase with my iOS app. I use it to authenticate users and then allow user interactivity during the life of the app session. I would like to be able to save a snapshot of my firebase data anytime that a value is changed, so that at some future time I can analyze all this data and use it to view h...
Is it true that overriding concrete methods is a code smell? Because I think if you need to override concrete methods: public class A{ public void a(){ } } public class B extends A{ @Override public void a(){ } } it can be rewritten as public interface A{ public void a(); } public class Conc...
In the section Method Names and Instance Variables, the Python Style Guide (aka PEP 0008) says, "Use one leading underscore only for non-public methods and instance variables." Why then, does the _replace method on namedtuple have a leading underscore? namedtuple classes themselves do not invoke _replace at all, and me...
Special Note: I asked a very similar question on Stack Overflow, but I have since decided the problem should be solved from a design standpoint rather than an implementation standpoint. I have removed a lot of the coding details from my original problem, as well as concerns about where individual bits of logic should ...
I have a stateless method that takes an input, and based on that input returns an output. This method has no state so in theory it could be made static. But let's say I don't do this. What problems might arise from this?
class A{ private List<Item> itemsList; public List<Item> getClonedItemsList{ return new ArrayList<Item>(itemsLIst); } public int getItemsCount{ return itemsList.size(); } } Does it make sense to have both methods in this class? By getting a clone of the list the clients of ...
We want to create a DSL in Scala where you can declaratively list the ingredients that a product consist of. These ingredients can consist of for example "Create product a", "Create product b", "Send mail". The ingredients can depend on each other (e.g., "mail" can only be send once both product a and product b are cre...
We are working on a game streaming product in a startup which works really well in its current state. Games can be played over the internet with very low latency on client application. Now there are multiple ways to make the system work for large number of users. First, Virtual Machines, i.e. one Windows VM for each c...
Background Team/Project Size Currently at our company, we have a team of 3 developers. We each have our own projects that we work on. So, we never have more than one person working on a software development project at the same time. Once in a while we may have a developer go and modify another developer's project (mont...
I'm building an application that queries several APIs and duplicates some of the data in a downstream, centralized database to make it easier to perform some processing on it. My application will only read these APIs. Checking for new and updated content seems easy enough (I can sort the data by last updated/modified)....
I have a class called ReplaceRule this is used by 2 classes DocumentRuleViewModel and SectionRuleViewModel as a List<ReplaceRule> in both Question 1: In my database implementation I have 2 distinct tables for each of the representations. Would it be more standard or efficient to have just 1 with a type column or is 2 p...
To explain what I mean, I'm going to give an example of a bad case for a subtype overload. Let's say we have a community of people. And depending on what kind people are in our community, our community has some statistics: (in java): public class Person {...} public class PoliceMan extends Person {...} public class...
I have an application that exposes a series of Web services. One of my entities has a bunch of one-to-many and many-to-many relations to other entities. My transactionality level is at DAO, and I'd like to keep it there to avoid the persistence context being open too long. Thinking of moving it up to the service level ...
There are text files and there are image, video, and music files. Why are image, video, and music files considered binary files, and why are text files not?
Something that often comes up in code reviews is the structure of the code, particularly related to the use of control structures, where individuals can be fairly opinionated on what is "right" and what is "wrong". I have my own opinions on the subject, but at the moment, that's just what it is. The code snippets below...
Background Most of the applications that I write are hour long sequential tests for electronic equipment. The equipment under test has a specification that is a state-machine that looks like... Get the equipment into mode A. Now that the equipment is in mode A, do a test. Get the equipment into mode B. Now that the eq...
Uncle Bob's three rules of test-driven development state the following: You are not allowed to write any production code unless it is to make a failing unit test pass. You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failures. You are not allowed to write a...
I have a class in Python that its only responsibility is receive text, a font path, max font size and min font size and print the text on an image if it fits. I have a function named word_wrap() and it does the following: declare variables (text, font) split text into lines if it finds any \n characters split each ...
According to Wikipedia the Liskov substitution principle states that objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program Normally the Liskov substitution principle doesn't apply to classes because they are not objects. Now in Ruby, classes are...
My C++ book says that if I have int anArray[25]; and I try to evaluate anArray[25] = 0; the program will simply overwrite whatever value is stored in the next memory address past the end of the array. Why? My thinking is compilers are stupid in that regard. All the compiler cares to do is calculate where anArray[25] ...
I have a PHP application with a MySQL database. I have not defined any formal relationships between tables. (eg. Set Foreign key, etc). Although in every query (CRUD) I always consider the relation between tables. Are there any significant downsides to not defining the relationships formally? Are there any performance...
Compare Database #1 and Database #2 below DATABASE #1 POSTS--------------------------------- |___Id________Category_Id______Body__| | 1 "For Sale" "...." | | 2 "Requests" "...." | | 3 "Misc." "...." | | 4 "For Sale" "...." | | 5 "Misc." ...
I've been working on a multi-threaded JavaScript runtime implementation for the past week. I have a proof of concept made in C++ using JavaScriptCore and boost. The architecture is simple: when the runtime finishes evaluating the main script it launches and joins a thread-pool, which begins picking tasks from a shared ...
(Please note that this question is linked to this: How can Continuous Delivery work in practice? - but it asks a more specific question regarding time and stability). CI/CD, no manual QA, super quick releases are the new buzzwords and I have read about this topic many times, but it sounds somehow unrealistic for cases ...
I want to limit file upload frequency to our webservice to prevent denial-of-service (directed at the server) - specifically, temporary folders filling up with fake uploads. This could be the user misbehaving, or, if this goes over http:, someone pretending to be the user. There are already some measures, like limiting...
As an semi-experienced procedural PHP developer, my OOP still needs a lot of work. I am still working through SOLID principles and other theories and guidelines of OOP, and am stuck with something that just looks UGLY to say the least, and definitely does not confirm to SOLID. I am busy redoing my in-house CMS, using C...
My concern is how to handle ResourceDictionarys in a WPF (MVVM)-Project. I usually only create small Projects, so it doesn't matter that much, but since I created a Project-Template to handle some of the boilerplating, I'm really interested into this Topic. I found the following approach on Stack Overflow: “Resource Di...
Background I am currently working on the architecture for a future software design. The design is one long running task (hours-long) with thousands of sequential calls to various libraries. I currently have a method of pausing this long-running task, that I would first like to discuss before asking my question. The flo...
I haven't really found a decent/future-proof way to version methods in my WebAPI. This is what I typically do now, but it can get confusing and hard to trace if it gets a bit large (I'll end up [OBSOLETE]-ing the older ones as time goes on). Has anyone come up with a more elegant or manageable option to versioning W...
I have a service class which is responsible for instantiating repositories and using them. It makes an external Http request which ideally I would like to mock for testing. However, I am not quite sure the best way to do this. For example, right now the class looks like this: public function lookUp($identifier) { $...
I've encountered many people who are dogmatically against anything which can be considered "optimization" in the general English-language sense of the word, and they very often quote verbatim the (partial) quote "premature optimization is the root of all evil" as a justification for their stance, implying that they int...
I need some help with the approach to a specific project. We have a large excel workbook with a ton of worksheets. There are many user inputs, which formula fields pull, return, repeat. This all ends up in a final report. Each worksheet has essentially become its own Model, View and Controller :). I want to find a way ...
I recently found out about JavaScript's Template Literals, and they help a lot with readability. But would it be worth changing my code from now on to these Template Literals, or should I keep using Strings? Example of Template Literal vs. String String var name = { first: John, last: Smith }; 'Hello' + name....
One scenario is when you're creating a search endpoint. In the example below, I want to search a database of companies and the queries can become complicated; enough where I want to have the parameters passed as JSON objects instead of a flat list. var hapi = require('hapi'); var joi = require('joi'); var server = new...
I have a REST API that for some of entpoinds like DELETE, POST or PUT I have some validation rules that can return an error. Now I need a new type of an error like a non-critical error, that it should fail in a normal way, but should go for the action if there is a "supress warnings" flags send. Such an user can be as...
I'm trying to work myself into the Clean Architecture by Bob Martin with respect to android applications. It seems to me like there are Use Cases which do not encapsulate the Domain Layer, but belong to the most outer, peripheral layer. For example: "Open Image", "Take Picture", "Turn on Wifi". Where to put them? In th...
I've been a developer for a while. I'm far from the best out there. (As I sit by myself in this room, I wonder if I'm even the best in here.) However, I've come to understand my tools, and I've come to trust in my ability to reason and learn. When starting a new job, I always believe that I can learn the codebase if it...
I have a small Java console application that runs a set of data through an algorithm. Given the size of the data and compute time, I often run 10 to 15 instances of the application, each working on a subset of the data. All that is behaving ok. The application occasionally prints a sysout for my information. Rather tha...
Does crow feet lies under the sub category of the UML notation or it is a whole other approaches. As far i have seen only difference between two of them is that crow feet uses crow symbol |------<- to show the relationship while UML uses the 0..* or number to show the relationship. I think i have seen both of the ap...
I work at a mid-sized company where an update is needed to an piece of the application due to an addition to the environment. The part that needs updated has been in place for 13 years, is fairly mission critical, runs very smoothly each day, and was written using the VB6 language. The program runs through an executabl...
Before you read any further, assume you know what sudoku game and how to go about solving it. So I have created a sudoku solver with brute-force: The algorithm goes as calculate(through an simple rule checking) all possible values of each cell that is empty. Count empty cells If any cell has only one possibility, set ...
I have a class, lets call it Calculator, with a method like this: public double[] performCalculation(double[] someInData) This method can generate a number of non fatal warnings (represented as an array of strings with warning names, such as InDataOutOfBounds). What is the most elegant and javaesque way to return thes...
I have a method in that checks some conditions and if required, will carry out some logic to empty an array of 'selected' elements. Is there a standard way to name such a method? I was thinking deselectIfRequired() or is it better to split the logic and the action so you could end up using it like: if(shouldDeselect())...
Consider the following UML diagram: In a nutshell: ChildClass1 and ChildClass2 use all of the members of ParentClass. ChildClass3only uses Member1 and Member2 and the value of Member5 is a constant value. (0) What would be the best way to implement this behaviour? At the moment, I've inherited the class as normal a...
I've been asked to explain why it may be bad to have an abstract class that implements most of the methods (as an extreme case, only one abstract method) and has many sub-classes. Apart from having to look at a lot of code if you change the signature of that method I couldn't think of anything else. My answer didn't se...
I'm planning to write a simple bootloader. Nothing too complicated. Just really basic output and maybe keyboard input. But it seems a bit crazy to restart my computer every time I want to run the bootloader. I have a vmware workstation license. Could I just create a VM and use it to boot my image or does vmware only s...
I am creating an application which will have a very large database to draw it's information from (a student registration system to be exact). The database is created with Microsoft SQL Server if that matters. I plan to implement the MVC pattern in this, but I am unsure of how to handle accessing the database. My curren...
I'm building a API that gets called from web / mobile applications written using Ionic (web languages on mobile), which uses Angular.js. We want to be able to do server side validation of forms but don't want to have to rewrite functions constantly to match each form. However, we need to make sure the forms are verifie...
Consider following table structure, for the backend of a website: [Article] ArticleId Text TotalViews AuditModifiedOn AuditModifiedByUserId [User] UserId An anonymous/not authenticated user visits an article, and this causes the TotalViews counter to increase. What should the AuditModifiedByUserId become when updatin...
We're university students taking a course in information systems engineering. We have project and we've had a meeting with the teacher playing the role of a dentist and a helping girl playing the role of a secretary , the meeting was for gathering requirements for a system for dentists. Anyway the teacher has asked...
I'm searching for an approach to a very generic problem. In my recent private project, I want to control different Applications from a single GUI. To make the idea more clear I'll explain my project a little bit: I want to make an Augmented Reality Program with different settings and features. The video will be recorde...
Forgive the title if it isn't correct, I am just not sure what I am trying to design is called. Say I have a number of tasks I want to run, N. Additionally, I have a maximum number of threads I can allocate at once, T. I want to run as many of these tasks in async as I have threads available (up to T), and once a thre...
I have a habit of constantly making minor edits to my code whenever I spot something I don't like - be it a bug or just some sloppy piece of code I see how to improve. Neurosis-Driven Development. The problem is this habit doesn't work well with VCS. I can be working on a new function and, by the time I finish it, I ha...
I'm reading though some notes. And I'm not understanding the following two statements. Polymorphism means that it is always the class of the actual object at run time that determines which method will be called at run time. class A{ public void m1(){ System.out.println(" A"); } } class B extends A{ p...
First a bit of background : Previously in V cycle process, we have a dev team and a product definition/tester team (we'll call them testers). We moved to agile few months ago with still this separation : people with dev knowledge and people for product definition/testing. The dev team has for some time already continuo...
Is it good or bad to duplicate data between tests and real code? For example, suppose I have a Python class FooSaver that saves files with particular names to a given directory: class FooSaver(object): def __init__(self, out_dir): self.out_dir = out_dir def _save_foo_named(self, type_, name): to_save = Non...
I'm creating a charter database structure. I'm trying to figure something out, I have read on here that databases should be normalized. Now, I'm a bit confused on this because I believe I have stumbled across database tables that have multiple items in a single column. What I mean by this is, let's say the db creator i...
We started out with one developer, and one svn repo containing all our code: ^/foo/trunk/module-a ^/foo/trunk/module-b ^/foo/trunk/module-b/submodule-b1 ^/foo/trunk/website1 (at the time this was a big improvement). After this got a chance to grow for a bit we started having problems with circular dependencies, slow t...
Let's say I have a Db class [ db.php ] : <?php class Db { // class properties private $db_driver = ''; // dsn credentials private $db_dhost = ''; private $db_dname = ''; private $db_uname = ''; private $db_pword = ''; private $db_tzone = ''; // timezone...
Say I want to get the same data from an SQL database, but want to have multiple ways of getting that data. For example, say I want to be able to search a database for users based on username, real name and date of birth. In my data access layer I would have GetUserByUsername(), GetUserByRealName() and GetUserByDOB(). H...
Currently I work in a company with several applications developed in Java, these applications share an "internal framework" with common task like find an employee, check user permissions, etc. These libs in the internal framework are called through EJB remote, so when setting up a new development environment I need to ...
The application I work on manages hundreds of thousands of records each in a different state in their lifecycle. A large requirement is to have a nearly accurate count of these objects in each state so they can be assigned in batches. I.E. User X needs to know there are at least 25 objects in state Y so they can assign...
I have been developing android application for a while now. What we currently do is we first develop our UI components in the mean time web API developers will be completing the web APIs required, so when the web API is done we design our database according to the fields that we receive but It may lead to the problem s...
I'm wanting to write unit tests to check that for given database responses, certain objects are create/things are done. The problem I have, is that when mocking the database response, I have to manually go through and define the exact behavior that database/database accessor will respond with, for each test. What woul...
Is there any reason a new public project being started, if given the choice (e.g., not constrained by their company), would use something other than Semver? Are there competing methodologies, i.e., Semver has not been widely accepted yet? This question arises because a very well known package that I use updated from 3....
I am working on a large command line tool, written for Python 2.6+ and supported for Windows, OS X and Linux. The target users are developers but it is also being auto-invoked by CI-systems etc. In the Windows environment, our tool runs in cmd.exe, but in the other OS's we allow whatever terminal the users have. I woul...
Particularly for the sake of unit testing, I'm trying to implement an application with a layered architecture. I'm coding in C# and using ASP.NET Web API for the service layer. I'm aiming at a 3-layer architecture: Service Layer Business Logic Layer Data Access Layer The Problem I'm uncomfortable with having to choos...
After coming across Douglas Crockford's views on class-free OOP, and doing away with new and this in Javascript I tried defining an object with its own variable and function, and returning it in a javascript object, as shown below: var newObj = function (name, lang){ var obj = { "name":name, ...
A good quarter of a century ago when I was learning C++, I was taught that interfaces should be forgiving and as far as possible not care about the order that methods were called since the consumer may not have access to the source or documentation in lieu of this. However, whenever I've mentored junior programmers and...
In the context of refactoring, you sometimes come across the term "bottom up approach", which makes sense in a way that you change the smallest moving parts first when refactoring. However I never heard of "top down refactoring" and can't find any resources on the topic, so I was asking myself if it actually exists or ...