instruction stringlengths 34 36.1k |
|---|
Which programming languages support operators as first class citizens? eg: Return an operator (+, -, =, ==, etc.) from a function, or store within a variable.
|
Scenario:
I have a situation where I need to refactor a Web service with a single API endpoint that uses complex logic to insert, update and fetch data from a database. The clients use one call, and depending on the data transfer object they send, the service is doing different things (the API was not designed by me so... |
Computer vision includes:
Character recognition (converting an image to text)
Face recognition (detecting a face in an image)
Object recognition (detecting various objects in an image)
Human recognition (detecting a human shape in an image)
Motion detection/object Tracking (detecting motions/movement)
All of these ar... |
It seems Java has had the power to declare classes not-derivable for ages, and now C++ has it too. However, in the light of the Open/Close principle in SOLID, why would that be useful? To me, the final keyword sounds just like friend - it is legal, but if you are using it, most probably the design is wrong. Please prov... |
In my project I've used a library marked with the LGPL license as a reference example to developed my own library which is completely different but it works roughly in the same way.
Now I would like to sell my project which clearly links my own library and not the original one.
Is there any limitation?
Thanks
|
My application is growing in complexity.
Currently, I have a collection of classes that make up a "Backend", this contains a DataInterface that talks to a database and returns POCO classes, a ModelProvider that wraps them up in models, and a ViewModelProvider that creates views, all dependent on each other.
These insta... |
I am looking for a Term/Word for specific type of tables.
I have tried to search a lot, but I could not come up with best search terms for this.
Tables that hold some master information, such as products, users, customers, brands etc. for the system are called - Master tables.
Tables that hold some transaction informat... |
I'm working on a ASP.NET application that is required to communicate with a Flask web service.
My initial thought was to include the communication with web service directly into the aspx file, similiar to Scenario 1. However, I thought that Scenario 2 could be a cleaner solution as I can hide the properties such as ur... |
I'm partitioning a stream of input data between n servers. The simple way of doing it is to use the hash of some property of each input data packet to assign a single server, using mod or similar, and be done with it.
However, I want some degree of resiliancy - if one server goes down, nothing is lost. I want to partit... |
In "Rob Pike's 5 Rules of Programming", he states, "Fancy algorithms are slow when n is small, and n is usually small. Fancy algorithms have big constants. " and as the next rule he states that "Fancy algorithms are buggier than simple ones, and they're much harder to implement." What does he means by "fancy" algorithm... |
Background
I am working on a project with C# .NET, and I've just added a new unit test project to my solution in Visual Studio. The way that I always have been doing this is:
Create a new unit test project.
Have that project include a reference to the project under test.
Just include (using) the project.
I guess the ... |
In my Android app I want to have a couple of demonstration functions (i.e., functions that are not yet implemented but I want to show what they would look like if they were).
All that needs to be done is to change the text and background color of TextView elements, at specified times.
For example, when the app starts u... |
My job involves a project that has a lot of different pieces that all need to communicate via XML messages. There are two schools of thought on how these messages should be organized.
In reality these messages can contain hundreds of fields and lots of nesting, but I'll try to simplify. So let's say the project is for ... |
I have a System which depends on Transactions, and a few other things. This list can become very long. Transactions can be (and will be) implemented in two ways or more, so every transaction is an interface.
public class System
{
ctor(ITransactionA a, ITransactionB b, ... ITransactionN n, ...)
}
In my DI tool, I r... |
Programmers often talk about point-free style. In contrast to the imperative style (pseudocode):
h := function(x) {
y := f(x)
z := g(y)
return z;
}
one might write the following point-free:
h := f . g
where . is composition and the argument is now implicit. I'm wondering if there is a name for
h := function(x) ... |
In the past, I used the standard way of adding @Deprecated annotations to API methods which will be removed in a later version.
Now I am preparing a major version for a library, with many API parts removed and renamed.
To make the transition easier for existing users, maybe it could be helpful if the new library versio... |
I have been experimenting lately with enums, and I found out that in Java they can do much more than simply representing a fixed set of constants.
Now, I am thinking about creating a new enum for my Logger class, to hold the different log severity levels (info, warn, error, etc), but I am wondering why shouldn't I tak... |
What's the semantic version of the same software for different OS ?
For exemple : X.Y.Z
X is a major version
Y is a minor version
Z is a patch
If I have the same version but for 3 different OS; How can I call them ?
I don't find the answer in semver.org or in google..
|
I'm desing API for generic task executor that currently supports two calls:
Accept task
Get task info
The (2) provides detailed information about the task with the task status and custom message, for example in JSON format:
{
...
status: "SUCCESS",
message: "The task has been finished successfully"
...
}
... |
This question may have been asked before and if so feel free to link to the answer. I'm looking for a modern and effective recipe for a common problem. I have a project with a main module, A, that depends on another module, B, that I develop separately. this module has 2-3 (C-E) other modules it depends on, each of whi... |
I'm having trouble understanding a small passage in The Structure and Interpretation of Computer Programs, and I'm hoping someone can help me interpret it.
In the book's introduction to Orders of Growth (Big O Stuff--Page 48 in volume 2) the book states:
We say that R(n) (resources required to compute a problem of siz... |
I am working on a project which is a rewrite of an existing legacy software. The legacy software primarily consists of CRUD operations (create, read, update, delete) on an SQL database.
Despite the CRUD-based style of coding, the legacy software is extremely complex. This software complexity is not only the result of t... |
In Erlang, an ordering of the built-in basic data types has been established:
number < atom < reference < fun < port < pid < tuple < list < bit string
This means that sorting a list with a variety of different data types is possible. ([1, 2, 'foo', 42, {3}, 1] becomes [1, 1, 2, 42, {3}, 'foo']).
However, it seems very ... |
After some time in every project sooner or later you will need to find a feature in it a fix it or extend it so I was wondering if there is already a system or a convention for marking those features in code... what I mean is to somehow mark a place or places in code where a particular functionality is implemented or t... |
In C#, when a field getting or setting requires logic, we use properties. For example:
private int _age;
public int Age
{
get
{
Console.Writeline("Club member is {0} years old", _age);
}
set
{
if(value > 0 && value < 120)
{
_age = value;
}
else
... |
Still learning and getting my head around Unit Testing, (also trying to get into TDD, though I appreciate it isn't the same thing) and in many ways it is changing/improving my code. But I come across scenarios where I am unsure how to test a piece of functionality. Which leaves me wondering whether it's my code desig... |
My colleagues like to say "logging/caching/etc. is a cross-cutting concern" and then proceed using the corresponding singleton everywhere. Yet they love IoC and DI.
Is it really a valid excuse to break the SOLID principle?
|
I'm investigating how we can notify UI/async clients (websocket) about an update which happened in an embedded view.
Let me elaborate...
We currently have a newsfeed where NewsItem is an aggregate root which acts as a wrapper for news about other aggregates. News is extracted asynchronously from domain events of sever... |
How to implement some constrained .NET struct/structure (let's say LimitedString), where its state with default values (set by CLR to technical defaults, i.e. nulls, zeros, etc.) should be prohibited due to some design constraint?
For example in case of trivial struct LimitedString, properties are String Value and int ... |
This programming style document has a general rule, that says :
The rules can be violated if there are strong personal objections
against them.
This collides with the way I am thinking, and there are many articles saying that coding style is actually important. For example this says:
A coding standards document te... |
I'm reading the JavaScript guide on MDN and trying to understand the usefulness of closures. This sentence helped me the most, "In other words, the functions defined in the closure 'remember' the environment in which they were created." And I understand that part, but I don't get why this function...
var getCode = (fun... |
In order to be able to create better documentation, better tests and to start using the just gotten to know requirement traceblity matrix I'm trying to understand the different software requirement layers/levels first.
I found that there are actually three of them. Would you say that in general this is true?
Business ... |
Our application is a 6-year old legacy application made by out-of-house contractors. Occasionally we stumble upon the skeleton of something they put together but never implemented, and it causes us to stumble as we try to figure out how it's used in the app.
One of these classes seems like it might be close to what I... |
I'm working on application in C#, where I need to serialize and deserialize some classes into/from XML. This operations will be implemented in Class Library. I chose XMLSerialization class to serialize/deserialize these classes to XML file. As you know, this implementation uses reflection, which has the condition that ... |
I am currently learning C++ from the C++ Primer 5th edition. The book's chapter on functions states that only large objects (large being relative as standard library strings count, but "primitive types" such as int or char don't) should be passed as references.
For instance, the following function serves as an example ... |
This is how I do my JWT refresh token:
A token is check for validity every time a request is made.
If it's not expired, allow access.
If it's expired calls another function named RefreshToken to give a new token to the user.
Ok this mechanism is good enough except that every expired token (of that user, provided that i... |
I am writing a simple IRC chatbot in Python and, in an effort to get more into OOP, made a basic "connection" class that manages all the backing-and-forthing involved. But IRC protocol is rather annoying to work with, so I wrote a function that takes the raw message from the server and translates it into a form that's ... |
I want to implement gamification in my education mobile application. I have a database with user activity and I want to analyze it and give badges to a user. There will be many badges with totally different conditions. Some badges will be given once, others repeatedly.
My current approach:
badges_awarded table that co... |
Like:
switch (value) {
default:
something_common()
case 1:
niche_case()
...
}
etcetera.
if-else statements require an "if" first and an "else" last, but switch statements are more flexible in their ordering. I think it's important to know what will happen "normally", which default indicates.
|
Im a beginner using visual studio 2013, and I know what they are, but I'm puzzled, why would one use a local variable? I would always just use a global variable.
|
I had a discussion with a co-worker about interface members having parameters that some implementations don't use.
Say I have an interface
interface IDoctor
{
string GetMedicalOpinion(Age age, Weight weight, SleepSchedule sleepSchedule, Symptom symptom)
}
Implementations of IDoctor won't necessarily use every meth... |
The compiler doesn't leave its own code in the software or link proprietary libraries with it, the source code is exactly the same one I used throughout the development process, everyone is free to access and modify the source code, but no one can actually build a modified version of the software unless they have bough... |
According to a book I read you can pass variables from one function to another by passing by value/address. When you pass by address it will no longer preserve the variable if it is changed in a function and returned back to the original function (ex: main()). The very next chapter, the book reviews "returning values".... |
In Instagram (web), when you click back/forward arrows - I've noticed that the content isn't loaded from the server and it immediately show up. After reading the docs on react.js + flux, I had this understanding:
Action -> Dispatcher -> Stores ... where the storeswould listen for changes and load new data from server i... |
I have recently worked on a Python project where we did dependency injection heavily (because we must in order for the app to be testable), but we didn't use any framework. At times it was a little tedious to wire up all the dependencies manually, but overall it worked great.
When an object had to be created in multipl... |
I add a lot of elements to a list of lists. If the list of lists my element should be saved to, does not exist yet, I handle this by catching an exception and adding a new list to my list of lists.
The reason I do this instead of checking every time, if the specified list already exists, is, that I add thousands of ele... |
When uploading a lot of images to a server, to minimize the space taken by the images, is it better to resize the images before sending to the server or upon receiving them?
It seems to me that resizing them in JavaScript can take long time for not a lot of gains. Is there any value to doing it on the client side?
EDIT... |
So, I've written some fairly big code for cent OS 7.1. The code essentially makes use of different command line tools by parsing the text output and shoving it in a database... pretty straight forward.
Now I'm tasked with making this code run on Ubuntu, cent OS 6, and potentially other flavors. The code of concern is p... |
I'm building a web application with C#, and I have an aggregate root which has several entities and value objects. Then I have a repository object which persists the aggregate to the database (I'm using ADO.NET as my infrastructure persistence layer).
The aggregate also has several events attached to its methods, so th... |
When I have some object with boolean state that can be changed (like a checkbox's checkedness), there are several ways I can expose it.
Getter property, Setter method
bool IsChecked { get { ... } }
void SetChecked(bool checked) { ... }
Getter property, Set true method, Set false method
bool IsChecked { get { ... } }
... |
When methods use a database connection, should the connection be a static field, an instance field, or a local variable?
Here are my doubts. I dithered which are correct and which are baseless. I tried to give sources to my assumptions, but most of it stems from things I have read here and there, and probably did not u... |
The mission: Implement a program that will listen to multiple client requests asynchronously (on TCP) and transfer them to a server (also on TCP) to which only one connection is allowed. The program will also receive answers from the server and transfer each answer to the relevant client.
The question: What is the best... |
I have three classes: User, Conversation and Message:
Message properties:
User sender;
// Some more
Conversation properties:
List<Message> messages;
List<User> participants;
// Some more
I want to show in the program the creator of the conversation. I wonder if It is bad programming to add a creator property to the ... |
I am looking around to create an offline HTML5 app to be used in both Android and iOS (I do not have the means to create a native iOS app), but when looking up some technology I find this interesting conundrum:
From the AppCache docs:
Deprecated
This feature has been removed from the Web standards. Though some brows... |
We currently have an ongoing discussion about which approach to move into - we want to replace multiple older environments with .NET applications, and two potential architectures are under discussion:
Client-Server ('fat-client'): requires an installation on each client
Web-based ('thin-client'): works in any browser,... |
I have a couple of schedule value classes that represent the value a schedule holds for a specific slot.
First, there's the ScheduleValue class for schedules with two dimensions, where the first one (rows) is the players and the second (columns) the timeslots (when the players play each match).
I represented the differ... |
I have a fairly complex immutable data type that I'm using a builder object to instantiate. Currently, I have a setup where I parse a file, setting various fields in my builder, and then build the object. However, the files I'm using are error-prone, so I want to do some verification on my unbuilt objects first. And... |
I noticed this in the heading of some source code
This core is written with the advise and consent of [author] and is
released under the GNU Public License. This core is freely available for
use in any freeware project, subject to the following terms:
Any modifications to this code must be duly noted in the s... |
In our company we have multiple test stages:
unit and integration tests (CI build)
application tests (all calls to
other systems are mocked)
system tests (interacting with other
systems)
all builds run on TeamCity
As soon as a build fails, one developer has to inform the responsible person which broke the tests. Th... |
In our system a media file can have several states:
invalid
empty
uploading
ingesting
ready…
..depending of the state, information about the media is accessed in different ways. For example:
During upload the file name is on a temporary upload info JSON file on the filesystem.
When the object is ready this file n... |
Looking for some help getting my head around ninject and DI.
Using the simple examples I've found online everything works nicely but trying to do something more complex is causing headaches.
I have a class library that receives files, analyses them and stores the result in a database. This library can be called from va... |
Background
Working as a software engineer in the field of electronics, I often find that none of the existing design patterns i.e. GoF typically fit the bill for what I need to do. One of the patterns that I frequently use works something like this:
Open up a connection to some electronic device.
Transmit a command to... |
I've read some answers to questions along a similar line such as "How do you keep your unit tests working when refactoring?". In my case the scenario is slightly different in that
I've been given a project to review and bring in line with some standards we have, currently there are no tests at all for the project!
I've... |
It is a well-known fact that there is no built-in mechanism that prevents member fields that are references from being invalidated, even if they are const. (For more background see: https://herbsutter.com/2008/01/01/gotw-88-a-candidate-for-the-most-important-const/)
The easiest solution is to only use non-reference mem... |
I'm starting to develop an android application where I have to persist user data. For server data I want to use Google Cloud with noSQL but I don't know what to use to save data in local memory when the user doesn't have connection. My principal conflict is to mantain synchronized both data (local and cloud). Is there ... |
In Pro Git you can see:
Remote-tracking branches are references to the state of remote
branches. They’re local references that you can’t move; they’re moved
automatically for you whenever you do any network communication ...
So remote tracking branches are described as read only but it is possible to update, edit... |
I have a problem while working with entity framework in JavaScript. I have two classes Table and Column
Class Table {
Columns: Column[]
}
Class Column {
Parent: Table
}
Everything works fine until I use function toJSON which I implemented for Base class (both Table and Column inherit from Base). This function just si... |
Given a simple directed graph G=(V,E) an induced cycle is a cycle where no two vertices of the cycle have an edge that is not in the cycle.
(Chordless cycles are induced cycles with at lease 4 vertices).
My question is what is the maximum number of induced cycle a simple directed graph can have?
I have looked around ... |
I wonder if there is a way that I can get the data from a website automatically.
Here's a sample link:
http://www.trademap.org/CompaniesList.aspx?nvpm=1|704||||03|||4|1|1|2|3|1|1|1|1
You can download the dataset by clicking on the Excel icon. I tried to look for the exact link of the Excel file but didnt succeed. Is t... |
I am currently studying R. While studying that I came across a command set.seed(any number) . After googling also I didn't understood much except that it has something to do with Random number generation.
But I am not familiar with the concept of Random number generation. So, can someone please explain this command to ... |
In order to achieve better immutability, should my API return java.lang.Iterable<T> or java.util.Enumeration<E>? Since Iterable's iterator has a remove() method, one could say Enumeration is the right choice, but the javadoc says "New implementations should consider using Iterator in preference to Enumeration".
I'm awa... |
I have a really basic question regarding how memory gets allocated in a code written in C.
Let's say that I have something like this:
int pointless(int a);
int main(){
int num1,num2;
num1=1;
num2=pointless(num1);
return 0;
}
int pointless(int a)
{
return a;
}
What I would like to... |
I have a class with several fields.
public readonly byte Id;
public bool Active { get; set; }
public List<Group> Groups { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public Gender ... |
I have been adapting domain-driven design for about 8 years now and even after all these years, there is still one thing, that has been bugging me. That is checking for a unique record in data storage against a domain object.
In September 2013 Martin Fowler mentioned the TellDon'tAsk principle, which, if possible, shou... |
I have a large set of values (let's say 1M entries) where I need to apply an exponential smoothing algorithm, but only incrementing one value at a time (all others decay to zero). The trivial implementation would be (pseudo-code):
function smooth_once(index, x):
// Decay everything
for s in s_vec:
s = s... |
I'm currently refactoring a Python 2 project which includes the ability to add or remove plugins, which are Python modules implementing a given API.
The main app accesses add/remove/update hooks in plugins by calling e.g. __import__('plugin_name').hook_add() after pulling plugin names from a database, but this seems li... |
Is it acceptable to declare new objects (and return them) from within the same object, as in the example below?
Or, is it better to move it to some kind of handler class?
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
//Gets a list of persons
public List<Person> Get... |
Recently, I was faced with a question that asked me to swap variable values without creating an extra variable.
i.e. A = 10, B = 20. How store 20 to A and 10 to B?
The solution is:
A = A + B #new value of A=30
B = B + A #new value of B=50
A = B - A #new value of A=20
B = B - 2 * A #new value of B=10
so A =... |
I have been using "static" classes as a method to group functions with relating purposes under a common name that provides readability and maintainability to the code at the cost of performance and possibly incorrect usage of the object model caused by ignorance.
I can absolutely do that with a normal class but when th... |
I was trying to find a concrete example online but I couldn't find one that also used one of the class' other attributes.
So, can this be done more succinctly with a Lazy<T> object?
public string BrandAbbreviation { get; set; }
private bool _brandPopulated = false;
private CommonBrand _brand;
public Co... |
Imagine we have resources like reports. We have a collection because every report contains its own settings to build some data.
Every report calculates its values on regular basis but not to often. There is a possibility to recalculate a report just right now to have the most actual data.
The question is: what kind of ... |
I've really big problems with versioning my apps. I'm trying to follow SemVer methodology (I'm not sure if it's a methodology or just set of rules).
I've draw a roadmap for my app's versions.
1.0.1
BUG 1 fix
1.1.0
FEATURE 1
FEATURE 2
1.2.0
FEATURE 3
My apps version is 1.0.1 recently (because I've fixed BUG 1). Af... |
I have a couple of simple classes that implement the Null Object pattern.
To illustrate the hierarchy, let's define a Config interface with two classes implementing it ConfigItem and MissingConfig, each defined in its own file.
// Config.java
public interface Config {
Something process();
}
// ConfigItem .java
pu... |
I am curious if there are common loop index variables (of single character or not) for dealing with 4 dimensions and above?
I was helping another student working through CS50x who was just learning about loops and she asked more or less "if x,y,z are standard for 3D axises with indexes i,j,k , respectively, what if the... |
I'm trying to design survey-type application that uses user responses to determine what the next question should be. For simplicity's sake, question types can be either combo boxes (they have a set of distinct answers to choose from) or images (user selects an image file from their system). I require this to be databa... |
I have a program that needs information from a database but it doesn't need all of the information at once, although it WILL need it at some point. Would it be better to pull all of the information from the database right away and use it as needed or to pull the information from the database as needed?
|
How can I calculate the number of buisness days (M-F, agnostic of Holidays) between two dates without a look up table?
There has to be some sort of algorithm based on the number of all days and the starting date, right?
Another Way of Phrasing it:
If I have a number X, how can I tell how many times multiples of 6 + 7Y ... |
In this particular problem I am having, I am not sure of the proper way to deal with readonly structs, passed to class constructors as a parameter when I want to store the data in the struct, in the class.
For example, I have a struct which contains some settings
typedef struct s_MyStruct{
int x;
int y;
std... |
I've created a Flask RESTful API which requires an email / password and Facebook login flow. This will probably need to be extended in the future to support more social logins.
I've chosen to authenticate users using JWT.
Since I want to support multiple types of login flows, I figured I need to define a custom grant t... |
Could somebody please resolve a particular licensing confusion for me?
I'm always really puzzled by how software licensing works.
I want for everyone to be able to use my software with minimal, if any, restrictions and no warranty.
So I just use a permissive license (MIT License was my choice) and write something like
... |
Yesterday I was working on a Rails 5 API project which is using the acts-as-taggable-on library to allow things to have tags (like questions on SE). Rails 5 is in alpha support right now. There is currently a PR to fix a bug waiting to be merged into master; the bug caused my feature branch to come to a halt halfway th... |
I'm working on a personal project that has a fairly complex UI. As much as possible I would like to remove mouse interaction. To help with that I am working on a kind of in app command line, where you can find all the actions by opening a popup and type in the names to run them. (think intellij ctrl-shift-a, or eclipse... |
Lets say I have an original mxn matrix like this:
1 2 3 4
5 6 7 8
For the purpose of my program, I then concatenate the rows into this new one dimensional matrix:
1 2 3 4 5 6 7 8
I know the mxn size of the original matrix. My question is, given a value's position in the new matrix, I need an algorithm to find its mxn... |
here is the UML class diagram
subscribe method is used to add a herbivore object to the plant's watchers. when a plant is told to notify, itloops through all of the herbivore object in its watchers list and tells each herbivore to notice its current state.
but here is a error:although the design allows a herbivore obje... |
This question might be a little odd, but is there any specific way to import a C++ reference into an ASP.NET C# project?
The problem I am having is that VS is giving me the following error:
Error CS0246 The type or namespace name 'LicenseAdminApi' could not be found >(are you missing a using directive or an assembl... |
Firstly, I realize that question title is about as terrible as the sample code I'll post below, so please bear with me while I explain the problem more clearly, and if you have a better idea for the title - be my guest and edit it.
Imagine a long plain text. It consists of words separated by punctuation marks and/or sp... |
There's a bug report that the original reporter no longer cares about and I can't reproduce the issue. Is there an English terminology used to tag those issues? Should they be kept open and tagged with that term (e.g. “timed out”) or should they be closed?
Note that this question is not the same as the one about bug no... |
When you declare a new instance of a class, you do so in a lot of languages as:
MyClass obj = new MyClass();
The two MyClass mean subtly different things, often you will see:
IMyClass obj = new MyClass();
where the LHS is an interface, or
BaseClass obj = new DerivedClass();
where the LHS is a base class from which t... |
One of the hard drive in my office's NT server was crashed two weeks ago. I had installed MS-SQL in c: and the data was stored in d:. The hard crased was c:. Thus I replaced the crashed hard drive and re-install NT server and SQL server again.
The problem now is how to restore the data from the .mdf files located in... |
I've done this so many times but I never end up liking how my code turns out. I'm asking if anyone else has the same problems and can offer solutions or conventions that they've used to make cleaner code.
When I build a C# service, I get TopShelf, Log4Net, and Ninject all installed and set up. Inside of my service pr... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.