instruction
stringlengths
34
36.1k
This seems to be a variation on the Travelling Salesman problem, and I started (as far as some reading at least) going down that route to solve it, but the ordering restrictions are confusing me a bit. I have a map with an arbitrary number of destinations on it. An agent is given a set of trade routes. Each individu...
I am developing a library from scratch. If I license it under GNU GPL (or a similar license), which conditions everyone to disclose the source code, does the condition apply to my other projects? Say I will create an android app that uses the aforementioned GPL library. Do I need to publish it under GPL aswell? Does it...
I'm working on an API and am trying to report back to the consumers certain errors (e.g. input errors, errors that occur during the processing of their requests, etc.). My API returns an array of errors (and warnings, and notices). I'm starting to see a couple of problems: I'm not completely DRY. A number of the error...
I have an example about design patterns that demonstrates the adapter pattern. But I see casting to derived class here. That is not very good. If I meet such code in my practice, what is the best way to refactor it? Or what principles should I follow to avoid such situation? public class SqlServerLogSaverAdapter : ILog...
I'm programming with the embedded device running Linux, where memory is less, I just have 64MB flash only. I planned to use queues for the thread communication. In which I came across with using POSIX queue or just use the simple queue. Actually, my need is I don't want the queue to be priority driven. I want to know...
I have two browser clients: A and B. They communicate through a signalling server Server. A has a clientside heartbeat that signals its ClientState to other clients. ClientState can be one of the following: StateFoo StateBar Sometimes, B wants to change the state of A. It maintains a representation of A locally. ...
I am writing software that makes use of a neural net. What makes my network special as compared to others, is the way I train them. Its non standard, its something that I don't want to give away to another company. So I've been thinking about how to protect myself against miss-use / stealing of my neural net training ...
For example, I have a Selenium WebDriver and as part of my initialization I would like to check if I am able to instantiate it and start up browser. I can't come up with a proper name. Is there any common-agreed practice, like naming methods with side effects to be verbs? Should it be one of these options, or something...
There's a unix shell command (udevadm info -q path -n /dev/ttyUSB2) that I want to call from a C program. With probably about a week of struggle, I could re-implement it myself, but I don't want to do that. Is it widely accepted good practice for me to just call popen("my_command", "r");, or will that introduce unacce...
I want to know if it's faster and more efficient to store and access objects in a nested dictionary Dictionary<string, Dictionary<string, int>> VS List<Object>. Though adding objects in a nested dictionary requires writing more code by checking keys, what could be the other differences that are important to consider? E...
In a book that deals with mutually orthogonal latin squares, there is an example of implementation of a generator. The part of the code is as follows: for (int k = 1; k <= numberOfLevels; k++) { for (int i = 1; i <= size; i++) { for (int j = 1; j <= size; j++) { squareArray[k - 1][i - 1,j - 1] =...
As part of a hobby project, I needed a rectangular Matrix object to maintain state of a grid. At first, the implementation seemed trivial and unworthy of further discussion: (I haven't included all the code, only the relevant code) template<typename T> class Matrix { uint64_t rows, columns; std::vector<T> _data...
Forgive me if this is a truly naive question, I can't find an answer anywhere (which makes me think it is maybe silly and naive). If I am to hold a reference to an aggregate inside another, I of course use the Uuid of that other aggregate. My question is how should I instantiate that object? Being that it is a value ob...
Does 1.0.0 represent the first patch of the first minor version of the second major version? Or does it represent the first major version, with no minor or patch versions? I've always assumed it to be the latter, and it seems so have many others. I typically see new packages in various package management systems start ...
I am wondering whether this is the correct way to handle my situation when packaging-by-feature. Use the following project structure as an example: com.foobar.web.Bootstrap.java com.foobar.web.TcpServer.java com.foobar.web.RequestHandler.java Everything part of the web feature is in the web package - good so far. As a...
I have a system that acts like a message hub. It normalizes data and stores it to be picked up by a different system. Currently I convert my object model into tables and columns for storage. I came to realize that a good deal of the data is being stored in columns and tables but its not really doing anything useful ...
I'm learning about HATEOAS and I noticed that every implementation always seems to implement a self-relationship first. For example a common response object might look like { title: "The Wonderful Wizard of Oz", author: "L. Frank Baum" links: [ { rel: "self", href: "www.foo.com/book/1234" }, ...
I am currently working on a voxel (Minecraft-like) engine in C++. Almost all of the code (ie. world generation, rendering, user input) needs to access data about the block types. To accomplish this, I created a BlockRegistry class with member functions to register and access BlockType instances. Each BlockType instance...
I wanna know what is the importance of multithreading in network applications? I have researched for a while but I didn't find references related to this specific topic.
In this question on the Aviation site, one of the reasons for the long development time of the F-35 was quoted as being Software. 8 million lines of code. Development from contract to in-service took 20 years, the last 10 years of which were mainly for systems since the first production aircraft was delivered in 2006. ...
I have heard a lot of times when other developers use that phrase to "advertise" some patterns or developing best practices. Most of the time this phrase is used when you are talking about benefits of functional programming. The phrase "Easy to reason about" has been used as it is, without any explanation or code sampl...
For a couple of months now Im writing a interpeter / compiler for a programming language in C#. I have encountered some issues recently which make the code feel incorrectly written Classes change a main state Classes are not really testable Classes are hardly maintainable Firstly Im looking for a good structure for t...
To be honest, I'm a student here, but I have seen many questions from teachers asking for ways to explain, and I have not found one for the MVP and MVC patterns. Model–view–presenter Model–view–controller My problem is, that I have studied these pages, I have written many tutorials and followed examples and even work...
I have a mission critical Backbone application built before AMD and CommonJS were widely used. This application makes heavy use of the Object Namespacing pattern, so that that all the views, controllers, etc. are nested deeply under a single ParentObject, e.g. ParentObject.Views.Feature.TableView. Continuing with this ...
Lets imagine the following scenario: I have a system that is on web, you can add data update it etc. Then you have a mobile phone which obtains the data from server. How will I keep track of the latest versions? In one word how will the device know when to sync? The app needs to be offline, and when it connects t...
I am working on implementing an API interface for my project. As i know, there are different forms to make pagination through the results, like the following: https://example.com/api/purchaseorders?page=2&pagesize=25 But, i see many APIs like google use a different approach, in which they use a "pageToken" to let th...
Background I'm trying to design a layer/component in my distributed application that will communicate between component A and component B. Right now, this "communication" is accomplished by replicating an entire database from the server where component A lives over to component B. But this design has proved to be ver...
I'm using Azure file storage and there was a huge number of files uploaded. A single file will be 250kb in size and there will be 7000 files in a directory. So when the user request I need to get the data from 100 files in a single call. At first, I was accessing the files using native file IO methods after mounting th...
I am publishing an Android app to the Google Play Store soon and have some questions regarding the use of libraries licensed under Apache 2.0. I am also releasing the source code on GitHub. I am only using these libraries, not modifying them. To me, these are two separate concerns so I will address them separately. The...
The situation Let's imagine a couple of developers start LittleProject™ inside of a company. No Unit Testing, no Jenkins, no Docker, a single development environment... "why would you want more? It would be overkill." The project is successful and grows bigger and bigger. More developers are added. A couple of testers ...
I have been searching for an efficient algorithm to merge overlapping intervals on a dynamic array of intervals. For example, (start time, end time) wise, [(1, 2), (4, 8), (3, 10)] becomes [(1, 2), (3, 10)] after merging because (4, 8) and (3, 10) are overlapped. Overlapping means any part of the two intervals share...
so I'm trying to understand how microservices are set up in a language agnostic manner for purely experimental purposes. For the sake of having a more concrete example, how would a microservice architecture work in a Node.js CRUD server, does a simple CRUD server even benefit from microservices? What are the kinds of t...
I understand the difference between a rich domain model and an anemic domain model. An anemic domain model contains classes with state only i.e. the behaviour is contained in application services. I recently asked a few questions about rich domain models. I notice that the answerers usually (well always) appear to s...
I'm building a simple shopping cart using Angular and ASP.NET Core with. There is no login require and user can always checkout and make payment as a guest. The front end would be built with Angular, with simple 3 dynamic components - Shop > Checkout > Payment path in a single path. I'm presuming I will be relying on A...
I have micro service architecture application. One of the services contains all user related information. Another service contains a set of business objects. The Angular UI calls rest APIs of user-service and business-service to perform operations like user management, business management. The tables in the business-se...
Whenever I was required to build a project, I always managed to build it, not beforehand devising a plan or design, but after first writing a class that was needed, fleshing out the entire project, building from the bottom-up. Now I know this is not the proper way to create software, but it is not easy for me to wrap m...
I’m working on a medium-sized project. One of the parts has to do with account creation. I went with a RESTful API design at first, but I’m now having second thought. Persistent data are saved in MongoDB. So to create an user, one API request is required to the backend. After creating the account, another API call to ...
For anyone who uses callbacks, how do I approach it when the method is an asynchronous setter? Here's an example class API { constructor() { this.token = null; } refreshToken(callback) { request("http://api.com/token", (token) => { this.token = token; callback(token); }); } } What ...
I have some data (list of parameters) that should be shared across the backend and the frontend. The changes are really infrequent, and changes usually mean a redeploy. Currently, it is stored in the DB, some tables have foreign keys on it. By extending the functionality we had to keep adding new and new properties on ...
If I have two use cases: Send Email, and View Contact Page. And Send Email includes View Contact Page. Do I still need to use association to connect my actor(user) with Send Email if I want to show that he can send emails? Or It is enough to connect actor with View Contact Page with association? Here how it looks like...
I'm designing a system at the moment using MVC (with Laravel, if that matters) and I'm trying to decide how best to architect a part of it. An an analogy, you could look at it like this: There's blog posts, and each blog post can have three different types of comments. Each type of comment is completely different from ...
There is that @Deprecated annotation which suits well for Java libraries. A minor release change would not break an existing code if a deprecated library method remains. The library compilation will not report deprecated code use warnings because the library itself does not call its own deprecated methods. But what if ...
My organization is investing time in writing the wrong kinds of tests (unit tests that are tied far too heavily to the implementation, are very time consuming to create, and often make the system harder to change). Also, context is often thrown away and tests are skewed to improve coverage metrics. The same assumption...
The Existing Code I have a C# project with about 45000 lines of code. It has a utility/helper class which contains static methods which make it easier for my code to work with PDFSharp/Migradoc to produce PDF forms, which are predominantly structured using tables. One such method adds text to a cell and has the follo...
Recently I was reading the AMQP protocol specification from the official website, however, because this is my first protocol that I am trying to study in depth so couple of generic questions about protocols pop up in my head that I would like to find an answer. How does a protocol contain type system, methods, constru...
I have a class that does reboots a machine and then prompts it for readiness. The prompting is done via ssh and the standard output needs to be formatted to verify if the machine is in ready-state. So should I write tests for the method that does the parsing? There's no actual logic in there, just cutting and joining o...
Let's say my object needs to use an API to communicate with a device. The API call that I need is Api.do_something(). What would be the best way to solve this assuming that I need to call it only once? I'm inclined to use the third option but isn't dependency injection really too much of a hassle when I only need to ca...
I have a specific use case, and have found 3 ways of doing it across the internet, which are defined for vague usage cases. I am staring at these three wondering which to apply. I tend to sit there not knowing what to do - then doing nothing... Is there a good way of choosing? Should I try all of them? To be more speci...
I've inherited some awful code that I've included a short sample of below. Is there a name for this particular anti-pattern? What are some recommendations for refactoring this? // 0=Need to log in / present username and password // 2=Already logged in // 3=Inactive User found // 4=Valid User found-establish their sess...
I have a class in python that is instantiated from the values of a (json) config file. I was wondering what is the best practise to do that (if there is a best practise and is not just a matter of personal preference). I call a read_config function (which is defined outside the class) in my main, that parses my config...
I created a wiki-like application. Currently, there is no security, so all the contents have "edit"-buttons where the user can edit everything. Now, I want my application to have a public read-only access and the read/write access to edit content. First of all, I think it is useful to do that with two roles: viewer and...
I have two cross cutting concerns in my design of my software. The memory allocator tracks memory usage in its struct(class) member variables. I also have a logger. Right now I am passing the logger and the allocator into the constructor of my objects. I can maintain a reference to them but then I would have to do ...
My current task is to set up a system that pushes out notifications to specific users based on a set schedule. Having tackled the push notifications issue, I am now trying to put together a system that will actually send out those push notifications on a regular basis. Since our infrastructure is based on a Kubernetes ...
Say I have a Calculator class similar to this: using System; public class CalCulator { public int Square(int num) { return num*num; } public int Add(int num1, int num2 ) { return num1 + num2; } public double Add(double num1, double num2 ) { return num1 + num2; ...
Lets assume I have a string for a class name (or part of a class name), and I have implementation somewhere. All I want, is to be able to get an instance of a class with the name in the variable. For example, dynamic_class_name = "Circle" # not a constant, comes from somewhere corresponding_class = some_magic(dynamic_...
I have a function that I can implement in two different ways. Each way has its own advantages, and performance depends on the arguments it will be given. Since each implementation has several short circuits, performance can be dramatically different compared to the other one, so I thought to wrap the two implementation...
I am using Command Pattern to execute actions and so I developed many command classes (CommandA, CommandB, etc.). Now I need a SuperCommand that receives a collection of data from legacy code, loops through it and calls one of previous defined commands depending on data type field. The pseudo code of the SuperCommand s...
I am building some middleware between our ERP and a cloud based online store. We have multiple business divisions who will use this cloud based ERP, however each business stores their attributes (such as product related attributes) in different fields in the ERP. Because of this, I can't have a standard method of grabb...
I am using a factory pattern to get objects that shouldn't be instantiated other than the factory class. These objects are of type ViolationType, which represent violations on a set of rule. Here is the summary of the factory and the available violation types: class ViolationFactory: def __init__(self): rai...
I am reading Martin Fowlers Refactoring book. On page 110 he talks about 'Replace Method with Method Object' where he turns a method with local variables into a class with instance variables. The outcome is a class called: PriceCalculator with three instance variables i.e. primaryBasePrice, secondaryBasePrice and ter...
How can I tell my software has too much abstraction and too many design patterns, or the other way round, how do I know if it should have more of them? Developers I work with are programming differently concerning these points. Some do abstract every little function, use design patterns wherever possible and avoid redu...
I'm building an API that, among other things, will allow the consumer to create a record. That record can have an array of images (passed as URLs). Assume that the consumer passes an array of image URLs, but some return a 404, exceeds a file size limit, etc. -- what should the API do? I see two possible options: Fail....
I am doing a microservice and I was trying to make a decision about how to handle Domain Model. I am planning to have multiple microservices, as an example: A ClientsMS and a PaymentMS. They both need to have a client class. One way is to have client class in both MS and do a mapping between the two, Or have a Model(do...
As long as I remember at least in older versions of Cassandra database, search was implemented in following way - During startup several samples are collected from sorted table and when data is needed the samples are considered. Then the data is search sequentially relative to the location of the sample. Note I...
I'm studying up on clean and as a result am quite dramatically rethinking a great deal of how I design and write software. I've thing I'm still wrestling with however, is for business rules like "on save updates to some item, first load All the list of items I have permission to view/edit etc, confirm that this item is...
A React website I am building is going to have these sections: Hero, Projects, Courses, Skills and a few others. The Skill section will iterate though a list of skills and display a React component SkillCard for each item (as you can see in sketch). SkillCard will open up a SkillDetail component when clicked. The Skill...
I'm currently developing an API (node/express js) for a blog website that uses a markdown parser (showdown) for rendering content and a html sanitizer (html-santize) for removing malicious html/js. Currently I am at the point where I want to let a user edit a post, but I do not want to expose "raw" content to other use...
I am starting to design the architecture of my family's small hotel business. But I'm a junior js developper and I miss the big picture when programming on the go. I am afraid that this might lead to confusion and/or bad practices. I have therefore started with a basic activity diagrams in order to document my ideas o...
I have a .net api backend for mobile apps and the question came up (in conversation with the iOS develper) if a JSON response for an empty GUID should return: 00000000-0000-0000-0000-000000000000 or null (by having the return type nullable Guid type (Guid?) If the first one, the mobile developer needs to create a p...
Suppose you have this: namespace Project.Services { public class ClientService { public IEnumerable<Clients> Query(Project.Models.Builders.ClientQueryBuilder builder) { //... } } } AFK namespaces help you to organize your project in a miningful way. It provides a context of how t...
It seems to me that Ruby hashes would be a good option to implement the Data Transfer Objects that the Application Services receive from the client code as commands and queries requests. For Application Service responses, perhaps a response object with success/failure and a result property containing the data as hash. ...
I am after advice regarding message queueing. We have requirements for "jobs" to be posted to a message queue. The original suggestion was just to use a SQL Server instance and process messages from that. Everything I have read on the internet suggests that using a database for a Message Queue isn't a scalable solutio...
Currently I have a class hierarchy for parsers with Parser as interface with CSVParser and XMLParser classes implementing it. The interface has following methods : List<AType>parse(File file) Now I want to add another parsing method that would take the same File type as the argument, but will return List<BType>. This m...
I want to know how does a file system write to and read from a storage device. I think this is how it works: A file system doesn't access the storage device directly, but rather the storage device is presented (by the device driver of the storage device) to the file system as a (very large) byte array. For example, if ...
I tried to give it a chance without thinking much and this is what I came up with: Room ---- | ID | No. | Type   | Price   | Beds | Hotel| Size | Minibar | Images | Booked | | ---|------|---------|---------|----- | --- | ---- | ----- | ----- | ----- | | 1 | 101  | Deluxe  | 5000.00 | 2   | A    | 31m^2 | ye...
I have a bunch of classes inheriting from Violation. These subclasses model violations to different rules: UsedTimeslot, TeamConstraint, etc... I need to check what kind of violation happened in order to respond to it: if team_constraint_violation_ocurred: corresponding_action() However, the only mechanism I have ...
We have a complicated ERP software written in native PHP and our own micro-framework which uses big and complicated queries. We want to rewrite the application using an MVC framework (e.g. Laravel). I have developed some other applications with Laravel and Eloquent and I think converting the queries of our ERP app int...
We are working on a software project, a team of 5-10 developers. The code base is continuously integrated using Bamboo. We have a build plan running also unit and integration tests and then a functional test plan. We get automatic emails about failures but sometimes days pass before a failed plan is fixed. Question: H...
I understand that objects external to an aggregate shouldn't hold references to entities and value objects belonging to the aggregate. My question if this also applies to the Application Service that exposes the use cases to the client code. For example, if I have an Order aggregate, and Order Line is a value object i...
I'm struggling with aggregates in actor model (akka) and how to store their state. I wonder what role does repository stands for in actor model in DDD. I have a situation, where my aggregate root creates another aggregate as result. But internally, AR firstly creates an actor and then sends additional messages to it in...
I'm playing around since a while with building a little open source project based on the output of facebooks pfff tool, that can parse multiple programming languages and output some kind of unified AST. For example, given a simple PHP file like this: <?php class FooBar { public function functionA(string $arg1) ...
I am learning design patterns in Java and also working on a problem where I need to handle huge number of requests streaming into my program from a huge CSV file on the disk. Each CSV line is one request, and the first field in each line indicates the message type. There are 7 types of messages, each of which should be...
I had initially posted a longer variation of the question below on the Stackoverflow site but was shut down for being too obtuse. I am a newbie at using VPS in general and wanted to try out something with a Flask website. I want to setup a Flask webiste on DigitalOcean with some links that launch some games either back...
I'm currently working on a architectural design for the testing of a product that's estimated to have over 100k simultaneous user hits. For the product specification, I'm including continuous integration and continuous delivery practices by using cloud CI services as Travis. Now, I want to also stress/performance test ...
I'm building a web service where I need to show different products/lists to different users based on their profiles/preferences. For example: John, 24/M, single: Show list A and D; Kyle, 48/M, married: Show list B and C; Jennifer, 22/F, single: Show list C and F; This is the first time I need to build something like ...
The problem I have with unit testing is that while it makes refactoring(regression testing) easier, it expands the code base and make it more difficult to prototype or to change the design. Developers tend to be averse to change the API due to unit testing. Is it possible to develop a testing system such that you don't...
I'm building a server for a turn-based mobile game. I'm using SignalR for communication and I was wondering if storing list of users in the memory is a good idea? Like.. a static object of "Server" class which has List<User> same for current games. The game is pretty simple - like tic-tac-toe. Are there better ways?
The traditional Waterfall lifecycle includes a specific phase for design and planning. In Scrum there is no big up front design. A small amount of design to conducted when breaking down features into stories, during the sprint planning meeting and during the sprint. Since sprint planning is time boxed to a few hours, ...
Our team has recently started conducting code reviews against each checkin. As the team lead I'm trying to find a balance between providing too many suggestions, annoying developers and decreasing the teams output, and letting go of code I would have written differently. Is there any evidence, study or guidance from we...
According to the definition available online, "Multi-tenancy is an architecture in which a single instance of a software application serves multiple customers". It means I have a Restaurant or School website and I provide access to different restaurant or school to use my application with their own data by using their ...
I am redesigning a PHP/MySql site that was about 7 years old and had lots of MySql statements. I had updated them all to use MySqli, but have recently heard about "prepared statements", so now I'm wondering if I should take the time to change all the MySqli statements to use prepared statements. For example, the major...
Just again another licensing question... By now I read so much stuff about licensing that I'm totally confused. Let's say I write two little java libraries and put it on github. One of them has a GPLv3 licensed dependency, the other one has a Apache-2.0 licensed dependency. Note that I'm just using these dependencies, ...
We have a master system storing customer data. Data is replicated to client systems (channels) at night. During the day data can be updated by users/customers on the master as well as on the clients. I need all data to be kept in sync between master and clients. Preferably "real-time" (within minutes). What pattern sho...
Over the years I've been switching back and forward on the idea of creating Sugar Classes. Sooner or later I find myself repeating the same operation over an existing type. Like string manipulation, date-time calculations... in these cases I am tempted to wrap the object into a custom class and get some extra syntactic...
I'm fine with staying under 80 characters per line for code (even if some consider that limit outdated), but I'm split (no pun intended) when it comes to splitting comments over multiple lines, versus writing them on one line (as long as it needs to be) and letting the editors taking care of the wrapping. I think comme...
As far as I know there are two types of CSS namespacing: Prefix one: .myapp-alert {...} and class one: .myapp .alert {...} Which one is preferable? Does one has benefits over the other one? Are there any other?
I'm finding that others not having the time to do reviews in a code-review enforced open-source (so volunteer) project is really slowing the velocity - it's really unmotivating to have 3-4 PRs of your sitting there for days and prohibits me from doing any new work. Real life taking priority is of course understandable,...
What is the best way to store historical information about products and pricing in a database? Our suppliers provide us with catalogues in various formats that usually contain manufacturer's ID of the product, product's name, GTIN-13, and MSRP. Based on that information I would like to create a database of produ...
From this bar chart on staff allocation I want to know what is the preceding activity for D and E in order to draw activity on arrpw diafram ? Is it B or both B and C ?
I have an MVC 5 ASP.net app that is working perfectly. A colleague of mine has made a project that reads in data from files and churns some of it to output some calculations for me to display in the web application. I call his methods and I get the data back and display on screen. As part of his project he has impleme...