instruction
stringlengths
34
36.1k
I write a lot of software to interact with APIs. These APIs provide data usually in the form of an XML or JSON document. These documents are suppose to follow a spec and structure. In practice however, this can be difficult to code for. Specs may change, fields may be renamed, moved, dropped, or made circumstantial. Is...
In the last days I have searched for a documentation on how and when is it best to use redux and how to design the state tree. My research ended in the conclusion that there is no one correct answer. Then I came across this answer in github on that manner by petehunt (The answer is intended for flux). He's answer is a...
Just saw a code snippet that used an array pop assignment in the while condition; was wondering if this is acceptable/good practice? var arr = [0,1,2,3,4,5]; var current; while (current = arr.pop()) { // do stuff to each element stored in current }
Whenever I learn about a high-level language I want to learn about, part of me says, "I should probably learn the lower-level language it's built upon to really master it". For example, Ruby => C Closure => Java Elixir => Erlang My experience with Ruby and C makes me think that I've got it backwards. I learned Rub...
I've got java logging user activities to Fluentd, Fluentd is then writing these activities into an elasticsearch index. Every user activity is recorded, some include: User1 follows user2 User1 likes article1 User1 creates article User1 searches for tag user2 signs up More... Now for each of these activities I'm stor...
Context: With my team I created an "online platform" for a client which moved their operation from a paper based system to a content management system (CMS) based submission system on a Virturl Private Server (VPS). A large group of users submit content to the CMS in the form of uploading PDF files. These are critical...
I have a complex problem to be solved, I have several excel files containing data from over 1200 counties from 56 states. Problem is that most of the counties has some columns which are different from rest of the counties. And one county may be in more than one state and having different columns. I have to upload these...
The interface-segregation principle (ISP) states that no client should be forced to depend on methods it does not use. My question is: how exactly can a client depend on something that it does not use? It looks like the existence, the state and even non-existence of something I don't use, I don't depend on. Perhaps, in...
the QA team should ideally do their testing on an environment that almost exactly matches the prod env (to minimize uncaught bugs that arise due to setting differences). If that's true, does the QA team typically do the testing again on prod post deployment in the googles and amazons out there? If the answer is yes th...
We are arguing with colleagues how to name a method: ProcessInstructions vs ProcessInstructionsHavingDeliveryInProgrssStatus Those who insist on the first name say that it is more generic, and does not reveal internal implementation. Furthermore, second name is really awkward. The other half prefers the second name. De...
I'm building an api and a bit into the development I realized that I constantly change the order of the page and pageSize parameters. Currently I use C# and javascript, so the method declaration looks something like this: public IEnumerable<Order> Get(int pageSize = 9, int page = 1, string name = null) And the client ...
I have a cli application, that has the option of displaying file paths in addition to typical output. Some file paths can be quite long so I want to cut the path off once it is longer than a certain amount of characters. Traditionally cut off sentences would be cut off with an ellipsis ..., however using three dots wou...
I'm trying to get my head around DDD, and I understand that I have a domain object and a domain service. My domain object is an interaction which can be different types of interactions with a client, like a meeting, telephone call, visit etc. So I created an interaction service and now I want to create the logic if the...
Having worked with a few programming languages, I've always wondered why the thread stack has a predefined maximum size, instead of expanding automatically as required.  In comparison, certain very common high level structures (lists, maps, etc.) which are found in most programming languages are designed to grow as req...
In my team we have a policy that each code should be reviewed by at least one other developer. When the review is done the reviewer just clicks the merge button so the code ends up in development. Recently a idea came up that the reviewer should not be able to merge directly, but should pass the code review to a member...
I am a front-end developer who is familiar with HTML, CSS, JS and to a degree, AngularJS. I've chanced upon Firebase (firebase.google.com) - and was wondering if I could, with my lack of knowledge with server-side code, use Firebase for my app. Will I need to learn JSON for this?
I m trying to understand the core concepts of DDD and I m having some troubles dealing with validations. In fact, I m actually wondering where and when should I use specification pattern instead of Entity / ValueObject validations. Moreover, I m trying to find a way to avoid this kind of validation in my Application se...
Sorry for the codeless post, but I am wondering how to handle a complete UI redesign for a big web product? Maybe somebody have experience and could actually determine the steps on how you would do this? Should it be done incrementally? Should it be redesigned at once and delivered to production? What could be the step...
I work for a software company which tend to deploy applications on premise for enterprise customers. The software normally consists of server side software (a few microservices) and 1 or many client applications. The deployed applications are usually a highly customised version of a general application. So we have a s...
I'm trying to understand what is the motivation for buffering the print to standard output. I've experienced this in multiple programming languages, a scenario where you're trying to trace a bug by doing print outputs and your print statements aren't printed real time just because the buffer wasn't flushed. So to get ...
Have a plain WPF that started a proof of concept got demoed and bought and went down that path for a couple years. Time to start fresh and would like to know proper pattern. A WPF app that will talk to a WFP Service with a SQL data store. The crazy light colors are sliders and clearly will not keep those colors. What...
I am implementing the dot operator/notation you see in languages (obj.method();) with ANTLR4. Everything is working fine (except one thing), a simple hello world program works: module test; sfunc main { std->println(obj="Hello, World!"); } -> in this language is the equivalent to . in Java and many more languages....
Why is it Create Read Update Delete instead of Get Remove Add Set ? I've been working with an API that uses ADD and SET and REMOVE. Most accessor functions are named get...() and set...(). I couldn't find anything online https://duckduckgo.com/?q=gras+crud&ia=web
I read somewhere (probably on StackExchange) that certain large enterprises and government agencies will only use technologies that have been around for ten years. Can't find the source right now. Could someone please confirm this and provide details on which (types of) organizations have this policy? I'm wondering als...
It happens so that the best practice of using EntityFramework includes taking advantage of the IQueryable inside using block, like: using (var ctx = new SomeDbContext()) { ...(do something with ctx) } If we want to decouple database and business (and eventually presentation) tires, it involves creating other objects...
I'm designing a vector drawing app. I need to implemente copy and paste, shapes insertion, deletion and transforming while still being capable of including new tools with easy in the future. The way I think about it, this is a finite state machine, so i thought about a State Pattern. The stage behaves differently based...
I've been designing and programing websites for the most part of my adult life. I've always done this solo, freelancing mostly and working from a single machine. Currently, I use Dreamweaver for the coding and also the publishing of the sites (via FTP) and I work directly on the live sites. That's about the extent of m...
I'm designing a JWT authentication workflow for a RESTful API which uses two kinds of tokens: Phone token, a short-lived token - issued by completing an One-Time-Password challenge. Its task is to prove "ownership" of a phone. It carries the phone number. Access token, a long-lived token - issued by providing a valid...
I'm coding along with the examples in Build Awesome Command-Line Applications in Ruby 2 I'm using git and storing my code on github. The example code can be found on the pragmatic bookshelf site. They mention: Copyrights apply to this source code. You may use the source code in your own projects, however the source co...
Let's say I have a client that is consuming Vehicle objects sent from a server. I have two types of vehicles: Car and Truck. Some Cars can be inHybridMode but not all of them. The server currently supplies three specific models in a list: Prius, Camaro, and F150. In the client I have created this hierarchy: abstract cl...
I am using the lombok @NonNull annotation for some of my fields, parameters and methods, partly for null checking, and also partly for documentation purpose. It is then confusing if I added a @NonNull/@NotNull annotation from other libraries. Then if I also want to add a @Nullable/@CanNull annotation for some of my cod...
I'm now a huge fan/believer of Jeff Patton's user story map. I'm currently reading his book.. Jeff talks a lot about depicting different roles on a user story. However, I'm not sure how to do this when there are different platforms per role? I.e. say I'm developing a software for buyers and sellers. For buyers, I devel...
Say, I created a custom button which includes some animation which is played when the button is clicked. The animation takes 500ms. During that time (until the animation is over), the button should not receive any inputs, and so should other items wait for it to end. If I implement it like this: public async void Click...
Simply put, what happens when I have a delegate, that delegate contains a method with a tail call request, and then I call it from a non-tail position? If I called the method directly, it would discard the existing params and reuse stack space. Does it do the same thing to the Delegate::Invoke's stack that triggers it?...
Various kinds of buffers have different names that more or less describe the functionality that they achieve such as the FIFO, or the circular buffer. They are both buffers, and serve similar purposes however their implementations are different. I have a kind of buffer that only holds the last X seconds worth of data. ...
So i've been going through some of my old code from the time i was learning the basics of wpf and i found something intresting. I had a class in the format below public class TempClass { public bool IsValued { get; set; } private SolidColorBrush _isValuedColour; public SolidColorBrush IsValuedColor get ...
I have a small Elixir module that takes up almost all the execution time of my program. I would like to optimize it. It seems like it takes around 15x as long time as the same implementation in C, so there should be some margin to take from. The natural step seems to write BEAM assembly for this module, but that doesn'...
I'm working on a software project which I intend to release as FOSS in some way. My code includes quite a few header/source files written by others: Better Enums A slightly modified GSL Lite An adaptation of some of GCC 4.9.3's libstdc++ for use in CUDA device-side code (so originally FSF code based on SGI code) An im...
I am having some confusion as to how to decide what to choose between Data Consolidation/Data Integration and Data Synchronisation? I know that: Data Consolidation/Data Integration: refers to the collection and integration of data from multiple sources into a single destination. During this process, different data sour...
My team implemented an alert broker system. The way it works is this: Event sources generate events, with mostly arbitrary structure, and the broker listens to them. Users go to the broker and use an expression language to create alerts for the events. The expressions can reference arbitrary attributes of the events. ...
First of all I am not a professional programmer, but a student with a programming hobby so I am sorry if my question is stupid. I want to write a chess engine to be used on the web and had already started writing it in JavaScript. After searching around I however found out that JavaScript is not ideal for this task. I ...
I'm creating notifier/notifee relationship. I'm not quite sure which is better in design though. As for "better", my goal is to get something that is extension friendly. As an example, see below: alien_enthusiast.notify( UFO_Sighting( London, 1500 ) ) vs alien_enthusiast.notify_ufo_sighting( London, 1500 ) Which i...
After starting the design of a sample application with Hexagonal Architecture I got to the application layer that should be basically an API to manipulate the domain in some way. My question is: In what form should I pass the parameters to the application layer? I can't pass anything contained in the domain because it ...
I'm trying to understand builder pattern usages and so to call to separate is usage types in groups. Here is what I discovered: Builder can be used to provide immutability (avoiding telescoping) for an object he is building. So called Joshua Bloch's builder. So, we use builder to facilitate building of object with a l...
I'm trying to build an architecture where I have a Domain project with all my domain models, an Infrastructure project with my Services and Infrastructure.Entity with my Repositories and entities. However, I'm a little confused on what's the best way to pass objects between the different layers. The presentation layer ...
C++14 seems to have omitted a mechanism for checking whether an std::mutex is locked or not. See this SO question: https://stackoverflow.com/questions/21892934/how-to-assert-if-a-stdmutex-is-locked There are several ways around this, e.g. by using; std::mutex::try_lock() std::unique_lock::owns_lock() But neither of th...
I often find myself puzzled with such a questioning. I need to version my projects for two reasons: publish source code with its whole history so that people will be able to get into it, explore it and make use of it. archive my project with its whole history so that I will be able to revert, fork again etc. There ar...
When migrating a project from one heavily-used library X to another library Y which is essentially equivalent but doesn't have the same API, it may be necessary to make a lot of changes. In the case I'm working on right now, ≈500 additions and deletions: not impossible, but I'd normally say, that's too many for a singl...
When I was reading Introduction to Algorithms (3rd edition, P188), there is an algorithm called Tail-Recursive-QuickSort and we have to prove the correctness of this algorithm. TAIL-RECURSIVE-QUICKSORT(A, p, r) 1 while p < r 2 // Partition and sort left subarray. 3 q = PARTITION(A, p, r) 4 TAIL-RECURSIVE-QU...
I have been writing some automation test scripts for a mobile application. Thus far my tests are very basic, I am struggling to know exactly what to test. An example of a test I have written: Enter valid login credentials > click submit button > (if element on new page is visible) > pass else fail So to test a click th...
I've been learning C# lately to see the other side of the coin (I have a decent amount of Java knowledge already) so I've been reading up on C#, and I came across an article called C# for Java Developers, and in reading the article, I saw something that I had never heard before. It is typically recommended that one cr...
Would it be feasible to calculate directly a k-permutation like k = 10^200000000? If not, What would be the computational limit to calculate huge k-th permutation in a today computer? How can I estimate it? Like, what's the biggest k-th permutation that I could calculate in less than a day? *Note, the permutatio proces...
In the interest of continuous improvement I'm interested in finding ways to improve our software development process. There are a lot of articles out there which define a set of workflows, but all of them always take the simple approach: 1 repository, 1 team, 1 product, 1 flow. But none of them seem to cover how someth...
Good day, I'm trying to find a way to program a lambda expression generator in java with this context-free grammar, and I would want to ask ; what would be the best way to tackle this problem and be able to manipulate them with basic lambda calculus functions such as beta reduction, alpha conversion, etc.? I tried doin...
I'm building an API, a function that uploads a file. This function will return nothing/void if the file was uploaded correctly and throws an exception when there was some problem. Why an exception and not just false? Because inside an exception I can specify the reason of failure (no connection, missing filename, wrong...
What is the best practice of a multi-step processing in a micro-service system which is using publish/subscribe architecture as internal source of communication and also requires immediate response? Is that even possible? Example would be a tourist agency which is exposing an API to their partners. API allows to book ...
I recently got an inexpensive phone with minimal browser support i.e. no javascript and on a small screen. Wanting to make the most of my device, I decided I would load some ebooks onto my device through a workaround. I saved a page for offline viewing and then connected it to my computer to explore the file-system. I ...
Sometimes you get into a scenario where a software team is iterating quickly and delivering lots of software. Over time, failure to do housework and paying off technical debt leads to productivity going down. They eventually approach a point where all the resources of team are used up in overcoming the accumulated cru...
Inside our UI there's an option to select something from a dropdown. Depending on what you choose inside that menu the rest of the fields inside the UI change accordingly. At the moment we handle it with if/else clauses which I think is not a good approach. Is there a pattern or a best practice to deal with something l...
In my WPF application, I want to create a new view. Where should I do that - in ViewModel or Model? The application is a (very simple for now) one-window form-like tool with single "send" button. In case if one of checkboxes is selected, new window using the same ViewModel should pop up to ask user for some additional ...
I'm using Spring Boot with JPA / Hibernate and I'm trying to decouple the business layer from the data layer. I would like to be able to (relatively easily) switch from a relational database to a rdf triple store. Here is a partial simplified description of my current try. I have entities such as: @Entity(name="Drawer"...
The way I see it, SQL injection attacks can be prevented by: Carefully screening, filtering, encoding input (before insertion into SQL) Using prepared statements / parameterized queries I suppose that there are pros and cons for each, but why did #2 take off and become considered to be more or less the de facto way t...
Given that a local copy of the Selenium server and web drivers are required to run an automation test, i.e... junit-4.10.jar selenium-chrome-driver-2.0a4.jar selenium-java-2.53.0-srcs.jar selenium-java-2.53.0.jar selenium-server-standalone-2.53.0.jar Is there any way to run a web service where, for example, when the ...
I have to create a method CalculateMean(int[] x) If the input is an empty array, should I return 0 (or some number), or throw exception?
According to https://www.quora.com/What-are-the-key-difference-between-ReactNative-and-NativeScript/answer/Valentin-Stoychev , "ReactNative as using the notation found in React for inlining the UI declaration in a single file." Is this supposed to mean that when writing React (or ReactNative) code you have to use inlin...
A couple of years ago (at QCon London) several talks name dropped the phenomenon where the software architecture evolves to mirror the office layout but I can't remember the name. I believe this phenomenon to be an influential factor in how solutions evolve and as an architect I don't want to make solutions harder to r...
I have a program that starts a task as follows: token = this.tokenSource.Token; var t = Task.Factory.StartNew(() => { while(!token.IsCancellationRequested) { // do the work... } }, token); My goal with this task is to perform some work until the user stops the program. The user stopping the progra...
Delphi BPLs do a DLL name mangling as explained in this German article http://edn.embarcadero.com/article/27758 (use your favorite translator page if needed). The name mangling is obviously different than using __declspec(dllexport) from visual C++ Are there any known ways of using the classes exposed in a BPL from Vis...
Problem: you are given n jobs, each of which has a start and an end time. The task is to simply output the maximum number of active jobs (ones that overlap with one another, inclusive), and to return the time range of overlapping jobs. For example (format: job = start, end): J1 = 0, 1 J2 = 1, 1.2 J3 = 2, 2.5 J4 = 0.3, ...
I was reading Python's requests library's code to find out how it works. Since this library has a simple usage interface, it creates a more complex object beyond. For instance: requests.get(...) Is a shortcut to something like: s = Session() r = s.request("get", ...) return r I do like this approach but I'd like to k...
I have a large WebApi project with a few dozen controllers. Each controller represents an endpoint prefix, just as a normal MVC project would. For example: CarsController.cs represents http://api.example.com/api/Cars In the above example, the first role of that controller is to provide CRUD actions for the Car entity. ...
This is a software design question. Not sure how to ask, so I'll illustrate with a scenario. I'll update the title to help reference for others if there is a better way to ask. Scenario BizLogic is the Business layer in a typical MVVM. It handles typical CRUD operations on a List. A requirement is that Data comes wit...
In GTK+, most if not all widgets are based on GDK windows, which are in turn each backed by their own X11 window, assuming one uses the X11 backend (Note that I'm not talking about toplevel windows, but about the window specific to each widget). What is the rationale behind this? Toolkits like GTK+ support other backen...
How would you model/program the following: We have items in our domain, let's say cars. We also have categories for cars. A category has certain characteristics. So for example we could have a car named Model A and place it in the category Sedan. The Sedan category has the characteristics 'five-doors' and 'five adults...
I am working with EntityFramework 6 code first approach and SQL Server 2014 Express. However, the DBMS may change in future. That setup allows easily to create a database and add some dummy data for unit tests. Currently, I am creating one database per unit test and drop it after the unit test finished. I am not sure i...
I currently have a program that has multiple derived classes. All instances of a derived class are stored inside of that class's static vector of pointers. I also have a static vector of pointers which is inside of the base class which stores any object that has been derived from it. Whenever I add an object I currentl...
I am trying to build a very basic instant messaging platform. I have three basic immutable types, and each of them has a subclass for dealing with CRUD (for SRP purposes, separating the class from the database logic). Conversation: public class Conversation { public uint Id { get; private set; } public List<Par...
Lets take the following example of inheritance in javascript: var Employee = function(name, salary) { Person.call(this, name); this.name = name; this.salary = salary; } Employee.prototype = Object.create(Person.prototype); Employee.prototype.constructor = Employee; Employee.prototype.doWork = function() { alert...
The private modifier is used to restrict access outside the class, but using reflection other classes can access private method and fields. So I am wondering how we can restrict accessibility if it is part of requirement.
The most likely answer is no, but I've come with this doubt. Can an actor act as a class? I know actors trigger events and can have prompts, but if there's a class modeling an actor (such as an user class) can we call methods over them? Or is this a complete misunderstanding of the actor role, which is getting mixed wi...
I am designing a plugin to uniquely identify content on various web pages, based on addresses. So I may have one address which looks like: 1 someawesome street, anytown, F100 211 later I may find this address in a slightly different format. 1 someawesome street, F100 211, or perhaps as vague as someawesome street F1...
In the ASCII table, punctuation characters appear between the non-printing characters and before the numbers (!"#$%&')*+,-./), between the numbers and the uppercase letters (:;<=>?@), between the uppercase letters ([\]^_`) and the lowercase letters, and after the lowercase letters ({|}~). On first glance, one would exp...
My understanding of Microservice architect is that much of the work is shifted to the front end client side in a single page application (SPA). The SPA will then interact with the back end microservices. This begs a question: Does Spring framework with MVC still relevant here? I think only SpringBoot with Bean injectio...
is there a way of having an (yet unkown) function as an argument of a function in python: def doSomething(<func>): #do something with func() at a later stage, functions could be defined, eg: def f1(x): return x*x def f2(x): return x+1 and I could call now: doSomething(f1,x1) doSomething(f2,x1)
I am setting up Vagrant with multiple developers using ScotchBox (v2.5) in our workplace, I have got the initial vagrantfile working ok however I'm unsure of how best to handle Database migrations. We essentially have two sites :- Frontend site (AngularJS 1.x) Backend site (Zend 1.x - PHP/MySQL) Colleagues will occas...
I want to find Haskell's analogue of infinite list in c# language. I want to use any possible interfaces for such list, like these: IEnumerable ICollection IList
I'm working on a piece of software which generates configuration data for certain hardware and currently needs to be adapted each time the hardware is released in a new version by an external company (this happens around twice a year). My current task is to introduce a plugin interface so the whole application doesn't ...
This great articles explains the difference between unit testing, component level testing and UI testing. At all my previous companies great deal of attention was given to unit testing and less to automated UI testing (end-to-end integration tests). I've never seen component testing practiced in these companies. It's ...
In a code base I am "starting from" there are a handful of interfaces with many default methods. They look something like this: public interface HasXY { double getX(); double getY(); default double method1(double x, double y) {...} default double method1(HasXY other) {...} default double method2(dou...
C++ has namespaces to prevent collisions of things with the same name. Header guards serve a different purpose. They prevent includeing the same header twice. However, they can suffer from the same problem: what if two header guards from different files use the same popular name? What if there are two libraries that ha...
I have a question about modeling. Quick introduce: I develop application to sales purposes. Application have users. Every user could be customer, employee or companyOwner. It depends on: Customer - just registered account, and buy product form any registered company Employee - registered account, and company owner assi...
When writing something that creates many (1000s) of small objects often, should you try to minimize it for performance? Especially if you don't know what system it will be run on, from low to high end desktops or even mobile. For mobile, I heard that creating a lot of objects hinders the performance a good bit, though ...
Definition: Purely microservice: Not using any web framework such as Spring, Laravel, Zend, Django. Web app is a single page app loading data via Ajax calls to web services Hybrid: The web framework is still used, only some not all data will be loaded via Ajax calls to web services My initial thoughts came up with po...
I am thinking how programmers mix languages. If I want to mix C and C++ language then what should I do? And how to mix languages?
I am working with a team of web developers. We are already using Git for version control of our code and it works well. However, while we are changing our code, it is also common to change the database structure, adding / deleting / renaming columns and tables. The normal answer to that is migration files, and we are a...
We have a huge project that desperately needs to be broken apart into multiple databases and applications. I can think of 2 possible approaches to this problem: Use a REST endpoint on each service to fetch/update data. Services that are dependent on each other simply call each other's REST endpoints to fetch/update da...
When I'm building views in SQL, I tend to do one of the following: Views that contain logic and criteria for selecting and joining records. I.e. "what records am I interested in and how do they fit together?" Those that focus on returning a certain set of fields, sometimes formatted in a particular way. i.e. "for thes...
I am a lecturer writing coding problems for students. What I want to do is give the students the boilerplate code with placeholders for the functions which students are to complete. I will give the students access to a private github repo to clone this. However, I also want a version of the codebase, complete with samp...
So I went for developer job at some company who sell gourmet food boxes based on recipes, I was turned down for a job after doing a tech test, I asked why I failed to improve on next time. They said my design for the rating system was subpar. (they basically wanted a system for rating recipies). Some basic context I ha...
I'm building a small interpreter for a language I created. The grammar, lexer and syntax analyzer are already done. What's confusing me is the interpreter part. I know interpreter pattern, but it seems too much verbose (more than it needs to be), I don't feel it's the right approach. What are other alternatives I have ...