instruction stringlengths 34 36.1k |
|---|
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() ... |
I have library with asynchronous thread and application who use them. Application can pass object to library of type provide by library interface. If application does not create new instance of object and pass for example object which is use to presentation layer than application be suspended for a few seconds may cras... |
If all data types are made non-recursive using tricks like a table of node IDs linking to data and data uses only other node IDs to form a graph, then can all memory be managed using just Reference Counting?
Furthermore is it possible to express a immutable list with the standard set of Haskell-like functions for the l... |
I'm working on the structure of the fields that are persistent in my Unity game. Things like inventory, etc. It is saved by serializing a class and saving to disk (as explained here). The problem I'm having is figuring out the best practice to structure it all. I want 2 classes that can access it - one that checks and ... |
Can I use the crypt() function in my commercial software source?
if I want to use crypt() I have to add
#define _XOPEN_SOURCE
that's why I m asking this question.
Can I use #define _XOPEN_SOURCE in my commercial software source?
|
I know this question is kind of broad, but all I really need is some best-practice code structure or a link to a good tutorial.
I am working on a CRM that runs on php and mysql. Currently, our search query looks something like this:
SELECT * FROM contacts WHERE name LIKE '%ric flair%'
Now, that's really dumbed down, bu... |
I was trying to find alternatives to the use of global variable in some legacy code. But this question is not about the technical alternatives, I'm mainly concerned about the terminology.
The obvious solution is to pass a parameter into the function instead of using a global. In this legacy codebase that would mean th... |
This my proposed structure for my C# program.
My LIN Comms Object/Thread.
Reads data from LIN, and fires two events (data received and data
changed)
then check to see if there is any in the write queue
if so it writes then repeats
if not it repeats
I would like to know if there is another way to structure my Mai... |
What is a technique in MVC that can be used to trigger updates?
Namely,
When user clicks a button save a product I have this:
function saveProduct($product)
{
$this->repository->saveProduct($product);
}
But addition of (any) product must trigger a global state update. I did it like so:
function saveProduct($produ... |
Is there a way to use the existing features of object oriented programming languages to work around the square/rectangle problem?
Can a child be defined in terms of being a more restrictive subset of its parent class rather than being defined in terms of additional features?
Former question:
I'm trying to reconcile th... |
I have the opportunity to work on a project to create a phone app. I have been given a document that's about 60 words total. There are a couple of phone calls and SMS message too, but it's clear to me that I'm going to have to work hard, just to figure out how hard I'm going to have to work.
In the software industry, i... |
My question is similar to (but not exactly the same as) this question. This question was also helpful but it is less similar to my current question than the previous question that I linked to.
I have a framework that runs automated testing. Basically, an XML "script" has data on which methods to call against our API; o... |
Now that we have Red Black trees and AVL trees, it means that inserts and deletes take log(N) time. (We also note that find_min() would take log(N) time).
Comparing these to heap, we have same complexities. However the above mentioned trees are BST so we can search in log(N) there. All in all I don't understand how hea... |
What do you call a class that has methods that
take input (from user, from GET or POST)
transform it to a business object and return that object
example ...
class Input
{
function getObject(array $input)
{
$o = new Object();
$o->setVars($input);
return $o;
}
}
$o = (new Input())-... |
In my application I have quite a few service classes that act as a façade and delegate most calls to one or more underlying manager classes. I've read very different opinions on how to test such façades. Some people say it's not necessary to test them at all, others say one should test whether the integration is workin... |
I'm developing a largeish application that will have custom finite state machines. That is, the admin users of the application will be able to create their own state machines, limited by little pieces of code that are pré built, lets call those tasks.
OK that is all fine and we are reaching a place where we think its g... |
I have a system that uses CQRS with the Queries written using Dapper. It's worked out well, except that there has been a proliferation of query classes that do almost the same thing. The downside of this is that additional queries mean additional maintenance overhead (especially because of the SQL strings) and other pr... |
I understand what increment and decrements operators are (++ and --) and the difference between post and pre (i++ vs ++i) but should they be avoided as they do increase the difficulty of reading the code? After reading the answers to the question Are assignments in the condition part of conditionals a bad practice? it ... |
I'm not sure whether I'm using the correct terminology here. I'm trying to come up with an algorithm that let's me find a vertex in an arbitrary graph so that the vertex has minimum distance to the farthest vertices.
And additionally, I'm also trying to come up with an algorithm that let's me find 2 vertices instead... |
When a modern OS loads a process, it pre-allocates a certain amount of space for stack. This means that the programmer has to be careful to avoid stack overflow by limiting call depth and/or by increasing the stack size in run-time.
At first glance, this seems unnecessarily complicated. Why doesn't the OS implement the... |
Let's have this C# class (it would be almost the same in Java)
public class MyClass {
public string A {get; set;}
public string B {get; set;}
public override bool Equals(object obj) {
var item = obj as MyClass;
if (item == null || this.A == null || item.A == null)
{
return... |
How can I handle the situation when exists the context that represents a collection of arbitrary objects?
This context can be created by code like this:
$context = new Context();
$context->add(new Category($current_category_id));
$context->add(new Filter($one_filter_id));
$context->add(new Filter($another_filter_id));
... |
I have a program that makes hundreds of daily CURL requests, SMTP request, and other requests. Less than 1 percent of the time, a CURL or SMTP request will fail. Best I can tell, the cause of the problem is external and can not be fixed to be 100% reliable. My program is always able to recover from it and no human inte... |
The business team in my company has come up with a new field to add to one of our entities. For new instances of this entity, it'll be calculated dynamically, but for previously existing instances, we need to set up a default value of, at the moment, 15. I can easily set that as the default value in the db, but to me, ... |
I had problems finding a good question title, so feel free to improve on that.
I want to implement an Entity Component System in C++, and wish to use TDD for the first time. Now I have doubts about how useful TDD is when the target "architecture" is already specified, but want to try it anyway. My problem is more of a ... |
The EntityFramework Reverse POCO Generator is a Visual Studio extension / T4 template which derives from the PetaPoco template. The PetaPoco project is licensed as Apache 2.0; and the derived work is labelled as being distributed under Apache 2.0 as well.
However, the author has added a clause to the top of the LICENS... |
Probably I am missing some key aspect here, because I simply have no idea how this metric is supposed to tell me anything described by the authors:
Defect Open and Close rate = (Defects found during testing in a
release / (Defects found during testing in a release + Defects found
after release) *100
What is it?
Wh... |
Is it good practice to store Nuget or NPM (or other) packages in the source control with the source, or to keep them in some other place?
My gut says they belong with the source, however a package will probably version less often then the source, i.e. when a release version is created.
I'm wondering what others people ... |
I'm trying to come up with an algorithm that allows me to find two vertices in an undirected, weighted graph that minimizes the distance to the farthest point.
Distance of the farthest point is basically the distance between two vertices (u, v) in the graph such that distance(u,v) >= distance(x,y) for any two other ver... |
As a budding software engineer, what is worth time-investment in terms of Javascript? I'm interested in long term payoffs in terms of a deeper understanding of languages, tech, software engineering, etc. over just using languages.
I really like JavaScript's prototype model and am perfectly comfortable implementing obje... |
I'm doing some research on authentication methods and I've noticed that not only does Azure call their cloud Active Directory interface API the "Graph API" but also Facebook use the same term with their "Open Graph API".
What does the word "Graph" actually mean in the context of user identity?
Is this just coincidence ... |
I am prototyping a bluetooth headset.
Wondering whether it is possible to buy an existing bluetooth headset, connect it to a computer and reprogram it (i.e. change the behaviour of the buttons etc.). If yes, how? Where can I learn more?
I am a complete beginner, so if it is not fundamentally possible to do, what are my... |
There are some things I am pretty strict about, but const has not been one of them.
For example, I might make a local variable that I use three times in a function, that does not get changed, and yet I do not bother making it const.
Is this something that I should be more strict about? Are there any tangible benefits t... |
I have attached the problem below with the answer. My problem is that I can't understand it. Can you provide an overall explanation in detail about parse trees and ETF grammar by deriving the first expression?
Just try to explain the first expression, a+b/c+d. I think it's not that hard, but I just haven't been able t... |
I don't want to say that is not necessary knowing design patterns. I just want to tell you my experience.
I've used Spring frameworks for four years and another frameworks (JSF, Mybatis, Hibernate, etc) in various projects where I've participated (I work as Java Developer). In all this time, I've used few design patter... |
I have a client which depends on data fetching from two different domains.
Client fetches the data from Domain "A"'s API layer and Domain "A"'s Data Depends on Domain "B"
There is an implementation on Domain "A" services layer to call HTTP Request to Domain "B" s API layer.
What I feel is we should fetch data by Using... |
A trace table is a technique used to test algorithms.
"The table usually takes the form of a multi-column, multi-row table;
With each column showing a variable, and each row showing each number
input into the algorithm and the subsequent values of the variables." ~ Wikipedia
Whereas in a pure functional language ... |
I have a 2D boolean array for example:
01000000
01110000
00110000
01100000
00100000
00111100
00000000
00000000
What I want is to efficiently create a scaled representation for this array according to some size, in example, if the size is 4x4 then the above array will be paratitioned to some 4x4 parts:
0100 0000
0111 0... |
I have multiple projects that I am involved in, and for one of those I have worked for 2 years and delivered a piece of software that is being used in production at customer site.
Everything went really great and customer got back several months after the initial release and said that they want to make some modificati... |
Whenever I am asked how I would scale out an application I inevitably tend toward a queueing model: split the application responsibilities into individual services and add queues between those services. This means you can spin up more or less instances of a given service as required and they simply pull from the queue ... |
I´m currently creating my first restful API for a WebApp and I´m at a point where I´m not sure, how to best structuring it.
Background Information
I´m developing a Holiday planer for a Company. The company is separated in a few departments. So some users are in Department A and some in B for example.
The department inf... |
I have a discussion with a colleague.
He thinks we should inject a mapping class (for mapping the domainmodel to a viewmodel) in a controller.
He thinks we now can test the mapping class (which is an automapper class for some properties) and we can inject another implementation when we need it.
My opinion is that the l... |
Suppose I have a method like this:
public int CalculateAge(DateTime birthDate)
Is this a Command? Query? Or should it be separated and not included as either a command or query?
It fits the query interface (TOut Execute(TIn input), but it's conceptually not a query, more of a mutator.
For a command we would need to ... |
My colleagues and I are struggling with a design problem. I'll try and explain
the situation:
We have a number of different components (let's call them plugins), that take
an input, do something with it, and give an output back. Each plugin takes a
different number (and different types of) inputs, and gives back a di... |
I got a trainee in the company I work for. We are currently working on a JS interface that communicates through websocket with a C/Lang server.
My trainee asked me a very good question this morning.
I quote :
"I understand the system of sending and receiving messages, but how
the computer actually receives and for... |
In a recent question, there's a debate whether or not an arbitrary default value in the definition of a column in a table is considered having business logic in the database. As we know, if an insert statement fails to provide a value for a given column, such default is inserted instead of null.
My question is, besides... |
The company I work at has a (in my opinion) slow build process. We use TFS, and checking in code takes several hours. It goes like this:
(Assuming change is made and code review has been approved)
First, you make your change and submit it for a preapproval step via a button in visual studio. This builds the entire visu... |
In a recent project of mine, I defined a class with the following header:
public class Node extends ArrayList<Node> {
...
}
However, after discussing with my CS professor, he stated that the class would both be "horrible for memory" and "bad practice". I have not found the first to be particularly true, and the se... |
Somewhere I have read that "Object Oriented" is a misnomer and that OO should really stand for "message-oriented programming".
What I am not clear about is ... what does it mean? For example in procedural style you could do :
/*
* Assume that $rawInput is an array
* and that function clean_raw_input returns an array... |
From Wikipedia on Single responsibility principle SoC
... class should have responsibility over a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility
class or module should ... |
Can someone explain if the context diagrams(as used in requirements engineering) have cardinalities(as defined in UML diagrams)?
What I want to ask is, are cardinalities part of a context diagram's syntax?
|
What type of software architecture style does the MEAN stack most resemble?
I am thinking Client/ Server because of the way messages are communicated between the different modules in both.
However, I'm not confident and would like some other people's opinion.
Thanks in advance
|
All of my projects up to this point have been solo (I develop single page web applications). I've always used an IDE which automatically uploads changes to a test Amazon EC2 server over SFTP and I simply refresh my browser page to see the changes. Then when Ive got a stable result, I upload the changes to my production... |
The replies in this post come very strongly against including headers inside a namespace and Doxygen is confused if that is done (which suggests that its team did not consider that usage either). I would like to ask whether including headers inside a namespace is justified in the following case.
I am developing a heade... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.