instruction
stringlengths
34
19.9k
Is there any difference if I were to write something like this: int row,col; for(row = 0; row < data.length; row++){ for(col = 0; col < data[row].length;col++){ //do something }//end for loop(columns) }//end for loop(rows) for(row = 0; row < data.length; row++){ for(col ...
I hope I can explain what is troubling me. Example: I have an object basket with a list of fruit objects. So normally I would build my routes like this baskets/{basketId}/fruits/{fruitId). But fruit is an interface and there are different implementations like apples and oranges that all require their own resource repre...
I have a c++ program with opencv library which takes an image as input and perform pose estimation,color detection,phog. When I run this program from the command line it takes around 4-5sec to complete. It takes around 60%cpu. When I try to run the same program from two different command line windows at the same time t...
I am redeveloping an old ecommerce website which is currently written in C# ASP.NET 2.0. Because this is a reasonably high volume website and has suffered performance issues I want to develop in the most efficient manner possible. To minimise database trips (using SQL Server 2012), as database performance is the usual ...
I saw often people use this code like interface IAnimal { void die(); } class Cat : IAnimal { void die() { ... } void meow() { ... } } IAnimal anAnimal = new Cat(); Cat aCat= new Cat(); C# knows for sure anAnimal.die() works, because die() is defined in IAnimal. But it won't let you do anAnimal.meow() ...
taking for example an application that holds Companies and as we move along time, more and more features are needed. I do tend to hold everything in the Companies table, but I rather get some input as I'm starting a new project and was wondering if I should keep those in a CompanyFeatures table: Should I have 2 tables...
I don't understand why the switch or equivalent is so popular in languages. To me, it seems like it had a place back in the days when the alternative was lots of nested if statements in the else part of other if statements. Now that we have else if, why do we need it? If we take the following: switch (expr) { case "O...
Surely most of you remember the Norton Commander application where similar (sometimes the same) data is displayed in separate decoupled views. I'm building a web application that follows the same principle. The amount of data is too big to be fetched/displayed entirely on the page, and potentially overlapping subsets o...
Writing a single var declaration per function is considered to be good for readability and maintainability. But, when I went through some of standard libraries, their dev version doesn't strictly follow this. For example, Underscore code has multiple var statements in many function which are spread randomly and declare...
For a given class, where should the comments about the purpose of the class go? /// <summary> /// <----------------- describe the class here (1)? /// </summary> public class Message { ... //class members here ... /// <summary> /// <--------------- or here (2)? /// </summary> public Message() ...
I am developing an iOS application, in which I have to draw some patterns on a view based on option selected by user. Let me explain you more clearly. User will be shown number of images as options to choose from. On selecting an option, a view will be drawn. This view is inheriting from a class say ParentClass where ...
Is it possible to use the framework behind the Windows 8 Metro UI to make Exposé-like application for Windows? I tried Mac and I really like this feature, on another side i like that I can drag the screen from the top of the screen into the Metro UI, but that is completely useless. So imagine if it is possible to use t...
I've recently ran into some issues where some reports were not generating the proper results. We already have a QA department that reviews the reports and then our business owners review them as well; this hasn't prevented the issue. I'm trying to figure out a decent way to have a test harness to ensure reports are giv...
Recently I've been reading and learning quite a lot about scrum and I like it a lot. However, I do have a couple of likely scenarios in my head to which I don't know the solution. So let's say that I might want to organize an agile team of (for instance) four web developers (one of them UI/UX designer). This team would...
Before I get started I need to issue a pre-emptive apology: It is very likely that some of the terminology / vocabulary I use in this post is plain wrong there is also a good chance I have entirely misinterpreted some of the keys aspects. I am new to this so don't be too critical, more than welcome constructive feedb...
Passwords exposed in URIs An application stores URIs to be used for file transfers via SFTP, FTP, FTPS and SCP. Many of these URIs contain passwords, for example: sftp://someuser:sekrit@host.example.com/ These URIs are visible to too many people. We cannot hide email addresses from these people. A mini-language to g...
I've currently got a browser talking via an "API" to the server. API is scare quoted because the API really wouldn't support another user interface very well, because it consists of every call our UI happens to need, in the form it happens to need it, and nothing else. Which could be fine. However, we are starting to h...
I have been trying to understand what it means to say "scope of a named entity". In reading about scope, there are terms like visibility, lifetime, accessibility and more that are used. What is confusing is the fact that the terms are at times used distinctly and at times interchangeably. Quoting from this IBM articl...
(Don't believe this is a "best practice" question as I believe there will be a single better choice). I need to choose a data storage option to store specific site data to allow easy management and re-usability: array; class; DB; Other; but am not sure which one would be adequate. The data in question is my Service...
We are currently working on a project that heavily relies on a database. Among many tables the main focus is on table "data" which is linked to another table "data_type" as many-to-one, which is then linked to table "data_operation" as one-to-many. The last table defines specific set of operations that has to be proces...
I want to organize tests for a project large enough that build time matters (especially for the CI server). Say I have this code that I would like to test : //foo/greet.cpp #include <stdio.h> #include "foo/greet.h" int greet() { return printf("Hello, World!\n"); } And I have this main program that is boilerplate that ...
I am in the middle of creating a Bundle for PHP application based on Symfony 2. I want the bundle to be clear and good designed, so I constantly move and refactor code, rename methods, reorder classes, move them to other folders, add some factories and adapters, proxies, and follow other oop design concepts. I'm thinki...
With bytecode-based virtual machine languages like Java, VB.NET, C#, ActionScript 3.0, etc., you hear sometimes about how easy it is to just go download some decompiler off the Internet, run the bytecode through it one good time, and oftentimes, come up with something not too far from the original source code in a matt...
Sorry if the title is hard to understand, it is easier if I describe the scenario to get the question across. I have a service that collects data, performs business logic and does all the normal stuff. I now have to perform an integration that will provide a set of data (for sage accounts) via an endpoint (http://examp...
That is if we were to see how Microsoft wrote this method what would it look like? I'm mainly interested in the use of the StringSplitOptions enumeration with the other parameter and how they probably structured their code to account for each option.
I have an application that allows the user to place a string of text into a PDF document. I have three different ways that they can do this: Use a Form Field. Then they have four properties to define: Provide field name provide instance of the field provide an X-axis Offset provide a Y-axis Offset Search for a st...
I am working on a real time multiprocessor scheduling algorithm. I found very few results via google research related to it. A few simulators are available but are not robust enough. OpenMp is an API I have previously used for small parallel application development. But I am not sure if it provides any support for re...
I make web applications, mostly MVC, object oriented and database enabled. I always have trouble going back to project after a few months of release and work again. I don't even remember what I made on that project. How should I overcome this problem? I can't afford too much time consuming documentations and so many di...
It is clearly a bad practice to incorporate several issues in a single bug. It is not convenient, hard to maintain, difficult to keep track of what is done and what is not, etc. But does all this concern bugs associated with documentation as well? By documentation, I mean only external documents (user guides, architect...
I was looking at cross-domain requests for a design and stumbled upon something that puzzles me. From a local site I'm firing an Ajax request to another domain (with jQuery and vanilla XMLHttpRequest). Sure, the request fails and I can only get a fail event, which seems perfectly normal du to same-origin policy. But I ...
I'm after a bit of OO design advice... I'm about to start developing a Windows application that communicates with an external machine via RS232. The machine has an onboard "system controller" consisting of registers (addresses). You can write a value to a register (e.g. to turn a pump on), or read a value from a regist...
Is it good practice to use __ convention while declaring the member variable? This also imparts private kind of feature of that data member. There have been cases when I found that its good to have hidden members of a class. This is certainly exposes only that feature that will help the the object to behave in more pr...
It seems to me that programming languages meant for use in science and engineering are consistently weird compared to general-purpose languages. Some examples off the top of my head: In Matlab, each function has to be placed in a separate file In R, <- is the assigment operator, as opposed to = in almost every other l...
Just finished Stanford lecture on SQL (by Prof. Jennifer Widom). However I have developed a confusion regarding the use of EXISTS clause. I thought it is just like a condition and an expression so that if it's true, the above query proceeds (much like the Boolean AND). So having a slight doubt regarding this question: ...
I'm a student currently on an internship. I've been asked to determine the feasibility of migrating an existing Windows-only C# software package to Mono. I've already conducted an analysis to identify the native libraries that will need to be ported or replaced with managed code, and identified the Windows-only API cal...
I am passing Menu items to View from ViewModel. My menu definition is a model with properties title, image, hasChildren and isEnabled. But this model is meant for UI unlike business domain models like Person, ContactDetail, Transaction, etc. So, when i see this menu model sitting along with business domain models i fel...
When a user browses some page and then switches a language, then the following actions should occur: If there's a translation for a page he's browsing now, then do redirect to that page. If there's no translated version of that page, then do redirect to a home page. So for example, a user browses /about-us page then ...
I have a non-language-specific problem which I'm having trouble finding a workable answer for. I have a 10x10 grid containing integer values from 1-10. Each value represents the cost of travelling across that square, moving north, east, south or west (cost is incurred while stepping off a square rather than onto it). I...
I forget the name of it but there's a rule that you aren't supposed to allow visibility into an objects inner makeup. It has to do with not allowing more than one dot in the implementation like this for example: return world = foo.bar.hello.world();
I feel kind of lost in this backend development process I am attempting right now. Most of the usual development practices I use while developing client-side applications don't apply here... Let me provide some context. The debugging process While developing a client side application (iOS, Java desktop app, or whatever...
I have to design a "widget", a script that partners will embed in their websites to display some UI and make calls to our API. Basically it will display our data on these sites based on some IDs they provide in our API calls. What we would like to avoid is someone abusing the API and using it to scrape the entirety of ...
There seems to be a trend towards immutable objects, and pure functional programming. While I recognize the benefits, I find it hard to apply these principles to GUI programming, for example. But I also find classical imperative languages with mutable objects lacking. I was wondering whether there is a language or syst...
I have recently joined a young hackerspace still in the process of setting itself up. We're fortunate because the space has a few internal projects that need working on and no shortage of volunteers to work on them. There have been some discussions on how to organize these projects. My most recent professional experi...
I am trying to create a timer that ever x minutes it will call to a server, get a JSON file and do something with it. The merits of that system are not in question right now, the question involves getting the JSON file. Currently I am using kimonify from KimonoLabs to create a JSON file from some other site. They sugge...
I've have two event queues(table mapped queues) based on two different states of same data stored in two different tables. The events are generated on create/update/delete on both the tables. Constrain is that both the tables have to be in sync. The create/update/delete in one table has to be reflected into other table...
For quick prototyping I have been actively using Hibernate. Recently I came back to an old project and I wondered why I had a lot of DAOs with what I suspect is commonly named feature bloat. E.g. I have a DAOs for single entities that contains from 15 to 20 methods each. Recently I have been using Hibernate Generic D...
For a while now I've been in the habit of differentiating different kinds of comments in my code. //this is an explanatory comment //!this line was commented out for debug purposes, DO NOT SHIP WITH THIS COMMENT IN PLACE //?this code was tested, and executed properly in 2.3 uS This has saved me a lot of trouble, as ...
I see a lot of talk in the OOP world about principles and laws such as Open/Close and Loose Coupling, I can understand how they are so high valued, However I seem to have ran into a problem with applying these principles and laws once I start to include relational databases. For example purposes, if I have a applicatio...
I'm creating a prototype scripting language similar to something like Javascript. In my language, every single reference to a variable is actually a function call (a getter function), whether it has parentheses or not. So for example, if do this: var foo = 3; var bar = foo; What really happens is foo.set() is called o...
This ASP .NET MVC application implements Entity Framework. I've declared the repositories in the DbContext like this: public class CompanyDbContext : DbContext { // constructor goes here public DbSet<Customer> Customers { get; set; } public DbSet<Order> Orders { get; set; } public DbSet...
If I chain some setters together and one of them does not return $this, then I will get a fatal error. But maybe that is a good thing. $object = new object(); $object->set('name','foo')->set('number',12)->set('color'=>'brown'); class object { protected $name; protected $number; protected $color; protected $al...
I'm writing a linear algebra library (long story short, it's a school assignment) that involves matrices, vectors, etc. In the process of creating this library, I'm going to be creating functions that perform mathematical operations on objects. For example, transpose matrix, invert matrix, normalize vector, etc. I wa...
An HTTP query can be parametrized to a list of pairs like name=value that can be encapsulated in general as Map<String, String> since an HTTP GET query is string pairs. I could need something for any combination of objects and primitives. A varargs method for example update(String s1...) could be written in general as...
I am currently learning functional programming using Underscore.js. What I want to do is add two co-ordinates together. Let P1 = (0, 0) and P2 = (1, 1). Therefore, P1 + P2 = (1, 1) I have a solution, but it seems so convoluted that I'm sure I'm doing something wrong: // Base 2D Cartesian Point var Point = function(x, y...
Scenario: a large existing system (~300 tables, 500 stored procs, 200 views and a code base of several 100k lines) with most security level stuff in stored procedures needs to be refactored (for maintainability reasons and just availability of skills more will likely be moving to the C# layer, as well as we are hoping ...
The way I usually do it is I make some namespace Platform in Platform.h and every OS call is encapsulated by a static function in this namespace. So the only place in the entire code base that knows what OS is being used is Platform.cpp. Is this a good way of making things easier? For instance when I call Platform::Mes...
I always thought pass by value is a legacy from the early languages, because the designers had never seen anything else. But after seeing the brand new languages like Go adapting the same principle confused me. The only advantage I can think of is you make sure that the value you are passing won't be modified. But ever...
What is the difference between dependent typed languages and languages like Spec# and Eiffel that allow you to specify "contracts" for functions in your code for pre/postconditions? Is dependent typing basically the purely functional version of Eiffel's "contracts"? From what I understand, dependently typed languages ...
The title question is unfortunately pretty vague (or at least may be asking differently than what I intend)... but let me elaborate. I know basic HTML5 and CSS. I don't need to learn the tags and how they work. What I'm looking for is some information on what sort of process to follow when actually coding a professiona...
Suppose the following DTO class. Which of the two getters breaks encapsulation least? class Foo { public: /*Return the most primitive type. Caller do not need to worry about what Array is*/ const RecType* dataBeginGet() const; const RecType* dataEndGet() const; /*Return ...
I have an array A of n integers, sorted from min to max, and two numbers a<=b, which are known to be in A. I would like to write a pseudo-code for a procedure whose running time is c1+c2log(n) and which returns the number of elements in A which satisfy a<=A[i]<=b. I wrote the following but am not sure it satisfies the ...
The cost of developing a feature in Agile is very high because it needs to be ready for shipment. It includes: Significant bug fixing Writing/updating and executing tests Writing/updating the user manual Polishing the UI design (placement of controls, color schemes, etc...) Updating the documents for FDA (in our orga...
I was faced with this question by my team leader. Statement 1 (written by me): lnkbtn1.visible = lnkbtn2.visible = lnkbtn.visible = false; Statement 2 (written by my team leader): lnkbtn1.visible = false; lnkbtn2.visible = false; lnkbtn3.visible = false; Which statement is better and why?
I am looking for a datastructure to handle cycling through a large number of ordered subroutines, some of which are active, most of which are not. I am thinking I need an implementation of a python set like object which remains ordered when modified, can be easily iterated over (I don't care if an actual for loop works...
I am looking to create a challenging AI project. There is an online card game that allows you to build a deck to play with out of randomly presented cards. You have to choose one each time out of a couple of cards. I want to build an AI that picks the cards as I would pick them myself using my knowledge of the game. M...
I was interested in solving several unrelated problems using generic graph search techniques, so after some fiddling around I came up with the following design: have each problem implement a generic "Problem" interface which has an initial state, and several methods that take in states and moves, and return new states ...
I have a website that is build with asp.net web forms. I would like to refresh design (using css, html5, responsive design) and also change it from web forms to asp.net MVC. To me this is more of a frontend project. Since there is already existing backend, it is "only" necessary to reuse it in MVC. Should I first star...
I'm trying to write a program to read GIMP curves files and apply them to an image. I have successfully implemented the curves for the red, green and blue channels, but I can't get it working for the value pseudochannel. For the colour channels I just create a lookup table from the curves, and iterate through the pixe...
I fully acknowledge that Python and Java are different programming languages and should be used differently. That said, "Program to an interface, not to an implementation" is good language-agnostic programming advice. Say I have some DAO interface in Java: public interface DataDao { Object load(); void update(); ...
Player A and Player B play a game. On the middle of the table there is a pot full of N apples of different weights. Player A starts first and choose an apple and start eating it. Losing no time player B do the same. When a player eats the whole apple, without losing time repeat the same procedure. In case both player h...
When I read well written code that checks to make sure all the input is of the correct format and type, and also catches all the things that possibly could go wrong, I find it difficult to understand the core of what the program is doing. It seems protection against the non-normal case obscures the normal case. This ...
I'm doing some android development in a relatively inexperienced group, and all of the data used by our application is managed in a database. There are several instances where we'll need to pull info from the database using the identifying information/PK of the user who is currently logged in. Because the only info fro...
We have several application servers (and different applications) running on Amazon AWS and our main method of logging is a combination of statsd, carbon/graphite, and an alert system based off of the metrics coming into carbon. This has been working great for a lot of different situations but I feel we need something ...
In a typical perfect-information strategy game like Chess, an agent can calculate its best move by searching the state tree for the best possible move, while assuming that the opponent will also make the best possible move (i.e. Mini-max). I would like to use this approach in a "game" modeling economic activity, where ...
Brainfuck is an esoteric programming language created in 1993 by Urban Müller. It was designed to challenge and amuse programmers, and was not made to be suitable for practical use. But still, it exists and some really cool stuff is written with it. My question is - will learning/practicing Brainfuck increase the depth...
I am stumped at this problem. Users authenticate at my client's website. Then the users see their profile page on my client's website. My client now wants me to provide a URL on their profile page, for his users, to download information from an external website. (This external website is not controlled by my client). T...
I have a code that highly relies on an Array structure like the following: $array['customer'][$customer_id]['details'][..]; // it goes to about 10 levels deep However, after almost two years since the initial development, now I have to include another high-level element to that array which will make it something li...
I am still very confused as to why and when to use Dependency Injection. If anyone could explain maybe using the below example that would be great, any other explanations would be appreciated. Lets say I am creating a web-app that will save movie reviews written in C# with ASP.NET MVC 5. If I have the following Model ...
Red zone is a fixed size area in memory beyond the stack pointer that has not been "allocated". Compilers do generate assembly to access that area in simple leaf functions. But I can't see any real advantages for red zone. Accessing memory beyond stack pointer is really dangerous and can easily lead to data corruption....
we have to migrate a very old project that are having more than 500 web forms and 400 tables and it is hugely depends on stored procedures, the current specification is: Asp.Net : .NET version 1.1 language: VB uses 2 Tier architecture (UI and business(includes DataAccess also)) xml is used to pass the data between UI ...
First of all, I know that reinvent the wheel is, usually, a bad idea, but I want to write a PHP framework to learn OOP in PHP and to understand MVC in my free time. Said that, I have to do two webs with few and simple database interactions, the basic funcionality of the webs is to show information. I want to use my own...
Is there a general rule of thumb, when we should pass a value as as class variable and when as a method argument? Or is it just a choice of the developer? For example -- are there any reasons, why following (PHP code): class SomeClass { public function __construct() { $this->id = $_GET['id']; $t...
Nowadays, almost everybody is using a dark color scheme in their code editor - dark background with light text. Even most web based editors (e.g on Github) feature dark color schemes. I honestly don't see the benefits. The human eye is much better at reading dark text on a bright background. Also, black on white color ...
Following my other question, is there a general rule of thumb, when we should pass a setting-like value, that controls class' behavior (for example displayed texts) as as class' constant or variable, one-by-one, and when it is better to "pack" them to one associative array? Or is it just a choice of the developer? For ...
When doing the Red, Green & Refactor cycle we should always write the minimum code to pass the test. This is the way I have been taught about TDD and the way almost all books describe the process. But what about the logging? Honestly I have rarely used logging in an application unless there was something really compli...
As I've been getting into embedded systems I've noticed that some projects (Arch Arm and OpenBSD for example) frown upon cross compiling. What is the reasoning for this? Is a cross-compiled binary somehow different from a natively compiled one? OpenBSD suggests that building on the hardware ensures that the system is ...
I have developed a search algorithm, which basically matches records on 3 different criteria types. Name, Address, and Keyword(s). "doh" , will find: Name: doh Address: re Keywords: me Name: re Address: doh Keywords: me Name: re Address: me Keywords: doh Now, when two or more records have a match, I am bas...
My question is about "big data". Basically, big data involves the analysis of a large amount of data to make meaningful insights from it. I would like to know: Whether or not large amounts of data can be pre-processed? (like say for example you are running some matching service for people, so you take all the informati...
I often see the following in HTML documents <link rel="self" href="http://example.com/something"> or like this in JSON link: { rel="self", href="http://example.com/something" } or in XML <atom:link rel="self" href="http://example.com/something" /> So I had some questions: Why include this link? What ...
I am having a problem in understanding how to apply camelCase syntax to some of my variable names. For example, how should I correctly write a word like "phonenumber" in camel case? Is it phoneNumber or phonenumber? Similarly with "username", is it username or userName? I think it doesn't look right with camel case l...
I've been thinking a lot lately about how to build a lean development team. Ultimately, I'd like to open up my own little software house with a small number of like-minded people. The goal won't be to become rich, but rather to have a healthy work environment. So far, I'm defining a lean team as the following: Small...
We've went ahead and purchased Microsoft Dynamics (see edit history for why) in order to write 2 functions to interact with one tiny part of it to fulfill one big need. What I want to know is, from other programmers who have integrated their software with MS Dynamics GP. Is there any way to connect with it (fully) wi...
Variables and the keys in key-value pairs are both identifiers for values, so, on a conceptual level, these seem very similar ideas. How would you explain the difference between these two concepts? Is it that key-value pairs are used in collections? Is it that variables point to a memory location? Or something else? ...
I have been looking into event driven programming in C and the language doesn't seem to have support for it. This has led me to wonder about the nature of event driven programming. Is it correct to say that an event handler basically spawns a thread that waits for a response from I/O and sets a variable? Or is there so...
Problem I am trying to optimize the architecture of my web-application developed in PHP using the Symfony framework. I have an object "pool" that contains "swimmers". I need to display the number of swimmers in my pool, but only those with a pink bath-suit. In order to do this, I see many possible approaches : Approach...
I forked a repo some time ago and created a few pull requests which went unanswered. Now, the software is MIT-licensed, and I kept the copyright notice there. Do I have to rename the software, or whoever forks a repo can keep referring to it by the same name? Thanks!
I have a method that generates a data URI from a byte array. In the event the input byte array is empty, what is the appropriate thing for the method to do? Here are the options I see: return data:, return an empty String throw an Exception By my read, RFC 2397 doesn't explicitly address the notion of empty data.
Currently, I have a system with a Data Mapper and multiple Domain Objects which inherit from the same class, let's say B and C that inherit from abstract class A. In order to retrieve data, I need to pass a parameter to the data interface (getObject('a'), getObject('b')), based on which data for class B or class C will...
I am writing a small game where a sea vessel (like a battleship) can be moved in a 2D place based on orders that it receives. I wanted to know if someone can help direct me to a post or example code that will help me move a ship from one location to another based on the speed and new vector. So, if I had a ship that is...
I've always been interested in how programming languages are created, so for the past 8 months I've been researching, practicing and more about the creation of compilers. I've been able to quite easily write front ends for languages and withing the past couple months have been reading more about the back end pieces of ...