instruction
stringlengths
34
36.1k
I have a program which generates events. They are ordered with a Lamport clock and sent over the network. They may arrive in a different order. On the receiving end I have an object which re-orders the events. This object can be popped like a queue and either returns the next event according to the Lamport clock or fai...
This may be a stupid question, sorry. I've read about the drawbacks of global variables a lot on this site. I'm finally trying to increase my code quality for a large project that'll be reviewed by many. I understand that using global vars makes code harder to debug, since one doesn't know where the variable may be al...
I want to maintain a list of domain names that provide web-mail services. I searched and received a list of 1634 domains(Free Public web-mail services) However, is it possible to get updates, if any new domain registers to offer web-mail service,through scripts or through tools. Or, is it possible to tell by looking at...
If I update an iOS app as a result of tester feedback during TestFlight, should I be updating the "marketing" version number, or just the build number? My current (initial) version number is X.Y.Z where Z is currently 0 and X.Y are out of my control (because they relate to the version of the upstream non-iOS product th...
One of Linus's emails mentions the separation of the Git tools into the "plumbing" (usable by automated tools) and a user-friendly interface on top of the that (which has later come to be referred as the "porcelain"). He also expresses the hope that Git would serve as a base for multiple different SCMs/file management ...
I am converting some .NET framework targeted projects over to Portable Class Libraries and looking for some best practices. Usually all of my projects use the same project name and assembly name, and that name is also the base for all namespaces used within the project. If my project name is Project.Name.Whatever, shou...
I am using darknet framework for object recognition listed here: https://github.com/pjreddie/darknet This is its license: YOLO LICENSE Version 1, July 10 2015 THIS SOFTWARE LICENSE IS PROVIDED "ALL CAPS" SO THAT YOU KNOW IT IS SUPER SERIOUS AND YOU DON'T ME...
I am a beginner with make and I'm wondering about when to use make clean. One colleague told me that incremental builds with make are based on the files timestamps. So, if you checkout an old version of a file in your VCS, it'll have an "old" timestamp and it'll be marked as "no need to recompile this file". Then, that...
So I have created an API endpoint (obviously not restful) that generates xml and returns the file path of the files. Its obviously more complicated but that is the gist. My issues is this. Inside my controller I have all of this code that grabs information from the database (using models / relationships etc) and then ...
Is it possible to buy the authorship of a piece of software just to be able to remove the credits from its source ccode? Would that be ok if the author of the library agrees to do so for a price?
I have a grid that represents a sampling of a continuous function in a 2 dimensional space. I'm looking for a (preferably fast) algorithm that can calculate the discrete line integral along a straight-line path from one grid cell to a distant grid cell. This seems like it would be a canonical problem with an accepted s...
Which is generally accepted practice between these two cases: function insertIntoDatabase(Account account, Otherthing thing) { database.insertMethod(account.getId(), thing.getId(), thing.getSomeValue()); } or function insertIntoDatabase(long accountId, long thingId, double someValue) { database.insertMethod(ac...
We're using ASP.NET Web API and Azure Service Bus and adding logging to our disparate services and systems. We need to track a correlation ID to the headers of each set of bus messages as well as logs related to a single business workflow/sequence together together. I'm just trying to nail down what this should be call...
I just ran across this old question asking what's so evil about global state, and the top-voted, accepted answer asserts that you can't trust any code that works with global variables, because some other code somewhere else might come along and modify its value and then you don't know what the behavior of your code wil...
I use C and structs where a struct can have members but not functions. Assume for simplicity that I want to create a struct for strings that I name str and I want to be able to do str.replace(int i, char c) where i is the index of the string and c is the character to replace the character at position i. Would this neve...
We've got a .NET Solution consisting of a MVC Website and a bunch of libraries for business and data logic. In the past the website was the only way to interact with our business logic, but we're finding ourselves having to share this logic between various systems, and we've decided to expose it via a REST API. The typ...
Lately I've been searching for information about creating API's. The company I work for wants to sell some of our products as stand alone devices. Currently these products work inside enormous projects with our own software to manage them. However some of these products have acquired lots of attention from companies wh...
We are using Spring and want to implement a REST with a "override file" call so we think using PUT verb with a multipart body only to find that Spring don't accept it. My question is it can't be done in Spring because it isn't the REST way to have a multipart body with PUT? Note: I know there are ways to skip this rest...
We have this bean with two properties: ContainerImage + name (final, not null) + id (null) Then there is this method: ContainerImage create(ContainerImage containerImage); It receives ContainerImage with name and without the id; and returns new ContainerImage with id populated, as result from the underlaying ...
It often happens that after designing my regexp (on regex101.com) I want to paste it in my program. Consider this regexp that matches numbers and string (but keep in mind this is general question!): ^(\"(?:[^\"]|\\\")*\"|\-?[0-9]+(?:\.[0-9]+)?)$ I overlined all characters that need to be escaped before pasting them int...
I´m struggling how to decompose a sprint in SCRUM. I know in many cases SCRUM is used only for the developing part in the software process, but I want to use it for the whole project (in our case: prestudy analysis, purchase from suppliers, and development. If I decompose a sprint based on a time limit (e.g. 2-3 weeks ...
I am working on a project and we have regular (usually weekly), informal meetings, where we discuss the status of the project and the GUI of it. I'm the only developer there, the other 4-5 people have a non-IT background. This meeting took much longer than usual, but at one point, one of my colleagues asked about some...
I would like to link a GPL project to another project with the following clause in its license: The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. Is this software compatible with GPL v2 or v3?
The db.collection.find() documentation includes this explanation of Query Exact Matches on Embedded Documents: The following operation returns documents in the bios collection where the embedded document name is exactly { first: "Yukihiro", last: "Matsumoto" }, including the order This seems so strange to me, since ...
I'm confused about routing. In some systems I've seen only naming conventions. In other's I've seen configuration, and in some I've seen both options (like in ASP.NET MVC5). In the naming convention based system, it seems to be a RewriteRule that puts the URI into a variable and then simply parsed out. What is the re...
Imagine a simple AngularJS REST Service which retrieves (GET) data from REST endpoints on a server. It maintains no state of its own and each method only passes back a promise to whomever is using said service. Now, should I write tests for this service? If I do, what exactly have I tested other than my mocked httpBack...
My understanding of how ORM persist works: //ORM "persist" oversimplification function persist(&$entity) { ... $insertId = api_actual_db_insert(...); $entity->setId($insertId); } //usage of ORM later ... $this->getEntityManager()->persist($entity); print $entity->getId(); //prints ID of newly inserted rec...
In CQRS/ES, a command is sent from the client to the server and routed to the appropriate command handler. That command handler loads an aggregate from its repository, and calls some method on it, and saves it back to the repository. Events are generated. An event handler/saga/process manager can listen to these events...
Many general programming languages are flexible enough to allow you to support dependency injection. Even without library or framework support. But even if a language is Turing complete enough to solve any programming problem, a language makes choices that impact what is easy and what is hard to do in them. Is the...
I have class GameState laid out to basically hold an Array of Players, an Array of StarSystems, and a few other fields that need to persist from save to save. Each GameObject keeps track of its own id, which is also its index in its array as well as the id's of relevant gameobjects. public class GameState implements Js...
We have a number of items which the end user will be able to organize into a desired order. The set of items is unordered, but each item contains a sort key which can be modified. We're looking for an algorithm that would allow generating a new sort key for an item that is added or moved to be either the first item, l...
For learning purposes, i'm trying to implement a small project using (buzzword warning!) microservices. There are plenty of resources online talking about the 'macro' microservice world -integration, orchestration, service discovery, health checking, topology, etc., however I've found that there is little to no informa...
In Android development, we have Parcelable interface. Since I wish to build Data Models that will run on multiple apps and services (not just Android), I would like to add two jar libs that will share some of the code across multiple implementations: 1. The first A is coupled with Android SDK 2. The second B is not cou...
The view model seems to be the most appropriate place to perform validation yet Angular seems to be pushing me down the popular form validation route. Why Model Validation? DRY - Applying validation to the model will centralize the validation logic as opposed to repeating it in every view. Unit Testable - Since the lo...
I am implementing an NPC to walk around a virtual space, specifically a cat. I have a series of short animation clips (3-5 seconds). My first instinct was just to choose a random animation when the last one ended, but I realised that it wouldn't look realistic as it would change behaviour too often, even if the next an...
I recently started developing a small calendar application, in which I can add and view several calendar entries, which contain several data like name, date, alarm settings and so on. Those values have to be saved locally, so the user can see his calendar entries from earlier sessions as well. Right now this is solved...
I am working as the sole .Net developer at a company and I have been tasked with a very large and complex project, an internal intranet site for inventory and time tracking. I have built a project that contains 3 applications, WebUI, Data Access Layer, and Core. The WebUI is my normal MVC stuff, the DAL contains the mo...
I have a collection of strings which have a lot of common substrings, and I'm trying to find a good way to define tokens to compress them. For instance, if my strings are: s1 = "String" s2 = "Bool" s3 = "String -> Bool" s4 = "String -> String" s5 = "(String -> String) -> String -> [Bool]" then I might want to use the ...
From what I understand a DomainService should be implemented against a RepositoryInterface, so we could change with easy the repository (which its a part of the Infrastructure layer) So, if I have: class UserService{ function __construct(UserRepository $rep){ $this->rep = $rep; } function createNe...
In Python, what is the difference in these declarations… my_list = [] my_list = list() …and in these? my_dict = {} my_dict = dict() Are they interpreted the same, and why would you use one over the other? I haven't seen or noticed a difference.
I am updating a database design that must be compatible with old and new applications. My goal is to make a design change which minimizes impact on the existing code. The Design Change Currently our database has universal data that is stored in each customer database. I want to move this common data out to a different ...
I recently started working on a new project where the team was considering use onion architecture, which I was not very familiar with, so I started reading about it. The application is a simple 3D format converter. It will read a sql database, convert the data and then write the new format in another MySql database. Th...
I understand what cyclomatic complexity is, but I was trying to find the origin/meaning behind the word "cyclomatic" and could not find anything that wasn't about cyclomatic complexity. Does this word exist outside of this phrase?
In most examples of clean architecture (Android projects mostly, though) I've noticed that the use-case/interactor classes (units that encapsulate a feature) often share base class/interface, like here or here. Others do not (like here or here), instead allowing interactors to accept some parameters that are then used ...
I am building a site with a GNU licensed program called OpenCart. Now I am not "distributing" anything.. but people can see my website and interact with it. Generally I avoid GNU like the plague as an app developer. No way my customers want their hard earned work set out to be free. In this case all I am doing is fil...
I'm writing this small utility, FOSS but not intended for wide deployment, packaging in OS distributions etc. My utility depends on several libraries - some are header-only (it's C++), some are headers+compiled libraries. Now, when it's a library with proper versioned released then life's simple. I have CMake look for...
In Martin Fowler's article OrmHate, he states the following: If you have an application problem that maps well to a NoSQL data model - such as aggregates or graphs - then you can avoid the nastiness of mapping completely. Indeed this is often a reason I've heard teams go with a NoSQL solution. This is, I think, a viab...
I am writing a program that needs to be able to process data from a number of different sources. The sources output data in a variety of formats. So, depending on which source is being used, I need to initialize a string list with a different set of column headers. The quantity of headers varies between 10 and 18 colum...
I have intermediate level of understanding on how TCP and serial works, I've also been able to develop system that uses 1 TCP client and 1 Serial 2 Serials 1 TCP Server 1 TCP client My problem is that whenever I am creating a new project there are different needs, sometimes it's 1 TCP client and 1 Serial, sometimes i...
Let's say we have classes something like this: public class Item1{ public Guid Id {get; set;} public string Name {get; set;} public decimal Price {get; set;} public int Quantity {get; set;} } And few more, which has additional or different fields, other have lists as properties. And those classes are b...
I have some platform specific code, such as a string needs different values at different platforms like it: test.cpp #if(PLATFORM==ANDROID) string url="android"; #elif(PLATFORM==IOS) string url="ios"; #endif I am trying to rewrite platform specific code using separate cpp: test.cpp string url=URLHelper::getURL...
I am building a program for a law firm. When a staffer is active (i.e. still works at the firm) he has a password to login the program; When a staffer is inactive (i.e. no longer works at the firm) he loses his password, but his data is still registered in the database (personal information, previous job description et...
Been thinking this for a while now, for example I have a UX that let's the user choose what IP to connect. I have numericUpDown1, numericUpDown2, numericUpDown3, numericUpDown4 to limit the user to choose numerical values only, then when the user choose save I will save it as string then concatenate the dot(.) to it to...
I have built a server-side Java application of about 10k lines of code and on a code review a colleague made me notice that when developing a new business feature , I have to touch several files. My explanation is the following: In a well-layered architecture, delivering an additional business functionality might req...
I have a class with several fields. public bool Active { get; set; } public List<Group> Groups { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public Gender Gender { get; set; } publ...
There is a debate in my company on whether we should use the JSON API specification or stick to plain JSON for developing APIs that will be consumed by mobile apps, mainly iOS and Android. One argument for JSON API is that since everything is defined before hand, if new developers were to begin work on the API they sho...
I'm struggling a bit with referencing between aggregates. Let's assume the aggregate Car has a reference to the aggregate Driver. This reference will be modelled by having Car.driverId. Now my problem is how far should I go to validate the creation of a Car aggregate in CarFactory. Should I trust that the passed Driver...
I am working on an application whereby I have designed classes to fit into several groups: Immutable: initialised through constructors, uses copy-and-swap idiom (inc. move), can deep copy (i.e. clone), only has "getters" (not "setters") and implements comparison operators (==, !=); Services: stateless classes that hav...
What is the "essence" of dependency injection? Is it the idea of dynamically swapping out/in core logical/structural aspects of a program at runtime? Traditionally, this is done in code via some DI container. For example, using Structure Map in C#: container.For<ICacheService>().Use<InMemoryCache>(); However, I've w...
I am creating a new site and will base it on ASP.NET MVC 5 & Dapper Contrib. I want to go all in with all these technologies - and get all the time saving / convention over configuration / terse code advantages available. I am designing the database in SQL Server 2014. Historically I have always named primary keys Tabl...
In our company we have a small program (.exe 500Kb size) that does mathematical calculation and in the end it spits out the result on a Excel spreadsheet that we use to continue our workflow. I want to modify the columns, spacing format and add VBA logic etc. on the Excel spreadsheet but since this parameters are not c...
Firstly, I am studying function with new type of signature and body, and in this code, I want to know, what type of object is values? It doesn't appear to be an array of strings based on my observation. Secondly, is there any method that returns the name of the class a particular object is? I thought it might be tost...
Given <div> <textarea></textarea> </div> Why is this <div> <textarea class="width90"></textarea> </div> .width90{ width:90%; } any better than this? <div> <textarea style="width:90%;"></textarea> </div> edit: I updated my example better. My question should be more related to generic styles like widths, ...
I'm trying to keep my controllers as thin as possible, so I keep my domain logic in services and factories. When I need to call a function in response to a user action like a click I assign the factory or service's function to the controller's $scope variable. $scope.saveStuff = myFactory.SaveStuff; myFactory.SaveStuff...
I have this 'table A'. It contains two columns; email and email_alias. A sample is below: ===================================== = email | email_alias = ===================================== = email1@abc.com | alias1@abc.com = = email1@abc.com | alias2@abc.com = = email2@abc.com ...
I've seen an increasing trend of people submitting code to SO that includes the use of .NET Framework data types. I understand that the .NET Framework has its own data types (like Int16, Int32, Boolean, etc) that map to the appropriate data type in the language you are using (like C#). But why use that over the languag...
In our database backed (C# WPF / Entity Framework) application, we want to build a system to enter, store, display and search arbitrary content linked to our main entity. The challenge here is to find a pattern for that. Data should mostly be entered as Key-Value-Pairs. Starting off with one or more pre-defined questi...
The Mono project used to have LGPLed libraries. In fact mbundle still says when you run it Note that statically linking the LGPL Mono runtime has more licensing restrictions than dynamically linking. See http://www.mono-project.com/Licensing for details on licensing. As of March 2016 they re-licensed them under M...
I have a shopping cart with a checkout page. On the checkout page is a payment button which takes them to a stripe payment form. I've read some books on building eCommerce shopping carts in which the order is created when the user clicks the payment button and the order id is passed to the payment gateway. In this sce...
Two of the top 3 security vulnerabilities in the OWASP Top 10 come from trusting user input (Injection and XSS). To deal with this, Ruby lets you "taint" Strings received from the user as unsafe. In a type-safe language like Kotlin you can (theoretically) take this one step further with a Tainted class that wraps a St...
Imagine a situation where we're using a library that allows you to create Circle objects, where you can specify the radius and the center of the circle to define it. However, for some reason, it also takes a required flavour parameter. Now let's say I really need to use Circle in my own app, but for the purposes of my ...
If a method has too many parameters, the suggestion is to convert them into a parameter object. Where to place such parameter objects? in domain/entity classes package? or if I have a separate package for DTO's, should I place there?
I was reading about implementation of producer-consumer problem with one producer and one consumer. Looking at this paragraph I see the implementation where shared resource access is not synchronized and producer and consumer can modify shared resource leading to its inconsistent state. semaphore fillCount = 0; // item...
What is the history behind the convention of naming constants in all uppercase? My intuition is that it started with the C preprocessor, where people developed a practice to name preprocessor macros in all uppercase so that they would effectively live in a separate namespace and avoid name collisions. My belief is tha...
I have a in-house messaging system, similar to a message broker. We have one master message broker and one slave message broker. A message broker just receives messages and sends them to all nodes. The slave is acting as a node, receiving messages from master and building state so it can take over in case of master fai...
I see a lot of questions revolving around accessing JSON keys that use hyphens (kebab-case), but now I find myself wondering should I just stick to camelCase or snake_case in my keys. I know hyphens also can create complicated mappings when ported between languages. I've seen some JSON deserialize libraries convert tho...
I'm writing an application for learning foreign words of exactly one language (english at the moment), which has currently an ineffective design. I use Java and SQLite-jdbc for saving the words. After starting, the application downloads a comma separated wordlist and inserts each value pair into the Database. I hosted ...
Here : https://github.com/gnufinder/prime-factor I submitted a contribution with the goal to find a prime factor of the number 2222+3333. The number has 3,638,334,640,025 digits, so ECM will take too long, but pollard-rho might be feasible, if there is a computer which can handle such numbers. With normal hardware, on...
It is true that we cannot be 100% technology agnostic when we are using a framework or tool, we will be always at least 20% dependent on the tool or framework. The thing is that I feel better if I can be as much agnostic as possible of the chosen technology. My main 2 reasons are: it's easy to migrate to a better tool ...
I'm looking for a notation that is familiar to modern developers and can supersede s-Notation. (additional insight into Rivest's proposal of s-Expression is here) Is there any Swagger, JSON or other notation that is very intuitive for ACL control?
If I were to write a header exposing functions in a sample source file that was licensed under the BSD 3-Clause License, what would I put up in the header? Should I simply copy-paste the license text in the implementation source file? Should I add a line saying I modified it or added the header? EDIT 1: I realised my...
I want to compare sequence numbers (given to this code from elsewhere) that may wrap around. Simply comparing two such values will not handle the case like 0x00000002 being greater than 0xfffffffd, but I can assume that the numbers being compared are close together, not nearly 4 billion apart. I get the desired result ...
I'm currently working on a neural network to try to predict movements of electricity prices in a big city with multiple power companies to choose from. I know from a friend in the industry that power companies base prices off of a blend of costs and competitors' prices, which means that reasonably good predictions of a...
I find myself writing a lot of functions whereby the first few lines "verify" the arguments, that is, they typecast, check falseness, range, etc. before doing any work. The main reasoning for this is to prevent idiots—human or otherwise—from passing invalid or illogical arguments to the function. An example in JS would...
I see only benefits to the onion architecture over the 3 layered architecture where the BL had responsibility to call methods on DAL (or an interface of DAL) to do CRUD. The onion has better separation of concerns, testability, maintainability and is cleaner. So is the onion architecture indeed better in all aspects a...
Suppose I'm developing an application with a simple graphical user interface, like a basic text editor. How do I choose a good default size of the application window? Should the height of the window be a percentage of the height of the screen? What about the ratio between the width and the height? Or should I just go w...
TDD is about designing code, guided by tests. Thus, typical layers aren't usually built upfront; they should slightly appear through refactoring steps. Domain-driven design involves a lot of technical patterns, defining well established layers like Application layer, Infrastructure layer, Domain Layer, Persistence laye...
I am new to rest API's as well as mocks. Please help me .. I have a set of rest API's for which I need to write unit tests. rest API in turn calls another service , gets the JSON response and sends the response [data] back. Basically it's querying a list of master data's like users, suppliers , countries etc etc. My qu...
So recently I was working on a project where I had a base class that provided some common functionality. It had several virtual (overridable in vb) functions. I noticed that some of these methods expected the override method to call them first before doing any work, and others expected the work to be done before the v...
I really enjoy the actual programming part of programming, and actually writing the code, and figuring it out. But on this project I've been working on, most of my time has been spent on kind stupid stuff (trying to run a Java program in the background (I swear javaw does the same thing as java) and trying to put a jar...
I was thinking, we are taught to perform code reviews, inspections etc. but in reality, does anyone really do formal (Fagan) inspections? I cannot find anything on the topic.
I have a MVP implementation, inside my presenter i have a lot of public methods like onSendMessage() for example. I need to track some of that methods, meaning track just call a trackClient.trackSendMessage(). That actions could be over 20 more or less and i dont want to make dirty my presenter with a bit of logic abou...
Seeing this UML class diagram : FileHandler, Uploader and Deleter are abstract classes. The four bottom classes are implementations. They extend on FileHandlerInterface which requires a handle method to validate the contract. But this method isn't in the implementations, it is in their parents (Uploader & Deleter). I ...
Let's say I want to create a shop/order system. I'll have an Order DTO to which I'll map the data from a request and results from the database. The object will consist of an order number, a customer number and a list of articles. The order number is pretty simple, I'll just use an int to store the number. But what abou...
I was trying to solve Problem 279-B. Given an natural number, t, and an array, a[0],...,a[n-1], of natural numbers, find the maximum length of a continuous subarray, a[i],...,a[j] in a where a[i]+...+a[j] <= t. e.g. a=[3,1,2,1] and t=5 -> 3(1,2,1) ; a=[2,2,3] and t=3 -> 1 I thought of an O(n2) solution. Double lo...
I am learning Java and JSR-353. My question is quite forward. Having the method below: public JsonObject createJsonObject() { return Json.createObjectBuilder() .add("address", this.getAddress()) .add("city", this.getCity()) .add("state", this.getState()) .add("postalc...
In my code I often need to differentiate between messages intended for logging and those displayed to users. I'm looking for a terse term for naming variables and methods that indicates a user-readable message. I've tried "userReadable", "userVisible", etc, but they all feel too verbose, especially when combined with...
Thanks to my new job, I recently discovered the inversion of control design principle (with windsor castle in C#). I really enjoy using it but something's bothering me. For me the good part about strongly typed languages is the fact that you can see errors at compile time and you avoid having your app randomly crashing...
We are moving to SCRUM - in our sprints, we work on a version 1.1, while version 1.0 is being in production. However, ocassional bug from version 1.0 is reported and have to be fixed. I found no information about how this should be handled - it does not seem right to me to make them part of the sprint (as they are from...
Does it make sense to talk about "agile development" or claiming that you are applying an "agile methodology" if the code base you are working on has 0% unit test coverage? (And you, as a team, are not doing anything about it). To make it clear: to me, it doesn't make sense. In my personal experience I found that unit ...