instruction stringlengths 34 19.9k |
|---|
I am writing a program that creates backup of directories.
Which of the following approach is better for code organization?
Create separate class for Backup and Zip logic -
class BackupUtil:
def backup(self):
None
class ZipUtil:
def archive_dir(self):
None
Or use function nesting like this -
cla... |
Whenever I want to add a new functionality, I introduce a new private variable into the class. Declare it just above the first method definition. leave a small comment. Set it in a certain method. And then use this set value in another method.
Now the possible problems which arise are, I dont cover all the possible cas... |
I want to implement my first application using CQRS pattern along with Event Sourcing. I am wondering how creation of aggregate roots should be handled properly. Let's say someone sends CreateItem command. How it should be handled? Where the event ItemCreated should be stored? As first event of a new Item? Or should I ... |
Iv'e moved this from SO as it's more of a design question than a code one.
In many applications third party websites/programs can access the website via a key.
For example, a web application hosts applications each of which have a unique API key. These keys are issued to the various developers to ensure they don't make... |
In my database abstraction library I am extending SQL prepared statements syntax to hint a parser with expected literal type. I take it as a very essential improvement, my reasoning you can read here. If you want to question the idea itself, please let me know in the comments - I'd like to start another question instea... |
Alright so I've learned this:
Classes have public methods that perform operations on the class's data and they hide away their implementations.
Data structures on the other hand, completely expose their implementation through properties (getters and setters) and don't usually have methods.
So my question is, let's say ... |
Simple question: I understand that Serialization in C# requires default constructors. This would eliminate the possibility of using Constructor injected DI (which is generally the favored style of DI, in my reading[citation needed]). So is it really an either-or situation, or am I missing something?
(Side question): Do... |
I am working on a ‘brown-field’ project, with a team of programmers. I understand each programmer will have different styles.
I am running into some criticism with my coding style, specifically creating ‘too many class files' (aka too many CS Files, not number of classes).
I have always tried to separate project/busine... |
It's common practice to make some tweaks or fixes in 3rd-party code (be it a simple gist or an entire library). But it's also common that many of these code have their own licensing rules and eventually a header on every file with copyright informations.
After making those modifications what's the correct thing to do n... |
I just read this quote online:
XML is a very useful technology for moving data between different databases or between databases and other programs. However, it is not itself a database.
Which is quoted from the book 'Effective XML: 50 Specific Ways to Improve Your XML'.
I don't understand what you would bother movin... |
Although its generally agreed by organisations like the OSI and the FSF what is and isn't an open source software (basically, the the terms of the source code license) what are the guiding principals for open source projects?
Other software movements have principals like the Agile Manifesto. It seems as though open sou... |
In my humble view of unit testing a unit test tests a single unit of code. For me, this means a single class. Every dependency for that class is mocked in the corresponding test class, and passed in the constructor (or injected via a DI container). This allows you to test the class in complete isolation from the rest o... |
In our organization some of the resources (such as QA machines etc) are shared. Different folks get done at different times and some tests have to be run (during dev and QA) on these machines. Right now, we just skype a message to the team stating "I am going to run some destructive tests on such and such machines - le... |
http://www.cplusplus.com/reference/cstdarg/va_list/
According to the above link, va_list is an argument or parameter used in some macros - va_start, va_arg, va_end. These macros are present in the stdarg.h file.
I know that va_list can hold multiple values but what kind of an entity is va_list? My question is what is ... |
I'm considering passing xml back and forth for error messages but each error has different scenarios.
one situation at hand is passing diffed text comparison while others are as simple as passing a text message.
What kind of serialization/deserialization strategy could I use for such a scenario?
The main issue with a s... |
I follow TDD religiously. My projects typically have 85% or better test coverage, with meaningful test cases.
I do a lot of work with HBase, and the main client interface, HTable, is a real pain to mock. It takes me 3 or 4 times longer to write my unit tests than it does to write tests that use a live endpoint.
I k... |
We are working on a fulfillment system for an online book store. Everyday we receive tens of CSV files (about 90 files) with data about purchased orders.
Example:
OrderId | BookTitle | Quantity | Price | BuyerName | ...
1 |The hunger games | 1 | 10 | John ... |
I'm running public web site based on Drupal. Drupal is GPL 2 or 3 licence. Of course I wrote custom code which interacts with Drupal code (modules). Can anybody write me an e-mail and ask for the source code of that my custom code? In other words, have I to publish that my code somewhere?
|
I have a website that allows user uploads of content. Part of the design, to date, involves storing the user content on a NAS that has been configured with a separate app pool in IIS that has scripting disabled, shorter lifespans, no cookies, etc for CDN-type behavior as a subdomain (static.domain.com vs. www.domain.c... |
I am very curious as to thoughts and industry best practices regarding static members, or entire static classes. Are there any downsides to this, or does it participate in any anti-patterns?
I see these entities as "utility classes/members", in the sense that they don't require or demand instantiating the class in ord... |
I'm trying to find the number of points in a matrix with the same minimal distances.
Start with a MxN matrix, where M and N < 50000. There is given a set of fixed points, with their respective coordinates.
The problem is to find the number of points in the matrix such as the minimal distance from any point in the set ... |
I was reading this article, https://weblogs.java.net/blog/emcmanus/archive/2010/10/25/using-builder-pattern-subclasses, about subclassing a builder class. I understood the article but there was one small bit that bothered me. There was this method,
public static Builder<?> builder() {
return new Builder2();
}
... |
In a classic implementation of the Observer design pattern, the subject has a list of references to all of it's observers, and each observer might have a reference to it's subject.
Is this considered composition? As far as I understand, composition means one object 'includes' in itself another object, in order to use f... |
This is the first time I have dealt with licensing issues so I am sorry if I am making any stupid assumptions. My issue is that I have written a program in Python that uses PyQT for the GUI and also uses another library licensed under BSD.
PyQT comes with GPL v2 and GPL v3 as well as a commercial license. From what I h... |
For a binary tree we define horizontal distance as follows:
Horizontal distance(hd) of root = 0
If you go left then hd = hd(of its parent)-1, and
if you go right then hd = hd(of its parent)+1.
The bottom view of a tree then consists of all the nodes of the tree, where there is no node with the same hd and... |
My web application calls a third party API.
If I successfully call the API but invalid data is returned which cannot be processed by my system what is the most appropriate HttpCode to return to the user calling me?
500, I'm not convinced. Although it was an internal error it's due to external factors
503, Perhaps, alt... |
Let's say you have 10 database records which you need to process in the following way:
Start
Pull 2 records from the database with the 'Processed' flag set to 'false'
Call the external web service with the custom data from this 2 records.
Update those 2 records in the database and set them as 'Processed' = 'true'
Goto... |
I am trying to follow TDD in my proj but I can't get my head around how to verify I am calling a dependency correctly or even if I should be trying to verify it. Here's the requirement:
Write an AddSalesOrderTask class that is responsible for adding an order to an ERP system. The class can take any dependencies nee... |
My current automated workflow looks like this:
I commit changes
I push changes
Build (actually just a lot of tests using mock database) is triggered
If all tests pass, the new code is deployed to the server
Now assuming there is a change in database format - first 3 steps do pass, but the code will not work on server... |
I inherited a code base where there is a lot of code that goes something like this:
SomeDataAdapter sda = new SomeDataAdapter();
sda.UpdateData(DataTable updateData);
And then sda is never used again.
Is that a code smell that indicates that those methods should actually be static class methods instead?
|
I need to write a handler for server error during user logout. What is a common practice?
ajax.post({
url: '/auth/logout'
}).done(function (response) {
switch (response.statusCode) {
case 200:
{
//update UI related to userinformation
}
case 500:
{
... |
I have many projects that have essentially the same high level requirement: test all hardware on a device. Each device can have a different communication protocol, requires different test equipment to exercise the device, etc. So, at a high level a test is essentially the following:
obtain handles to test equipment
a... |
Are there any existing algorithms which can look through a list of words and split or combine words into their more common form?
For example, I have a list of many business names in the health care industry. The word "healthcare" is often written "health care". There are also business names which might be split or comb... |
I am currently learning about design patterns.
I think most people would agree that these patterns are great tools, but should be used with moderation and not as the answer for everything. Using them too much would over-complicate the application with little benefit. Patterns should be used only where they can be the b... |
I thought both Project Lombok & AutoValue used compiler annotation processors, but from this slide presentation and this stackoverflow answer it seems that Lombok doesn't... or at least not annotation processors alone. What is the difference in the way that Lombok & AutoValue use annotation processors?
|
I'm currently developing a mobile application in Objective C for iOS devices. While doing the application I reach the point where I have to retrieve data from a database and show it on a table (the name of a specific workout routine and his description).
The way I see it I can do this in two ways:
I can select every w... |
I'm currently learning about design patterns. I learned about the Factory Method pattern.
This pattern means that in order to implement a factory to create objects, one should subclass the class that needs these objects, and have the subclass create them. This way the superclass only works with more abstract references... |
This is a pretty simple question but I'm new to java.
The linked list found in java.util.LinkedList.
I saw elsewhere that Java does not use pointers...
When I create a new list and add new elements to it, does the list contain references to the data and to the next/previous elements or does it also contain the object i... |
What is the word used to describe the type of programming languages that provide explicit syntax for defining classes and that support inheritance?
For example: "A ______ language, such as C++, Java, C#, or D."
I keep thinking "object oriented", but that also includes languages like Lua and JavaScript, which aren't qui... |
Many times I have to write a loop that requires initialization of a loop condition, and an update every time the loop executes. Here's one example:
List<String> currentStrings = getCurrentStrings();
while(currentStrings.size() > 0) {
doThingsThatCanAlterCurrentStrings();
currentStrings = getCurrentStrings();
}
One... |
From what I understand, genetic algorithms try out multiple variations and evaluate the fitness of each variation. Then they select the best variations, change them a bit and continue the process with the next generation.
But what if we have unlimited computation resources? Can we then just try out all possible variat... |
why is functions like len and max not a reserved keyword in python. Following are the only reserved words http://docs.python.org/2/reference/lexical_analysis.html#keywords
|
We're working on a new firmware for our new V2 device. The company has an older V1 firmware (and hardware). Hardwares are similar to each other (but there are some differences) so basically we could use V1 firmware with "some" modifications. Unfortunately V1 firmware is spaghetti code. We need to support both hardware ... |
I have to create a documentation structure for a legacy application, and I'm not sure of how to organize it.
Documentation goals:
List of use-Cases
Program flow for each of the use cases. (Flow-chart of all the logical steps the code does for a particular use-case).
As far as possible explanations of why a certain bus... |
I am working on an open source application which can allow users to add RSS feeds. All users of the site can read the content of those RSS feeds. It's not just for user's own feeds.
Using PHP and SimplePie library I have created a simple app. I am trying to implement category based listing.
I have a list of RSS/Atom fe... |
Given two sorted array in ascending order with same length N, calculate the Kth min a[i]+b[j]. Time complexity O(N).
Another variant of the question goes like this:
given a matrix with sorted rows, and sorted columns, find kth smallest.
We can easily formulate an O(klogk) solution with minheap, but the challenge is doi... |
I'm writing a public web app to get stock data from a magento store. I've accessed the data, but it turns out that i have to query each product individually for stock data. With thousands of items this is a resource hog and takes lots of time. This cannot be avoided. It's just how their API works and I have to do it th... |
I have learnt that if there are more columns in table, then get those results using join query.
How to decide the max number of columns in table?
How feasible is "Join Operation" if too many table involved?
And if join operation hurts performance
Can we define all columns in one table to get rid of join operation?
I f... |
I'll try to further explain what I mean.
Imagine you are the boss of a company. You have to deal with the tradeoff between the quality of the code and the speed of producing it. Let's assume to measure the coding speed according to Agile Methodologies in Story Points
Let's consider the two extremes:
Our developers sp... |
In this question I asked: Is the cost of designing more levels of abstraction to allow loose coupling worth the benefits, or not?
People said that it's often worth the cost, but one should sense whether his/her application will actually be using this underlying design later on, or if it's just going to be a waste of ti... |
There are two main differences between the design patterns Factory Method and Abstract Factory.
Difference 1 is that Factory Method is mainly based on inheritance. A class in a way uses it's subclass to create objects. The objects created depend on the subclass used. While Abstract Factory is based on inheritance but i... |
In Java 8, interfaces can contain implemented methods, static methods, and the so-called "default" methods (which the implementing classes do not need to override).
In my (probably naive) view, there was no need to violate interfaces like this. Interfaces have always been a contract you must fulfill, and this is a very... |
We have a C# ORM module that generates queries. It logs generated queries and other information into the error/trace file. It is used by our web application. Most of our queries are generated dynamically (based on dynamic business rules and user interactions) which we have little control over.
Obviously the ORM module ... |
Use Case
What are the use cases for creating a one-to-one relationship where the parent points to the child compared to a child pointing to the parent? If there is no difference, is one preferred over the other?
Example
+---------+ +-------+ +--------+ +----------+
+ Parent + + Child + + Parent... |
What is better and why? (From interface-design point of view) :
a) To have two Show() and Hide() functions
b) To have one SetVisible(bool visible) function
EDIT: For example some object have visibility state and this functions is used to change it.
c) To have all three Show(), Hide(), SetVisible(bool visible) functions... |
During all my work I've been working with ORM, WS, integration services, viewmodel and so on.
The common stuff in all these kind of work is that I had to make mappings and not always the available framework are enough to help in this mapping.
The question which I'm wondering is: is a consistent part of the development ... |
We have been using SVN for several years.
Recently, we switched over to git, since some members of the organization pointed out that if our SVN server dies our team is toast.
So far, we've got something worked out with the git workflow, however some team members really do not like this git process. They want to simply ... |
To learn dependency injection in a current side-project, I am writing my own dependency injection container.
But this has lead me to wonder, at what point is it worthwhile to use a third party product vs "roll my own"? What would be the kind of questions you would ask to figure this out?
|
Background:
My collaborators and I are writing an article for an academic journal.
In the course of our research,
we wrote a simulation program in Java.
We want to make the simulation program freely available for others to use.
We have decided on hosting the code on a GitHub repository.
In order to make it easy for oth... |
I have a singleton object. It's a DAO that looks somewhat like this (pseudoish code):
class UsersDAO {
public usersDAO init(string sDSN){
variables.sDSN = sDSN;
return this;
}
public array getUsers(){
//do a query to get users, make into array
return aUsers;
}
}
my applications makes an ins... |
We have a large web site written in WebForms and have begun implementing some new modules in MVC. We have a custom CMS in place. I put the data structure to hold CMS data in a BaseModel class. Now I`m wondering where would be the best palce to put the logic which calls the CMS data manager to get data relevant to the p... |
Let's say Mr. A goes to cinema and he gets a movie schedule. There are N movies on the program today (1 < N < 50) and for every movie the time of the start and the time of the end are given in minutes. Mr. A wants to see as much minutes of movies as possible. But, there is one rule in the cinema: If a movie starts, you... |
This may be a terribly stupid question, but I can't find anything even related on Google (maybe I am not searching properly). I've been a developer for around a year now. I do desktop and web apps using Visual Studio at my day job and use a WAMP setup for freelancing. For storing data I have either used a database or n... |
I'm building a WYSIWYG designer in Ember.js. The designer will allow users to create campaigns - think MailChimp.
To build a campaign, users will choose an existing template. The template will have a defined layout. The user will then be taken to the designer, where he will be able to edit the text and style, and addit... |
I'm currently employed by a business to do website development in Wordpress. I've written a number of custom plugins specifically for a number of clients over the time of my employment.
Today, I asked my boss what I would be allowed to use as code samples because I'm quitting. My boss has forbidden me from taking any o... |
I need to make an architectural decision for developing (actually porting) my embedded solution on a tablet.
The choice comes down to Ubuntu or Android, so I have some specific questions to help me decide.
On Android, is it possible to develop applications outside of Dalvik, using Python? If yes, can I access the hard... |
Is it possible to determine the creation date of the mail account for the address supplied within the authentication process flow; Or at least determine that the mail account was/was not created the same day as signup (or specifically after confirmation)?
A use case is to flag such accounts for closer scrutiny as part ... |
I am working on a web api and I am curios about the HTTP SEARCH verb and how you should use it.
My first approach was, well you could use it surely for a search. But asp.net WebApi doesn't support the SEARCH verb.
My question is basically, should I use SEARCH or is it not important?
PS: I found the SEARCH verb in fiddl... |
When designing a RESTful interface, the semantics of the request types are deemed vital to the design.
GET - List collection or retrieve element
PUT - Replace collection or element
POST - Create collection or element
DELETE - Well, erm, delete collection or element
However, this doesn't seem to cover the concept of "... |
I am currently studying design patterns from the book (which, although I didn't try anything else, I find excellent) Head First Design Patterns.
I'm confused about two concepts: The Factory Method, and the Factory Method Design Pattern.
I was trying to understand what each one means, and I came to some conclusion. I'd ... |
I was hired about a year ago as the lead (well, really the only) developer on a new project/product we will call product "B". Product B was designed to pursue a new market for the company.
This company has had great success with a similar product for a different market. We will call this other product "A".
“A” is almo... |
For personal educational purposes I am making a site for a conference. One of the object that exist in a conference is a session, which has different states and in each state it has slightly different attributes:
When submitted it has a speaker (User in the system), Title and abstract.
When under review it has revie... |
this is a kind of data i have to de-serialize
{
"id": "M:11427",
"title": "DAX30",
"nextStartId": "S:727831",
"sections": [
{
"type": "HIGHLIGHTS",
"baseResults": [ values of type highlights ],
"hasMore": true
},
{
"type": "CHART",... |
I am developing a video conference application with the following requirements:
Audio works like call conference, where all participants may talk at the same time.
However, video works like broadcasting, where only one designated client broadcasts one video to the rest.
Clients will be Android devices.
One way of doi... |
I'm attempting to expand my knowledge of how database designs and concepts work. I'm working on a hobby web/mobile app for practice that will challenge me. However, I am running into an issue.
What my novel concept is that there are two buttons 'yes' and 'no'.
The buttons can only be clicked once a day.
If 'yes' is cl... |
I have a number of distinct Java utilities that are shipped together. Currently there are two startup scripts for each utility: a .sh one for Linux and a .bat for Windows.
I'm thinking of rewriting the startup scripts using Python, or perhaps Ruby, Perl, Lua or other scripting language. This way I avoid having differen... |
As a 30-year software developer, mostly in OO languages, but a newbie at python, I'm looking to find what is best practise for isolating unit tests in python.
Let's say I have the following, semi-pseudo-code. I know some_database_client isn't a real database client:
from some_database_client import connection
connecti... |
I have a C# class that represents a content type in a web content management system.
We have a field that allows a web content editor to enter an HTML template for how the object is displayed. It basically uses the handlebars syntax for substituting object property values into the HTML string:
<h1>{{Title}}</h1><p>{{M... |
Let me start by doing a small summary of the changes we did in our code in the last year. We have a software (VERY big) that is used to visualize multiples underground networks, enter data in the entities in the network and create simulation in this network.
In the 20 years of development of this application (in MFC C+... |
I'm working with a Java project that has several interfaces, many of which have only one implementation. (See related question)
For a given revision of the software, one could think this acceptable because the interfaces were some plan for future extensions. However, when I look at the 200+ revisions over several years... |
I am refactoring a huge legacy code class. Refactoring (I presume) advocates this:
write tests for the legacy class
refactor the heck out of the class
Problem: once I refactor the class, my tests in step 1 will need to be changed. For example, what once was in a legacy method, now may be a separate class instead. ... |
I've gotten into the habit of using excessively descriptive names. In addition, I've also gotten into the habit of creating the conditions for ifs like so:
bool user_is_female = user.get_gender() == GENDER_FEMALE;
bool user_is_warrior = user.get_unit_class() == CLASS_WARRIOR;
bool user_can_wear_battle_skirt = user_is... |
I'm wondering about functions used like this:
object1->objectMethod1(arg1, arg2);
if objectMethod1:
- does not change the object state
- does not use the object's state at all
- is used by the class extensively
- logically fits as being used by the class
should it be made into a member function?
example:
class CSV... |
I like using .NET MVC and have used it quite a bit in the past. I have also built SPA's using AngularJS with no page loads other than the initial one. I think I want to use a blend of the two in many cases. Set up the application initially using .NET MVC and set up routing server side. Then set up each page as a mi... |
Is there any specific reason they decided to go with Call by value? Is it for simplicity?
|
I have a team member who refuses to use any form of private source code repository on Github or Bitbucket due to "security concerns". As a result, we have a hard time sharing code with him. He appears to be concerned about source code theft by some party. To me, using cloud based source code repos is fairly standard... |
While it is relatively possible for an experienced developer to estimate how long it will take to implement code when the pattern and problem the code is solving is well understood, how can you make a good estimate when, while the end goal is well understood, the implementation is 95% theoretical/problem solving and ha... |
I'm a bit confused about how the 4+1 architectural view model maps to UML.
Wikipedia gives the following mapping:
Logical view: Class diagram, Communication diagram, Sequence diagram.
Development view: Component diagram, Package diagram
Process view: Activity diagram
Physical view: Deployment diagram
Scenarios: Use-c... |
Here's a common scenario that's always frustrating for me to deal with.
I have an object model with a parent object. The parent contains some child objects. Something like this.
public class Zoo
{
public List<Animal> Animals { get; set; }
public bool IsDirty { get; set; }
}
Each child object has various data a... |
This question regards the usage of the Decorator pattern to add little functionality to objects of large classes.
Following the classic Decorator pattern, please consider the following class structure:
For example, imagine this happens inside a game. Instances of ConcreteCharacterDecorator are meant to add little func... |
On the Nehalem+ architecture Intel CPUs what is the interaction between the L1 cache, L2 cache, L1 DTLB and L2 DTLB? On all the images I have found there isnt a clear explanation whether the CPU looks at the L1 DTLB first, then goes to the L1D cache, or whether it only goes to the L1 DTLB cache if there is a cache miss... |
What I'm wondering is how running programs communicate with each other, and if someone could post some sample code for how to do this, so I can try it out myself, just for educational purposes.
For example, I've worked with databases before, and in my code I always have to "establish a connection to the database." The ... |
I'm looking at developing a simple application in Java for a game which allows a user to keep track of which items they own and how much experience they have obtained while using the item. All of this data is input by the user.
What is the idiomatic/standard way to persist the data that is being manipulated (the model... |
I've been reading in basic concepts of OOP,as i'm trying to make this shift from transactional scripts to more oop manner in php, and i often come across this definition :
An object stores its state in fields (variables) and exposes its
behavior through methods (functions). Methods operate on an object's
internal ... |
So far my best ideas have been as fallows
A) Represent a "card" in one structure and have a "deck" in another
a deck being an array of 52 cards and a card being 2 chars one for and rank one for suit.
B) The second seems like it might be easier to manage but less obvious in code. Creating an array of ints each with a di... |
For example, a bit or a boolean can be either 0 or 1 so the number 2 is associated with it. Similarly, for a byte which is 8 bits, the maximum number of different assignments would be 2^8.
Is there a name for this number?
When we pass everything through our system that has ECMAScript, Java and MySQL, then a boolean doe... |
I am trying to design database for this case:
Assignments have vectors, relation is 1:N
Assignments have submissions, relation is 1:N
Submissions have executions, relation is 1:N
Every execution have one vector.
Business logic
teacher creates assignments and defines test vectors
student upload his solution, so rec... |
What is the current way to authenticate users in a mobile/global fashion? In other words, assume a mobile application. And if there is a database server in the backend, how would these users typically register/login? Is there a current standard for non-domain, non-enterprise authentication?
I was thinking just havin... |
I've been noticing lately, as I've played around with javascript, HTML5, and node.js for the first times that javascript seems to be a language that is used very differently (and with different syntax) depending on where it is used at. My observation with javascript is this:
-Front end javascript finds the JS embedded... |
I have an array of integers of length 20, filled with fourteen 0s, two 1s, two 2s and two 3s. It is like this:
[0,0,0,3,0,2,0,0,3,0,0,0,1,0,2,0,0,1,0,0].
I need a way to list all of its 20!/(14! 2! 2! 2!) permutations, without repetitions. (Note that in the list there are duplicate elements!)
I'm just looking for the ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.