instruction
stringlengths
34
36.1k
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".
I retrieve some pieces of information from four forecasting APIs, I have three main methods that I will implement in each API's manager: history (only one of them provides this function) forecasting (all of them) yesterday data (only two) I am thinking about the following pattern (it's similar to facada/str...
Often, I'll abstract common logic out of a class by creating an abstract base class with only protected members. For example: class Base { protected: void foo() { ... } std::map<KeyType, ValueType> d_map; }; class Derived : public Foo { public: Derived() : Base() { ... } // ... }; My logic here...
Pretty much what the title says. I'm asking with Java in mind; however, I'm not limiting the premise to java. Would it be considered counter-intuitive to have a cloned object not pass equals function?
I'm working on a Desktop application, and to allow frequent updates without too much hassle, I want to install a simple "bootstrap" application to the "Program Files" directory, and the actual application to "C:\ProgramData". This would allow me to automatically update the application without administrative access, sin...
I remember in the past, for some languages which I can't remember, be it Fortran, Pascal, or Scheme, a logical operator 2 || 3 will always return a boolean value. But in the modern languages: JavaScript, Ruby, Python2, they all return 2. I want to be careful about: which common languages return strictly true / false, ...
I'm in the process of writing an bidirectional, asynchronous socket server and server handler. The base handler class I'm working off of is as follows: class BaseAsyncSocketHandler: async def send(self, data: bytes) -> int However, I want to write a subclass that sends two arguments, an event and arbitrary corresp...
I'm currently designing an application, and I'm confused at how to break apart my monolith application. After doing some research, service fabric actors seem to be the best solution for simple processing, but I'm confused at the approach I should take. How my current application works in my monolith: IRC Message comes...
If got a native application which adds value by for instance analyzing measurement data from measurement programs. Some of them have an API, so I can get their data via IPC. But how can I achieve this for specific native programs, which won't support this? AFAIK I have to reverse engineer the assembly, look for the var...
Why is there no key specified with .NET KeyNotFoundException (in message/property)? Is it because of performance reasons? Is it because when Dictionary finds out there isnt any requested object by the hash it already doesnt know the context of the original key? I couldnt find an answer to this question anywhere.
On my local server, I create aliases like these to speed up my work: alias bashrc='vi ~/.bashrc;source ~/.bashrc;echo bashrc has been sourced' alias bashprofile='vi ~/.bash_profile;source ~/.bash_profile;echo bash profile has been sourced' alias aliases="clear;cat ~/.bash_profile|grep --color \"alias\"" alias home='c...
I'm working with an external system which sends event-like data to us. An existing SDK from the third-party guys parses the JSON so in the end we get something like the following class: public class Event { public string Type; public dynamic Data; } The requirements are as follows: All events should have a d...
According to a JSPerf snippet (and some others), default JavaScript map() implementation is 21% slower than using a basic for. Looking at the official polyfill, I immediately understand why map() is that slow. Polyfill strange part line 15: var O = Object(this); Initial object is converted (and duplicated) in a JavaSc...
How do programmers retain knowledge for languages/technologies they don't use on a regular basis? Take for example the PC Assembly Book. The author states he rarely uses ASM at all. Yet he was able to write an in depth book on the topic. How was he able to do this? I've spoken to a lot of people who agree that they sta...
A simple DB containing two tables could be: CREATE TABLE Stock ( StockID INT StockDesc VARCHAR SupplierID INT PRIMARY KEY (StockID) FOREIGN KEY (SupplierID) REFERENCES Supplier(SupplierID)) CREATE TABLE Supplier ( SupplierID INT SupplierName VARCHAR PRIMARY KEY (SupplierID) ) (Assume each stockID has only one su...
I have a set of nodes arranged like the below image. Left columns are parents, right columns are children. A line denotes ancestor/descendant. When I select a node, I want to find the immediate family, and then any children-of-children and parents-of-parents. But not parents-of-children or children-of-parents. So in...
If I have written a privacy tool as a .NET web application which is to be hosted on a commercial hosting site, other than hosting it in a privacy friendly country, how can I assure users that the application has not been compromised by a third party at the host? Obviously SSL will be used and the assemblies will be as ...
Suppose I have a repository that is private (always has been), the code in this repository has been licensed under license A for a very long time with hopes of making the repository public in the future. I now decide to make the code in this repository public, before I do this, I decide to change the license to license...
I'm trying to think about the best method to write a function whose primary operation is going to be doing crud on the database. Here's what the overall structure of the function (sans any refactoring) will look like: public function cancelWorkRelease (workReleaseID number, key string){ validate key... ...
I'm reading the book "Agile Software Development, Principles, Patterns, and Practices" by Robert C. Martin. When he talks about the Dependency Inversion Principle he gives the following example of a DIP violation: This seems very clear to me, as the higher-level object Button is depending on a lower-level object Lamp....
I'm working on a system split into multiple services. Some services (and especially the front end web server) depend on other services to function. When developing these locally, do you point to the dependencies in staging, mock them out, or run them locally? Are there any tools to make this easier? Would it be a good ...
We need to have an endpoint that allows us to check if a user's email is unique. This operation doesn't seem incredibly RESTful and we're struggling to figure out how to make it fit. We've been debating on whether we should make this more of an RPC style endpoint that might look like the following: URL GET identities/c...
This is a naming convention question. In C#, someone suggested that variables of type List<T> should be named as listBlah instead of just blah. Similarly for variables of type Dictionary<keyT, valueT>. I think the reason is because we can guess the type of a variable by just looking at its name, without having to find ...
Suppose you have a PBI or User Story which can be split by platform like: "As user I want to read my feed so I can be updated with news" But that User Story is for iOS, Android and Web, so we use to split by platform and create a different card for each one, but when the sprint finish, and only two of the three cards a...
I have a cyclic dependency in my architecture design. Let's assume there are the following modules: FileSystem (uses Logger) Handles file operations like reading, writing files etc. This module should log its actions. The logger is injected via dependency injection. NullLogger (implements Logger) Discards all log mess...
I've been mainly programming PHP, and I recently started with C++. In PHP the return of a function can be of any type, so you can do checks like this: public function doSomething() { if (! this->userHasAttribute()) { return false; } return "you are logged in."; } So basically, if the user would not...
I'm designing an application that will be appending blobs to a file on disk (local filesystem) and I'm currently thinking of how to deal with consistency issues that could occur if: The application suddenly crashes The whole system stops, e.g. due to a power outage The goal is that, when the file is later-on read, th...
The system I am working on employs quite a sophisticated caching/preloading mechanism for external third-parties, and since it is built on a microservice architecture, I would like to extract the whole caching/preloading functionality from a feature microservice (say, booking/searching) to a dedicated one: +-----+ ...
I have a current situation where I have to design calls to multiple webservices, coming from different companies, let's say EnrollFacebook, EnrollGoogle, EnrollYelp, EnrollBing. I need to build different options that bundle this enrolls, for instance: PlanA: EnrollFacebook, EnrollGoogle, EnrollBing PlanB: EnrollGoogl...
I'm going to implement a BFD module (for MPLS LSPs) in VxWorks and was wondering the following: Is it better to create and use a separate timer instance (<2048) per BFD session at the specified Tx interval or is it better to use a global timer that runs at 100us and checks each session's the time that has expired since...
I've been puzzling over a good implementation for this for a while. I have a program that does a long-running I/O operation (downloading a file) and a long-running CPU operation (parsing its contents). To improve efficiency, I wanted to have one thread pool perform the I/O section and have it pass tasks to another th...
I have a very simple question that has been haunting me for a while when my code starts growing. Should parameters be replaced by global variables when they go through long routes of nested function calls? I understand that global environment can make the state of a program unpredictable because many functions can mod...
At work we have a project where we're pushing pieces of the monolith into modules. (A java project making smaller maven modules that we pull in via maven dependencies). The pattern we're using pushes each module into a 'pair' - with a module for the interface, and a module for the implementation. The thought occurs t...
Suppose we have a class Player with classes PhysicsComponent, InputComponent and StandingState, DuckingState. The class Player itself does not have an input function, the InputComponent does. But when we change states to DuckingState, for example, the behavior of the input function changes. So how is it set up? a) The ...
I have implemented a mutex on an embedded system that have armv7 processor and a basic scheduler There are several instructions in armv7 instruction set that are used for power efficiency. Two of these instructions are WFE (wait for event) and WFI (wait for interrupt), the instructions enter the processor to idle mode...
I know this is a classic problem but it's so hard to chose the right way or the best. Let me present you a simplified version of the code. Design 1 using switch : public class Disease { private Color color; } public class City { private String name; private int yellowCubes; private int redCubes; private...
So, at the moment I find myself building my c#/.net (web) application ( or folder/project/package-...) structure often like this, thinking about it in a "somewhat onion-architectural way": myApp - API - Controllers for HTTP, REST etc., may even be a whole gui, though ... - Domain.Model - "Busine...
I have two engineers with very different development styles. Engineer A prefers a high degree of upfront planning and designing, considerations for all possible options with pros/cons mapped out. Engineer B prefers to find the quickest path to test. We are a skunkworks team and are responsible for testing a bunch of n...
I am facing a BIG BALL OF MUD pattern (according the Foot and Yoder paper) at my current job attribution. Interestingly that's not really classified as an Anti-Pattern, and yes the Product works at least. My question is a bit different regarding the How do you dive into a big ball of mud? How do you dive into large c...
I have a large-ish application which's purpose is to aid the user in designing and analysing multiple configurations of Battle Mechs in Mechwarrior: Online. The curious can find the source here. Essentially the data model is a VFS of directories and files where each file is a "loadout", a loadout is a base Battle Mech...
I am building a solution for the recruitment division of an organization. The requirement is to create new employee records in the organization's database for the applicants who have cleared the interviews and are joining the organization. I have built an API to receive the 'Applicant' object from my HR system and cre...
Feel free to correct my history, but as far as I understand it, Rx and the Reactive Manifesto trace their roots back to C# and its Reactive Extensions, which is uses push (callback-based) messaging, so that Publishers call Subscriber methods with values, rather than returning values to a subscribing scope like an itera...
If I had a development workflow that supports SCSS and uses bootstrap. I can place bootstrap tags two ways... Inside the HTML: <div class="col-sm-3 offset-sm-9 col-xl-1 offset-xl-11"> Part of the SCSS: <div class="mymain"> with the following SCSS .mymain { @extends .col-sm-3; @extends .offset-sm-...
I need to design an UI to edit a research paper, I don't have enough knowledge about the research domain but still I tried to do my best and thought to design a normalized schema. I am describing the requirement below. Sample paper format: Below paper showing 4 authors affiliating 3 different organizations. Decoupling...
Might be a silly question, but what is more logical: object.actions.bark() or object.action.bark()? Simply about plurality. I know arrays are usually pluralized. But if I were to be consistent; ideally, objects should be singular in nature, right? I guess you could say my example was more of an associative array rather...
Let me provide an imaginary scenario so that my question is fully understood. Let's assume you are an experienced cross-platform developer for iOS, Android and Windows Mobile. Someone asks you to make them a simple digital clock. Nothin fancy or special and not even a specific font is required. All they want you to d...
I'm switching from Java to Python and am having trouble understanding the @Property decorator. I realized in OOP languages (such as Java) I don't fully understand the point of mutator methods in the following sense: Say we have a private variable x. So we need to make a mutator method public void setX(int val) { x = ...
Say for example I have some unused code that I want to use in the future and does not work with the rest program,or say that I come across some interesting code online. Is there any good program that I can store different pieces of code in?
Specifically for ReactJS and responsive frameworks that show/hide elements based on width like Bootstrap. Because ReactJS has a virtual DOM I am presuming doing the DOM manipulation is faster and in the end a bit easier to debug because you are not trying to think which parts are display:none and there are less element...
I need to design a system where I need to check if a key exists or not. Currently I am already using aerospike for the cause but my use case is slightly different. I will have a key like this ( A group of 3 integers) -- For eg. 1-105-1133441 222-1000-1891893 I just need to know if this key exists or not in the set. If ...
Me and my collegue were having a discussion about when assignee should update 'due date' of the task in JIRA. My point is, assinee should update 'due date' only after he starts working over it so that he has some idea about the time estimate of efforts required. His idea is that 'due date' should be set by managers so ...
In a Java program which I did not made and cannot change, only write extensions for it, the design forces me to create an object which will never be garbage collected. I tested and I can do it through the use of statics or anonymous object instantiation. I know I can do something like: public static MyObject eternalObj...
I want to test my web service/web method not by using SOAP but with Junit or other framework. The first solution that I have founded is to create stub of my project and use a client to call this method; but what I want to do, is not to use a client, but directly call my webmethod inside my project; I am using maven and...
I am working on one project which redirects user to custom page after login, registration etc. FYI, the custom page can be configured as per customer from admin settings. I am trying to follow some design-pattern guidelines to achieve this. So far I have designed my classes as below File: RedirectInterface.php interfac...
I'm planning out a microservice adoption for a rather big monolith. The current plan is to create new features using microservices and constantly extracting features from the monolith into services. During that process is it problematic to let microservices talk to the old monolith? For example, A new Product is develo...
For example, facebook and google have a lot of APIs, like getting data and doing actions on behalf of a user (backup files to Google Drive). I can read all of their documentation but I usually like to keep it very technical. Documentation has a lot of unnecessary text :( Is there a standard for querying a site's (serve...
I am currently in a class for software testing where for our semester project, we have to perform multiple types of testing on it, such as unit testing and integration testing. For integration testing, the professor said to use mocks and mocking libraries (like EasyMock and Mockito) for our integration testing. I'm g...
The "Reinvent the wheel" antipattern is a pretty common one - instead of using a ready solution, write your own from scratch. Code base grows needlessly, slightly different interfaces that do the same thing but slightly differently abound, time is wasted to write (and debug!) functions that are readily available. We al...
I'm designing the database for an application that will need to track inventory. I'm not sure if it's good database design to use "inventory pulls" and "inventory pushes" tables to store each change to the inventory, and calculate each item's count based on those pulls and pushes. Doing it this way would would allow me...
I'm designing a system where items can have tags, which is easy enough. The problem is we also need items to have arbitrary attributes. For example, an item could have an attribute called "Length" with the number value of 10. Another item could have no "Length" attribute. This is to allow users to search for all things...
The background I am working on an ECS in C++ for fun and I am trying to make it as efficient as possible. One of the optimisations I am striving to implement is to minimise cache misses by storing the components contiguously in the memory. Since I want to expose the interface to Lua, I cannot use all the compile time g...