instruction
stringlengths
34
36.1k
I found myself wanting to put a table in a table. I had a momentary war flashback of legacy webpages and email html templates and was about to shelve the idea, but then I considered that it kind of made sense in this case. I have a table showing tabular game information. There are 2 players in a game. I want to show th...
Long methods are generally considered bad, however in my code I have some hard-to-understand long methods (more than 50 lines). I have trouble making those methods easier to read because a single statement inside is already more than 50 lines long, and that hard-to-read single statement is to build a database query usi...
I got a class A that creates an object of type B and persists it on a database. The class B can be created in several ways so it receives an interface ICreator so it can create the object. Problem is that now I found myself needing to do something after the object is persisted on the database. This is a very specific c...
We have a Java Application running on Tomcat as the AppServer & Apache as the Webserver. Currently, we are handling Malformed requests in the Application itself. However, I was wondering if it's better to handle it in Apache by writing some mod or using some existing mod. What's standard practice for this?
I am using DDD approach with c# and for data storage I am using SQL server. Also I am using code first approach with fluent api in order to build database objects from domain. Since I am using domain to write data and finders to read data from SQL, I was thinking about an approach where fluent api in write mode would b...
Basically, TCHAR and the associated macros (_T/TEXT) are only really necessary if you're targeting both ANSI and Unicode, and, like 99.9% of developers out there, the possibility that someone might be using Windows 95, 98 or Me is not really a concern of mine. I use WCHAR, LP(C)WSTR, etc. in my applications. If I'm e...
For each row entered, the user will have one piece of data in either grams, kilograms or pounds. I supply 3 fields and the user must enter in one. The app then calculates the other two values off the entered value. I am wondering if it is best practice to store all 3 values in the database, or just store the single va...
EDIT: note I want a static compile time method, when I know exactly what needs to go where at compile time. I often find myself having multiple functions which follow the same pattern, but only a few parts change. Often I opt for the Template Method Pattern, however class based approaches (especially in c++) seem ver...
Based on this Question and its answer : Object in Business layer same as DTO with logic? I want to ask : What if instead of DAL, I'm getting data from a remote service (API) through DTOs. My DTOs here represent prettymuch the business objects with all the relationships in between. Although there is BOs in the API t...
I came across a DTO class like the below one. class PersonDTO { private String firstName; private String middleName; private String lastName; private String dob; // some 50 fields more private List<PersonDTO> persons; //getters and setter } Question 1: Is it a good practice to have such huge DTO...
It is said that in CQRS it is easy to fix a bug, you just redeploy and then replay the events. But, what if one of the events should cause an external system not in your control to "ship an item" to the customer if you just replay the events the item would be shipped twice. How do you resolve that?
I am designing a database for a document management app for my office. I want to get the backend right so I don’t have issues in the future. Basically all users will be categorized into roles e.g, super admin, admin, staff and interns. All documents will have access restrictions e.g public(all user roles can view the d...
I am working in a Peruvian company that develops desktop accounting software(.net C#). We have many clients (companies) each customer can create several companies, in addition there is a new database for each year of each company. Example: DBCOMPANY1_2045658512_2015 -------------------------- DBCOMPANY1_2045658512_2016...
I have a application where user purchases/click the certain products. I need to design the click stream analysis here which product got clicked how many number of time, user/geographical detail click those product Here is the design i am planning Whenever user clicks the product , generate the async call to produce t...
I have a class like this public final class Outer { static final class Inner { /* Used in the package. */ void f() {...} /* Used in Outer. */ WHATEVER void g() {...} /* Used in Inner only. */ private void h() {...} } } In Java, every member defined in the same ...
I wish to write a chess AI which simulates the way I think over the board, using C++. My focus is on writing the algorithms for choosing moves (decision making), not defining the board and pieces. To my knowledge, most chess programs written to date are focused on taking advantage of the computer's calculating powers (...
I've switched back and forth ~5 times already. This REST endpoint at /api/tags/ will be for internal use (no 3rd party clients), I'm the only one working with it. I'm deciding between these two representations: Flat { "types":[ { "id":1, "text":"Utility" }, { "id"...
In golang, one can import packages with urls such as import "github.com/foo/bar". Do I still have to include the license of the remote package, as I'm not including library source code directly? How should I deal with this?
Lately, there has been a lot of hype around Neural Networks. They took over the field of AI, finding applications in computer vision, medicine, natural language processing, etc. There are active fields of research in understanding them and their capabilities, but it seems like solving more and more AI problems is more ...
Suppose I am to make a commit that wrapped a section of code inside another thing, so the section came to have 1 more level of indent. In diff it will show delete 100 lines, add 100 lines though all it changed is indent level, and this is very noisy noise. If I split one commit into two, the first one is the real code...
Let's say I have a container in C, for example something similar to C++' std::deque: struct deque { // blah }; struct deque* deque_create(size_t element_size, size_t init_deq_size); void* deque_get(struct deque const* deq, size_t index); void* deque_push_back(struct deque* deq, void* elt); void deque_pop_front(str...
Service-oriented architecture (SOA) is a style of software design where services are provided to the other components by application components, through a communication protocol over a network. Web services are a popular implementation of service-oriented architecture. What are the other implementations of service-orie...
I have some doubts about defining non-functional requirements relative to security, modifiability and usability. Relative to security for example a requirement for a system that needs to use https because it deals with financial information. Can a security non-functional requirement for this be "all transactions that i...
This question might seem too broad, but I really need help with this. I am required to choose a standard or notation to model an integration between two business processes, one of which is external. I'm thinking of UML Activity Diagram or BPMN. But are there any other standards or notations than could compete with th...
Say I have a Business class called person: public class Student { } Say I want to create a factory method for this Student class - something like this: public Student getStudent(string studentType) { if (StudentType=="P") return new PostGraduate(); else return new Undergraduate(); } Should this method go i...
How do I make a good project structure that allows me to work on Linux as well as Windows with Visual Studio? So far I've only been using my Linux machine when working on my project and I used this, A Simple C++ Project Structure. For each application, the folders are: * bin: The output executables go here, both for ...
I'm creating a math library that will deal with points as function inputs (as shown below). public struct Point { public int X; public int Y; } public static class MyLib { public static float CalculateSomething(Point point1, Point point2) { ... } ... } My plan is to be able to use it alongside various g...
We have a concept that all code in a Pull Request into master should be production ready. This makes sense and is a fair statement in my opinion. The idea here being that once you create the PR, you are stating that you would have put this into master, but would like some reviewers to simply 'concur' with you and spot ...
Why do some companies prefer private Microsoft solutions when in the majority of cases there are open source solutions or free software for them? What does Microsoft offer that the open sourece or free software communities do not offer?
I have read this article: https://www.gaui.is/how-to-mock-the-datacontext-linq/ Since this article is almost 4 years old I have no hope that in article's comments my question will be answered so I decided to ask it here. In this article author creates another MockRepository and MockUnitOfWork classes and implements the...
As interface segregation principle suggests no client should be forced to depend on methods it doesn't use, so a client should not implement a empty method for its interface methods, otherwise this interface method should be put into another interface. But how about concrete methods? Should I separate the methods that...
Sometimes when I write a class or piece of code that has to deal with parsing or processing of data, I have to ask myself, if there might be a better solution to the problem. Example 1: In a recent exam we had to write a simluation for a carsharing service. We were given a city which was divided into several (n*n) dist...
So I'm writing a Flocking System (http://www.red3d.com/cwr/boids/). Each boid calculates it's vectors, I would like to draw these vectors with a helper class for debugging purposes. Who should implement the DrawAllLines function ? Please note that I'm using c#, so there is no friend functionality like in C++. Please a...
I'm working on a Scala project that uses DynamoDB for persistence, and does this by modelling the records as case classes. This is becoming increasingly more relational, which means we have classes like this: UserRecord( id="1", name="Matt", friendIds=Seq("2", "3") ) which are then converted into a busines...
thanks to the .NET evolution, today we have a lot of different frameworks and technologies. I'm very confused about the differences about it. What is the difference between: .NET Framework ASP.NET .NET Core ASP.NET Core .NET Standard ?
I have read that Windows 3.11 uses cooperative multitasking, which means that the OS does not do process scheduling whenever it wants, but rather the currently running process "yield" the execution to the OS whenever the process wants, and then the OS chooses the next process to run. But what I want to know is what is ...
I'm pretty new to domain driven design, but I'm interested in its benefits. Currently, I'm working on a C# application that will run on a one-off basis to import data from many different spreadsheets (over 100) into a cloud-based system. There is no UI, and there is no user interaction. There's simply a target folder t...
I am developing a Rest API, and I am asking myself: Is it a good Idea to put base64 encoded data in Json, e.g. for file uploads? What if the base64 contains some of {,},: characters and breaks the json content? If is not a good idea, what alternatives are widely considered to be best practices?
I used Spring Boot 1.5 which uses Logback. I created event objects in controllers and validated them using @EventListener. When a validation error happened I raised an ApplicationSpecificException and caught it globally using a @ControllerAdvice @ExceptionHandler. I thought it will make my design cleaner. The thing is ...
Is it OK to use table column names as keys in a key/val pair on the JS side when making XHR/AJAX requests? In JS, I'll do something like this, where I specify the data to insert into the table, using actual table column names as keys in the key/val pair: function createAccount() { var params = { name : 'John Smi...
We have SQL Server databases in every retail store, and one database in main office. We want to collect data from all stores and load the main DB (for BI), but we also want to sync data from main DB to retail DBs, when new product is awailable for selling. The solution has to provide reliable and scalable mechanism for...
How can I define some rules or additional effects of an action and select it dynamically? For example, let's imagine a FinancialProduct, which can be a Share or a Bond, each of them having a Hedge. Now while there are several different kind of Hedge, their number is still finite and known beforehand, it is just the Hed...
I'm struggling to wrap my head around sizing business logic placed in stateless session beans. It is important that I have little experience in this topic. In the case I have now, there is a JEE application where a REST service (JAX-RS) is responsible for providing data to external systems. In the application the busin...
we're quite new to DI and we're refactoring our application to use Prism/Unity. We're almost there but got stuck on a circular dependency. I've been reading a lot, there are a lot of similar questions but I'm in doubt as to what would be a 'correct' solution in our situation. The application is similar to some IDEs. We...
I have a react element that will potentially call an API multiple times in a short amount of time. Every new call would invalidate the old one as it is a pricing request to the server. Is there a way to verify that I have the most recently made request when updating the data on the front-end? I was thinking that it co...
I'm currently building an Asp.Net website that will allow to import data in several formats into a database. The import status of the the single import jobs are visible to all users and given that a user has sufficient privileges he can also stop an import started by another user. If an import goes through the data is ...
Occasionally I look at the code metrics in visual studio for my solution. I don't ever see anything I would find alarming. My maintainability is usually pretty high with exception to some obvious classes (entity config classes, DAL classes that call SQL, etc). The only time I really ever find the cyclomatic complexity ...
I am developing on a a large webapp system that has multiple docker containers. Imagine a webapp but with many external restful services running on different containers. A microservices setup. I am looking to put in place a centralized logging system. So we can trace and find errors. My initial thoughts was to spin...
I work for a small startup, < 10 employees. Each of them comes from a very different industry and most are not engineers. This, as you can imagine ignites argument after argument that our product should not do feature X because industry Y doesn't to it however we must do feature Z. After working for a few other startup...
I've been implementing Andrei Alexandrescu's allocators as an exercise, but I've gotten stuck on his Freelist. Andrei's Freelist looks something like this: template<class BaseAllocator, std::size_t kMinSize, std::size_t kMaxSize /* Actual size of each block on the freelist */, std::size_t kBatchSize, st...
I was reviewing some old code and stumbled upon a loop nested inside a conditional like this: std::cin >> number; //number is used elsewhere, so should be preserved if (number <= 10) for (int i = number; i > 0; --i) std::cout >> '*'; std::cout >> std::endl; However, I've since been taught to avoid nesting ...
Suppose we've a permissionManager which tell us if user has some privileges to some action or not. We've quite a lot of them(dozen, maybe more). I see two ways to implement checks for a user, like a: Dedicated method: permissionManager.canAdminister(user); Method with a parameter: permissionManager.hasPermission(Pe...
Evening all. We currently have two feature teams, one Web one mobile. They have their own backlogs. Each have their own product manager and scrum master. Team size is 11 including scrum and product role per team. We have an increasing demand for delivery outside of the product backlog from other projects. Some will tou...
Implementing a Finance app, and one of the questions that came up is where to keep an underlying container? Right now I currently have these classes: class DataGrid : public View { /* widget stuff */ class Presenter { /* handle DataGrid interaction and update model */ } class Accountant : public Model { /* Model for...
I'm looking to host an entirely static site in Azure and I have the following requirements in decreasing order of priority: reliable, low-maintenance (easily configurable/deployable), performant. I need to run a grunt command (requires some Node.js packages) to generate my html files after cloning/pulling from my git r...
I'm looking for a way to send a signal between a raspberry pi and a smart phone. What I want to do is hash a few basic bits of information about the phone to use as a UUID. I then want to transmit that UUID wirelessly to the receiver (pi) and then have the pi send that data to my database to be verified. For transmitti...
I am aware of Regular Expression Denial of Service (ReDoS). Is there any reasonable way to allow users to create custom regexes while guaranteeing that they don't submit an exponentially slow pattern?
The codebase I'm working on makes a lot of use of interfaces that don't actually enforce anything. They're in place more to make sure that a type 'is a' something. For example: public class MyBatchTask : Task, ITask<MyTaskType> { ... public interface ITask<TId> : ITask where TId : ITaskId {} pub...
For example, if I use an enum, which all values are manually defined individually, for example: public enum MyNum{ Zero(0), One(1), Two(2); private final int value; MyNum(int value){ this.value=value; } public int getValue(){ return value; } } public class Test{ p...
I'm making an simple application that involves books, using a NoSQL database (MongoDB) -- I think I need to make a DB/schema that stores generic books and their information (title, author, etc.) and then another DB/schema that stores individual instances of books that users own (and user-specific information, such as w...
This is more of a Computer Engineering question, but what is the feature of a CPU to run Javascript fast? I use to access the internet with an AMD Phenom II with 6 cores and I could almost have as much tabs open and almost everything is instantaneous. Then for the past 3 or so years, I've been accessing the internet wi...
I'm trying to build a simple file transfer program that transfers a file from a server to a client. I gave it a try myself by simply writing the file to an ObjectOutputStream. This didn't work. I did some research and I found a whole swath of solutions that utilize a byte[] in which the contents of the file is written ...
After browsing several answers an Stack Overflow, it is clear that some natively compiled languages have garbage collection. But it is unclear to me how exactly this would work. I understand how garbage collection could work with an interpreted language. The garbage collector would simply run alongside the interpreter ...
I have two unrelated classes that both share a certain behaviour. Is it appropriate to use a common abstract base class for the two classes, even if a simple base class would achieve the same thing. I will never use register nor does my abstract base class use @abstractmethod. The only reason I would derive the base cl...
We're using Service Now and have 2 week sprints. Our management team want to release to production once every 6 sprints and use the term Version for this. When a story is complete in terms of development and testing, prior to production release, it will sit in the Done column (far right of our board.) If a story is not...
I'm familiar with OOP and PHP, but I'm new to MVC frameworks. I'm currently using Laravel and have found it wonderful so far, but things have gotten trickier as I've progressed, and now I realise I need to rethink my architecture. The project is a digital assets manager for a small client, but I still want to make sure...
In his book, Eric Evans distinguishes between value classes and entity classes. Value objects do not have an identity and continuity. Do Value classes contain behaviour? Is it acceptable for Value Types not to have behaviour? The reason I ask is because a rich domain model differs from an anemic one in the sense that ...
We are having a debate in our teams at the moment around the best process for building our software. My team is following gitflow and building once at the start of the deployment pipeline and promoting that build through each environment. The other team is building once per environment except for prod where they promo...
Please see the code below: public List<DenominationDTO> CalculateChange( decimal cost, decimal paymentReceived, string currencySymbol) { var currency = CurrencyFactory.Create(currencySymbol); var denomination = DenominationFactory.Create(0,0); DenominationsCalculator = Denomination...
I know there is a distinct difference between a requirement specification and a user story. However in our company, many of the requirements can actually be defined in a standard template. This goes for small and medium sized business applications based on a single SharePoint site. I have found that it is much easier t...
I've been working on a project for about a month now. I am extremely familiar with the code and understand it to the extent where I feel that it is so easy to understand, that most methods don't need comments in my opinion. I can't tell if it's because it is actually simple code or that I am just very well practice on ...
I need to make a category/type class to identify an object. The usual way to do it is just pass a string to initialize a new category: category = Category('A') obj = Object(category) However, the set of categories to use should be fixed. Nobody should be able to create a new category and use it in an object. What desi...
I understand the difference between methods and functions. I also understand all methods are functions but not all functions are methods. I always refer to methods as functions. It feels like a more natural term, probably because in PHP the word function is right next to the name of the method. However method seems to ...
I wanted to know if the way I deal with source files that need to be deleted from version control could be regarded as bad practice. I want to explain it to you based on that example: I recently got very angry because I had to tediously sort out Java classes in a programme that were basically dead code however it was ...
I'm a little hesitant on what to name a view class. I have a view class which I call ChooseImageView because that's what the user does in that view. After the user has chosen an image I display a view called ChosenImageView. Is it wrong to name classes after the user action instead of what the view class actually "is"...
Say I have this function def function_A(): blah blah blah return A When is it justified to make that long function_A into smaller pieces, say function_B and function_C and then call function_B and function_C inside the function_A?
There is a need to separate services working with data into two groups: ones that perform read-only operations and others doing Create(or Add) + Update(can also be called Modify) + Delete(Remove). First one will be (obviously) named ReadDataService or ReadOnlyDataService. What about second one? I'm looking for a commo...
Say I have the following classes: ServiceLayer.Service > BusinessLayer.BusinessClass1 > BusinessLayer.BusinessClass2> BusinessLayer.BusinessClass3. In the scenario above; Service calls BusinessClass1, which calls BusinessClass2, which calls BusinessClass3. Say each of the classes have a dependency that needs to be inj...
Back in the old days, we did Hungarian notation. That's now considered passé, and for the most part I don't use it anymore, but I still find use for the m_ prefix to indicate member fields. For me, if I'm reading through someone else's code, and I see this: count = 3; I assume that count is a variable local to that f...
I'm a graduated software developer. In the last year I worked like a sysadmin, nowadays, I entered on a different software company as a VB.Net Developer, it means I need to learn and master a very, very huge solution (project) and... well, I don't know exactly where to start studying. This solution involves a lot of c...
Somewhere in our GUI we have a string where a spinner (sometimes called a stepper, depending on what toolkit you use) is sandwiched between two labels which make a complete sentence, "Use 1 in every n items as test data". This has sticky i18n issues that I don't know the answer to. Can I think of this kind of "1 in n...
In order words, what's the advantage of writing this: Listing 1 var sortBy = function sortBy(p) { return function (a, b) { return a[p] > b[p]; }; }; Compared to this? Listing 2 var sortBy = function sortBy(p, a, b) { return a[p] > b[p]; }; Reference.
UncommentatedPannen's (pannenkoek2012) newest video describes a glitch in the Nintendo 64 game Super Mario 64, which allows an object to push Mario out of bounds, which isn't normally possible, by utilizing a stale/dangling pointer in Mario's structure that normally points the the floor Mario is currently above. Pannen...
I am designing a REST API but came across some difficulties while naming it. I have an API like this: GET .../users/{userId}/categories/count GET .../users/{userId}/categories/{categoryId}/count GET .../users/{userId}/categories/{categoryId}/tickets It seems like the API is about users' categories, but actually ...
I'm working on a Web App where the data is quite sensitive and is required to be encrypted before it is stored in the database. Now there are two ways through which I can achieve this: Encrypt data in the code Encrypt data in stored procedures (using symmetric keys) Now I don't know which approach will be better reg...
I am building a JavaScript application where its behavior (some rules and logic) is configurable via JSON. The configurations are deploy only with a new version of the app. Currently my app, when initiated make few ajax requests to its JSON files. I would like to know: Should I include the configuration as a JavaScript...
Please see the code below: public class Calculator { private readonly int Number1; private readonly int Number2; private readonly int Answer; public Calculator(int _Number1, int _Number2) { Number1 = _Number1; Number2 = _Number2; Add(); ...
This question is inspired by Mike Nakis' answer to a question I asked earlier: Should a Calculator be a value type or an entity type?. Please see the code below: public class Calculator { private readonly int Number1; private readonly int Number2; private readonly int Answer; public Calculator(int _Nu...
Background: I am a Php developer with a keen interest in Enterprise Design Patterns and Architecture. I have a relative (living in a different continent and has no business dealings in the country that I am in) that has just launched a major Online Enterprise Platform that will provide an ERP solution for a certain mar...
I have a three layer application with your basic client layer, middle layer, and database layer. The middle layer is intended to take requests for work and data from the client, process it, and then store it in the database. There are a few key points here: First, requests for work from the client layer should be asyn...
In TFS, when we put comments for things to be fixed in a Pull Request before we will accept it, should we mark it as Reject or Wait For Author? Which is better?
I have a function get() which gets a human object from somewhere. That is literally the only use of human, to provide a collection of properties of a human. struct human { std::string first_name; std::string last_name; unsigned int age; std::string location; }; Doing things like human user; user.first_...
If I may jump straight into it. I have a web api endpoint where I pass in a collection and it works amazingly but with one caveat. If one object in that collection contains malformed data (missing required data) it returns a bad request, thus voiding the whole collection - the normal shenanigans but tech lead suggest...
I'm familiar with the concept of technical debt as the cost of effort (through maintenance, support, rework etc.) incurred when choosing an expedient solution over a complete one. What I am wondering about is, is technical debt incurred for any choice you make? Take for example securing an existing application that nev...
I'm writing some code to do some SSH jobs on a remote machine and one of the methods I'm (forced of) using returns a Vector type. I've learned about them several years ago but never had the chance of actually using them until now. What I do know about them is They are not thread safe They are very old and are depreca...
On another SE site I saw code similar to this: int x[] = {1,2,3,4}; .... x[0] = {99}; For the assignment, is there an advantage to this over simply: x[0] = 99; http://ideone.com/xwA0Yh
What are the gains in actual computing speed (verbosity of code being put aside) and for which case would each be recommended for, as a good design pattern? I would like to know the above in general but also if it helps in the context of the following which can re-written in all 3 ways static void parallelTestsExecutio...
In the context of sports scheduling, I have a ViolationChecker class intialized with a Match, whose task is to check whether placing the match in a given time-slot produces a rule violation or not. An example of its usage would be: checker = ViolationChecker(match) match_fits_in_timeslot = checker.check(timeslot) The ...
Please see the code below (contained in an IEnumerable method): int Quantity = (int)Math.Floor(ChangeRequired / CurrencyAmount); ChangeDenomination = ChangeDenominationsFactory.Create(CurrencyAmount, Quantity); yield return ChangeDenomination; ChangeRequired = ChangeRequired - (ChangeDenomination.Amount * ChangeDenomi...
I have a class that is used to create a "settings" GUI for any other class. Quick example for clarity: I use attributes to decorate the individual items. For example, you can specify ToolTipText: [Attributes.Display(ToolTipText = "IP Address of target computer")] public string IPAddress; Now, the actual question: ...