instruction stringlengths 34 19.9k |
|---|
When a function has reached the end of its life, we add a @deprecated tag into its doc-comment to notify other developers that they should stop using this function, and then a couple years later it's removed.
I was just thinking about an @beta tag to signify this method is brand new and hasn't been tested in a variety ... |
I try to follow the Single Responsibility Principle (SRP) and also to omit Code Repetitions. However there are often places where there are code repetitions that are nothing more than code blocks of invocations that are resistant to extracting them into at least meaningfull named method:
DoAction1();
DoAction2();
if (... |
I was wondering if any design gurus out there could help me understand how large web companies design their services to be highly available. The scenario I'm thinking of is:
Client A connects to Service A
Client A sends N requests
On the N+1 request, Service A blows up
Client A reconnects to Service B
Service B servic... |
We have a requirement to be able to match people with locations based on availability and certain conditions.
Let's say I have a group of people each with 3 types of things they may need to park. A car, a truck and a boat. Each person also indicates their preferred parking location (choices 1, 2 and 3).
I also have a... |
I have read this statement:
"A parameter is used as a sort of temporary messenger, carrying data originating from outside the constructor or method and making it available inside it."
So, does that mean that values of parameters are stored at first in the constructors and then passed to fields?
I still didn't understan... |
I need to compare two curves f(x) and g(x). They are in the same x range (say -30 to 30). f(x) may have some sharp peaks or smooth peaks and valleys. g(x) may have the same peaks and valleys. If so I want a measure on how well these features coincide without visual inspection. I have tried to solve this problem in the ... |
I want to know what is exactly a method header and what is a method signature and is this the same among programming languages or just in C#?
So, is it correct to say the following is a method header:
public void SumNumbers(int firstNumber, int secondNumber)
and the following is the method signature:
public void SumN... |
I am currently maintaining a Java web application that is initially designed to work only as a single instance (not in a cluster/farm). Now, the client is planning to upgrade their infrastructure and part of their plan is to place our web application behind a load balancer.
I have already identified several serious de... |
I would like to understand how a spreadsheet (a group of named or otherwise identified cells containing values or formulas referencing other cells) is solved. I have tried looking at existing projects, but there was so much going on with the GUI, serialization, events, etc. that I couldn't find the spreadsheet.
At its... |
I'm very new in using GIT as a versioning system and despite a lot of searches, I can't seem to really understand how to handle my scenario.
I have this web project that needs to be developed in two versions:
the first is a general version used for demos
the second is a customized version for my client.
As for now, t... |
I would like to understand the impact of different resourcing models for software projects. First, I would like to identify the different resourcing approaches that are used to resource software projects. Here are some models that I can think of based in my own experiences:
Product centred resourcing
Planned resource... |
I've written some code to manipulate sparse graphs for school work I'm doing, and I have an operation which requires me to loop over all the edges of a graph. The interface I need to implement is some function
int gimme_some_edges(graph* g, int k, int* I, int* J)
which puts the next k edges of the graph g into the arr... |
I'm a computer engineer and all the courses we have had about programming and computer languages were an introduction to C/Java and OOP. Now I feel like reading Java language specification to learn a deep understanding on Java language but I understand that there are something like grammar description in the specificat... |
The Setting
I often have trouble determining when and how to use exceptions. Let's consider a simple example: suppose I am scraping a webpage, say "http://www.abevigoda.com/", to determine if Abe Vigoda is still alive. To do this, all we need to do is download the page and look for times that the phrase "Abe Vigoda" ap... |
According to WikiPedia
"Some languages do not support mixins on the language level, but can easily mimic them by copying methods from one object to another at runtime, thereby "borrowing" the mixin's methods. Note that this is also possible with statically typed languages, but it requires constructing a new object with... |
Say I'm defining a directory and then including files from it. Is it better practice to do:
define('PATH', 'C:/xampp/htdocs/includes/');
require PATH.'header.php;
or:
define('PATH', 'C:/xampp/htdocs/includes');
require PATH.'/header.php;
|
Consider the following case: there are two models Image and User. Users have associated images and they can pick one of them as their profile image. There are essentially two ways of modeling this:
1)
User:
id - primary key
profile_image - nullable foreign key to Image
Image:
id - primary key
user - foreig... |
Reading code and discussions pertaining to code, I often see the words "state" and "status" used interchangeably, but the following tendencies seem to exist:
When a variable holds a value intended to indicate that something is in a certain state, the name of that variable more often than not contains the word "state",... |
Most code samples I see that demonstrate shell code preface each command with $. Having a prefix makes sense, but I'm confused as to why $ is used in particular. Some other symbol, like !, that can be copied and pasted into a prompt without affecting the command's execution makes far more sense to me. So where does thi... |
I have been seeing two implementations for syncing data between the server and the client on majority of the apps. This assumes no GCM is set up:-
Running an intent service periodically which downloads the data from the network and stores in the database.
Implementing a Sync Adapter which runs periodically.
Which of ... |
I have a DAO method that utilizes Spring for JDBC access. It calculates a seller's success rate of selling an item.
Here is the code:
public BigDecimal getSellingSuccessRate(long seller_id) {
String sql = "SELECT SUM(IF(sold_price IS NOT NULL, 1, 0))/SUM(1)
FROM transaction WHERE seller_id = ?";
... |
I've been reading Joel Spolsky's old article about "Top Five (Wrong) Reasons You Don't Have Testers". it's an old article date back to 2000, but it's insightful as most of its content make sense after a decade.
I cant agree more about the importance of test in order to produce qualify software.
But there is one parag... |
I initially started a project with Facades and Polymorphism as a way to create simple extensible design following SOLID Principles.
Here is a sample code:
public interface IInterface
{
void FillList(List<InputPocoObject> listOfInputObjects, out List<OutputPocoObject> ListOfOutputObjects);
}
public class SampleClas... |
As the question states: When implementing "SOA", is it a concept intended for communication between systems over a network or is it intended as a concept that operates within the language as a pattern?
|
One of the greatest piece of documentation I ever read is the TeXbook by Donald Knuth—the manual of the TeX typesetting system, and I used it in my first analysis.
As far as I can tell, the type of information conveyed by documentation falls in three categories: recipe, reference and expert knowledge that I describe he... |
I have a WCF Service and a Main Lib1.
Say, I have a Save Profile Service. WCF gets data (with predefined data contract) from client and pass the same to the Main Class Lib1, generate response and send it back to client.
WCF Method : SaveProfile(ProfileDTO profile)
Current Version 1.0 ProfileDTO have the following
UserN... |
I want to use LGPL for my project, can I use some source code which is apache licensed ?
If I only use the apache licensed component as library in my project, how should I make the clarification in my project ? Do I need to put some information about apache license at the beginning of source code which uses the library... |
I'm kind of new to PHP. I can create basic sites with login/registration, etc., but I always struggle to build complex sites with lots of features, because eventually the code becomes messy and I just run into more and more little bugs, and then fixing those produces another, and so on. I realise that that's partially ... |
I have been trying to wrap my head around the finer points of this today.
Essentially I have fallen in love with this format for booleans:
Class {
public static bool myBool {set; get;}
private static void Method()
{
if (!myBool)
{
myBool = !myBool;
// stuff that needs to... |
I read an article online which I give the reference to below which compare between Native apps and web apps, in addition to standard website. It seems from that article that native apps are faster than web apps and websites. However, that was not clear for me.
Could a native app be built to be used exactly as a web... |
I've need an interface that assures me a certain method, including specific signature, is available. So far his is what I have:
public interface Mappable<M> {
M mapTo(M mappableEntity);
}
The problem arises when a class should be mappable to multiple other entities. The ideal case would be this (not java):
public ... |
For the sake of this question, let's agree on this definition of "good commit message" from here:
Your comment should be brief and to the point, describing what was changed and possibly why.
and accept that referencing a bug/issue in a commit message is a good thing.
Now, there are a lot of tools that integrate with ... |
As my team move towards embracing the new features in C++11, I'm struggling with how to make the side-effects of std::move self-documenting in the code.
The issue is that an object that has been moved should no longer be used after that point. All I can come up with is a comment:
std::string x = Func();
Other(x); // ... |
While using IE autocorrect "naive" got transformed to "naïve"!
My regional settings are Au English, from a Unicode search point of view the two are nothing alike. I am not even sure whether there are other characters that are being replaced, but from a programmers point of view what are the consequences and remedies in... |
I'm trying to compare Haskell's type classes and C#'s interfaces. Suppose there is a Functor.
Haskell:
class Functor f where
fmap :: (a -> b) -> f a -> f b
How to implement this type class as interface in C#?
What I have tried:
interface Functor<A, B>
{
F<B> fmap(Func<A, B> f, F<A> x);
}
This is invalid impleme... |
I have been researching this extensively, and I am stuck. I am writing a Drupal module that uses a class that I have created. This class is a classic Singleton - it only needs to be instantiated once, since it is assembling a bunch of data from a database. Note that my potential Singleton will not update any data in th... |
I am creating a Mobile application (CRM) for another software company. They told me they need these these stuff from here and there, within 15-30 minutes. But they never provided a detailed client requirement document in writing. I have been asking this for number of times, but still no. As soon as I started working I ... |
I have to write unit tests for some classes my group is developing. The classes are fairly simple, and I'm not sure how to best test them.
public class MyObjectRegistry
{
private myDataSetMapper = new MyDataSetMapper();
public boolean StoreObjects(list<MyObject> myObjectList)
{
myDataSetMapper.S... |
I'm using Django as an application framework and it only needs to consume web services (no need to have traditional Django Models and the related ORM).
In this case, since Django is a variant on the MVC architecture (MVT, to be precise) should I wrap the web service calls into a 'model' that my App uses or should I jus... |
Not sure how to go about this method to reduce Cyclomatic Complexity. Sonar reports 13 whereas 10 is expected. I am sure nothing harm in leaving this method as it is, however, just challenging me how to go about obeying Sonar's rule. Any thoughts would be greatly appreciated.
public static long parseTimeValue(String s... |
I keep running into Senior JS positions where they want CoffeeScript. The reason I don't use CoffeeScript is that my first impression of it was that it puts limitations on JS OOP features that I find valuable. I've seen claims that the two can inter-mix freely but that sounds dubious to me. Should I even bother applyin... |
Actually, I'm writing my undergrad thesis, that consists in analysing the BitTorrent algorithm and see its application on Transmission client as an example of implementation.
Reading through its code, written in C, you can see many layers of functions
static const char*
tr_metainfoParseImpl (const tr_session * session... |
Do you think it is a good practice to use function return values as if conditions? I'm coding in PHP atm but it holds for many other languages.
if(isTheConditionMet($maybeSomeParams))
{
}
or
$res = isTheConditionMet($maybeSomeParams);
if($res)
{
}
I can't think of a situation where the first one creates a problem, ca... |
Our development process is as follows
code the task -> someone else QAs code and documentation -> task is merged into trunk.
Recently a colleague is refusing to pass the code QA due to issues with indentation and whitespace.
Here are examples of these issues (syntax is SAS):
Additional whitespace:
%if &syserr ... |
when using closure in other languages, it just feels nature, variables from outer scope are captured automatically , without the need of declaring such captures.
in c++11, good to see we have closures, but why they make it so uncomfortable to work with, not only have to declaring the capture, but also read write contro... |
In the case of an application with a single simple responsibility (eg, a simple replacement for grep or wc), which of these designs is preferred and why? I find that they are all testable and they all do their job. Does any of them have any significant advantages over the other?
1: All methods in the main class:
public... |
We've all faced this. You apply to a cool project and they ask you to send them a piece of your code. On the surface, this look OK and I am fine with it.
But what shall I send them? My cool utility? Snapshot of structure in complex project? Something else?
So far, I have tried to persuade them to have a desktop share ... |
In A Critique of Common Lisp written by Rodney A. Brooks and Richard P. Gabriel from Stanford in 1984, some design decisions retained by the normalizing committee of Common Lisp are discussed. While most of the discussion remains valid, there are two statements that refer to the technology available at the time and ma... |
Should a class know about its subclasses? Should a class do something that is specific for a given subclass for instance?
My instincts tells me that is a bad design, it seems like an anti-pattern of some sort.
|
Let's say user A does something expensive (regarding CPU and/or memory), which takes a few seconds. Concurrently, user B needs a very small amount of computing time.
In this case, will the computing for user A significantly slow down that of user B (even block maybe?), or are these situations handled in most systems?
... |
I have been using git for about four months now. While I like most of its features, I find it rather inconvenient that multiple developers can make concurrent changes to the same file and then a need for merging ensues. In fact, I would prefer waiting for a file to get unlocked over tedious and brain hurting merges.
... |
There are so many programming language like PHP, Perl, Python, Java, C, C++ and many other. These programming language has some open source license.
If i develop application from scratch which is not related the source modification of these languages. Is my application has to be open source license??
There are billions... |
I am creating an app where the user enters 8 characters. After he enters the string I have to see if it is an eight letter word. If not, check if contains a seven letter word etc.
I am checking against a given pool of 150k+ words. I only care about the longest possible match. Is there a better way then this one:
WordP... |
We have recently adopted (or are trying) to adopt managing our projects in an Agile manner. During our first sprint I asked our Scrum master (who also happens to be our primary resident Agile go-to person) if it was possible to see the progress of our sprint so we could identify if we were on schedule or not (an possi... |
Conceptually, I used to think of types as sets. However, I think I've seen people wishing to distinguish types A, B even if they represent identical collections of values. So I figured a better definition of type is a pair (type_name, set), where two different types cannot have the same first element.
Then I ran into a... |
I've written a special indexOf function for a list of unsorted unique values.
I can search for one or multiple (unsorted) values, passed as array/list, and the function will return me an array/list of indices (possibly empty).
Based on the following circumstances:
I know that the values i'm searching for are in the li... |
I am looking for the name of a computer algorithm. I'm fairly sure that one should exist which will help me, but I can't for the life of me figure out what to search for.
If you have implementations of the algorithm, that'd be awesome - but I'm really just researching this because I'd like to figure out how to build it... |
I am writing a web application that pulls small parts of articles from Wikipedia and presents them to users.
I do not wish to delete entries of the articles because I do not want to be sending a ridiculous amount of requests to the WikiMedia API, putting unnecessary load on them.
My question is, since Wikipedia is by n... |
I was just thinking how much easier it would be to read code if, when calling a function, you could write:
doFunction(param1=something, param2=somethingElse);
I can't think of any drawbacks and it would make code a lot more readable. I know you could pass an array as the only argument and have the array keys as the pa... |
KernelDevViewpoint (an apparently serious source) makes kernel development look like an accessible art. According to them:
Contrary to popular belief, kernel developers rarely need to know math
at the calculus level. You need to be good at basic arithmetic and
you must know Boolean algebra to work on device drivers.
... |
There is a project that is written in python which works great and is under the BSDv3 license. I wanted to use it as a base template for a ruby project instead of starting from scratch. I'd be refactoring (converting) the code from python to ruby, as if the author wrote a ruby gem along with his python library.
My ques... |
I was asked about immutable strings in Java. I was tasked with writing a function that concatenated a number of "a"s to a string.
What I wrote:
public String foo(int n) {
String s = "";
for (int i = 0; i < n; i++) {
s = s + "a"
}
return s;
}
I was then asked how many strings this program would ... |
I want to make a synchronization. What's the algorithm for it in a nutshell?
1) A client reads a local data and sends them to a server afterwards. The server compares them with its actual data, decides what are newer and overwrites its data with received data in case received data is newer.
or
2) A client reads data f... |
I have a class Container, which represents wrapper around std::list.
This class contains following public methods:
void add(Shape *item)
void next()
void setBegin()
Shape* curr()
and protected variables
std::list <Shape*> _container
std::list <Shape*>::iterator _iter
Now I need add sorting of Container without cha... |
I am wondering if there is a design pattern for such problem:
Let's say we are building a web shop for a doors and windows manufacturer, where customer has a catalog (list) of products, from which he can choose some and customize them, before placing an order.
Each product has it's properties defined, like name, price,... |
I am working on a CMS, in which we have multiple clients that use it, so the code is stored on their servers. Each client has the default code (user manager, pages manager etc), but every client also has it's own set of code (themes, scripts, custom modules).
I am trying to figure out a way to maintain an up-to-date co... |
I have a xlsx file, that has some tabs with different data. I want to be able to save each row of a tab in a list. The first thing that comes to mind is a list of lists, but I was wondering if there is another way. I'd like to save that information in a object, with all its benefits, but can't think of a way to generat... |
Well, the first question would be: Is it legal to take hold of the NT Kernel Source? If so, proceed to the second paragraph; if not, proceed to the third.
The first thing you'd probably ask is "Why NT Kernel Source?" The answer is simply, I want to make my own OS compatible with Windows. This is of course, all a hobby,... |
Given the following code:
class AnimalDescriptor {
String species;
boolean hasLegs;
boolean hasTeeth;
boolean hasHair;
public AnimalDescriptor(String species, boolean hasLegs,
boolean hasTeeth, boolean hasHair) {
this.species = species;
this.hasLegs = h... |
I'm a back-end engineer who works on a small team so occasionally needs to do some front-end. I like to develop a good workflow and project structure before I start anything, so I'm wondering about creating a responsive front-end for a web app.
What's a best-practice way to strcture CSS for creating responsive websites... |
This question has come up while writing a simple text adventure game where your character has an inventory, which can include containers that also have things in them. I want a clean way to style the inventory output, like so:
You are carrying:
a bag containing:
a ring
a backpack containing:
a l... |
I'm exploring using HMAC style secret-key authentication with timestamp expiry, but am struggling to get my head around how you validate the timestamp portion.
On the client side you would do:
my_hmac = hmac(my_secret, my_values)
Where you would have a timestamp field in my_values.
On the server (where you also know... |
My questions are specifically dealing with dependency injection through the constructor. I understand the pros/cons of service locator pattern, constructor/setter injection, and their flavors, however there is something I can't seem to get past after choosing pure constructor injection. After reading many materials for... |
I am currently building a small in-house search engine based on Apache Lucene. Its purpose is simple - based on some keywords, it will suggest some articles written internally within our company. I am using a fairly standard TF-IDF scoring as a base metric and built my own scoring mechanism on top it. All of these seem... |
I have begun working at a large software company and was assigned to a project that is over a million and a half lines of code. It's part of a program suite that is sold to clients (not an in-house project) and the source code can be purchased if they desire (although given the extra fees associated with it, this seems... |
I am having problems understanding how this equation works in c:
char *sum(char *a, int b) {
return &a[b];
}
printf("%d", sum(5, 4));
I understand how arrays work, and I understand how to reference and de-reference a variable to a memory location, but I don't understand where the addition comes in to play here.
I... |
I hope someone can help me with this, as I'm thoroughly stuck. I'm working with a group at my university, on a first semester research report that should end up as a finished program, solving the problem described below.
We've been mulling over this issue for a few days now, and I promised I'd find a good place to ask ... |
I can see in this tutorial on bit manipulation, under the heading "Extracting every last bit", that -
Suppose we wish to find the lowest set bit of x (which is known to be
non-zero). If we subtract 1 from x then this bit is cleared, but all
the other one bits in x remain set.
I don't understand how this statement... |
I'm maintaining some legacy code of a physical simulation. The calculation object is build as a singleton, to ensure there is only one instance. A co-worker told me, that singleton are completely out-of-date and I should instantiate it through a smartpointer. But I think it is not the same, because the initialization b... |
I have a client/server java application with a firebirdsql backend. This is a pain because I have to install java and the client on every workstation, etc
So it is now time to rewrite the application, and I am deciding what technology to use.
My strengths are php/js/C#
The application can be single user or multiuser (I... |
Task - Consider an array of n elements. Count the number of pairs that satisfy condition X (sum of the two elements < an arbitrary number, k) .
The basic approach I could think of would be O(n^2), where I evaluate all n*(n-1)/2 pairs. How can I solve the problem in a better time frame i.e., O(n log n) or less?
The best... |
I'm working on visualizing a hierarchy. There will be clusters of objects, each cluster containing rectangles of fixed width but variable height. I'd like to arrange these within a rectangular space so as to have equal visual spacing between them, something like this:
Before I spend a day inventing the wheel, are th... |
We are developing an enterprise network appliance which has got some GPL softwares like linux and apache and some others with APL license.
But the core of the service is proprietary software and access is provided only via a web interface.
My query is what all I need to do in order to comply with GPL license in this ... |
I have a simple project,
which enable to record the voice and execute associated commands. I
think it can be an interesting and useful project. I don't know how to make it known.
I already wrote an article and I published it on hackernews but it wasn't very popular.
What can I do to make my project known?
|
I am working on a problem similar to the assembly line scheduling by dynamic programming.The issue is that unlike the classic problem where we have predefined stations now I only have information which task should run before which other(could be more than one) tasks.
I have to find out which tasks to put on which line ... |
Working on a E-commerce solution where I need to handle checkout based on anonymous customer and as of now I am not able to think properly how best this can be implemented.
Our ShoppingCart is being saved in database and and every update/ edit in ShoppingCart is being updated in database.
Now I need to take care about ... |
I have a client server application. Assume I work as a Support executive, resolving customer tickets. We(our support team) have got two tickets to work on.
Ticket 1: Client "Liver" raised a ticket to update his phone number.
Ticket 2: Same Client "Liver" raised a second ticket to update his email ID.
I am working on ... |
I currently manage a library which has a lot of public usage, and I had a question about semantic versioning. I want to refactor one fairly important part of the library which is implemented incorrectly - and has always been implemented incorrectly. But doing this would mean changes to the public API, which is a major ... |
What kind of problems may I face, if I won't use Software Design Patterns? Can you tell me about the problems of approaching the design using standard object-oriented techniques?
|
I'm writing a simple game in Java and I want to learn Clojure, so I've decided to refactor my current Java code to Clojure. The problem is that I've coded so much in object-oriented languages that I cannot see how to do it functionally.
To be concrete, I have a Map<String, Country> inside a singleton class that can be... |
Perhaps the question might be tied to a theoritical or mathematical forum, but since it is for programming purpose, i ask here first:
In a computer vision context, i write a couple of interfaces intended to be the "read-only" part of vectors. So i define "IVector2R" and "IVector3R" that only contain getters. The questi... |
class awesomeClass {
std::list<A> myList;
//...
void fillList();
};
awesomeClass::awesomeClass() {
fillList();
}
void awesomeClass::fillList(){
//...
foreach(A a, otherList)
myList.push_back(a); //add to list
}
Compared to :
awesomeClass::awesomeClass() {
myList = fillList();
}
s... |
I'm trying to build a bot that will parse the list of classes offered by my university and let me know when the one I'm looking for is open. The problem is that in order to get to the registration/search box, I have to log in with my university username and password. I'm trying to figure out what protocol that my sch... |
On a SO question I asked here about some code I was unsure about, someone replied "BTW, horrible code there: it uses the error suppressing symbol (@) a lot."
Is there a reason why this is bad practice? With things like:
$db=@new mysqli($db_info) or die('Database error');
, it allows me to display just a custom error m... |
I have been reading up on dynamic programming lately. Would like to hear from someone who started from scratch and now is pretty good at identifying and solving DP problems. I am struggling in identifying these problems as DP and framing a concise solution.
I have gone through most of the beginner DP problems and MIT r... |
I am volunteering my time to update a website for a local business. The current website they have is not up to date and it fails quite a few "web tests".
For example, the pages are too large, the images are not compressed, and the site is not mobile friendly.
All of these things are measurable - eg. the time taken to l... |
Suppose a rest api returning this json:
{
"status" : "fail",
"data" : { "title" : "A title is required" }
}
Since the client application would always adapt the error message, would it be better to return an explicit i18n key that the client would have mapped rather than "A title is required"? :
{
"status" ... |
Background
Looking to develop a WYSIWYG editor for ordered lists so that people can directly edit lists of instructions on a web page.
Problem
The contentEditable attribute is woefully immature for editing ordered lists (e.g., <ol contentEditable="true">...</ol>). I discovered four bugs in Firefox 25.0.1 within seconds... |
I was getting tired of repeating types when writing things like this:
NSDictionary* d = @{@"so": [NSNumber numberWithInt:index]),
@"much": [NSNumber numberWithBool:accepted]),
@"repeat": [NSNumber numberWithDouble:height]};
So I defined a generic macro (a new feature in C11):
#d... |
In my organization I work on orders based on date, so earliest work orders first. We also have an option for order to be marked "priority" in which case those orders are done first but not always.
I've asked my boss some questions and I couldn't get answer that made sense...
If one order has today's date, and another ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.