instruction
stringlengths
34
36.1k
Consider that the Facade has inside it lots of sub-components but it done not pass messages from one sub-component to the other but also has some business logic in it. Is it still Facade pattern?
Recently a co-worker has taken to checking boolean values in the following manner: if boolVar.boolValue { ... } These variable are generally declared explicitly as boolean types either using: var boolVar: Bool! or var boolVar = false I am under the understanding that if a variable is declared as a boolean then i...
I am building a stream processing architecture and was wondering what to do with metadata about the stream. For instance, every message of data coming from a source has the same attribution, as it passes along from source to processing, enriching and eventually to a sink that attribution data does not change but is re...
Just watched a video about continous delivery and there it was suggested to trigger a build and execute unit test on each commit. For our team of 10 developers and a build time of at least 10 minues I wonder how this will work as in 1 hour, all developers might deliver something ==> we might end up having multiple ongo...
TL;DR: I have bad, no .. horrible, horrendous code that kind of works but is a mess and is not easily maintainable. I want to redesign it and repackage it to where objects are well defined and messages that pass between the objects are well-defined, and the whole architecture makes sense and is easily maintainable. Th...
Many places in stackexchange state that you should not unit test implementations, only the public interface of a class. But what if the public interface is a method that doesn't return any value, for example a public SendMailNotifications() method with certain logic that has some internal logic (private methods) and se...
How'd I go about copying a function in memory to a different location and be able to run it from the new location in C++? I thought maybe memcmp would work, but I'm not sure how I'd go about running it after it copied to the new location.
The problem goes like this: There are n piles of wooden planks and m machines, let xi be the number of planks in i-th pile. The machines produce different parts for chairs; each machine requires a different amount of planks, let's denote it by yj for j-th machine. To create a chair, you need one of each part. You ar...
So, as part of my final year project, I'm writing a web crawler in Java to gather website data that I will then process. One of the attributes I need to gather is "number of popups". I know a pop-up blocker can display the number of popups blocked on a given website, and this information would be sufficient. Alternati...
So here's the problem. I have a massive C# project in Visual Studio. It has a big GUI that manages a large number of classes. In one of the form windows, there is a bunch of textboxes. The user fills in the data and then clicks a button and then my class is created to do whatever. How do I work on and quickly run this ...
In code there are private and public declarations. Why shouldn't I make everything private or make everything public?
This question is followup to this question. Is there any benefit in avoiding the 'this' operator when implementing pure methods? That is, are there any advantages to making all dependencies explicit via argument lists, versus allowing implicit dependencies by referencing instance data via the 'this' operator within the...
The Python 3.1.5 docs refer to the % style formatting as "Old String Formatting Operations" and provide this warning that it may be removed: Note: The formatting operations described here are obsolete and may go away in future versions of Python. Use the new String Formatting in new code. The replacement section appe...
I'm working on a boilerplate component that's supposed to generate a working sort-of "getting started" project structure. Think of it, in a web app context, of a component that will generate a Controller, a View and the routes configuration so that once you call it, you can immediately go to the browser, type the route...
So currently where I work we try to mimic our production environment as close as possible to our production environment. Our micro-services (APIs, listeners, data stores) are organized in the fashion that if it performs a responsibility (down to the data model) different than something else it deserves its own containe...
arr[2^30][100000] for (int i = 0; i < 2^28; i++) { value = a*b+c;//only a example. In all, value is an integer. arr[value][arr[value].length++] = i; } My code like above. Random access a 2D array 2^28 times to save the position. But this code is too slow for my algorithm. Does there are any method to speed i...
In my naive opinion it should be O(n) in worst case since Tree could get spindly and unbalanced.
I have a list of domain name that contains wildcard ('*' character) Example: *.google.com *.domain.com ... It contains nearly 1 million domains. The data will be stored on a mongodb or redis database. Given a domain name, such as "abc.domain.com", I need an algorithm that will check the data for a match. For example,...
What is best practice when writing acceptance tests for a form l without knowing the exact layout of the HTML file? Would it be for example to test that the page contains, let's say an element with div[@id=form_field_name], and "force" the developer to use that id? Is there a better way to approach this? I'm using Rob...
First of all I know nothing I can do that 100% prevents illegal copying of my software. I'd like to just make it reasonably hard for a competent person to do, and almost impossible for an unknowledgeable person to do. I have a contract job coming up to develop a web app using the WAMP stack, commissioned by a company's...
In my experience, many of the projects I have read in the past didn't have relationship definitions in the database, instead they only defined them in the source code. So I'm wondering what are the advantages/disadvantages of defining relations between tables in the database and in source code? And the broader question...
In the last several years I keep hearing the term multi-tenancy being thrown around, and each time I Google its meaning it leaves me confused: (Wikipedia) : The term "software multitenancy" refers to a software architecture in which a single instance of software runs on a server and serves multiple tenants. A tenant i...
Is the building process such as waterfall or agile used to implement a system, linked to the way an enterprise system is rolled out in an organisation? As an example: A system is developed using an incremental approach and is implemented into the organisation as each increment is finalized. or A system is developed us...
I make some changes in console application that was released under the MIT license but i don't understand much about the license. Is it required to credit the original author in it and do i need to credit myself for changes?
As getters in C# may be relatively costly, I wonder if they will be called every time or if the compiler will do any optimizations. Let's have a look on this: List<A> CurrentList{ get; } void DoSomethingWithList() { if(CurrentList.Count > 42) { foreach(A processingA in CurrentList) { ...
Java service classes... I have two service classes one for 'store'(save) data, another service for 'load' to display content. It was implemented , now new requirement - depends on user input for load (for ex version) if it is not latest one do some logic to upgrade(based on some xslt transfomation) and save(store) the ...
How do you keep track of maven dependency versions? Let's say you are using version 1.0.5 of an library. <dependency> <groupId>groupIdName</groupId> <artifactId>artecfact-id</artifactId> <version>1.0.5</version> </dependency> But some people find a very bad security bug in version 1.0.5 and they release ve...
Context Our group builds and is responsible for maintaining multiple apps for a larger institution. We are in the process of breaking up our monoliths into reusable microservices (hooray!). When we got up to notifications (primarily email notifications) we got stuck. Our users consume multiple applications, and each se...
Today we have vendors selling cloud based enterprise systems which an organization can lease and also configure and customize to fit the organisations needs. Even if there is work in performing configuration and customization, the implementations can still be done quicker than if the system was to be built in house lik...
Encapsulation is a mechanism of wrapping the data (variables) and code acting on the data (methods) together as a single unit. Client code is expected to inherit from system-supplied classes and then substituted for the system's classes in its algorithms. Inheritance is when an object or class is based on another objec...
The title of my question is general because I feel like this problem is of a general nature, but to set the stage I'm going to provide a specific example. We use a homegrown workflow engine that is driven by database tables. Within those tables lurks a directed graph that represents the workflow. The graph contains S...
The following code examples provide context to my question. The Room class is initialized with a delegate. In the first implementation of the Room class, there are no guards against delegates that throw exceptions. Such exceptions will bubble up to the North property, where the delegate is evaluated (note: the Main() m...
I had a job interview recently and I was supposed to do an exercise where one part of the coding was using the ExecutorCompletionService. Well, there were other ways, but this would have been the easiest. My problem : I did not know about this. After I found out about this, I could look it up easily (tutorials, example...
Note: I get that refactoring is something you do along the way, you don't treat it as it's own "thing", or it's own specific task. I am talking about refactoring along the way, however I am not sure how much time I might end up spending refactoring or rewriting instead of solely implementing new features. I've been ask...
I am implementing a finite state machine in Python 2.7, and I am considering using an English word that I don't commonly see in code: "stimulus". I have a transition function that accepts some kind of input and the current state to decide which state to transition to: def transition(self, stimulus): # each state c...
Recently I worked with a Restful API server and encountered a problem with handling database error. The basic approach is every time a SQL exception occurred, the server will return "500" to client and client will have no idea what is wrong inside the server. It's fine for server errors. But sometimes, the errors are ...
I have a website that's running on a production server, backed by mongodb. Every hour or so, some new data becomes available that I want to add to the db, inserting new documents, and updating old ones. I get the new data on a development server, and update the dev server's copy of the db. If everything looks good, I ...
I know requiring javascript on a webpage has been a hot topic the last couple years. I'm wondering if someone wanted to use custom elements but still allow the website to be usable without javascript how would they do that? Would they have to add a <noscript> with regular elements? or is there some way for browsers to...
I have a seemingly standard task of sending push notifications to Apple devices from a server written in Java. I have never done that in the past, so I went to tutorials and Apple documentation. 1) The APN Provider API claims that THE protocol to send push notifications from the server is HTTP/2. I failed to find any t...
The following program starts with hundreds of permutations and shrinks them down to a small result set. Furthermore, I am only looking for the first valid result. What techniques can I use to make this more efficient? #!/usr/bin/python3 from itertools import permutations, zip_longest def get_result(): checked = [...
I'm about to write a Java library. Basically, this library provides something like this to its user: interface Foo { void doA(); boolean aWorked(); void doB(int value); } The user is not supposed to implement this interface (obviously). Thus, user code will look something like this: Foo f = Library::SomeFactory(...
These days I have seen couple of sites (including Youtube) that stream videos through Ajax calls (XHR) in few MBs or even less than MB. For an example of what I said see the highlighted lines in the image below. I want to know: What this technique is called in programming terminology? How it works?
In the relational database world, we would tend to store unique pieces of data uniquely (e.g., in a single table, for example). However, now, with object stores (e.g., Firebase) it seems like storing the same piece of data in multiple places might be the best-practice? Is this true? For example, I want to have users st...
I have a StringValidator. A StringValidator is either a Regex or a string pattern using '*' wildcards. I want the StringValidator.StringIsValid() to perform one action or a different one, depending on which overloaded constructor was used. I can think of several ways to do this, but I have no idea of the best way. Note...
I'm using a third party product that has a class I can extend to provide a new way for that product to get data (the product is Sitecore but I don't think it's super relevant to the question). They have a DataProvider class that I can extend: public class Sitecore.DataProvider { public ItemDefinition GetItemDefinit...
Let's say you have three development branches going at once (dev 1, dev 2, dev 3), each branch working on different features for a given software product. If I understand continuous integration correctly, these development lines would each need to constantly check code back in to a shared main line (once it has passed ...
While creating server.js file we need to provide routes information as var Login = require('./routes/login.js'); app.use('/login', Login); Now, suppose the node project is a REST services project. so this type of entries could extend to lots of lines , meaning for every route we need to provide the above given 2 line...
Given finder : List of map, key : String, Val : String. On receiving super map : a map which is super set of one or more map in a finder, find map from finder list which has contains maximum elements from super map. For instance Map { Name = Adam, Qualification = Engg, Job = Manager , Country = US, City = Seattle} l...
I was wondering what the best practice is regarding databases for integration tests on the build server. If there is a best practice. Currently, our build will create a new database from scratch for every build. Integration tests are then performed against this. However, as the project has a long history, and continues...
I have a large number of classes with an abstract base class (A) that contains behaviour that must be supported by all the sub classes say [B..I]. In my code, I end up with a collection of objects that is created based on input from an external system. These objects belong to subclasses described above and they go thr...
I was going over some old code and found the following peculiar naming convention at a template method implementation. // TEMPLATE METHOD // Checks condition and fail fast if condition is met. // Otherwise call the hook method (to be implemented by subclasses). @Override public boolean accept(String text) { if (con...
I am working with a big set of data right now and I wrote a program that calculates a result based on some inputs. I have 10 inputs, each of them has about 20 different possible values. I am not sure what technique to use to find the combination of these inputs that will produce the biggest result. Here is a made up ex...
If I have a complex attendance project to track the employees attendance and leaving, and according to that they get overtime money through a workflow. The schedule is something like that : 6 weeks clickable on the top and the dates of the month in the right hand side. I save the overall calculation but sometimes so...
I'm currently writing unit tests for my PHP code. I've read that unit tests should not interract with external elements such as network and filesystem. In my code i have a curl wrapper class to simplify curl calls (i just use $response = CurlWrapper::call($url)) For my tests, i added a mock to replace this wrapper. my ...
I'm currently trying to build an API to be used for reporting-purposes. Therefore I do only need to implement some GET endpoints. In my simple scenario there are two resources. An event and the creator of the event. Each event has one creator. For one report I do need all events created between a given time-frame. GET...
I've been told that in functional programming one is not supposed to throw and/or observe exceptions. Instead an erroneous calculation should be evaluated as a bottom value. In Python (or other languages that do not fully encourage functional programming) one can return None(or another alternative treated as the bottom...
In investigations into REST, I've seen a lot about CRUD vs REST (see Difference between REST and CRUD) and how REST is not CRUD. I've come across a couple of articles that talk about exposing intent resources and I'm trying to understand what is meant by that. The best I can understand is that this means the REST API ...
I have a polyglot database solution that includes the following components: a management interface that consists of a web application and a document based database (either rethinkdb or mongo) a routing service that is a key/value store database... with a simple REST API that allows CRUD functionality. The routing d...
I am working with an application that is composed of several different, disconnected, components and each piece has a dependency on up to three different Data Stores (SQL Server, Doc Storage, BLOB Storage). The SQL Server connection details are always known at design / deployment time, however the Doc and BLOB storag...
Consider the following (example) code: class A { private: int *_a; public: A() { /* initialize _a to something */ } ~A() { /* deallocate _a */ } void setA(int i) const { _a[i] = 3; } }; This code compiles and will perform as expected (i.e., if you call setA with some input i, it will se...
We have an activity metrics page where users can select a date period and see other user's aggregated activity (by action) and optionally filter everything by 4 or 5 fields. Actions happen sequentially, but one of the fields is "Tags" and the user may change old action's tags anytime. The data is in a Cassandra 3.7 wit...
I am currently learning to apply the SRP and decouple code. But I found that having a lot of small classes blows up constructors of my classes. And it feels like code that uses another module of my application has to know more of that module than I like to know it. I found that many books mention that classes should be...
From Operating System Concepts by Abraham Silberschatz, Peter B. Galvin, Greg Gagne 5.8.3 Implementing a Monitor Using Semaphores We now consider a possible implementation of the monitor mechanism using semaphores. For each monitor, a semaphore mutex (initialized to 1) is provided. A process must execute wait(mut...
I am currently working in my matrix class. After completion of the matrix I am planing to write a unit test for this matrix class testing all the functions that I wrote. class Matrix{ Matrix(size_t, size_t); Matrix transpose(); Matrix operator+(const Matrix&)const; ... private: std::vector<std::ve...
Apropos of What kind of bugs do "goto" statements lead to? Are there any historically significant examples? I am not that learned in C, and to me the puzzle is that a single exit of a function is mandatory, but a goto is considered bad. Often one has to exit a function on a error condition, and then use a goto to the e...
We've got a solution with 20 .NET Framework 4.5 .DLLs (say helloworld01.dll to helloworld20.dll) where we want to add Linux support (to each) in the near future. We think this means each of those needs to be recompiled as .NET Core 1.0 targets. Leaving source code porting aside and only looking at the organization/stru...
A context - I have been using TFP as well as TDD for more than a decade now; In languages like C++ where there was no Test Framework at that time, to other programming languages and different domains. However whenever I try to mentor, convey the importance of TDD to others, most people inevitably think I am talking abo...
I't s a Database related Entity Relationship (ER) doubt: Better to have a single table storing A,B,C as a unique identifier or a Relationship. O better to split it up to three tables having then A,B - B,C - A,C The result should be the same , having identified uniquely an A,B,C triple. But what's could be more performa...
I am designing a Deployment diagram and a Component diagram for an existing Java EE application. The app has integration with 3 external systems through soap web services and ftp. I am including these systems in the Component diagram but I'm not sure if I should include them in the deployment diagram. Should I? I could...
I'm trying to convince my team lead to allow using exceptions in C++ instead of returning a bool isSuccessful or an enum with the error code. However, I can't counter this criticism of his. Consider this library: class OpenFileException() : public std::runtime_error { } void B(); void C(); /** Does blah and blah. */ ...
I am having a long-term debate with my architect about architecture choices. The entreprise where I work in is migrating from a monolithic architecture to a microservices one. The debate is located on the good approach for handling database access. One of us is standing there is no need for separating DAO and service (...
We're developing an app that has slightly different requirements for each business market (countries and states) that it's available from. It seems like a common situation but I can't seem to find a good article about structuring code/modules for this scenario. It's a C# app and we're debating between Strategy vs Temp...
I've recently read up on PSR-3 and am interested in learning about the best way(s) of approaching a logger implementation across a web application or website. I understand how a logger is defined and how they can be implemented per PSR-3, but what about accessing/referencing them across the application for various logg...
I've a query for you relating to best use of EF6 when using Winforms yet not having justification for changing things to something more modern. I've got half a dozen classes that are based on DbContext so there's no change tracking (I've yet to understand why but that's a different question). I've a databound form that...
When comparing the Windows, macOS, and Linux kernel to each other, do some make better use of hardware in terms of cache efficiently, page lookups, or power consumption? I noticed this after comparing macOS to Linux on my machine side-by-side where Linux ran significantly warmer than macOS, and consumed more power. Wh...
I'm developing a system on which there are two requirements that seems to be in conflict. Since this seems to be a situation that can be more general, I thought it to be valid to ask here. The system in question is for management of the finances of a company. In the system the customers are registered and in the custo...
From Operating System Concepts by Abraham Silberschatz, Peter B. Galvin, Greg Gagne, Peterson's solution to the critical-section problem has two processes Pi and Pj, do { flag[i] = true; turn = j; while (flag[j] && turn == j); critical section flag[i] = false; remainder section } while (true)...
I think it is well understood that the risk in a software engineering project increases with the size of the project, and the slope of the scale exceeds linear. As the number of features increase, not only will an estimate increase, but the margin of error in that estimate increases as well. For this reason, Agile met...
I'm not finding via Google any explanation that my brain can grasp. Can someone explain this, and if possible, give an example of each using either pseudocode or C#? The term 'total' function was introduced to me in the comments section of this question. The comment is: when you work with total functions, you can comp...
I'm making a Clue(do) board game in Java to improve my programming skills. I've done a lot of work so far, but now I'm stuck at finding an algorithm to make sure if a player can make a certain move. Quick draw of how it's organised: Superclass GameTile Subclasses for each roomtype (RoomTile, DefaultTile, StartTile & O...
I'm having a difficulty to figure out relating an item to classes properly. For example, I have a business directory website that shows profiles of different companies according to the products/services they offer. "LG" company, for instance, produces smartphones, TVs, blenders, etc. I want the company to show up on e...
A friend of me and I would like to easily know if stuff like chores were done, and we're both in two different locations. So, would it be very hard (would I need a lot of experience?) and take a lot of time to make an app that both me and my friend can have on our iPhones that communicates with each other over for exa...
I am looking for an algorithm that calculates positions of nodes in a non-binary tree. The positions in that layout will be used for drawing the tree. I am using the tree in a mind map application. Currently I use algorithm by C. Buchheim et al, "Improving Walker's Algorithm to Run in Linear Time" (2002). Unfortunately...
If the set of MIPS instructions were changed to accommodate 128 records and 4 times more instructions type-I, which would be the largest hexadecimal immediate value that could be supported, keeping the 32-bit instructions?
Let's assume I want to write a function that concatenates two strings in C. The way I would write it is: void concat(char s[], char t[]){ int i = 0; int j = 0; while (s[i] != '\0'){ i++; } while (t[j] != '\0'){ s[i] = t[j]; i++; j++; } s[i] = '\0'; } Howe...
In bare metal or minimal RTOS type embedded systems with multiple processors is it possible to have an identical program running on each processor that uses Message Passing Interface (MPI) to provide load balancing and also redundancy in the case of processor failure? Such as a state machine that changes what actions o...
Imagine scenario: need to strip out spaces from a string to be used lets say in url. Now would it be smart to do this once before saving in DB, and than use raw db results when outputting. Or would it be smart to write helper function and just do space removal when outputting and keep data saved raw in DB?
This is more a curiosity than a real-world requirement. As an example to demonstrate what I mean by 'Controlling how an interface is implemented'.. Say I wanted to implement a new task scheduler, and I exposed ways for the user to enqueue new work. The work adheres to some interface IWork.DoWork, or whatever. How can I...
I've been doing research on CI (continuous integration) and I can't find any info on the changes CI would introduce to ticket sizing. CI states developers should merge to the mainline every day (or even multiple times a day), but if that is the case doesn't that mean when sizing tickets those tickets would have to be b...
We're developing a web application that is now growing to quite a few pages, all dealing with complex data and rather complex interactions between pages. For instance, the login flow encompasses the following different possible requests to our controllers: Login -> Forgot Password -> Send email [POST only] -> Password...
In large PHP OOP application is it bad practice to have procedural code outside of class definitions i mean that works independently from objects? e.g. intertwine OOP and Procedural code in same application. Should i try generally to keep all code inside Class'es as much as possible? I mean of course i got to have cod...
I'm working through the Head First Design Patterns book and am currently on the Decorator Pattern chapter. Since the book examples are written in Java, I'm adapting the, to C# as I go. This example simulates a coffee shop ordering system. There is an abstract base class for Beverage and subclasses for specific beverage...
I am trying to create a java console program which displays a Menu with few options. Each option selection performs some independent operation say executing a script or performing some db operation, for example: 1 option1title 2 option2title 3 option3title ... I need to design this such that I should be able t...
In a project, its program is written in C++, and implements some http service. The testing program for the project is written in Python. The Python testing program doesn't call the C++ project program at source level, but loads and executes the executable compiled from the C++ project program, and interacts with the ...
Some operators cannot be overloaded as class members. One such example are the bitwise shift operators used for streams see here for example. The reason for that (as far as I understand it) seems to be that the left hand site operand is the one you define the behaviour for and you cannot define behaviour for the built-...
I have a question regarding a specific case with our product. Let's say I have two services; Service A and Service B. (The number of services varies from an installation to installation). They are deployed into our Docker Swarm. They do not publish any ports, meaning that they are not reachable from outside our Swarm c...
I'm trying to figure out how to create abstraction over different APIs, which have common things. For example let's take the mobile platforms you have Android, Windows Phone and IOS. Let's say I want to create and API or program or domain-specific language, which will allow me to write one program and work on all of th...
I'm writing an app, and I would like users to have the ability to sign in across multiple devices and still have their data. My question is, when the user signs out of their account on device X, should I delete the entire database and reload their data from the server when they sign in on device Y? This is an issue for...
I am working in a team that mainly write small PHP sites. Currently we don't have a habit of writing unit test. Testing are done by using the site as a user by our PM, who don't know how to code, and UAT by the customer. However, as the projects we take are getting bigger, it starts to have more bugs created due to cha...
Is there any purpose for declaring an init() method for a type? I'm not asking whether we should prefer init() over a constructor or how to avoid declaring init(). I'm asking if there is any rationale behind declaring an init() method (seeing how common it is) or if it's a code smell and should be avoided. The init() ...