instruction
stringlengths
34
36.1k
this is my first post on here. I am wondering if there is any disadvantage to using websockets as a communication method for a non-web-based client application to connect to a server? I am looking at designing a turn-based game, using a client-server approach. I would like to design the game server so that different ty...
Currently implemented the model and working on the UI for a scheduling application. This is just an in-house application for work between ~5 people that may occasionally have the application running at the same time. It will be run from the network and use a SQLite database (I understand the concurrency issues and fee...
I'm creating a database schema for a internet store and I wonder how to better create the tables "images" and "products". A simpler way will be to have it as one_to_many, that is: images(....., product_id references products(id)) The more flexible way is to create it as many_to_many. However, I can't think of any s...
I would like to ask what is a prefered way when you have such a code, (this is distributed transaction since I cannot delete the item and publishToKafka atomically), and I don't want to have event sourcing right now: if(exists(Item)) DeleteItem(Item) PublishEventKafka(ItemDeleted) Now obviously if a crash is bet...
I am reading about SOLID principles and have just read that Dependency Inversion (DI, to be distinguished here from Dependency injection, which is one way of achieving the inversion) is an extension to the Open-Closed Principle (OCP). How is that exactly meant, if OCP is about making class extensible without touching t...
I'm working on a Scala project and Wartremover shows an error about Option#get usage in my code: Option#get is disabled - use Option#fold instead While I do understand how get should often be avoided, I think there are cases where it's reasonable to use it, like my current one: First, I create an answer item (in the d...
While trying to solve an issue, explained on the StackOverflow forum, somebody advised me to use dependency injection. For personal reasons, the moment a person mentions to me the usage of a design pattern, I always start thinking of very difficult constructions. After some thinking and investigating, I've invented fol...
Please see the code here and specifically using System.Collections.Generic; namespace DddInPractice.Logic.Common { public abstract class AggregateRoot { private readonly List<IDomainEvent> _domainEvents = new List<IDomainEvent>(); public virtual IReadOnlyList<IDomainEvent> DomainEven...
I'm currently working on a rest service writen in c++/qt and i'm also thinking about the future web ui who will use this service. I admit i'm not super expert in html/js since i've always worked on the back-end side, and i'm not sure how the modern ui patterns are today. As first question i aks: is a html/js only ui (a...
First of all please excuse my english mistakes; it's not my native language. Second, I couldn't find a better title to summarize my inquiry, so let me explain it below: Let's say we have a software that invoices some products. The invoicing process highly depends on the current legislation. For example, the current law...
I have a small question. Which approach is correct in the context of SOLID principles? 1 or 2 ? In the first case, the "CreateTask" method does not return the Task object, but places it on the list that it accepts as the method argument. In the second case, the "CreateTask" method does not accept arguments, but returns...
So an Instanced API is one that behaves like an object. So for example: foo* GetInstancedAPI(); void MemFuncSetter(foo* fooThis, const int arg); int MemFuncGetter(const foo* fooThis) const; This is as opposed to a non-instanced API which would depend upon look-ups: int GetInstancedAPI(); void MemFuncSetter(const int i...
Is there some reliable way to detect device/browser/OS of web page visitors except using the user agent string? This is not for rendering/functionality of the web page/application, but only for statistics (how many percentage of visitors use ipad, iphone, pc, mac, chrome, edge, firefox etc). This can be done either by ...
I have read that using "new" in a constructor (for any other objects than simple value ones) is bad practice as it makes unit testing impossible (as then those collaborators needs to be created too and cannot be mocked). As I am not really experienced in unit testing, I am trying to gather some rules that I will learn ...
Problem I have a Python library which sends XML requests to an external API. If an issue occurs, the API responds with an error containing an error code and description with error details. These errors can be caused by anything from malformed XML data, an invalid username/password, editing a read-only attribute, or try...
With a list of thousands of words and a small list of letters I am trying to find the least amount of words to make use of all given letters, assuming my dictionary of words covers all letters. The first step is obviously to remove all words with none of the letters. Then I approached this by calculating the relative ...
Let's say I have thousands of pdfs that are each about 30k words written in conversational English. In each of the pdfs there is a name / names of a person/people who snowboard. There are also many other names. I need to extract the name(s) of the snowboarder(s) from any future pdfs. What are some tools / methods you c...
First off, I want to say that I am used to doing Procedural Programming as my hobby - I'm trying to learn OOP in a couple languages, and understand the theory, just not the practice. I have a pet-project I wanted to build, specifically in PHP with a database backend (didn't care what one). My main reason was for the ap...
I'm working on a project where I have two programs which need to invoke methods on some of each other's objects. I do this by sending JSON objects over a TCP connection. These objects have a receiverID, methodName, and then a list of parameters. Each program has a HashMap from receiverIDs to actual object instances, an...
I am working on a java server, which has a bunch of seemingly distinct "services". A lot of which are just effectively classes. From a software architecture point of view I wonder what the opinion is on such a setup. Is there any advantage to be gained by splitting the related services off into their own server? Or is ...
I have an API server, and it's SPA client (node+ react, but it's unrelated). All the API endpoints are under /api namespaces, and the SPA just keep make REST calls to perform operations. We're working on a feature which require our users to link their Foo Service 3rd party account through OAuth 2. OAuth 2 requires the ...
Context I am making a service class that essentially functions as a business datetime calculator. That is, it can perform various calculations such as what date is X business days from a given date, when is the start of the next business date, is a given date in business hours, etc. The catch is this class has to take...
I am trying to make some version control locally on my Android project. It is just to have control about my changes, but I do not want to upload them to any external repository. Neither I want to create infernal folders with dates of updates... I would want to use Git, in which I am a bit familiar. I am also familiar w...
I'm still currently learning OOP. I need a method that takes in a List<JsonNode>. Now there are multiple components that need some resources from the List. Component1 needs all of the keys. Component2 only needs the keys that have a numerical value. As we understand, these two both need keys, thus requiring a function ...
I've been programming professionally for years now at several different companies and I consider myself to be a fairly competent programmer. However, of everywhere I've worked there are usually dozens of different software engineers and programmers with dozens of different coding styles, and patterns. I've read tons of...
I am developing a BSD 3-clause library. In the root of the repository, I have the full license text, and at the top of each file something like /* This file is part of <project name>, developed my <me>. * * All rights reserved. Use of this source code is governed * by a BSD-style license that can be found in the L...
We have a system that generates lots of logs and we have to somehow maintain logging workflow in a project. The 'strict' (let's assume it's strict) requirement is that there should be a document describing format for each message and each message should comply to that format. (By format I mean BNF-like things like 'som...
I’ve been wondering about this for a little bit, but I couldn’t find much info on Google. What do big websites like YouTube do to manage all the traffic they get without their website slowing down? How are their servers different than a home web server? Do their servers run off of one network from an ISP or something e...
I have been looking around for some practices to write testable code and gathered the following: • Public methods virtual if not using interfaces -- makes mocking easier • Dependency injection -- makes mocking easier • Smaller, more targeted, choesive methods -- tests are more focused, easier to write • Avoidan...
I have a node app with a queue for processing jobs in the background. I have a file that exports a function which when run, creates a job in my queue. In that file, I also have the handler for this type of job. It looks like this: const actuallyDoStuff = async (...) => { // code that takes time }; queue.process('d...
I have a quite large private codebase which has evolved for about ten years now. I'm not using phpDocumentor but since using docblock sections has become quite the standard in open source projects I have adopted writing docblocks for all public methods in my repository as well. Most blocks just contain a small descript...
I admit this was asked to me in interview a long time ago, but I never bothered to check it. The question was simple, how does Python make Queue thread-safe? My answer was, because of Interpreter Lock (GIL), any time only 1 thread is making a call to get the element from queue while others are sleeping/waiting. I was/a...
My team is in dilemma, we have an existing maven spring-boot Java8 project with following onion architechture. controller --> service --> dao --> jpa repositories | --> filesystem | --> jdbc template Dao earlier using jdbc template and jpa, so it had more than ...
I've been thinking about this over the past few weeks, and I've come up with no good arguments. My perspective is from Java, but if anyone has any language-specific cases outside of this language, I'd love to hear them. It seems to me that the benefit of using a List over a Deque comes from the fact that one can acces...
I'm building a Sudoku generator. I have a board class with a number of methods: public class Board { public Board() { /* Creates an empty board */ } public bool ValidateRow(int row) { /* Checks for errors in row */ } public bool ValidateColumn(int column) { /* Checks for errors in column */ } ... } I'm...
AFAIU a SAAS software is any software which is runs on a browser and performs a certain service, (aside of giving a way to contact the owner of that software) and is also aimed for reuse, whether if it's gratis or not. Is PHPmyadmin, the Database Management Tool (DMA) SAAS actually?
Usually, getters always return the value of a variable. I learned in my literature that access to fields is controlled by getters and setters. When I had my code rated by programmers, it was suddenly said that getters and setters violate object-oriented thinking. So far, I have always set the output-statements in the m...
I have a set of services that are used to read/write to the database. These get injected into my controllers: ISystemSettingService _systemSettingService = null; IStatusTypeService _statusTypeservice = null; public MyController( ISystemSettingService systemSettingService, IStatusTypeService statusTypeservice) ...
I recently asked this question: https://stackoverflow.com/questions/48582699/equality-for-a-dateofbirth-value-object. I am going to avoid a DateOfBirth value object. Instead I am planning to use a type alias. I have a few options with regards to my constructor: Option 1 using DateOfBirth=System.DateTime; DateOfBirth...
If I write an application and decide to develop only a single graphical interface for it, and never intend to develop multiple GUIs, then by today's standards it is okay not to use the MVC pattern or MVP pattern, or should you generally prefer the MVC pattern for object-oriented software with output? The advantage of t...
I want to do something like Facebook does. We can see any time where we're logged in. e.g.: Windows PC · New Delhi, India Edge · Active now Windows PC · New Delhi, India Chrome · 8 minutes ago Xiaomi Redmi 4A · New Delhi, India Facebook app · 10 hours ago Now, I have created a table in database that stores mainly use...
I am looking at a scenario for creating an aggregate instance from a trigger an a different aggregate. I've incorporated some logic in my DDD and Event Sourcing with Onion architecture learning scenario around User Registration and creation of a User Account. Currently I have a simple Registration class instance which ...
Apologies if this is a repeat of an older question but I did attempt to find a similar question and didn't have any luck. I'm going through the tutorials at www.w3schools.com for writing XSDs and XMLs. I have a basic understanding of namespaces but my question -- why do many XSDs that I've seen contain a reference to h...
Since I'm learning the MVC pattern, this might be a very naive question. I know that when something happens on the view (e.g. user clicks a button), the view calls the controller which in turn updates the model (e.g. set a flag to true). However I can imagine some scenarios in which the model changes without user inte...
Our company is in the early stages of starting to use microservices. One question that came up the other day was 'is scheduling/calendar a micro service'? We have so many monolithic apps that have built their own calendar/schedule - some allowing appointments to be scheduled in the morning and afternoon and some more g...
The background In MVVM, we tend "not" want to couple windows to view models for various reasons. Though from the very second screen on your application you start hitting this conceptual grey zone. The problem You see viewmodals tend to want to open windows/Views (its just a fact of life). Windows/dialog APIs tend to ...
I am developing a REST API which accepts JSON using Spring Boot. I use Spring Security for authentication. I have a use case where I have two services, one to test connection to a 3rd party system and other one to fetch data from the 3rd party system. api/system/connection api/system/customData When I call the first ...
As you know Facebook saves login sessions and we can see them in settings where we've logged in. Now, they show IP address, Phone name (if logged in with phone) and App name in the phone and Browser name in case we use browser. I want to store these info for my site using PHP and JavaScript. One way is to use inbuilt f...
I am currently making a console program about buying property in a city. Properties can be bought from the city by someone, transferred to another person, or returned to the city if the person who has ownership dies. I have created 3 classes: Person, City, and Property. My Person and City classes both have vectors of ...
I want to create a mobile app(iOS and Android) for business need, ex: the business is Health and Beauty. So I need a mobile app for sale some goods and service. However, I need push notification to who is subscribe my topic like, health tips, magazine and new product etc. So I plan to create: Web application back-end ...
I am new to programming, I have been trying to get my head around this. Context My project is about defining investment packages for various construction projects within a country based around an economy model. There are 5 regional models, and I am writing about a company working on the interface that will allow inte...
I'm confused I use to build mobile app couple of years ago and I know that android is java I read some framework like Ionic HTML/JavaScript Framework that can export to mobile app. I going to have android projects soon and I will going back to java for mobile app, I'm at web development. I saw this that Ionic framework...
I am working on a web app which uses Google oAuth flow and Drive API to list user's Google Drive files. With the access_type set to online, my app doesn't receive a refresh token. My question is, once I receive user's data, which is just meant to be shown so storing in DB is not an option, should I store that huge data...
I am researching cohesion topic and found out that some claim TCC metric should only include public methods, some other sources claim all methods. Would it be wrong to use either approach? Why private methods should be excluded, as some suggest?
This turned out to be a rather interesting problem contrary to my expectations. Imagine a simple chat app, a user registers then can add other users to their contacts list and start conversations. I want to be able to show in real time each user's online status (for simplicity just online/offline). The problem is how t...
I'm still a beginner when it comes to domain driven design, and I am trying to model something like an RPG's battle system as a bounded context. I am trying to model a bounded context in which a Combatant has a list of abilities, and each Ability has a list of effects that it would apply. For example, a common Effect...
I'm currently trying to create a system for a specific tournament but I can't figure out how to generate the matches table. I have a tournament with <T> teams. Each team needs to play vs each other team exactly once. The tournament location has <M> fields which can be played on at the same time (Therefore limiting the ...
I stumble across this case somewhat often, and I'm surprised about finding so few similar discussions around the web. This question is very related, but my problem is that I want a method that does the more general "do X if Y" rather than "do X if needed". The answer in that link is to use the prefix Ensure, but that w...
I ask because I found no answer to this, maybe because is too obvious (I think there is no thing like "legally obvious"). Imagine that I make a small library (DLL) or a styling template (CSS) or whatever, and I want to make it public and open source (yay!). Until now, I used to license these kind of things with GPLv3 i...
I've been reading a lot of comparisons between NoSQL and SQL. I feel like NoSQL might be the way to go but I'm still uncertain. So here's my example: I want to be create an inventory system. There will be user accounts with the usual details (email, username, etc.). Users will be able to create stores and lists. Stores...
Writing a User object in Swift, though my question relates to any strongly typed language. A User can have a bunch of links (FacebookProfile, InstagramProfile, etc). A few questions around this. Is it good practice to wrap links in their own object? struct User { var firstName: string var lastNam...
I am designing a state diagram for my software. I want to represent the following scenario The application is in state X ---> (state X) It can have two events/actions, eg. action A and action B If action A is performed, it goes into the same state X and again action A and action B are available. But, if action B is pe...
As an experienced software developer, I have learned to avoid magic strings. My problem is that it is such a long time since I have used them, I've forgotten most of the reasons why. As a result, I'm having trouble explaining why they're a problem to my less experienced colleagues. What objective reasons are there for...
We get problems on production systems every now and then, most of which can't be replicated on dev/systest/uat for following reasons, We don't have enough data on dev/systest/uat e.g. production has million rows... but our other environment only have few thousands We don't have right data structures, depth of data etc...
Subj. Atm I'm using Selenium and Python, but the same applies to any other scraping solution. I'm wondering: which of the options outlined below are optimal/recommended/best practices if there are existing solutions/helper libraries, which keywords I should look them up by. To stay objective, "optimal/recommended/be...
We are building a new product in real estate space and the end users of this product are not so tech savvy. To have better user experience with our product, we want our users to find relevant things quickly and easily. Apart from a simple UI, a universal search bar seems to add value. The search bar with auto-complete ...
@Component public class RepositoryContainer { @Autowired public CommentRepository commentRepository; @Autowired public ItemRepository itemRepository; @Autowired public UserRepository userRepository; @Autowired public PostRepository postRepository; } In this way, I just need to inject a ...
Please see the code below: public class Person { public DateTime DateOfBirth; public List<Offer> Offers = new List<Offer>(); public Person(DateTime DateOfBirth) { int age = DateTime.Now.Year-candidate.Year; if (DateTime.Now < candidate.AddYears(age)) age--; if (age < 18 || age > ...
Ok, I'm working on DynamoDb-based caching. We have an API where each call costs us real money and the information retrieved is "fresh" for 2-3 weeks, so it makes sense to cache it. There's no problem with calling dynamoDbClient.get(apiUrl) and retrieving the stored JSON response. They have batches - 25 batch items ...
I am developing a (Java) library providing an API to read a file in a specific format into an object. The format is basically a map, and specifies valid values for some of the keys, and valid types for values for others. E.g., the value for colour may only be one of red, green or blue, while the key date must be provid...
We had a discussion over this topic at the work not long ago. We have the following situation: A legacy database which is currently the base for the main operational application in our company. A new content management system that should receive master data information from the mentioned database. That master data wil...
What is the cleanest way to obtain progress from a class that will also be used in a no-gui environment for the purpose of displaying said status in a JavaFX Gui? Example: import java.util.ArrayList; import java.util.List; public class ExampleFetcher { public List<Entity> fetch() { final List<Entity> resu...
For the simplification, I am talking here only about the time, invested into the project starting from the task being defined for developers and functionality being passed to testers. AFAIK, the mostly used tool for support of the project management is JIRA now. Using it, we can find how much time was used for differen...
Suppose there is a Page class, which represents a set of instructions to a page renderer. And Suppose there is a Renderer class that knows how to render a page on screen. It is possible to structure code in two different ways: /* * 1) Page Uses Renderer internally, * or receives it explicitly */ $page->renderMe()...
I'm part of a small team that currently uses an Access database for scheduling a larger team's availability. This has presented some issues with corruption of the Access database. Additionally, I want to implement additional functionality over time. I've set out to create an application for the 4-5 of us to use that wi...
I have a Report class that is basically an interface for creating HTML reports generated via a Python template engine. The Report class currently generates the report but also has a few methods dealing with retrieving/uploading data from S3. These S3 methods are mostly agnostic to what I would consider the core part of...
How can we safeguard REST API to be accessed only from trusted clients? Let me explain the scenario, lets say there is an API which will be accessed from mobile application MA and web application WA. Besides these two applications, this API should not (and must not) be accessed by any other client. Key Points: I canno...
I have a function/method which throws some exception when database is being called. I was writing Junit tests and I was told to have good coverage. So, should I write Junit test which catches exception. I think it don't make any sense, since I have to mock the database to do so. So whole scenario will be like this: pu...
Is there an operator equivalent of nor? For example, my favorite color is neither green nor blue. And the code would be equivalent to: // example one if (color!="green" && color!="blue") { } // example two if (x nor y) { // x is false and y is false }
We have several ongoing projects and need to figure out the way to manage the repos. The current situation is Project A is in production, in a SVN Repo A. Project B is in development for another client and is actually project A with some add-in features, in a SVN Repo B. So every time we have a fix on A, we need to wai...
I can see several post where importance of handling exception at central location or at process boundary been emphasized as a good practice rather than littering every code block around try/catch. I strongly believe that most of us understand the importance of it however i see people still ending up with catch-log-reth...
I am wondering how do big development teams do it, when they all work on one project. Options are: 1 virtual machine in cloud that they ssh into and push updates via ftp ? each developer have their own local virtual machine and updates are being controlled by git, when merged together by master branch on cloud? any...
I'm creating an application which, so far, has an identity service(using identityserver4), a front end, and a calendar service. The user logs in via third party(say, google) and grants permissions to the application to manage their calendar. When the user logs in, identityserver stores the access and refresh tokens i...
Is there an automated approach to generate a grammar (which could be used later in a compiler tool such as ANTLR or similar) from given examples of a language? With more detail: assumed a technical language such as Java, C or (in my case) MQSC, and some source files of that language, is there an automation to derive t...
I'm building a website where I plan to support multiple languages. Not only via UI, but via the content too. I have several tables where I have text columns such as "title", "name", "description", "body" and so on. What's the best way to do so? Will I have to create an additional table for each one where I have text...
Quick question, I've been digging into CQRS and Event Sourcing and there's one thing that I have not been able to find info on, what happens when your Write Service crashes and you need to start it back up? I understand how you can recover your Read Service by replaying the events, that makes sense to me. What I can't ...
In my (primarily C++) development, I have long adhered to using out-of-source builds. That is, my source usually sits in a /project/src directory and the builds live in a /project/build/bin/release, /project/build/bin/debug directories. I have done this because it keeps my source directories clean from intermediate f...
We're starting to work on microservices to rebuild our legacy application, piece by piece. We started by building a register module which is responsible for the whole register process. To simplify, let's say the RegisterModule will use a CustomerModule to persist a customer, and then a PhoneModule that needs a customer...
In Clean Architecture, Robert Martin talks about the necessity to "decouple the structure of the tests from the structure of the application". He notes that a test suite that has a test class for every production class/a set of test methods for every production method is deeply coupled, and thus fragile. He thus advoca...
I'm currently building an app that includes sales promotions. There is an option in the promotion that allows the manager to have a start and end date. I do not want the manager to have to manually select the winner, but I want my software to read that the end date was reached and auto close the promotion. This sounds...
suppose I have code like this someFunction:function(userId){ var url=SomeClass.SomeNetworkConnector.SOME_URL; if(url !== undefined && userId !== undefined){ this.openURL(url+"?userid="+userId); } } Initially I think the name of actual constant SomeClass.SomeNetworkConnector.SOME_URL is too long, so I use a v...
I'm a CS student and in order to practice my coding skills I'm trying to implement an e-book reader and I want some advice from more experienced programmers. I'm using C++\QML but I'll try to keep my problem non-specific to any technology. Small preface Once the book opened I keep it in memory. I also generate an array...
I need to call a method that is available in a third party library, but it is a private method. There is no direct or indirect way to obtain the same functionality via public methods available. I could do this in at least two ways: Copy paste the class into my source code tree (the license permits) and change the meth...
Imagine a program which exposes a REST service/gRPC service/whatever service, which uses several 3rd party libraries. These libraries can of course throw exceptions if something goes wrong, for example if the user tried to access something which he isn't allowed to. The problem here is that it isn't possible to check b...
I have a couple of classes that are doing the same thing: filling a series of object using data sources passed as a parameter. As I need two distinct of them, my interface holds the following contract: // Arbitrary names, didn't find a good name for the application field yet public interface DataMapper<O> { /* ...
I am trying to figure out how to measure the relative success level of a given (but unsolved!) Rubik's Cube state. My first idea was to calculate the number of overlapping "cells" in the destination (solved) state and the given (unsolved) state, and present this as the following: number of actual correct cell positions...
Say that I have the following one-to-many relationship: If I don't want to store any information about the relationship, I can simply put the primary key of School as foreign key in the Student table. But let's say that I want to store the date on which a student has registered in a school. In this case, can I still p...
What is the recommended way to reference other classes within a container class while keeping everything decoupled? In the below example, I'd like to automatically add to the SceneGraph the constructed Path. class SceneGraph { constructor() { this.children = [] } addChild(child) { this.children.push(chi...
I'm building an Android application, and trying to follow the Clean Architecture pattern. I am a little confused on what my entities should look like regarding some of my use cases. Example I have a list of channels, and each channel have programs. I want to display a list of the current program for each channel, and w...
I have some doubts with Agreggate Roots and working with Entities. Imagine we have a Box object, which contains Potatoes. In this case and in a DDD point of view, the Aggregate Root would be the Box object, so in case we want to add Potatoes to the Box, we have to do it through the box object. Now, imagine we have to c...