instruction
stringlengths
34
36.1k
Just except that Chain of Responsibility might go one straight line, but in the HTML event handling, it is first the "capture phase" (capturing), then the "at phase", and then the "bubble phase" (bubbling), so it is Chain of Responsibility by going from the first item to the end and back to the first item. And any item...
In the early time, maybe just few line code, But I have see too many repeated and messy codes involve serialize/deserialize interference the main logic. So I try to persuade the team members to wrap a function for operations like read/write/update data ,example as: void updateCopyTimes(int times) { player->getE...
We are trying to move (slowly) into Microservices architecture from our current monolithic based architecture. I've done my research on microservices architecture and would like to get some feedback on the architecture I've described below from the community. Information about the application It's a web application us...
The relatively large size of std::mutex on different platforms (e.g. 40 or even 80 bytes) is often explained as ensuring the mutexes don't occupy the same cache-lines and so don't incur logically unnecessary fetches and synchronization activity. However a std::mutex is commonly embedded in a larger object and its very ...
Do you name a dictionary by the key or the value? I have a dictionary that will hold gradient data and the component: dictionary[gradient] = component; Do I name it gradientDictionary or componentDictionary?
I have a question on writing clean code. I’m trying to refactor the following method: private static Map<String, String> createMapOfAttributes( final String Id, final String attributes, final Map<String, String> invalidLines ) { final String[] arrayOfAttributes = attributes.split...
we have a hierarchical structure where every node is derived from a node base class public Node(INodeFactory nodeFactory). The factory is injected so the node can create its child nodes using Get(int id) At a later moment some nodes need a reference to another node in the structure. The information necessary to get the...
I am dealing with a pretty big codebase and I was given a few months to refactor existing code. The refactor process is needed because soon we will need to add many new features to our product and as for now we are no longer able to add any feature without breaking something else. In short: messy, huge, buggy code, tha...
My app has a large dependency on external endpoints. As time passes some of them are changing and evolving. Some of these changes are breaking changes... So far i have about 10 dependencies for a single project (i have other side-projects too) and keeping it up-to-date is not the easiest task of all... Integration te...
We have a legacy system which will eventually be deprecated, at which point we will switch to using a new system. What are the pros and cons of maintaining separate databases for the old and new system, versus incrementally adapting the original database?
Today I saw that React (React JS) has lifecycle methods, such as componentWillMount() and so when the component or container is instantiated for the first time, this method will be called if it exists. (if it is defined). One example of it is, when the component is instantiated for the first time, if the above method ...
I am strucuring our rest API resources and came accross an interesting dilemma. Here is the scenario and I am going to use a car analogy /cars/1/ { "id": 1, "make": "Toyota", "year_build": 2015 ... } /cars/models/1/insurances { "id": 1, insurances: [ { "policy_number": 101, "company": "Insurance C...
I am building a new simple web application using dotnet core (.NET Core) and Angular SPA. Does it make sense to split API and Web App into different projects? This would complicate things (especially with authentication) whereas I could simply use 1 single MVC controller that would render my only view that spits out m...
So I have a singleton in Objective-C, there's one static method exposed to access the one and only instance: + (id)sharedMyClass { static MyClass* sharedMyClass = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedMyClass = [[self alloc] init]; sharedMyClass.myString...
I am having trouble calculating the complexity of this problem: REVERSE3(A): // Reverse the order of elements in an array // P is an array; assume generating next permutation takes 1 step. for every possible permutation P of A: for index i = 1 to N: if P[i] is not equal to A[N-i+1]: contin...
Generally speaking in canonical OOP situations, the rule of thumb is to write your classes with the least access as necessary. i.e. only make public only what is necessary, make protected only what is necessary, etc etc. (There are exceptions and what I describe does not always apply. FWIW, I find the idea of "least ac...
I have a binary file that I want to parse. The file is broken up into records that are 1024 bytes each. The high level steps needed are: Read 1024 bytes at a time from the file. Parse each 1024-byte "record" (chunk) and place the parsed data into a map or struct. Return the parsed data to the user and any error(s). D...
We have our own proprietary software that we are developing for commercial business. We want to sell the software and we do not have any problem in distributing the source code to our customers. Due to the lack of good build infrastructure and complexity of the software, it has become difficult to manage and has lost i...
I have code along the following lines: public void processInput() { List<String> input = readInput(); final Object[] returnObj = createInternalStructureFrom(input); final Dictionary dictionary = (Dictionary) returnObj[0]; final List<Order> orderList = (List<Order>) returnObj[1]; final List<String> i...
UPDATE 2017/04/19 Another view is using wrappers for late binding. Introduction I believe that objects should be immutable, so I only set properties via the constructor. In that case, the object state never change. Problem There are cases the required parameters for the constructor aren't known at that moment. So I nee...
Introduction Let's say that you have such design in your application: - application (laravel) - web scraper (used by application) - query builder (used by web scraper) The application is what actually uses the Web Scraper to fetch the data from the web, however since we use the Web Scraper as a search engine as...
A user has to perform a somewhat complex task on my website (submitting a rating). For the sake of example, let's consider it's a rating for a movie, done through a controller. There are several possible "paths" the logic could follow The user wants to cancel his rating submission (eg he didn't go to the movie) He ...
Take this example public static boolean uniqueNumbers(int[] x){ for(int i = 0; i <x.length; i++){ for(int j = 0; j <x.length; j++){ if(i != j && x[i] == x[j]) return false; } } return true; } The loop body will execute x.length times for loop wit...
I need to design code for a complex multi-table update, ideally using a repository pattern to fit in with existing code structures. Some of the tables which will be updated are specific to this flow, whereas others will be updated in future from other flows. e.g. Specific Tables A, B, C, D Address (common) Customer (c...
In the case of unit testing, I'm testing as many cases as I can that when I do X, Y happens. I'm also concerned in some cases that when I do X, Z does not happen. But for the sake of protection, I could also test that A, B, C ... do not happen either. And going that direction I could basically test a billion things tha...
I have posted this question on Stack Overflow and there few people suggested to post it here. I understand the both factory and factory method pattern. In factory pattern we create instance of my classed by another class function dynamically where I pass some parameter to another class function and based on that parame...
I'm developing both a REST API and a frontend web app. What's the best way to go about plugging the API into the web app while I'm developing locally on my machine? I could spin up a local copy of the API and point my web app to localhost:api-port, but that seems like unnecessary administrative work to have a local co...
During work, i only make commit and push my work to our shared repository at Github, when i consider that I have done my task up to necessary changes which I may realize later. So that means that I don't commit and push my work on a daily basis, but often once in several days. Generally, is daily commit and push neces...
On a REST api I have these endpoints: GET: /tracks.json GET: /tracks.xml GET: /tracks.csv It receives a tracks resourse and the format gets defined by .^string^ that is after the resourse. eg the tracks.csv sends the tracks resourse to the client as csv format (with the appropriate mime extention to Content-Type http ...
I am trying to have a lean database size, so I thought that if an input, which will always be a string, should be checked for its value type and therefore saved in a specific table that is appropriate with its type. Meaning if an input represents a string, then it should go to a table that saves string, or if an input ...
Update: Without fluent interface, builder pattern can still be done, see my implementation. Edit for possible duplication issues: When should the builder design pattern be used?: My question is about the actual advantages of Builder Pattern(of GoF). And the chosen answer in the link is about Bloch Builder, which may(S...
We are developing a.NET web application that uses WebApi. We have separate layers: UI (HTML, CSS, js etc.) ApiController - receives input DTOs from the UI and calls the appropriate endpoint in the Business Layer (for instance, StudentBLL.Add or StudentReportBLL.GetFollowReport) Business Layer - contains all business...
I'm trying to build a Java application that connects to a remote database that stores and retrieves video files that can be over 200MB. I could store/retrieve these files in MySQL directly as LONGBLOBs, yet I read again and again how that's bad practice for various reasons. One solution commonly offered is to store the...
I am using JWT for authentication in a micro service architecture. There is 1 UI web app and multiple REST API exposed services in the backend. I am considering a IAM service which will give a JWT to UI with permission information. The UI can use this to contact another Micro service X. But in this case should X contac...
var list = ['a','b','c','d','e','f','g','h']; Each time I make an API call and get that list, showing it here as a JavaScript array, I would like to know if any of the items have moved quickly (defined as, say, more than x positions) in either direction over the past n requests. Each request I get an array with the sa...
I came across this programming technique while doing pair programming in an interview and couldn't find the name of it on google. The idea is that you first write the expression which uses the variables and then you write the code that computes the variables later on. To use some example code here: private bool Valid...
Background I saw this figure describing the different crowfoot notations used in ERD: I'm not able to find the difference between the "many" notation and the "zero or many. However I was able to find an example (see bottom left for the "many" notation): (source) Question When to use the "many" notation and what is ...
I'm building an Android app where different "types" of users can log in - lets say User and Admin are the two roles (there could be more than two). User can access some views in the app, by pressing buttons that are presented to it. Admin can access those same views but more, via buttons exposed only to the admin. Furt...
My question is actually two questions about GNU GPL and monthly fees: If I build a server and use GNU GPL as a license, can I run it and charge the users a monthly fee without the need to distribute the source code? My understanding is that since the users buy the service and not the server, I can charge whatever I wa...
I have a question about a geofence triggered action. Does anyone know if you can trigger a credit card transaction by location? An app I'm having a guy work on requires this function and the guy says it can't be done. Thanks in advance
I'm planning to implement a system with a super class named User and 2 subclasses of the class User, named Seller and Buyer. They are specific types of Users. So, I have 3 files with 3 classes: - User.php (class User) - Seller.php (class Seller extends User) - Buyer.php (class Buyer extends User) When there is a sess...
I'm refactoring a legacy codebase. I have 4 very similar objects that I decided would be a good target for becoming polymorphic, so I moved all the common code to a base class and added an interface. The real problem arises when trying to create those objects. Every class has 3 different constructors with 5-10 paramete...
I'm writing java library(jar file) to log Web service request and responses in a Database for in-house application. This library will have two methods registerReuqest and registerResponse. I'm wondering is it good idea to pass database connection to these library methods? Passing connection to library will have some p...
I am currently designing a web application where the data needs to be stored encrypted. Planned technologies used: ASP.NET Core API ASP.NET Core Entity Framework MS SQL Server 2016 any Web Frontend Because of the specification we need to store all data encrypted in the database. Which would be a good approach to achi...
I am reading a book "Black-Box Testing by Boris Beizer". In this book, there is a sentence as follows, Object-oriented programming and improved operating systems promise to eliminate many currently common inter-component interaction bugs. While I understand Object-Oriented design concept (such as in Java Programming ...
The add operator of the set class returns a boolean which is true if the element (which is to be added) wasn't already there, and false otherwise. Is writing if (set.add(entry)) { //do some more stuff } considered good style in terms of writing clean code? I am wondering since you do two things at once. 1) adding ...
I am trying to understand SaaS (software as a service). What are the different ways of delivering it? We all know using ssh -X $host we can run software on a remote computer. Can this be considered SaaS?
I have been reading about distributed databases and the like providing weak and strong consistency guarantees, but perhaps I am short on imagination - when would you want to use a weakly consistent system? Most examples of real use-cases - services that share state across a distributed system, or read-write services a...
My team is preparing to add new capabilities to an OpenAPI contract and our implementation of it. There are pre-existing clients. We are planning to take our API from v1.1 to v1.2 while fully respecting semantic versioning. Our team is debating whether we must go to v2.0 instead of v1.2 if we add new possible values ...
Say you have a UI that reflects some sort of server-side data and the UI can manipulate that data via HTTP requests. For a more concrete example, consider a user database with a web interface that can add, edit, and delete users through HTTP. The client itself stays in sync with the server through periodic polling and ...
According to Effective Java's Item 15: Minimize Mutability, it is always better to make classes Immutable. According to that, how would I handle classes that are by nature given to change? Some examples would be: A Customer class, where an address or phone number can (and probably will) change. A ShippingRule class,...
Something I've noticed recently is when I am doing the following types of projects: When beginning a project Working on an MVP/prototype Adding features which aren't entirely defined Working on a smaller scale project For reference, I am working on a Python project now which currently has ~1k lines of code, including...
I am using Java for creating an application for Android (so I can use many of Java 7 options, but cannot use all of them). I have two classes: class A{ static String getScript(String input){ return "result of functionality_1 on input"; } ... } class B{ static String getScript(String input){ ...
I structured my "service" layers (or, what I thought to be service-like functionality) as static classes where each class is a grouping of complementary functions that together provide a cohesive set of operations for supporting the consuming layers' needs. public static class ElementService { public static Element...
Is it possible to optimize a .NET application running on a server version of Windows for near-zero latency TCP communication? Or will there always be unpredictable/unavoidable delays? For example, while searching for low-latency open source apps I found this OpenPDC application on Github which seems to be the de-facto ...
Currently I am working on a health related application which was being developed for 5 years and lot of developers have contributed in it. The application is quite complex and highly used by lot of users. During code review, I have found that lots of its code and implementation patterns have been deprecated and they c...
I'm fairly new to software engineering, and so as a learning exercise I wrote a chess game. My friend had a look at it and pointed out that my code looked like for (int i = 0; i < 8; i++){ for (int j = 0; j < 8; j++){ while he insisted that it should instead be for (int i = 0; i < CHESS_CONST; i++){ for (int j...
I'm familiar with HTML/CSS, and some non-UI programming using C#/node.js/Java and looking at options for building a simple mobile app. I will definitely use Xamarin, and have to choose between Xamarin native and Xamarin Forms. How much of an overlap is there between a UI coded in XAML and an Android UI coded in XML? I'...
I had a discussion about standardizing return structures in an API and the best way to enforce it across our services. The quickest way we went with was just to have our controllers in .NET Web Api return the same templated class so we came up with something like this class ResponseObject<T> { public T Data {get;...
I have an application written in C. I have to develop a GUI for it. This application will be connected to the internet and will send and receive requests and responses through the network. One way is to write the code in PHP to send and receive requests and responses by POST or something, and compile the C code into an...
I have the following code: struct AInterface { XXX some_method(/* some params */) = 0; }; void foo(const AInterface & a) { do_work(); while (x) { do_work_2(); foo_process_input(a); } return some_value(); } void foo_process_input(const AInterface & a) { do_inefficient(a); } H...
Recently, I was given a task of re-writing a really old piece of software. The whole software itself is well written, except for the one thing that worries me, classes containing a huge amount of code. A lot of that is nothing but really really big validation chains that go like: if (!isFooValid(dataObject.getFoo())) ...
I have many cars in my C++ application all contained withing a RaceTrack. Each car consists of hundreds of parts. Each part depends on some other part or two. I've read a lot of SO questions on DI and Mark Seemann's book and it looks like I should not define a Car class just to hold car parts because all car parts will...
Normally, a C++ class is written with public: and private: applying to a series of members: class Foo { private: int x; int y; int z; public: int getX(); int setY(int val); void print(); } An alternative coding style is to explicitly prefix every member with public/private. Is this a good or ba...
I am using MVP in my project, but I am new in MVP. I have two comboboxes. When I select an option in a combobox, the other combobox should be filled with new data. This action will be done in the Presenter. I got my view 'view1' in Presenter, and introduced Combobox1 and Combobox2 as properties in 'view1', because I ne...
I am trying to understand Clean Architecture as explained by Uncle Bob. My application requires a user to do a test. A test consists of a collection of questions that a user needs to answer. A audio file is played for every question. After the test the user is provided with a test result. Possible use cases? Do a test...
One of the stated reasons that structs can be more performant than classes is that no ARC is needed for structs. But suppose we have the following struct in swift: struct Point { var x:Float var y:Float mutating func scale(_ a:Float){ x *= a y *= a } } var p1 = Point(x:1, y:1) var p2 = p1 //p1...
I understand Ken Thmpson hack involved like someone has mentioned on here he hacked /bin/login to introduce a backdoor. he did this by hacking the compiler to introduce the backdoor into a binary whenever it detected that it was compiling the login source code. he also hacked the compiler to introduce the backdoor-pro...
I was reading software engineering a practitioner's approach when I came across this question. I think the answer is no but I don't have much of a valid reason so I would like to hear other people's opinion .
This may be a convoluted question, but I'm trying to get a better understanding of statelessness. Based on what I've read, web applications should be stateless, meaning each request is treated as an independent transaction. As a result, Session and Cookies should be avoided (as both of them are stateful). A better ap...
I'm trying to implement an application but didn't want to reinvent the wheel. I've been searching for an design pattern closest to this application but to no avail. On startup, the application will prompt the administrator to choose from a list of tasks and copy the selected task into this year's tasks. Throughout th...
I'm doing a small project for the company a friend of mine works at. The project is a tool for doing Quality function deployment using the House of quality method. As part of the initial planning phase of the project, they want me to perform the same (House of Quality) method on the project, in some kind of meta way :...
If I have software written in C for 32 bit system, what changes do I need to make in it to run it on a 64 bit system?
Scenario: I have a simple text-based post. Which can receive comments and likes. All entities have their own tables. Like and comment generate notifications. Basic Parent-Child RelationShip in database (RDBMS): Current Approach: When I have to delete post, I delete comments, likes and their notifications too. Becau...
When I retrieve data from database I name the class as Model, for example UserModel. When I send data to the View I name the class as ViewModel, for example UserSettingsViewModel. How to name the class that exchange data between layers?
I want to solve Synchronization with a Message Queue In the wikipedia page of message queue, I read: Most messaging systems support both the publisher/subscriber and message queue models in their API I used python-rq (celery in the past), with fun and success. .... but I don't understand the (academic) difference bet...
This is sort of a follow up question on Multiple Same Object Instantiation. And I think, is not really language specific, so this is applicable to Java and C#? Version A public MyClass { public void methodX() {} public void methodY(int i, object o) { GeometrySplitter splitter = new GeomterySplitter(in...
In Java, Collection.add() returns a boolean which is true if the added element wasn't present in the set whereas Map.put() returns the value that was previously associated with the key (or null if there was none). Is there any reason that aren't implemented the same way (e.g. both returning boolean)?
Note: I am no architect nor security expert, I will try my best to explain. Currently I have been tasked to set up a new Web API2 asp.net, c#. The layer is as follows... Client >> New(public) Web API >> Current WCF >> MSSQL DB. The current WCF will be replaced eventually with an internal web API. So it will be like ....
Consider the following two queries in SQL (Transact SQL): UPDATE [database_name].[dbo].[table_name] SET [database_name].[dbo].[table_name].[field_name] = @value WHERE [database_name].[dbo].[table_name].[field_name] = @searchvalue and the alternative UPDATE [database_name].[dbo].[table_name] SET field_name = @value WHE...
In some languages (e.g. C#) a class can only ever have 1 base class which seems like a problem for what I'm trying to do. I will give you an example of what i'm trying to do, hopefully this will make my problem clear. I have got a lot of data objects, some of these data objects have an hierarchy, they can have a parent...
In functional programming languages, such as Scala, data types and structures, are really important. I am in two minds about the use of type-defs in helping with the readability of the code manipulating non-trivial data structures. Here is an example of a function that takes a generic collection in Scala, traverses it ...
Before I start the question I want to tell you guys I'm new to this type of workflow. The previous companies I worked didn't used Version Control and/or changelogs. Also, I've been working as freelancer for sometime, so never felt the necessity to do so. But now I'm trying to have a better organization of my projects a...
My understanding of ISP is that the "client" in the definition (see below) can mean either a class that implements the interface or an instance declared with 1 of the various interface options, based on client mentioned in Wikipedia definition: The interface-segregation principle (ISP) states that no client should be ...
I read with interest this article which states: A DI Container should only be referenced from the Composition Root. All other modules should have no reference to the container. This means that all the application code relies solely on Constructor Injection (or other injection patterns), but is never composed. Only at ...
I have been reading the article entitled "A manager's introduction to RUP" and I have some doubts about what does iterations really mean on this methodology. For what I know RUP has 4 phases: Inception, Elaboration, Construction and Transition; each of these phases has some "deliverables" or milestones that should be a...
I need to move two database tables data into code. These tables consist of some data settings (30 and 1000 lines accordingly). This movement of data is a first step towards bigger refactoring. As a result i would like to get rid of two tables, have this data stored somewhere in code. I can not do: use application sett...
Based on what this guy says: http://toddfredrich.com/ids-in-rest-api.html Let assume he is right about using UUID to identify the api resources. Then I run into troubles trying to implementing it that way, this is: class FooEntity { final String id = null; //auto-generated by my backend (mongodb), not shared ...
I need a system for creating Python subclasses in a simple manner, and I was thinking of using a (custom) config language similar to json, xml, etc. Here's the initial structure I thought of (one file = one subclass, files are in a folder where they're read from automatically), which is basically just a simple config l...
Front end developer here... I am working with a teammate to create a simulation game. We would like to allow users to create and account (we were going to handle this through local storage or cookies) but are now looking for a solution to handle an actual account. I figure I could port our scripts over to a Meteor/Rail...
I create my API and now I generate SDKs for my users access them. Swagger generates a ugly name, e.g: public void sellersSellerIdShipmentPost(){ ... } Of course it's difficult to read and understand. What's the method naming convention for SDKs? In Facebook API, they use somenthing like CreateAppGroupDialog but seems...
Given a very trivial function, int transform(int val) { return (val + 7) / 8; } It should be very obvious that it's easy to turn this function into a constexpr function, allowing me to use it when defining constexpr variables, like so: constexpr int transform(int val) { return (val + 7) / 8; } My assumption i...
I'm building a web application in PHP to handle attendance tracking at my small English school. I've got the database up and running with PostgreSQL and I've been importing data and working out the user interface for adding data. I'm still a beginner with this kind of thing, but I think I've planned the database out we...
I'm working on a large web application. Users are organized into Companies, then Roles, and then possibly Teams or are individual users. For example, Bob is a member of Company A, has the Officer role, and is on Mary's team. Our development team is tasked with adding the ability to restrict access to various features...
I'm used to programming in Java, so my view of these things is quite Java based but I doubt this is the correct way of writing Python code. I found this https://stackoverflow.com/questions/106896/how-many-python-classes-should-i-put-in-one-file link which asks a similar question to what I am about to ask. In Python, wh...
Let's say, I have an interface ISomething. I also have up to n implementations of the interface, for example ASomething and BSomething. I want to determine all the implementations of that interface and save them to a list or another useful data structure. One solution I know is, find all implementations via a reflectio...
I'm thinking of creating a cron job that checks out code, runs code formatters on it, and if anything changed, commits the changes and pushes them back. Most projects that use autoformatters put them in a git hook, but doing it automatically every few hours would remove the burden for each dev to install the git hook. ...
I have this out of context scenario, where what I think is good practices leaves me in a situation of both implementing an interface, and using composition to do the implementation. Imagine the following: I have a Character with Health and Mana, like so: interface ICharacter { Health Health { get; } Mana Mana ...
We are developing a B2B web application in which we are using(suggested by seniors) two servers. One is Node.js (to serve all the request related html & static content) and the other is Tomcat to implement REST services for serving back-end. I think it will add an unnecessary overhead if we consider the following: Nee...
When developing a system or application that you plan to use with a certain framework, is it best practice to design the system without the framework in mind, or is it better to design the system with the mindset "well the framework would have an easier time with this".