instruction
stringlengths
34
36.1k
I recently had a discussion with a friend about code maintainability with regards to modifying an iterator inside of the body of a loop (C# syntax): List<int> test = new List<int>(); for (int i = 0; i < 30;) test.AddRange(new int[] { i++, i++, i++ }); The code works fine, and as expected adds 0 - 29 into the list....
My team and I have this Desktop client developed in JavaFX. It basically has a "Remember my password" checkbox. If the user ticks this checkbox, reboots, and reopens the app, the user should be automatically logged in. I'm using a cheap trick just saving a temp file to the temp directory. It's encrypted and it contains...
I'm actually studying about web development. I was just asking why a lot of web apps and chats(Whatsapp, Telegram, Discord, and a lot, a lot more!) are using cache. I mean, after learning cache systems like Redis and Memcached, I was asking how could I use them practically. For example, Redis can cache entire pages for...
From general observation I've come across the standard to be 36. I was looking to incorporate a uuid in my urls but didn't want it that long. Is there a minimum where I can still keep the uuid unique?
I'm designing a relatively simple web application using .net core. I've mostly done desktop development in my career so far, so I'm a bit new to the nuances between desktop and web development. In this application there is a business logic layer and a presentation logic layer which takes the business logic and transfo...
Although I understand privacy concerns, the measure has been imposed by politcians and I want to know what the proper way to put this into place would have been. Right now, each site has to implement GDPR compliance which is kind of redundant with no promise that your wishes are actually respected. Wouldn't it make mor...
While designing a complex system some of my colleges came back with the idea of having two separates APIs, one that will perform the writes into de databases and another one that will only do the reads. I fail to deeply understand why separating those two concerns can be useful for the whole system. It can be useful wh...
Relatively new to Domain Driven Design i decided to try it out in an saas app currently under development/refactoring. I've refactored the identity part out to it's own context (class library in .net) and came up with the following Domain models: Organization. Is an Entity and Aggregate Root (all users in the system s...
I have a collection with millions of items of Generic type T. Assume this list never changes. I want to perform many types of searches with subsets of fields of type T. Some with only 1 field and others with 2 or more fields. Each search almost always returns more than 1 result. This answer is very close to what I want...
I'm working on a problem, in which i have some real time weather information of different cities through out the world. I'm exposing subscribe function to interested people/clients, with input:- location(this would be the name of the city) and time(HH::MM::SS). Now, lets suppose, N number of people subscribe for Locat...
UML Diagrams says: A use case is a kind of behaviored classifier that specifies a [complete] unit of [useful] functionality performed by [one or more] subjects to which the use case applies in collaboration with one or more actors, and which [for complete use cases] yields an observable result that is of some ...
While mostly every company got it's standard on APIs, the question just came out after that one of my colleagues stated we must use different object models for creating and getting objects from API. To be clear, he states that when you want to get the object from the API you will receive an object like this: { id: '11...
I am trying to figure out the optimal branching strategy for my organization. And I have few doubts. We have 3 main environments, Live(Production), UAT (pre-release) and Staging. Similary in GIT we have 2 Major branches. Master(State of Prod) , and Dev. Developers start with checking out Git Dev and creating a feature ...
I'm looking for a design pattern that might work for this class I am working with. This main class is an entity using Domain Driven Design. public class TimeCard() : ITimeCardHeader { public int TimeCardHeaderID { get; pivate set; } public int ContractorID { get; internal set; } public S...
I have one request interface IRequest and two classes ClientAddress and ClientOrder are implementing it. The same design is followed for Response with inteface IResponse and classes ClientAddressResponse and ClientOrderResponse. I have tried to do it 2 ways but I am not sure which is better way With Explicit type cast...
I want to have two methods, one which returns all items and another, which returns specific Item by name (assume Item has name field): Item getItem(String itemName) List<Item> getItems() How should I name these methods? I'm not sure about getItem and getItems cause these methods just looks too simular (it's hard to ca...
An application I'm considering writing needs to show a text that a user has edited at a particular time. So consider if we have a text the user is editing from Time A to Time X, and I want to show what it looked like at Time L. This text can be for a long running process, and it can be theoretically big, therefore it ...
I recently started working as a programmer and I am currently going through some codes (in C#) written by my colleagues. I have noticed that they tend to include logic within function calls within some conditional statements. For example: if (MoveSpace(currentPos, distance * time)) { doSomething } They would also incl...
I am developing a financial system and want to have a defined policy for rounding monetary values. Given the following layers: View API Entity Model Persistence If I am passing a monetary value through these layers, and maybe using it in calculations in the model, at what layer (if any) should I be applying my "defau...
Scenario I have an application where some operations require the authentication of an admin. Example Steps: I need to validate the admin's username & password insert a row into a MySQL table (if credentials are valid). One Trip Approach If I use a single Connection to the database, with multiple PrepearedStatements...
I'm trying to encapsulate permissions logic for a particular view model in a way that the permission logic has access to the view model object, but is also exposed inside of it Trivial Implementation: public class ClientViewModel { public Client Client { get; set; } /* permissions section */ public bool Ca...
Why do I define my Queries, Data, and Mutation as Singleton when using GraphQL in .NET Core? From the doc's dependency injection page: public void ConfigureServices(IServiceCollection services) { services.AddSingleton<IDependencyResolver>(s => new FuncDependencyResolver(s.GetRequiredService)); services.AddSingleto...
A language agnostic approach since I see this problem in both compiled and interpreted languages with the builder pattern. Let's say I have a Model that has 10 required fields and 5 optional fields. Of course, adding all these fields to the constructor would be a mess, but the constructor would allow us to easily chec...
I would like to be able to debug building a binary builder. Right now I am basically printing out the input data to the binary parser, and then going deep into the code and printing out the mapping of the input to the output, then taking the output mapping (integers) and using that to locate the corresponding integer i...
e.g I'm parsing whole Excel file with many rows, that has an column which contains Date. I'm not sure how to handle error-handling when it comes to parsing string to DateTime Here's an sample code which is in C# for (int i = 1; i < sheet.RowsCount; i++) { // cells are strings var cells = sheet.GetRow(i).Cells;...
Most of the react application I've seen are organized with components that, in my opinion, do too much. They may follow this pattern: class MyComponent extends Component { constructor() { this.prop1 = this.props.prop1; this.prop2 = this.props.prop2; } render() { //.... } o...
Currently i'm working on a small platform with a simple client-server model and will soon go in a closed beta with a launching customer. In essence it's an Electron application which is mostly used for logging in, and fetching files/information from a simple PHP+MySQL backend with some other related functionality rega...
Let's take the classical example of a function that may return a number or not. In typescript this can be represented like this: function f(): number | undefined {} A more elaborate way would be to build a maybe type and use that for the typing: type Maybe<T> = T | undefined; function f(): Maybe<number> {} To check ...
I am working on a project where logs of all kinds (e.g. errors, warnings, etc.) are stored in a database table, in the same transactional database used for the other business purposes. It is a MSSQL database. A good practice is to use a NoSQL databases to store logs, stream them and query them (e.g. using the ELK stack...
Generally, I read that large methods benefit from some sort of inlining and the C# compiler does this sort of micro-optimizations automatically. I understand that if a method is called just one time in an enclosing method, performance might improve when inlined even if the method itself is large. However, if a large me...
Kubernetes provides a very elegant mechanism for managing configuration for pods using ConfigMaps. What's not clear from the documentation is what the recommended practice is for using ConfigMaps to manage different configurations for different environments, and also to deploy configuration changes when they occur. Ass...
I have a very large monolithic legacy application that I am tasked with breaking into many context-bounded applications on a different architecture. My management is pushing for the old and new applications to work in tandem until all of the legacy functionality has been migrated to the current architecture. Unfortunat...
I am trying to do a design for notification part in the system I have 2 parts inApp notification and email notification so I used strategy pattern where I have interface NotificationSender with one single method send NotificationSender{ public void send(A,B,C); } then I have 2 implmentations InAppNotificationSende...
We have two teams, each using git, and would like to share a small project between them. Git submodules sounded like an obvious answer until I started searching and found lots of "submodules will bring you pain!" opinions out there. An answer to a related question here suggests git subtree, which seems to be baked in...
I'm trying to create a website as a forum similar to Reddit, but on a smaller scale (no comments also). The website will allow users to post a link to a forum. Then they can view a list of New or Trending links based on upvotes (gathered from an external API). So basically all I need is to have a REST API to post links...
Consider an abstract example, just to illustrate - you have a service for loans, which gets requests to borrow X USD, checks if there’s enough USD to lend that, if yes - marks that amount as reserved for a loan and sends a message to another service which actually processes the loan, and responds with success, if no - ...
If passwords are stored hashed, how would a computer know that your password is similar to the last one if you try resetting your password? Wouldn't the two passwords be totally different since one is hashed, and unable to be reversed?
We're building a new web-based industrial application and one of the questions that are hammering our heads for the last few days is about the integration between different "microservices" on this architecture. I'm using microservices with just a pinch of salt because we're not totally embracing the concepts to define ...
We're trying to re-think the installation process of our software suite and I'm trying to find out what specific pitfalls we're facing without using my/our limited lens of the Windows software landscape today. We have gathered a set of issues that an installation of our software potentially has to handle, and I would l...
I have many models in my project that are unrelated to each other. I wanted to group them but I wonder what's better: Folder/namespace per group Group1.Constants, Group2.Constants Group1.Models, Group2.Models Group1/ ├── Models/ │ ├── Class1.cs │ ├── Class2.cs ├── Constants/ │ ├── Constants1.cs │ ├── Constant...
So the basic scenario is I have a class that starts/stops service objects with the methods start(String serviceid)/stop(String serviceid). It is designed to then forward various execution tasks to the appropriate service. What I am trying to achieve is for the start/stop methods to be non-blocking. Hence if you start y...
We are trying to move from a monolith application to a microservice architecture faced by a spa application. One of the reason, is that we want to expose some services of our business to partners and another reason is to build a better user experience via an spa application. In the old application I had a webapplicatio...
The pain that I've often felt when creating database migration files, is best described in this Speakerdeck: Sane Database Change Management with Sqitch. Paste entire function to new "up" script Edit the new file Copy the function to the new "down" script Three copies of the function! And I end up with no clear di...
Please let me illustrate with a simple example. Suppose we have a Weather object: class Weather: def get_forecast(self, day, place): forecast = "code that calculates forecast" return forecast On the other end we've got a weather forecast web app that accesses the Weather.get_forecast method direct...
I have <5 years experience in the software industry and this is my first time doing QA. Before the stories in a sprint move to UAT, I am supposed to retest every single story in ~1 day in an environment between QA and UAT. The purpose is that multiple teams have their own QA environment where they exclusively test the...
I'm creating a proof-of-concept for a Go-app for my organization. I've read all of the intro docs on setting up a Go workspace, packages, etc. However, I am still unclear about the relationship amongst the recommended directory structures, packages, AND the fully-compiled applications that will eventually be deployed. ...
I am currently writing a memoire on the evolution of developing tools. Among them is of course the programming languages. I made some researches, and a lot of the most popular languages are scripts languages like Javascript, Python or Ruby But when comparing performances, they are not as efficient as VM languages or co...
I have a script that migrates data in the database. It copies property X to property Y. If I want the script to be idempotent, what should it do on subsequent call if X changed? For example: X is 'a' ==> I run the script, then Y is 'a'. now X is 'b' What would subsequent call to the script do? set ...
My application has a grid with a list of Car objects from a third party system [{id: 1, make: "Ford", model: "Focus", ...},...] The user can select a Car and use its data (after some transformation) to create a Car specific to my application. The app does this by filling in a form on another HTML page with the transf...
I have a class that uses constructor DI for IEventAggregator public SomeViewModel(IEventAggregator eventAggregator) { this.eventAggregator = eventAggregator; eventAggregator.GetEvent<SomethingChanged>().Subscribe(UpdateResults); } I have another method in ...
I want to setup a dedicated test computer that can be restored to a specific system state. The reason for that is that the software tests to be executed on that machine include the installation process. Software can certainly be uninstalled, but that often does not revert the whole system back to its original state. I ...
In most definitions of negative testing, the idea is that we test outside what is specified/expected and it is highly related to robustness. So basically, if the behavior for such conditions is defined, I would be positive testing as we verify behavior that is specified, isnt that so? An example requirement: REQ1: Nam...
I am new to ef and liking it since it reduces the overhead of writing common queries by replacing it with simple add, remove functions. Agreed. Today I got into the argument with my colleague who has been using it for a while and approached him for advice on when to use Stored Procedures and when to use EF and for what...
I'm working on a server, which you can pass some form of authentication as input (like connection string) and it will connect you to your database. So the DB connection is going to be dynamic. There can be multiple users at the same time, connecting to different databases. What I'm wondering is, is there a preferred wa...
I am planning some app as a part of our product. One part of the app will be to receive push messages. Sometimes it's months between uses of the app and, by experience with other apps I've used, it seems like there is some timeout. If you don't use the app in a while, it will stop receiving push notifications. So, doe...
I'm trying to modernize a very old PHP application for a customer to keep its code base up with modern coding standards. I am permitted to restructure things a bit, but dumping the entire app and switching to an existing framework is not yet an option. I just need some general tips on how best to restructure the applic...
Let's say you're loading a denormalized flat file of purchase transactions that looks like this: | location_name | location_zip | product | product_price | |---------------|--------------|---------|---------------| | downtown | 90001 | fries | 2.99 | | west side | 90048 | burger | ...
Anyone know, how many users are valid to use the prototype of the software that we have made? I have conducted research on the reference to the "Software Engineering A Practitioner's Approach book Roger S. Pressman". There is no mention for valid users of software testing?
Is it a bad design pattern / anti-pattern to create a whole bunch of specific middleware to replace functions in-route. So instead of doing this router.post('/myRoute', (req, res, next) => { checkParams(req.body).then(paramsResult => { if(paramsResult.status === 'failed') return res.send(paramsResult); ...
What data structure i can use to lookup given a fromCode and toCode apart from hashMap which results in more number of entries in the memory. We are ok with log(n) efficiency also. Example data: fromCode toCode distance 100 200 10 100 300 20 ----- ---- ---- Assume fromcode and to...
Currently: ASP.NET Core 2.2. I've been doing quite an extensive research in this topic (Domain Driven Design used together with Clean Architecture): DDD: Where to place domain event handlers? And I've seen a couple of DDD and Clean Architecture Repos to better understand: https://github.com/VaughnVernon/IDDD_Samples_N...
I am working on a web application which allows users to review pdf documents. These documents are submitted from another public facing website. A typical workflow involves: A document is uploaded on the public facing website and stored into document management system (DMS). The internal web application grabs the docu...
I am trying to add a new template to an existing CodeIgniter 3.0 project where the original developer had not planned for additional templates/themes. The primary objectives are to: a) make a usable copy of all existing views and css files and leave the originals unchanged. b) allow for core updates as they are release...
My question is how I can achieve more encapsulation in TypeScript. I have a class Item, with a public setter isOwned, but I only want to call this method in specific situations: if the item is picked up or dropped by a Player. /** @package A */ class Item { private _is_owned: boolean = false // ... /** ...
I am recently studying computer science and I was introduced into boolean algebra. It seems that boolean algebra is used to simplify logic gates in hardware in order to make the circuit design minimal and thus cheaper. Is there any similar way that you can use it to reduce the number of code lines in your software in h...
I have a C-coded function that realizes a very long calculation on a microcontroller. I try to optimize it for speed at the moment. The function content is created automatically using Mathematica. It has hundreds of calculations and looks like this: void calcResult(float *result, float arg1, float arg2, ... float argN)...
I like to write classes with two constructors: a primary constructor used in production code, and a default constructor just for unit tests. I do this because the the primary constructor creates other concrete dependencies that consume external resources. I can't do all that in a unit test. So my classes look like this...
I would like to save the current "value" property of several components (e.g. a Slider) as a configuration profile when the user clicks on the Save button in my application. However, the Save button is in a different file than the rest of the components. How should I deal with this? Some solutions that I have thought: ...
I'm working on a .NET Core REST API and I'm writing a service class to create new user accounts. I have the following code: public async Task<UserDto> RegisterNewUserAccount(CreateAccountDto userInfo) { EnsureUserDoesNotAlreadyExist(userInfo); EnsureRfidCardIsNotAlreadyClaimed(userInfo); ...
I'm using a lot of async Task<IEnumerable<T>> methods and I want to stop doing this everytime to get the items as a list: var items = await AsyncMethodThatReturnsEnumerable(); var enumeratedItems = items.ToList(); So, if I do something like this var items = (await AsyncMethodThatReturnsEnumerable()).ToList() Will it ...
Could it also have made sense to call it a "Form", as in the Platonic sense of the ideal form that represents the thing which earthly objects strive to emulate?
Why is argv declared as "a pointer to pointer to the first index of the array", rather than just being "a pointer to the first index of array" (char* argv)? Why is the notion of "pointer to pointer" required here?
My question is about the construction of main loops running in the background listening to commands and signals and how are they constructed to be efficient. For instance in live music synthesis programming languages like SuperCollider or PureData, you have somewhere a sound server waiting for changes in your source co...
Consider the following architecture: Application A Application B Commons-Util A and B share a lot of functionality. That's why we plan to extract the shared code into a commons library. I am aware of the advantages and disadvantages of multi modules vs. separate repositories. However, I'm not sure for what to go in ...
I know that the following function is a virtual function and needs to be overridden when extended by another class: virtual int getAge()=0; What i don't understand is the following syntax I have seen in places: double getAge(int id) override; Is this also a virtual function? I thought the word "override" is only use...
In Javascript, converting [] to a number (e.g. +[]) gives 0, while doing the same to {} gives NaN. This leads to entertaining wats like this: > 2 / [] Infinity > 2 / {} NaN Is there a historical reason for this, the same way that there is a historical reason for typeof null === 'undefined'? http://2ality.com/2013/10/t...
My project relies on a specialized component which is stuck (by its configuration) to an older version of the framework my project is using. This makes updating to the latest version of the framework impossible. What are the best practices when dealing with this type of issue?
I'm having trouble grasping the value proposition of the "command" half of the CQS principle in a system that doesn't implement command query responsibility segregation. The CQS principle states that a method that returns a value is a query, and should never affect state. A method that affects state, should never retur...
I'm writing a program, part of which consists of determining if a given file is a PNG. Knowing that a file doesn't have to be named with its respective filename extension to be of a certain type, I decided to check for it's header. However, after not being able to think of anything better, I wrote this if statement wit...
I'm working on a web project that executes CLI commands to perform running tasks to spare users from having to wait since PHP/Apache combo cannot (to my understanding) create a separate process for said long-running processes. Is the this the best approach for running long for running long processes that do not force ...
I'm in the process of designing a new desktop application which is very different from other stuff I did before, and so I'll be happy if I could be pointed towards the right direction regarding the basic building blocks of it. The application should read a binary file, process it "line by line" and after some chunk of ...
I have a problem to solve that's very much like a thread pool, and I was hoping to hear some strategies or find some resources to information on managing the size of the pool. Let's say I have the following: public interface IWorkerBee : IDisposable { Task Configure(WorkerBeeConfiguration config); Task<WorkIte...
I have made a lot of forms for my desktop application, some forms were using the same method which I have to copy and paste the code (not OOP). Let's say I have a method called FirstDayOfWeek() and this method is needed in 5 forms, that means I need to copy and paste the code 4 times to the other forms. What I want to...
Issue: I provide a small web portal for customers with partial personal data like name, address etc. which is stored in the database in plain text. Now I need a safe concept to encrypt the personal data in the database. The encryption is no problem, but how to handle the decryption of the data? 1.) server-side: proble...
When a caller makes a call to a callee, exception's are used to inform the caller that something different has happened so that he could change the flow of the program if required. In that sense, exception is not an error but a predictable outcome at layer of abstraction it was raised from. Most programming languages s...
My application stores two different types of json data in s3. For example: Schema-Foo and Schema-Bar. Up to now I used the content-type application/json for both. I would like to make a distinction between both types in the s3 storage. I am unsure what the best way would be. Is it possible to do something like applicat...
I am investigating how to test a project. Some information about the project: Microservice architecture, with roughly 20 services. About 10 of them with a separate database. We use ServiceFabric There is a fair bit of service to service communication. Each server is a separate repo. With no references to each other. T...
So I'm running into an issue with us trying to test multiple features in our QA environment at the same time. Essentially, changes are taking too long to get promoted in our CI/CD pipeline. The way we have it set up now, we push feature branches directly into our QA environment if the build passes. We're using docker s...
I have being learning about deep neural networks and how the increase in hidden layers give better results. but the problem that i found was we usually get rid of loops in calculations by using matrices. Is there any way to remove the for loop which loop though the layers in forward and backward propagation?
I have two models in my current design, student and group. Student and group are both aggregate roots. A student can be added to a group (method on group aggregate root), and it can be active for either the whole duration of the group or part of it. The group has an invariant which says that "all students added to a gi...
A company I work with uses a "skeleton" project as base scaffolding for each project they have. I work on several edits to the skeleton. Some of them are few lines on huge source files. What's a good way to document all the edits I'm making?
I have a simple c++ code as the following: #include <iostream> int main() { int a = 5; int *b = (int *) malloc(40); return 0; } Setting a breakpoint using GDB on line 5 and running disas will output the following: Dump of assembler code for function main(): 0x0000000100000f60 <+0>: push %rbp 0x000...
This is a general question seeking guidance for the best practice(s) on implementing a Single Sign On (SSO) across many various installations of the same application. The hypothetical example I would like to pose - imagine you have 200 Wordpress installations / websites that you manage. In order to log into each envir...
I have a switch structure that has several cases to handle. The switch operates over an enum which poses the issue of duplicate code through combined values: // All possible combinations of One - Eight. public enum ExampleEnum { One, Two, TwoOne, Three, ThreeOne, ThreeTwo, ThreeOneTwo, Four, FourOne, Fo...
For my application logs for a REST server, I'd like to log some details about each http request. I'm using sl4j. Should I use logger.debug or logger.info More generally what sort of things should be logged in logger.info?
While researching RESTful API frameworks I've come across (generally speaking) two types of frameworks: The first type will (more or less) directly (or nearly directly) map an ORM/ODM scheme of your database to the resources. For example, tbone. It does give you options for what fields to expose, as well as the abilit...
The issue I care about here is high throughput, there are a lot of sensors (monitoring devices) which send data to the server at high frequency. It looks really like that we have to use UDP protocol for such kind of data transfer. However I've never used UDP for high-level logic API programming, a Web API using http wo...
Working on a huge application with lots of legacy code, I often encounter environment "checks": db_name = Rails.env.production? ? 'staging_db' : 'production_db' ... desired_processes_count = Rails.env.production? ? 6 : 1 ... Rails.env.production? ? "index,follow" : "noindex,nofollow" and so on. It's Ruby on Rails, but...
I am trying to follow scrum framework as much as i can but i am facing some confusion. I like to know what are the standard guide lines for a sprint. I am designing the sprint but i am not sure to get to a concrete value in terms of hrs/day. And what is the standard practice ? Should i also lock meeting hours, deployme...
I'm rather new at programming so I'm still getting a grip on things. I'm creating an offline login system in C# that will have the ability add/remove users. The computer will not be connected to the internet. This was the approach that I was going to take: Have the username and a salted + hashed password in an XML file...