instruction
stringlengths
34
36.1k
I'm trying to understand what this pseudocode does and I can't seem to understand what the comma is suppose to do here. I know that j <- 1 is j = 1 but what about the i? And what does j <- j do in this case? fib iter(n) i,j ← 1 for k ← 1 to n−1 i,j ← j,i + j return j
I have an api end point which receives some parameters and process them returns a csv file. But the processing time may take more than 15 seconds. My server has build in timeout and some client systems may have also timeout set. How can I overcome this timeout issue with out changing any system settings? I have gone th...
I heard a case where two teams are planning each others' sprints (estmating stories and deciding what goes into the sprint). The stated benefit is to solve one of the two team's problem with not finishing their stories within the sprint. The concept seems strange to me and I'm curious about hearing opinions on this app...
I'll describe the anti-pattern I see occasionally as this. Rather than using encapsulation or inheritance, a utility library grows with feature specializations directly added to it. Subsequent usage by another component requires a dependency (header, linker, runtime) to that feature code. Thereby increasing developer ...
This is a question about Android, and iOS apps. The technology is Xamarin (C#) but this is not really important. The app will be deployed to the stores. The client app must be compatible with the back end up. As we know, a user can reject an upgrade at any time, so the client must try to work with the current version ...
I was watching a presentation by Uncle Bob. In the end of that presentation (last 10 min), He argued that we should abstract everything (Even frameworks) from our business logic. JAVA EE does a great job in doing so. UI is abstracted by JSF (and other technologies). The database is abstracted by the persistence layer (...
There is a pattern in C# classes exemplified by Dictionary.TryGetValue and int.TryParse: a method that returns a boolean indicating success of an operation and an out parameter containing the actual result; if the operation fails, the out parameter is set to null. Let's assume I'm using C# 8 non-nullable references and...
So this is my DataStructure: Project - Name - ID - Image - History - User - Comment When my application first starts it is pulling all projects with all details. obviously very slow -high RAM (mostly because of images) For now it is working but as projects add up performance is getting more wor...
I want to build an app that will have have several monoliths. My question (similar to this one) is, how do I centralize User model between these apps, i.e. how to deal with user management/authorization/authentication without duplicating code. For some context, I'm using code driven development with Django. This is wh...
Are there any guiding principles of OO design to take into account when deciding which of two interacting and linked objects should be included as a component into the other (or referenced from it)? For example, I am trying to realise the A* shortest path search algorithm with classes and objects. Besides a given grap...
I have a microservice(opsApiServ) which hosts API to do operations(ops). /ops - POST, GET /ops-item - GET ops-item is just a single unit of operation, and ops is collection of operations (ops-item). Since, there are payload and getaway timeout limits, we just let clients do only 5k ops in one request. Now, there are ...
I couldn't find a question on SE but it has probably been asked elsewhere already (in case, please mark it). A method containing code to run just with specific external conditions can: decide whether to execute after checking those conditions, or just blindly run, sticking to the Single Responsibility Principle; and l...
I know, there are lots of sources on the internet, but I do not understand them. Wikipedia: "Late binding, dynamic binding, or dynamic linkage is a computer programming mechanism in which the method being called upon an object or the function being called with arguments is looked up by name at runtime". I do not unders...
Could someone give a hint, in plain english, what it means to debug an HDL program? Debugging is understandable as far as it concerns software but at this low level what does debugging means?
Suppose I'am writting a GUI desktop application which has a main window with a corresponding presenter. This main windows may host one or multiple panels which each also have their own presenter. The main window has a an input field where the user can set a global option. The panel sub views need to react to a change o...
Before I started using auto-implemented properties, I was taught that when assigning properties in the constructor (because of the potential of making a property read only), I should assign directly to the private member for the property (which we would usually name with the property's name with an underscore in front ...
For example, suppose I have a class, Member, which has a lastChangePasswordTime: class Member{ . . . constructor(){ this.lastChangePasswordTime=null, } } whose lastChangePasswordTime can be meaningful absent, because some members may never change their passwords. But according to If nulls are evil, what ...
In my current case, I've got two variables. Let's call them action and status for ease of use. They can have any value between 1 and 9. Depending on business logic, I've to either call subActionA() or subActionB(). I'm trying to write this in the most readable way, and so far I'm not happy with the results. What I've e...
What is the best way to prevent wrong states in an object? This is the source of my question. Basically my curiosity started with the intention of not letting a class exist with wrong values. Prevent programmers from making mistakes in class implementations and extensions. I did not want a class to even bother to have ...
I'm dealing with a higher-level data abstraction that I would appreciate some input on. I'm working on an application that uses a large data lake. The data lake is consisted of thousands of large binary files (250MB+ up to many GB each), each of which contains a very small amount of metadata (a few kB) that uniquely id...
I have a single web server running multiple web applications and websites. For simplicity we'll just say I have App A,B,C and websites D and E. All use a shared database and some tables are used in more than one app/site. I'm at a point where I'm looking at restructuring a lot of this code, but I'm trying to figure out...
Why do the compile times not vary significantly between different era CPUs, even though disk (NVMe vs. HDD) and CPU benchmarks vary significantly in performance? Why does disabling hyperthreading affect performance significantly with the Ryzen CPU? Over the past few months I have seen some different machines all runn...
I heard that there is some DB design in relational databases where updating a record will create a new record with different timestamp or status. Also, deletion will be soft-delete (it updates the status or effective date to past date). It does not actually delete the record. I would like to know if there is a name for...
I want to place validation in one layer for the reason of simple code maintenance. I was thinking of entity validation, cause this protects directly database. Am I right, or should I add validation also on dto level? I would be happy, if someone share his experience on the topic.
I have a doubt about if there are some recommendations for call directly an attribute in a class I think that in OOP you always should call an attribute by the get method. For example: On set public setAtribute(Atribute atr){ this.atr = atr;} On get public Atribute getAtribute(){ return this.atr;} On the constructor...
As far as I know, the single responsibility principle concerns functions, classes and modules. Now I am designing a database and I wonder if this principle should be applied to relational tables. Concrete example: I see lot of similar design cases as the following table shows: CREATE TABLE Units ( UnitId TINYINT UNSI...
(Probably my question is somehow similar to this, but I'm interested from the point of program engineers.) What are chances and under what circumstances, a computer program could ever made a mistake itself? Like the program didn't evaluate true conditions: if(true) { ... } I assume that a hardware issue in CPU mig...
I'm constantly supporting a specialized downloader I wrote 5 years ago! It has to login and download from more then 40 sites. I have kept changing the code over and over as I encountered new sites or when a site's structure completely changed. This approached worked until now, but recently more and more changes are com...
Consider two facts of a typical organization: Some entities are very common (e.g. Order in a POS system) Some entities might have complex relations (e.g. Order might have a list of Items, a PaymentMethod, the Address of the customer and such) Say the organization had a lot of (REST / json) micro-services and they all...
I have been learning to create water waves in a mesh from a paper commonly known as the Tessendorf paper. Which is quite well known. But those who don't know this is the equations it mentions in the paper: The paper is here (and is freely available, it is not protected): http://citeseerx.ist.psu.edu/viewdoc/download?d...
I have n classes that extends from a State class, the purpose of the State class is to manage the state of the extended classes. For each class we need to save it in the database, remove it and select all the data in order to recover the classes to the same timestamp we stopped (in case of system failure or shutdown). ...
I have a database which stores timestamp, and a UI frontend which contains a date/time field and a time zone field, where the user is supposed to enter the local time into the UI for convenience. Specifically, I am recording the start and end times of past (not future) local events. The date/time is converted to UTC ti...
In a software library, I wrote, large parts of the code use x509 certificates for various purposes like signing documents digitally. Is there a best practice for storing test certificates used for the unit tests? Should they be stored in git/the same versioning system where the code is?
I wanted to ask if this is a valid class diagram: I tend to think not, because it forces a certain wheel to belong to two vehicles at the same time (because of the 1 multiplicity). If the multiplicity on the vehicle side were 0..1 it would be OK. Is this logic correct? Additionally, if this logic is correct, how woul...
To provide a bit of context, the system I'm working on is a football database. A Squad has a collection of Rivals. Arsenal (Squad) has Tottenham and Chelsea as rivals, where Chelsea has Tottenham and Leeds United as rivals. These rivals are also Squads. I'm thinking 'Rival' should probably be a value object, but I'm no...
I don't have a lot of experience with these kind of issues, but I feel I need to consult on this issue. The current codebase I'm working on is using what I consider to be a questionable technique to reference entries in Database tables. We have a system where for certain rows the value in that row is referenced with a...
I am trying to get a database instance via any model-class that uses the database. This is ideal in my opinion: class UserAuthenticator { private $db; private $customer; public function __construct(Database $db, Customer $customer) { $this->db = $db; $this->customer = $customer...
Given these lines of YAML: version: 1.00 y: 1 What does this represent? According to the YAML spec (I'm not a delicate enough to read the spec like a lawyer), does this necessarily represent that a key str("version") maps to a value float(1.0), and a key bool(true) maps to a value int(1)? Or is it up to the parser to ...
I'm currently working on a protocol which passes automated instructions between separate organisations. I'm looking for a way to delegate authentication of devices to which ever organisation a device belongs to. This doesn't affect authorisation models, only authentication. So to put this in terms of DNS domains: or...
I'm trying to realize a service that executes operations at a certain time, those operations are specified by another service by messaging, here's the scenario: The service A receives a request to create an object, the service stores the object in its own database For every object, an operation must be executed at a g...
My manager recently promoted me to "software designer". I am not aware that this title exists. As far as I know SAs creates high level code design and do diagrams. I have a hard time understanding what high level code design I should do. According to my manager, I should design all classes and all methods inside those ...
In statically typed languages or dynamically typed languages that use a type checking system you can guarantee that the input type is the type that you specified in the contract. However, in dynamically typed languages without type checking systems in place you don't know how other people will call your function. In th...
I have created a Angular 7 web app data-driven display of navigation items and content to be shown when a nav item is selected. I have the following nav item interface: interface NavItem { title: string; icon: string; link: string; pages?: NavItem[]; } Where it can be implemented like so for an Angular route: ...
I am writing a library call that will allow you to filter and map in the same iteration of the loop, this is async/callback style in Java. The problem of course is that for filtering we usually return true/false, but for mapping we need to return the value we want. So I am thinking of something like this: (val, v) -> {...
I am working in a fairly old code base. In the code base they have the classic source control, gigantic code blocks at the top of the files and above the function definitions that have something like date, name, and what they changed. I wanted to start refactoring the code and remove these blocks but not lose the histo...
It seems like HTML5 has about a zillion different layouts and methods for positioning divs, few of which seem to work exactly as described in most browsers. Imagine an implementation of, say, Tetris in HTML/CSS/JS. So you have some kind of background, some pieces already on the screen, and a moving piece, all of which...
I'm working for a company with a big ass legacy codebase. Changing existing code is like a guarantee to break things. Most functions are a few thousand lines, using some global flags, having different modes, which basically leading to a totally different functionality. Refactoring most of these things is impossible and...
I'm relatively fresh out of college so most of my familiarity with relational databases is from my databases course where anything not in BCNF or 3NF is a travesty. Certainly that's one end of the extreme, but my team at work really seems to take it to the complete opposite end. In our microservice db schemas, entities...
What is the best practice when it comes to passing variables around? Is it better to pass objects (models) or is it better to pass primitives that will be required by the called method? What are the pros and cons of both approaches? For example one con of passing values (Example 2) when you suddenly require the user's ...
I have the following case: We register data from sensors. Let's say that it is a value reported every second, for one hour a day. So we have over 3k values. These values are processed to try and eliminate sensors' faulty behaviors. At the end, there are some performance indicators calculated based on the processed set ...
I'm trying to create a flexible datamodel and i'm not sure what's the right approach. My application is used by several clients (big and small). Big clients need all the seperate layers, but small clients only need a few. Here's what i mean: Flexible requirements Big client: company rayons locations departments users...
Currently I'm leading a team of 4 developers, all of them started their careers 5-6 months ago. I can consider ourselves lucky, as we've been assigned to a greenfield project, it's completely up to us to achieve the business goals. The company itself is quite small and they have a long history of maintaining legacy app...
I have written a code in C# to generate the power set of a given input list of integers. public List<List<int>> GeneratePowerSet(List<int> Set) { int setCount = Set.Count; int powerSetCount = 1 << setCount; // Temporary list to hold the all subsets List<List<int>> subsets = new List<List<int>>(); ...
A few developers and I are attempting to refactor a class that has grown too large. Currently this class is around 3K lines long. The goal of the refactor is to make the logic more maintainable. The class holds our validation logic, which performs various checks to make sure things are good before moving to the next st...
All of the controllers in our project are as dumb as we can make them. Rightfully so, they simply validate the incoming payload, hand the request over to a service layer, and return whatever response is necessary; http status code, json, etc. I'm trying to see if I can trim down the number of tests we're writing so tha...
Microservices are the latest software development craze. All the kids are doing it. When I started hearing about the concept, the first advantage that came to mind was the single responsibility principle. If you take the principle from other aspects of the software engineering principle, it seems to follow than a servi...
On Linux Mint 19 with C++ compiler version: g++-8 (...) 8.2.0 I am compiling and running my project named: getPixelColor Using a shell script: #!/bin/sh g++-8 -std=c++17 -Wall -Wextra -Werror -Wpedantic -pedantic-errors -o getPixelColor getPixelColor.cpp -lX11 && ./getPixelColor "${@}" Finally, I defined a personal ...
I have have a business process that receives an order request which also includes full customer information. In the cases where the external customer ID from that order request is not found in our DB, we need to process that piece of the "create order" command, before we can actually save the order for that customer. I...
I have a product which has a un-normalized legacy data model which contain millions of records. This has cause problems when adding new features and with performance. Also this contributes to high storage requirements at data file level on databases. I'm looking into a finding some good architectural patterns which i c...
I'm moving from REST APIs to gRpc but having a hard time figuring out how to structure my logic. The basic layout of my solution is having a business layer/API and a few different front-ends (Windows app, console app, Web app, etc). I would like to have each of my front-ends simply be able to connect to my network usin...
I have a class Item. Then another class ItemCollection holds std::map<int,Item> item_collection_. The reason to create the class ItemCollection is if I want to do something with collection of type_a I can delegate that task to class ItemCollection. For me this seems normal way of doing tasks on those collection of item...
I want to know others opinion about this approach that I use in a lot of projects, for example, I can show the last time that I use it: public class DataStorageService { private enum Keys { USER_NAME("userName"), USER_ID("userId"), TELEPHONE("telephone"), EMAIL("email"); private final String key; ...
Context: I own a service that's distributed across VMs, that themselves are distributed across multiple data centers. Scenario: I'm adding an API that calls a single downstream dependency. This dependency has a very small throughput (relative to the API). Further, instead of just returning 429 if it's called too often,...
I am working on my first web development project, SQLite4Web. Long story short: SQLite4Web is a web interface for SQLite database files. The user can access their database via /db/{dbToken}, where dbToken is the database's unique identifier. In all cases, the HTML file sent to the user is the same (index.html). The htm...
I'm giving a talk on concurrency which will cover multithreading, multiprocessing and green threads. I'd like to give simple real-world analogies of single threaded programs, multithreading, multiprocessing, and green threads. These are the analogies I've come up with: Single kernel thread - A single line of customers...
I have an in-house built job scheduling application that accepts Job configurations in form of Apache Config files (something similar to XML). There are tons of configurations (for example a way to specify a dependency on a job, way to provide configurations related to auto-rescheduling a job on failure and many more)...
For example, I have an interface Requests that basically lists all the requests a client can make to a server program. Now an obvious problem arises where I have to add a new request to the program i.e. the interface. Existing implementing classes would then have to implement the newly added method in order to compile ...
I am struggling with the clean architecure. I have constructed a minimal example of how a usecase/interactor could talk to the database without being dependent on it: The use case: class SaveDatatoDBUseCase: def __init__(self, AbstractDB): self.db = AbstractDB def execute(self): self.db.save() The gateway: fr...
After doing a bit of reading, I have a vague understanding of the use of a stack in calling functions when one function calls another, where the arguments are placed on the stack for the called function to retrieve them. So, in the following example, calling the function add, would place the values 5 and 6 on the stack...
I am currently reading through Robert Martins book "Agile Software Development" book and I am struggling to see how his modem example provides any benefit. He says that he has an interface that violates the SRP interface Modem { public void dial(String pno); public void hangup(); public void send(char c); pub...
In a bit of a dilemma. At work we are having issues with an API service that communicates with the client side through a WebSocket. The problem so far is that the WebSocket seems to be unreliable. We have sufficient logs that tell us this, but for some reason everyone is on the boat about adding logging to the front en...
I have a table "products" and a child one "product_modifications" Some products have "product_modifications": "colour", "size",, .... But not all. When a client orders a product, views pictures and other things, he might do that with either product or its modifications, depending on whether or not a particular product...
Algorithm explanation: based on an unsorted list I want to find the indexes of the values in another sorted list. Note that all values are unique and the two lists have the same values, only in different order, for example: # O(log n) def binary_search(data, value): n = len(data) left = 0 right = n - 1 ...
In an application that doesn't use an ORM, is it good practice to check whether an object exists before attempting to update/delete it? For example: @Route(method="DELETE", path="/posts/\d+") public function deletePost(id: number) { let post = model.getPost(id) // this method does a SQL SELECT if (post ==...
(Assuming a single-threaded environment) A function that fulfills this criterion is: bool MyClass::is_initialized = false; void MyClass::lazy_initialize() { if (!is_initialized) { initialize(); //Should not be called multiple times is_initialized = true; } } In essence, I can call this fun...
I want to make a social game for Android. I am using NoSQL Based Database (MongoDB) and I am using NodeJs. I am using Android-Volley library to make POST and GET requests. But I am stucked on something, I need to see friends of friends or send some game requests or friend requests from one user to another. However, I a...
As defined in the documentation of the gamma parameter for Tree Booster: Minimum loss reduction required to make a further partition on a leaf node of the tree. The larger gamma is, the more conservative the algorithm will be.
I'm writing a reader for the custom binary file format used in one game. The format has multiple versions for example: struct FileHeader { ushort version; uint fieldX; // version 1 uint fieldXX; // added in version 3 uint fieldY; // version 2 uint fieldZ; // version 4 } The problem is, different versio...
When I was a beginner it took a while to learn the language syntax and the idea that languages couldn't improve after they were invented. But now we're seeing new language features added every year with ES5, ES6 the so on. If I don't write software for a few weeks or months when I come back to it I have often found f...
So the scenario is that I'm asked to redesign and refactor a REST API by combining multiple endpoints that do similar tasks. For example, now I have 10 different endpoints that are all used to upload different resources e.g.upload_job, upload_script, upload_action, upload_sound ... The main idea is to reduce the number...
Context: I recently found out about Semantic Versioning, and am trying to determine how to best use it practically for my own projects. Given that semver takes major changes, minor changes, and patches into account for versioning, when should a commit not be tagged with an updated version? It seems to me that every cha...
I am dealing with C++ code that I want to model it as component diagram (UML2.0). So, a main step is to realize which parameters are input & output signals. One problem with that is: Not every parameter has to be an input/output signal, because it can be passed from or read by an external function in other module. An e...
I found a great project on github with a useful central feature but which is rough in the "polishing" of error handling, logging, config, and setup. The project is 5 years untouched, and only a couple hundred lines of code. Still it's useful enough to have brought itself attention for a decent number of watchers and a ...
The codebase I'm working on frequently uses instance variables to share data between various trivial methods. The original developer is adamant that this adheres to the best practices stated in the Clean Code book by Uncle Bob/Robert Martin: "The first rule of functions is that they should be small." and "The ideal num...
I am trying to refactor a huge chunk of our software, and it requires to set up a factory. However, I am not sure where lies its responsibility. (PS: The code below is shown simply as an illustration and may not be perfectly designed, please do not unleash hell on it :() Should the factory only return the correct inst...
I am writing a gui that is supposed to replace a fairly large shellscript in order to make the usage easier for not-so-technical people. The script calls a certain program (saga_cmd) multiple times with different parameters, i.e. saga_cmd grid_calculus 8 -GRIDS "TriGridResult.sgrd;TpiGridResult.sgrd;SlopeResultGrid.sgr...
In UML sequence diagrams, given two objects A and B, if Object A sends a message to Object B. Does this mean the message is a method in Object B which is invoked from Object A?
A colleague, and frankly better software engineer that me, is telling me that this pattern let variable = someDefaultVariable(); if (some_boolean) { variable = someOtherValue(); } is better than this pattern let variable if (some_boolean) { variable = someOtherValue(); } else { variable = someDefaultVariab...
A SW-Component "SWC-A" is integrated with a SW-Component "SWC-B". The SWC-A has an output interface which provides "Distance in meters". The SWC-B receives this value and does some calculation. If in SWC-B interprets the received value is interpreted as "Distance in Feet" and not in meters. How can this scenario be te...
Let's assume, that frameworks I use, provide some kind of dependency injection automatically available in testing environment. Let's also assume, that I have a lot of micro services in my application. Testing each of them separately in ideal unit tests scenarios doesn't bring too much value to me. It is usually because...
I was just studying the interdependence of state and behavior exhibited by the state of an object and its behavior.was wondering if an object can have behavior without having state. Because i am very sure that the other way around is very much possible
This came up when a developer brought in these planning poker cards, one of which is Yak Shaving. There are various articles on google/wikitionary which basically say: Yak shaving is programming lingo for the seemingly endless series of small tasks that have to be completed before the next step in a project can move f...
I am trying to understand UML class diagrams. Imagine two classes that are related with each other by association. What is the difference between {ordered} and {sequence} for the association?
Do you think its a good OO practice to use parts of an object to build itself? Here is an example. var car = new Car { Make = BuildMake(), Model = BuildModel(), Vin = BuildVin(), }; car.Wheel = BuildWheel(Car.Vin); In the case above, I had to move the wheel out of the initialize ...
First of all, C# solutions are needed. So in my team I am responsible for creating a program that will receive a "task" in json format from an API, from this json it needs to figure out what website to create an account for, for example: wordpress.com weebly.com whatever.com Now, each of these sites will have separat...
I am in the process of building an heavily data-driven web application written in Node.js / Typescript with Mariadb for the database engine. I am trying to put an emphasis on extensibility and DRY principles. One thing that I've come across that is repetitive and time consuming to write code for is data validation. So...
I understand OCP in SOLID can be applied when we have same set of interfaces defined via abstract type, so that we can have varying implementations of those interfaces via concrete types. For example, I have my business logic working with IRepository with defined set of operations: interface IRepository<T>{ void save(T...
I understand that in OOP languages like C#, it is generally viewed as bad practice to create utility classes, and it's preferable to put methods in the classes in which they will be used. To that end, I wanted to create a transpose() extension method for double[,] types; however, it told me that extension methods must...
I have Facade class which requires an Endpoint instance to function (it uses it in most of the functions). Endpoint is attached to Platform that is passed in Endpoint's constructor and has to be started (Platform.Start()). Both Platform and Endpoint come from external library and use Start/Stop pattern. Before Facade i...
Let's say I have a react component like this: const MyComponent = ({data}) => (<div>{JSON.stringify(data)}</div>); const myReduxSelector = (state, id) => state.someData[id]; export default connect( (state, ownProps) => ({ data: myReduxSelector(state, ownProps.someId) }) )(MyComponent); Now this work...