instruction
stringlengths
34
36.1k
We've started looking at functions, and our homework requires us to include some simple ones in our programming. As we've left it a little late in the semester to explore functions, we're well-used to declaring/assigning multiple variables of the same type on a single line, as below: int a, b, c = 0; This, however, do...
For the purpose of writing a coding styleguide, how should final methods in software design be judged? By final I mean the Object-oriented sense that a class that can be subclassed provides methods, and that class using special syntax to prevent subclasses from modifying certain methods. In languages like Java, there a...
I'm making a desktop application where it would be perfectly sensible for the user to have multiple instances of the main window open at the same time (i.e., with different documents open between them). Going by the simplest approach: if I create a second window from within my application then it will live in the same...
When using Dependency Injection across internal classes (implementation details) in a library which is to be consumed by multiple applications, is there a good way to configure the IOC container? From my understanding, the canonical way of doing this in a regular program is by setting up the dependencies at the “Compos...
I'm looking at the source code for a client - server program that communicates using TCP sockets. 5 connections are used to communicate, named very_slow, slow, medium, fast and very_fast. A socket is chosen based on the size of the message being sent. I believe this is done so that messages containing only a few bytes ...
For class Foo, what is the rationale for calling the physical code module something different e.g. FooBar.cs Is this just a style thing, or does it serve some other purpose/intent? It is accepted that partial classes are a special case as these, by definition, exist in different files that must have different file name...
I'm currently using a third-party API to fetch results, using a REST client (Retrofit). The problem is that the amount of requests per second that I can do to the API is limited with interval: I can't do more than 10 requests per second with 100 ms between requests. As I want to multi-thread those calls for performanc...
a discussion that rose among us devs: how to do unit test of Business logic layer that depends on data access layer. the two options are create test data in a test database (for example, H2). let the Business logic layer call the real data access layer that is injected with test database connection. mock the data acce...
I think depending on nested packages is wrong, because the nested packages are always going to depend on the parent —aren't they?– and this can lead to cyclic dependency issues. When I look at how UML alternatively represents package dependency, it shows the anchor icon in an unidirectional way, e.g. the nested package...
Let me explain the problem I am dealing with. I have a custom (jar) API that I use in my production code. This API contains an ENUM that looks as follows: public enum Cars { AUDI("BERLIN", "FRANKFURT", "HAMBURG", "MUNICH") VW("BERLIN", "FRANKFURT"), MERCEDES("HAMBURG", "MUNICH") private final String[] city...
Here are two endpoints (or methods): ListResources(user_id) - Fetch the resources based on the given user id. SearchResources(query_options) - Fetch the resources with specified conditions. The query_options looks like this: { user_id : "", // the resource owner id keyword : "", // the resource name...
I have been told by another fellow C programmer to write large applications in several different .c and .h files, and then compile them together. They say it will run faster. Does a multifile application run faster than a singlefile one? If so, what makes it run faster? Also, what other benefits are there to multi fil...
Today I went across a weird case for which I have no explanation, so here I am. I have two files with identical content, but one is encoded in UTF-8 and the other one is in IBM EBCDIC. Both of them have approximately the same size (336MB and 335MB). But if I compress the files (ZIP or RAR) one of them is reduced to 26...
It seems to me that the sooner a developer merges with released code, the better. In the original GitFlow article this isn't done. The original picture is this: When long lived feature branch on the far left is finally merged into develop, it is still based on version 0.1. Wouldn't it be better practice if the deve...
I am currently designing classes for the User Interface (UI) of my application. When defining the interface of a class MenuTabSelector I faced a design decision of whether I should inject the user input as a dependency. My Current Implementation MenuTabSelector is responsible for selecting and maintaing the state of on...
I am a Java dev for almost all of my programming (at least in the workplace) but I do some Unity for fun on the side. I have used C# properties many times and they are convenient to still provide encapsulation without having to write out getter and setter methods. With that said, is there any disadvantage to writing a...
I don't know if this is the proper forum for the question as any answers will be rather subjective. But here it goes, please advise if there is a better place to ask this. I am designing a small template engine for a very small MVC framework in PHP. Right now, the views take in an array from the controller that can be ...
We currently have REST API, where you have a set of different resources, like: GET /cats GET /cats/{catId} GET /dogs Clients decide whether they can perform an action based on resource permissions. To query those the client calls: GET /cats/{catId}/permissions And gets back a list like "deleteCat", "sellCat", "initia...
For an application that is starting out I do not want to over pay for servers and resources that will not be used since the budget is very limited at this point. This will be a for an iOS and Android productivity app. What is the best way I can accurately estimate the resources and grow them based on the number of use...
Given the following structure where I want a method with a common name for each class, but each derived class needs an additional piece of information in order to form the appropriate result. Descending the inheritance tree accumulates additional needed arguments, but always needs all parents arguments as well. class...
Say I have a shipping service where I have both a driver and a dispatcher, but there are multiple roles and a user can belong to more than one role. Both the driver and dispatcher roles can mark a delivery as delivered, but a driver can only mark deliveries completed if they're assigned to those deliveries while a disp...
We're having a debate here on our server development team, and I'm struggling. I've always used master as source of record for production, with the master branch (or some designated release branch) acting as a long-running release branch. I'm in favor of using GitFlow for our process, releasing from master and tagging ...
I am developing an architecture for a new MVC system. The legacy system has a layer it calls "facade", but it is not the classic GoF Facade. It is more like a service aggregator. It is used as a convenience layer to call multiple services, aggregate/munge the responses into the response it needs, and then returns that ...
I often need to evaluate the time required to do software modifications and include this time in the evaluation. What is the average percentage of the time evaluated that should be used to perform the evaluation ? For example, if I evaluate the testing time of a modification to 9 hours and it takes me 1 hour to do the...
TL; DR Given BDD documentation with features composed by several scenarios, should we: Create a single interactor per feature Create minor interactors per scenario, and composing the feature interactor Details We are trying to refactor a huge application and we are mapping the current (and future) features into BDD (...
Have a database table which business / sales folks could and will keep modifying: year from | year to | points ----------------------------- 1930 | 1943 | 20 ----------------------------- 1944 | 1978 | 10 ----------------------------- 1979 | 2012 | 07 ----------------------------- In future the...
I am in the process of refining my code to adhere more to my current understanding of the Single Responsibility Principle (SRP). Originally, I had a class called Animal that had a set of methods and several instance variables. According to the SRP, the main idea is that a class is only supposed to change for one "reaso...
I really like the fundamental principles behind the Hexagonal Architecture (Ports and Adapters) and I have mostly applied it to my system/application. There is one thing that I wasn't able to completely grasp: The system needs to wake up and do some actions during specific hours of a day. For example, it needs send no...
I am a junior back-end developer at a large company in the US. At the moment, my 10-member team is changing its approach from Kanban to scrum (2 week sprints). My current way of working is this: I pick up the highest priority piece of work for which I'm suited and I complete it to a good standard, as soon as I can with...
This was recently a question I was asked in a screening and it got me thinking. I never totally settled on how the conversation ended, and I did some digging. None of the answers I saw seemed satisfactory to me. The question is essentially "how would you implement a thread safe hash map?" Obviously protect with a mut...
I implememted two versions of the collatz problem and felt an icy terror in the pit of my stomach as an optimized solution was slower than tail. The tail recursion is simple: // calculate the next term in a Collatz sequence def nextTerm(term: Long): Long = if (term % 2 == 0) term / 2 else (3 * term) + 1 def byTailR...
So I was given a task of making a class diagram for a bicycle. I know what a class diagram is and the concepts behind one. The requirement is that the bike can brake, turn or speed up. Now to me, a bike has three major components: the brake system, drive system and steering system. And each system has each own activa...
Naive sorts like Bubble Sort and Insertion Sort are inefficient and hence we use more efficient algorithms such as Quicksort and Merge Sort. But then, these two sorts are recursive in nature, and recursion takes up much more stack memory than iteration (which is used in naive sorts) unless implemented as a tail call. H...
I have a web-app with multiple functionalities and each functionality has multiple workflow/process. For example, Workflow A has Steps A => Step F, Workflow B has Steps A1 => Steps G1 and many more workflows. I hope I am able to explain my requirement. The web-app is written in Angular 6. My task is to create a tutori...
I hear and see this statement almost in every academic book related to software engineering Testing can detect the presence of errors and not the absence of errors. But I do not get it clear. What can be its possible explanation? I have topic of testing in the Software Engineering course in my academics. Does it me...
I'm trying to implement a feature with option to turn it on/off based on a flag. I'm doing it in the following way which I feel like a overkill, public interface Feature { public interface EnableState { void execute(); } public interface DisableState { void execute(); } } Exposed an in...
I was doing a Monte Carlo implementation of the Birthday Paradox in Python and I wanted to check if the results where the same as in the analytical implementation of the same problem (As they should be). The question I'm answering is: If 20 people are chosen at random, what is the probability that some of them share ...
Let's consider following code: class Table { private static int number_of_Tables=0; public Table(){ ++number_of_Tables; } public void finalize(){ --number_of_Tables; } public static int current_TableCount(){ return number_of_Tables; } } What I want to achive is that when GarbegeCollector (GC) destroys the...
During our class, he posed the question 'How are electrons moved by code' for our own reflection, the question seems to be vague but I assumed how are electrons moved in a processor/CPU since we were in a computing class. I know that it moves because of conductivity but what does a code have to do with it? So for about...
I have a list of dates in which a certain event happened. Taking into consideration that a particular occurrence of the event can: Be a one time thing or Be part of a periodic series, which happens every N months, where N is an integer I want to classify and group the dates as they relate to each other. That is, I wa...
Problem: I'm writing a service in Laravel 6.2 that will send out a push notification to different users at specified times down to the minute. Users select how many times a month, week, or day and at which times they want to be notified. I originally tried to store the index day (0-6) of the week and the UTC time stamp...
I have developed an android application on food delivery where I have used Firebase to store and retrieve data. I wanted to implement collaborative filtering algorithm on my dataset and I am stuck on how to begin. For now I am using an excel sheet where I have inserted my values. I am using openCSV to read and write ra...
I have been struggling to understand programming paradigms. OOP is a paradigm with sole aim of modeling complex (real-world) systems, and it got me thinking: is OOP the only programming paradigm that lets us model complex system? if No, why is OOP Unique or Super Popular? because, functional programming contains a bu...
The idea of programming katas is kind of widespread at this point. A lot of people know what that is, not a lot of people actually practice it. Furthermore, you can find a lot of resources about coding katas on the internet, majority saying that katas can improve code quality, programming skills and etc. Still, there'...
Suppose you are dealing with a situation where you need to handle lot of errorcodes from different server, what would be the design to apply? Suppose 400 is errorcode, sometimes errormessage can vary. For example, a) 400:Cannot handle , b) 400:Unknown User. I have currently created an enum, which lists all the error...
I thought this would be a more common problem, but I'm having trouble finding anything that provides a solution for me. I currently have a user story that has 2 users/roles. I am wondering if there is a best practice solution to split that story, noting that writing user stories is an art and not a science. Scenario: ...
Some (link 1, link 2) programming languages allow spaces in their identifiers (e.g. variables, procedures) but most of them don't and instead programmers usually use camel case, snake case and other ways to separate words in names. To support spaces or even other Unicode characters some programming languages allow enc...
I am new at domain driven design, and want to learn some about aggregates. For example I have a User and Role entities. public class User { public string Id {get; set;} public string Username {get; set;} public IEnumerable<Role> Roles {get; set;} } public class Role { public string Id{get; set;} publ...
In Design Data Intensive Applications, If all you need is to scale to higher load, the simplest approach is to buy a more powerful machine (sometimes called vertical scaling or scaling up). Many CPUs, many RAM chips, and many disks can be joined together under one operating system, and a fast interconnect a...
I am currently developing a software for a multi languages environment using visual studio (en, fr and es). The soft is some kind of a 3d configurator, if I take the exemple of a car configurator, the user will choose all the spec (engine, chassis, color...) and the configurator give him a price and generate a 3d file....
Interacting with an external server is a major part of the functionality of an app I have to write. I've always been told that automatic tests are not supposed to interact with the outside world. Instead, enpoints of the app that is being tested are supposed to be mocked out. Thus, if, for example, my app is making cal...
After a period of time in my life when I was making it a point of my honor to reject all programming principles and patterns I finally came to the conclusion that I was indeed being arrogant and ignorant... so I'd do best to actually learn the best practices of this craft. Given this, when tasked by my boss to write an...
Many times I want to define an interface with some methods that maintain a behavior relationship between them. However, I feel that many times this relationship is implicit. With that in mind, I asked myself: Is there any way to enforce a behavior relationship between interface methods? I thought about defining this be...
I have a question regarding user stories and with agile in general. I read a few articles about user stories and there is a thing, that is not clear to me. For example in this article there is the following sentence: User stories are a few sentences in simple language that outline the desired outcome. They don't go ...
Summary: Why shouldn't I put model, serializer and view classes for the same object in the same file in my Django Rest Framework application? I'm building an application using the Django Rest Framework, which I'm relatively new to. I've had some exposure to Ruby on Rails so I'm familiar with the MVC idiom and its logi...
Suppose we have a DB with a table holding Person: id first name last name age The DB is a black box. And there are a lot of get and post requests for these records. We cannot change the DB but only calling its API. The API is very slow. How can we come up with a design to reduce the impact of slow DB access? My in...
I'm building a system that horizontally scales with many nodes. Any of these nodes could consume an API that's hosted on https://example.com/api. The authentication for this API is token based. My question is, should each of my nodes authenticate separately and fetch their own token? Or should I build a shared cache be...
Is it a bad thing to have a large number of contributors in a code repository? My current company has a really large repo. This repo has over 40 contributors. And there's a debate about whether or not it's a bad thing. What do you think? What's the good practice about it?
We have an architecturally layered application, with web frontend, java backend, java and python microservices, DB etc. so when we do a User Story representing business value, it's mostly broken down into 2-5 different technical tasks, worked by multiple people (we have tech specialization rather than cross functional...
I'm trying to write a GUI library for a project (also for learning purposes) from scratch (in C++), and it's working pretty well, but since this is my first attempt i feel that the design of the event system isn't that great. basically, how i'm handling events now is that whenever a mouse click occurs i iterate over ...
As I was reading an update on an issue in github an user suggested me to read the '12factor' principles. While I was reading it I started having some questions on some concepts written in the Dependency Management section. The quote goes like this: Twelve-factor apps also do not rely on the implicit existence of any ...
I have been writing some code in PHP for a bit of time, but I am still pretty new on it. I have a script with all functions I need for my webapp. The script looks like this? function foo(bar){...} function bar(foo){...} ... And the script that handles the user requests from the front end is like so: include 'script1';...
I have a general question about the implementation of the ASR (automatic speech recognition) API of Google or a similar company. We need to create clients (desktop applications) that send the microphone audio to the API and get the transcription back for further analysis. Please, note that we are talking of real-time (...
I am making a chat-app using the XMPP protocol and ejabberd as XMPP server. I want to build a push notification functionality for the app. The app is similar to WhatsApp. I came to know three different techniques on FCM to deliver push notifications: Topic Registration token Device group messaging I am confused which...
Let's say I have an processing pipeline. It receives a file, converts the file to data, interprets the data, and then persists it. At every step of this way, I would need to collect statistics, so I can show a comprehensive "Import Report" at the end. Retrieving some of this data is not possible once the algorithm fini...
Consider I'm writing a mobile app with user-login feature, using a framework which can be simplified like that: class UserData{ static token=""; static name=""; static balance=0; } class Main{ constructor(){ this.loginPage=new LoginPage(); this.welcomePage=new WelcomePage(); . ...
I made a code that seems to mix Singleton design pattern, and Fatory method. But my factory method is in an abstract class inherited by my Singleton ... what the hell have I created ? Does it have a name ? Here is the situation (in PHP I hope to be understandable by everyone) : I had a circular inclusion problem : clas...
I was design a server communication module of native application. As starting point for now I have 3 classes: HttpSession — class which contain all necessary data for sending requests. ResourceManager — class for handling loading, parsing and storage server data. It's not thread safe and needs to be used within a sing...
In AWS I've got lots (dozens) of lambda functions. As my organization has gained experience with AWS, we've gone through various generations of infrastrucure around building and maintaining our functions. Currently we're making use of the SAM template and Code Pipline created from a CodeStar project to keep track of th...
We're working on building a multitenant application, and we're using Entity Framework Core as our base data provider. With EF Core, you can use Global Query Filters to define custom filters that apply to all queries generated by EF. These filters work great and appear to serve most of our purposes, but we begin running...
I am currently facing the following scenario: When defining the requirements of my system on a piece of paper, I described two different entities A and B (e.g. Cat and Dog) After listing what A and B should do, they ended up having the exact same behavior requirements (e.g. the behavior of an Animal). To reflect that,...
In the seminal 1989 Microsoft memo Zero-defects code by Chris Mason (which is still a great read even today), the term 'hand native' is used several times. Some examples: 1. Users measure our products by their speed (a major part of usability) as much as by their features. Our methods do not reveal this. We often let ...
I saw the code of a few testing frameworks and most of the times it contained self-tests. I mean they used the framework to test itself, not a different testing framework to test theirs. I always found it odd, because at start you have nothing to test with and even if you have something, then you cannot be sure that it...
I'm encountering difficulties with making a reusable design for a game server in C#. Are there better architectural or design patterns that could be used here? If I group similar system functionality, it would look something like this: Game (common for multiple types of games) Add player: the player is created with ...
The SOLID principle is supposed to be the underlying framework for object oriented programming. The "S" part stands for: "Single responsibility principle" which in wikipedia is defined as: A class should only have a single responsibility, that is, only changes to one part of the software's specification should be able...
I am applying the principles of Hexagonal Architecture (Ports and Adapters) and one aspect is slightly bothering me. In my opinion, the ports and adapters of the secondary actors should completely be isolated from each other. No dependencies between them. Maybe this is a false expectation but it instinctively feels rig...
During my last job interview which was about half year ago, the technical guy asked me, whether the better option is to use e.g. 100 processes to do some work, or only one process but with 100 threads. There wasn't any information about how many cores the CPU has. I'm aware that the best answer is...it depends but.. In...
Let's assume I was building a collaborative document editing platform ala Google Docs. Collaborators work together on a Document. A Collaborator must be a user of the platform. There's a Comment subdomain that allows Collaborators to communicate within a Document. When a Comment is created, all Collaborators should be ...
I'm creating a branch in source control to strip large parts of an application out. Whilst giving this branch a name, I started questioning if "removal" is the right word. As I'm not specifically just removing the code, I'm also rewriting a few other parts to fit around the new code structure. I was wondering, is there...
I was reading SOLID principles on a website, in which for D - Dependency Inversion Principle it says: “Depend on abstractions, not on concretions” In other words. we should design our software in such a way that various modules can be separated from each other using an abstract layer to bind them together. Dependency ...
According to What Wikipedia says about Structured Programming Paradigm The following qualifies a language to be called Structured "Sequence"; ordered statements or subroutines executed in sequence. "Selection"; one or a number of statements is executed depending on the state of the program. This is usually expressed w...
I have a scenario for which I'll take an analogous example to help understand better. There are N buckets of known varying capacities. We have M balls that we need to put in these buckets to fill them fully or partially. The existing algorithm works as below: For each bucket calculate the fraction effect = (Bi + 1)/Ci ...
I'm trying to split the use of a business entity (e.g. a post) thought an application uses, trying to obtain a clean architecture So I will likely have: A class model, where the business logic lives class Post { private text: string; public constructor(text: string){ this.text = text; } pub...
I am not too familiar with the computer architecture terminology yet so please bear with me. I seem to understand that von Neumann architectures are more robust ("universal Turing machines") as opposed to Harvard architectures, but don't know too much about the details yet. After spending the past few nights looking in...
I am working on creating a simple VM sort of thing in JS: let sp = 0 // stack pointer let m = [] // memory initialize: sp = 0 invoke: m[sp] = m[sp - 1] // position in stack m[sp + 1] = input[m[sp]] // method m[sp + 2] = m[m[sp + 1]] // size m[sp + 3] = 0 // link iterator sp = sp + m[sp + 2] // new stack po...
I my job, I am tasked with the responsibility of improving the code quality. To meet this responsibility I often pair program with developers and conduct sessions on design principles and design patterns. I was surprised by a developer who said either he has to violate Single Responsibility Principle or YAGNI. Single R...
According to my understanding on factory-method, factory should always return a new instance, meaning no cache, So in essence, every time when the factory method is called, there should always be a new instance returned, otherwise, it would not be a factory method pattern. For instance, the following code is not a fact...
im working on a RPG (combat system) and have a question about a specific part of the design / code. First I have to explain some background information about the system: Every time a character deals damage to an other character (weapon attack, spell damage etc) the buffs / status effects of the attacker and the target ...
It is my first post here and I thought it really fits on this side than on the regular website. I am sure many of you (programmers) must have had nightmares with this Date 'object', either in your early days or in some code you are inheriting from someone. Let's just assume there are more programmers in then rest of th...
A bit of context: I used the password recovery of a website I am using (the website of a big corporation). My password was immediately sent back to me via text message. I did not receive a reinitialization link or a temporary password but my real password in plain text. After contacting the webpage owner to ask him if ...
BASIC QUESTION: We have a small application that uses a MSSQL database to save data. We want to use Windows-Authentification to allow each client (15 in total) to connect to the database to write/read in a table. For now, we ask the database administrator to create in the database the 15 users (adding their Windows na...
I'm writing a code for the Discrete Element Method where I have balls (spheres) and walls (planes) interacting with each other. Those simulations are run for billions of time steps, so performance here really matters. Right now, I'm considering different designs and am not sure which one is the best. I'll try to explai...
I have a service that fetches data from a target source (not through an API but via scraping) which can change. I want to do pagination so that I return 35 items per page but the target source is 25 items per page. Is there a way where I can convert between these formats so that I keep my pagination even if the target ...
Let's say I have to create tons of different SQL views. Having actual and target table DDLs, is it possible to programmatically automate view creation? Example: I have 2 table DDLs: CREATE TABLE target_ddl ( invoice_sum INTEGER, date date DATE ); CREATE TABLE actual_ddl ( amount INTEGER, year INTEGER, mont...
I have some difficulty, when trying to understand about the architecture (presentation i.e. UI layer, business logic layer, and data access layer, and MVC) and deployment (which part runs on client or server side) of web applications. Nowadays, with modern frontend frameworks such as Angular, React, and Vue, does the ...
Calculating a user's daily profits / losses using their previous balance and their current balance (let's say for things like financial portfolios) is pretty trivial. The part I find difficult is how we do calculate profits and losses using a user's account balance when they make a new deposit or withdrawal. For examp...
I am applying the Hexagonal Architecture (Ports and Adapters) to my system and I have noticed a dependency from my primary (driver) side adapter to the secondary (driven) side port. This doesn't seem right; there should be way to handle this. Let's say I have two very basic ports in my domain; one is at the driver side...
I am building a Loopback4 app just for learning; I have a scenario where I have to check for a couple of things before sending that request to the database, so my entry point is my Controllers Method, and it is not something that you can resolve with database constraints like foreign keys. As my application's entry poi...
I've created a database and included in the tables are these three relatives Game GameHasPlayer Player I've created a data access API project, with simple methods for getting filtered results: GetGame(s) GetGameHasPlayer(s) GetPlayer(s) I've created a website which can call the API, and the aim is to have this API ac...
I am adding authentication to my web app and I consider the following case: I have USERS table which look like this simplified version Id {int} | Username {nvarchar(100)} | CollectedPoints {int} | DateDeleted {datetime(2)} _______________________________________________________________________________________ 1 ...