instruction
stringlengths
34
19.9k
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 ...
My Question is not about how to use HTTP session or how values are being used in session. Question is more oriented about approach. In my current application there are few values being stored in the Session and we require those values every now and than, here are few values we fetching from session Store Language Cust...
In comparing REST [api] structure with a OO model, I see these similarities: Both: Are data oriented REST = Resources OO = Objects Surround operation around data REST = surround VERBS (Get, Post, ...) around resources OO = promote operation around objects by encapsulation However, good OO practices do not alwa...
My team currently use an Ant script to execute various Java programs. Note that I am not asking about managing the build/deployment cycle for which we are already using Maven (quite happily). For example, we use something like the following: <path id="lib"> <fileset dir="path/to/lib" /> </path> <path id="run" > ...
I've been thinking for a while about reasons that prevent a lot of programmers — myself first of all — from writing clean, modular and expressive code while developing, for example, CocoaTouch apps. What I discovered is that my top-three of reasons are following: UI code. Device-specific UI/UX, general clutter, 'quic...
I am trying to write a simple program to find the product of two numbers (X, Y) without using multiplication. Meaning that I will only use summation to find the product. I am trying to use the "Divide-and-Conquer" technique, and am using the obviously known concept that: 5*6 = 5+5+5+5+5+5 Multiply(uint X, uint Y) { ...
In many articles about Rest API's best practices, it is recommended to not depend upon sessions on server side since it leads to a stateful mechanism. I currently use Play 2.2 framework, with a mechanism that store the data about logged in user in the Play cache (temporary persistent so). When the user wants to authent...
Whenever a potential customer downloads a copy of my software they get the "Unknown Publisher" warning message. I understand that if I purchase a code signing certificate this message goes away and the customer does not get the scary warning. I'd like to know if anyone has information on how effective these code signin...
Thanks to a question over at Code Review I got into a little disagreement (which essentially is an opportunity to learn something) about what exactly the Cyclomatic Complexity is for the below code. public static void main(String[] args) { try { thro(); thro(); thro(); thro(); ...
The problem that I face is how to combine encapsulating and optimal memory use. I can't show you my code and therefore explain it on extensive (I hope) example. Let's say we need to have a database of mans. We want to know only 2 things about those people: Age of the man (in hours from birth). Name of the town he live...
I've recently started looking at Android development. This has brought me back into the world of Java software development. The last time I worked with Java, I'll admit, I didn't understand OOP nearly as much as (I think) I do now. Having mainly used C# in my career, I'm noticing a startling difference in how inheritan...
I've done this piece of code for creating bernulli samples, but I think that it is a so heavy algorithm because every time I call this recursive function I create a new vector that is passed to it. Is there a way for making this algorithm faster? Here is the algorithm and the description: As already said, this function...
I'm working on a multiplatform game in Flash. This game utilizes Photon Server for authoritative physics and user statistics tracking. I'm looking to leverage Facebook authentication as an alternative to creating a domain specific account. I'm curious if I can use the Flash SDK for Facebook to indirectly authenticate a...
What's the database design or business logic for creating an app for messaging between users? I am having difficulties with choosing how to approach the relationship between each Conversation of User Thread. I show this figure, but it was really hard to grasp the concept How all this threading message works (like Gma...
I want to build a time expanded graph with time discretization Dt that starts at t = 0 and ends at t = T where between the node (n1, t) and the node (n2, t') is an arc if and only if (n1, n2) were connected in the original graph. How can this be implemented in pseudo-code? The problem I'm stuck on is how to pass from ...
I have a rather difficult problem: I periodically receive a Dictionary<decimal, int> subDict containing 100 records where decimal is a Price and int is Amount The outcome I need is a dataGrid showing prices with amounts. But I cannot display subList directly, because sublist is often missing some prices: subDict: P...
I've been working with some basic extreme programming concepts for the last two weeks, for a small scale, for-profit, multiplayer, arcade game. I've spent a week developing user stories and determining requirements to create a release plan. I've also spent a week coding and applying the first iteration plan I came up w...
I have a big collection of strings a[1], …, a[N] where N is about several millions. I am provided a string m and I need to iterate over all the strings a[i] that contain m. In other words, I need to find all the strings a[i] having m as substring. What would be the most efficient data structure for that problem? I need...
localStorage and indexedDB are used for offline storage of data in HTML5. What are their key differences and which one is preferable in what situations?
I have designed a generic DAO in Java and am having confusion about whether to refactor it to different design or not. PS Don't say to use already existing 3rd person framework. I know there are some present but I am learning Java and design patterns so I need all the practice I can get. If there's any confusion then p...
I have a requirement where MS Access application needs to be re-platformed to java application.The MS access app has about 45,000 records and 53 columns with SQL connectivity.These record data need to be edited,data used to send email with pdf report attachment.Report is designed using SQL reporting services.I need to ...
I am having a lot of trouble understanding how to unit test my web client. I have just finished a project using TDD for the first time - this project hd no external dependencies such as API calls or databases, it was pure C# code. I definitely saw the benefits of using TDD and I would like to continue practising it. ...
Systems / programs / distributed algorithms / ... are often described with the predicate robust or fault-tolerant. What is the difference? Details: When I google for +robust +"fault-tolerant", I only get two hits, both unhelpful. When I googlescholar for the terms, I find a lot of papers that have both terms in thei...
for clarity, code review = a team meeting and reviewing/sharing code What are the potentially negative aspects of the code review process in a development environment? What comes to mind for me Strong criticism can lead to negative interactions and feelings of animosity between colleagues. Laziness to read and unde...
I am working on a website with PHP as backend. There are things from the front-end which I'd like to accomplish using AJAX calls. Which of these methods should I use to design them and why? Call to different PHP files for different uses Call to the same PHP file, with instructions on what to do A RESTful API Any oth...
I am working on a web application implemented in C#, that follows MVC conventions. This application contains a page that allows me to create or update a Wingding. The view passes a complete Wingding Model back to the controller for me to create or update. The problem is that the page also has a checkbox that allows me ...
I want to sell a simple calculator that will help a certain industry. This calculator would be installed on the computer (as opposed to a web service). How is a registration key mechanism implemented?
I have a DB that stores some complex objects of my app. When my app starts I load the objects into list and store them on the RAM. But sometimes I would like to search for an objects that fulfills conditions (filtering), even the conditions are complexes. I was always wrote a for loop (sometimes a very complex one) for...
In my ASP.NET application there is some data that doesn't change often and so there is no point in querying the database to re-check it every time. In my current situation I am checking user credentials on every request to see if they have access for what they are attempting to do (i.e. view a particular page). The sec...
I need to expose an Array[][] to many different clients (iPhone, Android, PC, Unix, etc), and need to make it available over HTTP/s This brings me to JSON, and makes me wonder how do all the other *endian machines work with JSON and will I need to worry about how the array will be reconstructed on other platforms. Init...
So I'm developing this small engine that does a remote integration between two systems in order to sync data, both systems have webhooks for create & update events, and both have APIs (one is REST one is XML), so it is an event-based integration rather than a typical batch one. My problem is that if System A creates an...
Don't understand some things about evolution versions of some applications. Please tell me why, for example, firefox 26.0b1 released earlier than 25.0? What it means to "x" version? (5.x)? release candidate (rc)? Alpha? Beta?
I am trying to understand the linux kernel and there is one thing that is puzzling me for quite a while. As linux is used across variety of platforms (like smartphones,desktop,supercomputers etc) and also on various architectures, so does the same kernel code is used by all or a different one and also since it includ...