instruction
stringlengths
34
19.9k
I'm currently designing a search algorithm for a document, and just got curious about this while designing the algorithm: how do web browsers search a webpage? For example, in Google Chrome, you can press the keyboard shortcut Ctrl-F to activate the "Find" bar, which will let you search a particular webpage for text. H...
There are instances where the references to objects, fields, variables etc can be null and there might be a possible occurrence of Null Pointer exception occurring at that point. Is is a permanent solution to put these code blocks which expect Null ponter exception to be put in a try catch block?
In environments where software is built internally by one team and then that software is used by other internal teams, how does one decide what the required quality should be for the produced artefacts? For example: documentation completeness and accuracy extensibility/re-usability of artefact (without hacking at sou...
I'm developing a system which involves 2 Android applications and a Java web application. For my UML class diagrams I have not included third party classes I use e.g. observer type interfaces. Should I include them? If so how can I differentiate between my entities (classes, interfaces, enums etc) and their entities? T...
For example I have a utility Class which contains a few constants (GCMConstants), this class is used in one method in the application. However as it is not a member of the Class it should not be modeled via an association link. Should I continue as is and not include a link or should I include one? I've checked my UML ...
I'm wondering if there is some license which I could put on my website on which I could publish an open-source application that potentially could be used for purposes of cheating in one game for smartphones. Now, I have to stress that the goal of the application is in no way cheating, so with this license I want to eli...
I am thinking of managing a product source I am doing using Codeigniter + HMVC. Right now my folder structure is something like this: application |-modules |-module1 | |--controllers | |--models | |--views |-module2 | |--controllers | |--models | |--views assets ...
I was reading an article about functional programming where the writer states (take 25 (squares-of (integers))) Notice that it has no variables. Indeed, it has nothing more than three functions and one constant. Try writing the squares of integers in Java without using a variable. Oh, there’s probably a way to do it,...
(Originally asked on StackOverflow - https://stackoverflow.com/questions/14896121/what-is-a-practical-level-of-abstraction-in-a-web-application) I still consider myself a newcomer to OO programming, especially in php, so forgive me if I have missed some fundamental principle! Say I have an intranet application with a s...
Due to test-driven development, one ends up with many classes doing just one thing. It is quite a headache just to see where such classes would be placed inside the folder structure. First of all, is it considered a bad-pattern, to put related classes in the same file? Any suggestion on what one uses in actual-produc...
Writing code that will still run years from now Programming languages change. Libraries change. Some code from 5, 10, or even 20 years ago might still run and produce expected results, whereas some code from 2 years might fail with a syntax error. This is partly inevitable, since languages evolve (at least, most do). D...
I'm starting a project that will have a web front end for the users coupled with a database. There will then be a stand-alone service running that will, on a specified interval, poll an API and update the database with the changes it found. What I need advice on is how the service should be setup. When a user creates a...
I am working on a text editor in javascript. I have created the front end and i need to prototype a backend. I need to model the structure of the document using this as hierarchy: Character , Word , Tag , Document I am trying to create objects based on this hierarchy. For example: Characters are represented a linke...
I am working on sorting out my Javascript code. Currently I have views implemented without any Model or collection. Now I working on separating Model from View. So for this transformation, I am planning as follows: View ---> X <--- | ---> Server < Client side > Assumptions: View will not have a...
I work for an insurance company. They have a contact database that gets pushed to the field agents by Lotus Notes. We're trying to move away from Lotus Notes, but we first have to remove our dependency on it. It has been suggested that a HTML5 solution could provide offline access to agent contacts and be used to sync ...
I changed from PHP to ASP.NET, now I’m working with webforms in a somewhat large company. I given some though and research to back my impressions on ASP.NET webforms and I came to the conclusion that Webforms is an attempt to make web applications easier to write for those who came from the "desktop programming" world...
I have an interesting problem for you all. I have a partial solution but I feel you guys can come up with an efficient solution. What I have a SQL table with following structure: StockId <- a unique ID for the share StockHolderId <- a unique ID for the share holder StockPrice <- The price of the stock - if this is a r...
If I wanted to implement my own version of the std::exception for no good reason, are there any special things about implementing this kind of object that I should be aware of? It seems like a fairly simple thing that is mostly a string wrapper... Here is my implementation so far: #pragma once; #include <string> clas...
I have a remote procedure call API where the connection parameters need to be stored somewhere that the API code can access. This API is expected to be used mainly to create web services. I originally planed to store these parameters in a separate xml file, and require users of the API to define the path to that file ...
i have a scenario where i have to make available a document for viewing and editing to multiple users, the users can edit and view the document at the same time. Now the problem arises here if for example user A and user B are viewing a document at the same time and if both the user change the state of the document and...
I have been working on a project for several months now to write a web-based tool that will help me at work. I work at a call center and the CRM software that is used is wretched, we basically have to input all of our information into notepad templates and then paste it in to a description box. My initial goal was to c...
I am really confused. The GPL states that if you start with GPL code, and modify that code, that you must release your code with modifications free of charge also under a GPL. But what if you simply use the existing GPL code without modifications as a library? Can you then write software to interface with that code, un...
I have developed a protocol for a Client-Server application and developed it in conjunction with another developer. The client application at this moment is written for the mobile phone. The protocol uses comma separated fields with start and end deliminators. Because some of our fields are free form ASCII text we ...
In the O'Reilly book on Scala, I read that copy-pasting of code creates: ... creates issues of code-bloat, maintainability and skew, I can't see any obvious definitions of the word skew in context. I am aware of the problems of copy-pasting, but I can't make them fit with the word 'skew'. Since this is used in an O'R...
I see now that Racket has types. At first glance it seems to be almost identical to Haskell typing. But is Lisp's CLOS covering some of the space Haskell types cover? Creating a very strict Haskell type and an object in any OO language seems vaguely similar. It's just that I've drunk some of the Haskell kool-aid and I'...
Today I feel like I finally grokked currying (in Javascript), and of course, like any programmer who has learned a new trick, my mind immediately began racing over how to improve my current codebase using it. And again, like any programmer, the little voice shouting "[new trick] all the things!" was silenced by another...
I'm trying to implement a modified version of the Lamport Mutual Exclusion algorithm. The original algorithm assumes FIFO message ordering between connected systems, but I would like to use UDP a protocol which does not guarantee FIFO. Is it possible to modify this algorithm to work without FIFO? EDIT: Forget UDP. Just...
Disclaimer: If you're not into parallelization (on clusters), this question is probably not interesting to you and probably not worth a read. TL;DR: I search for a communication model (preferably compatible with MPI) that efficiently assures that each data line is processed once. Read the next paragraph as well to know...
In Python (and occasionally PHP) where variables do not have fixed types, I'll frequently perform 'type transformations' on a variable part-way through my code's logic. I'm not (necessarily) talking about simple casts, but about functions that change the type of a variable while leaving it basically representing the sa...
Currently I'm using something like a master-cron server, which starts the tasks on the slave-worker servers. But there are so many tasks, that the timing gets lost entirely. Is there a an algorithm, which eliminates the single master?
Given an input device (basically a keyboard) that reports keyup and keydown, how may I most efficiently store and retrieve information about which keys are currently depressed? My first thought was a dynamic array, but maintaining and searching a dynamic array seems like a serious drain on resources. Many thanks in adv...
My needs are very simple but I don't know the terms I should be Googling for: I need to occasionally send a SMS to a machine and that machine is going to answer with another SMS to the number that did send the first SMS. I've got no say as to how that machine works: it's closed and all it does is receive SMS and send S...
I'm trying to learn some best practices while I ramp up on MVC4. I have a solution with three projects: Web: MVC stuff Core: Data Model Tests: Testing classes I'm now trying to add: Services: Business Logic This will take logic such as "GetFilteredItems()" from my controllers and place them into a Service project, ...
I don't have any experience working as a programmer - I just code as a hobby so far. Some years ago, I heard a programmer say that I should focus on making my code just work despite being slow (it was for a game, so it was more noticeable if my code was slow or not) and then I would spend my time improving it to make i...
I'm trying to understand the strategy pattern and asking myself: is the context class must-have or can I leave it out without compromising pattern's purpose ? I was under the impression I needed some kind of switch for reading different types of files but didn't want to just hack something and later deal with refactori...
I recently heard of an interview question: Given a string and a dictionary. Break the string into meaningful words and I remember solving this before with dynamic programming fairly quickly (maybe O(n) time? ) in one of my old algorithm classes but I can not remember the name of the algorithm. Could someone point me ...
I am in the early stages of planning for an input device which will consist of some as-yet-to-be determined number pf physical controls. From previous experience with such devices I have found that it would be extremely advantageous to have the device return data about the state of all controls in response to a query f...
What is controller layer and where we put this in our 3-tier architecture? 1)UI 2)Business Logic Layer 3)Data Access Layer I search in net but unable to get exact ans.Any links or sample example helps to understand better.Thanks.
I have always been using this method: from sys import argv and use argv with just argv. But there is a convention of using this: import sys and using the argv by sys.argv The second method makes the code self documented and I (really) adhere to it. But the reason I prefer first method is it is fast because we are imp...
I don't understand why Fibonacci heaps have marked nodes (picture). A node is marked when its child is deleted. Quoting from Wikipedia: "[Keeping degree of each node low] is achieved by the rule that we can cut at most one child of each non-root node. When a second child is cut, the node itself needs to be cut from its...
I have project written in C++ that I am working on which has a parent-child relationship where each child has only one parent. I had previously decided after looking at this post that I would make the children know nothing of their parents. A little background on my project before I go into my question: The parents in ...
In my code (Python+numpy or Matlab, but issue can apply to any array programming language), I often need to count the number of elements in an array where the elements are true. Usually, I implement this as sum(x>0.5), but this may be considered improper. See Is it correct to add booleans in order to count the number o...
I've come across a recurring issue in a few of my recent projects in which I find myself using enums to represent state, or type, or something else, and I need to check against a few conditions. Some of these conditions span multiple enums, so I end up with a load of logic in switch and if blocks, which I don't like. T...
I am studying the Array class in C#. The following is the implementation of System.Array class: [SerializableAttribute] [ComVisibleAttribute(true)] public abstract class Array : ICloneable, IList, ICollection, IEnumerable, IStructuralComparable, IStructuralEquatable I have two questions regarding this: I have read...
I'll be specific: Java 8 is promised to bring lambda expressions as well as method and constructor references among other things. As a Java developer I'm super psyched about that. In my day to day programming I see more and more opportunities where using these features would greatly simplify code that would otherwise b...
Hypothesis: I have a table (named BigTable) which could experience 5,000,000 INSERTS per day (with possibly just as many SELECTs). Each row inserted is about 50kb. These daily INSERTs are split across 5 clients equally (the table has a FK called ClientID). There is never a need to SELECT or JOIN data across multiple c...
I am creating a RESTful API. I am struggling to decide on the best way to design my database tables around my resources. Initially, I though a table per resource would be a good way to go, but I'm now worried that this will result in exponentially bigger tables the further down the resource chain you go. For example, ...
In programming what is called Principle of Least Astonishment? How is this concept related to designing good APIs? Is this something applicable to only object oriented programming or does it permeate other programming techniques as well? Is this related to the principle of "doing a single thing in your method and do i...
I have an program that collects data from other servers. I don’t have access to these servers so I can’t change anything. The servers can give incorrect data, I can solve the problem but I’m a little bit stuck on “when to do the correction”. I download the data from the server, the data gets processed and stored on the...
I am working on a product in which the responsibility of one of the modules is to parse XML files and dump the required content in a database. Even though the present requirement is only to parse XML files, I want to design my parsing module in a fashion that I can support any kind of files in the future. The reason fo...
How can one apply DDD to a EAV database model? Consider this EAV database model: How am I supposed to build a domain model if all my entities and their attributes will be stored in the database? UPDATE To help clarify the question I'll give an example. If I'm building a Store that is going to sell some Products then...
I know that profiling is useful to identify bottlenecks and determining what parts of the code require how much time to execute. The latter isn't always very easy to track in the midst of other paths being executed, so once I decide what I want to optimize it might be problematic to see the improvement in numbers. This...
We had a disagreement in a code review. What I had written: if(unimportantThing().isGood && previouslyCalculatedIndex != -1) { //Stuff } if(otherThing().isBad && previouslyCalculatedIndex != -1) { //Otherstuff } if(yetAnotherThing().isBad) { //Stuffystuff } The reviewer called that ugly code. This is what ...
I am about to develop a ASP.NET MVC 4 project that will make use of maps. Our company has it's own map API which is very basic at the moment, but is intended to be further developed in future to match some specific customer needs. The project will have a mobile/tablet interface in addition to it's web interface and nee...
I have two resources: users and links. Users can have several links associated with them. I have designed my RESTful API so that you can reach the links associated with a user at the following URI: /users/:id/links However, I always need to have a URI for just links – sometimes I might want all links, regardless of use...
My high school is starting a program where, instead of following the 'traditional' method of teaching programming (learning variables, then operations, loops, methods, and finally OOP), students are immediately introduced to object oriented programming without any other programming knowledge. Is this a good idea? My ...
I just started playing around with async/await in .Net 4.5. One thing I'm initially curious about, why is the async keyword necessary? The explanation I read was that it is a marker so the compiler knows a method awaits something. But it seems like the compiler should be able to figure this out without a keyword. So wh...
My company is using Git, and is using a peculiar branching scheme - work is done in master, and branches are reserved for releases. This works fine, so long as all of the work done in an iteration makes it into the branch, but if a critical production issue comes up, we have to ensure that the work somehow makes it in...
I have a problem with my teammates. Long story short: We are three students working at a project for a competition. The project consists of 2 separate applications: one for Windows (that I develop) and one for Android (my colleagues are responsible for developing it). Our code bases will never intersect, the apps will ...
I have been asked to investigate the possibility of re-engineering an existing ASP.NET AJAX Web Application as under MVC. The project, as it stands ATM, is very heavily relient on Telerik's ASP.NET AJAX controls. I've yet to have to opportunity to interview the person responsible for this request, so I'm unsure of the ...
I have pretty large code base for the client product I am working on. I am using Visual Studio 2010 for my development and it's hectically slow. I can get rid off this by disabling the installer project within the solution file. Is it a good idea to include setup projects within the same solution? How can I increase...
I am studying about optimizing alogrithms.(Prof. Skiena's Algorithm Guide book) One of the exercises asks us to optimize an algorithm: Suppose the following algorithm is used to evaluate the polynomial p(x) = a^(xn) + a^n−1(xn−1) + . . . + a(x) + a p := a0; xpower := 1; for i := 1 to n do xpower := x ∗ xpower; p := p +...
I learned to code in OO languages. I've always been interested in design patterns, clean code, etc., etc. - you know the type. Now at work I'm using a BASIC dialect. Given modern programming values, should we try to carry over these same principles to new procedural code? I'm pondering the following issues, and I wond...
I have a question about the best practice in this situation. At one point, my small application allowed the client to upload a file to a server, and download a file from the server (it would also compress / decompress as well). This was created in 1 solution which consisted of 4 projects: FTP CompressDecompress UI Tes...
I am building a RESTful API, and so far, to make sure that my resources work as I need them to, I am using a REST client called Postman. This makes it easy for me to store routes and quickly make requests to them for testing. My current collection of routes in Postman looks like this: The trouble with testing the API ...
We're working on an iOS project and right now, and whenever the designer has some feedback about fonts, colors, positions of elements, what images should go where etc., I have to go back and go through each little detail and make sure it's fixed. I'm thinking there's got to be a better way to do this, where the designe...
Is there a model that describes the different strategies that a company may use where the organisation is split into an engineering division and a professional services division? This is the sort of model that is followed by companies like Microsoft, whereby Engineering (or R&D) produce the core software, and professio...
The very simple piece of C++ code below is incorrect, it's easy to see why and tools like Valgrind will tell you. In running several C++ codes containing this kind of error, I noticed that each time, it ended up with a Segmentation fault at the line which tries to use the address. So my question is: is it safe to claim...
There is an issue which appears while running the application. It is not an Exception, but the desired UI change is not been implemented. While debugging to find the code which should be changed to fix this problem, the UI changes can be seen correctly, To be specific, if we put one breakpoint in the class where it is ...
In a C++ code base I've been working on, they have a bunch of instances of the observer pattern, but it's a little different from the classical pattern. In the classic, the Observer is a specific interface with specific method(s) that are called when the Observable changes or has new data. Observable ...
I started my new job as a JS developer in November and starting implementing Backbone pretty soon after. This was a big enough learning curve for the team (me included), however I'm thinking about looking at CoffeeScript, which I'm guessing would require everyone on the team to know it? Is that too big of an ask, just ...
We've started implementing some caching code in our MVC project. We've derived from .Net's ObjectCache to store it in a SQL database. What we do right now is in each method we want to cache we have code like this: public StatusCounts GetCounts() { var cache = new SqlCache<StatusCounts>("mykey"); if(cache.HasCach...
I was recently hired by a large multi-national corporation to head up mobile development for their sales operation/support team. In a company of close to 10,000 people I am, at least in the America's, the only mobile developer. They are testing the waters and phase 1 (temp-to-hire) went well enough for them. Now they ...
I am interested in integrating the results of 3rd-party news API's into my for-pay application. The APIs would be a very small part of the app (e. g. the app is not just reselling the APIs). I have found that many APIs such as Yahoo have "non-commercial" conditions like the following: YOU SHALL NOT: Sell, lease, share...
The iterator pattern is very clearly defined. What would you call the consumer of an iterator?
-I'm trying to figure out how to identify Application Services in my application. I think I can identify a Domain service by 2 things: It acts as a facade to the repository. It holds business logic that can't be encapsulated in a single entity. So I thought about this simple use case that I'm currently working on: An...
I read that Liskov's substitution principle is violated if : Preconditions are strengthened, or Postconditions are weakened But I don't get fully yet how these two points would violate Liskov substitution principle. Can some one please explain with an example. Specifically, how would any one of the above conditions c...
Recently I was looking at an open source project to contribute to however after going through the ugly code base (which seems to break quite a bit) and reading some things about the current maintainer I decided it would be a good fit for me. Right now my thinking is to just start a new project with the same goal but us...
I am facing a problem with changing behaviour of a library (thus cannot or don't want to change its internals because of future updates, etc.). In this library there is an abstract class which shares few methods with all its subclasses. Now I need to change few methods in this abstract super class without changing the ...
On the Android operating system details about the phone are available via the Android.OS.Build class. These details include things such as the phone manufacturer, model, version, etc. The customer may want us to collect this data and save it to our database for analytics and tracking. I think this raises some privacy c...
It seems to me that the best way to manage priority for programming tasks in a backlog is to simply put them in order. Do the top task first, second one next. If priority changes, re-order the queue. I thought this was exactly how things were supposed to work in Agile. I have yet to find an online open-source team task...
Every example neural network for image recognition I've read about produces a simple "yes" or "no" answer. One exit node corresponds to "Yes, this is a human face," and one corresponds to "No, this is not a human face." I understand that this is likely for simplicity of explanation, but I'm wondering how such a neural...
I'm writing a WinForms desktop application which will be shipped out to several different clients and am wondering what the best way to implement a user configuration file is. Normally I would use the built in Settings.settings or app.config to store user settings but in this case what I want to store is unique for eve...
I work on a open-source web application (Moodle) which connects to a number of external services such as Google Drive, Dropbox etc. to allow users to exchange files with these services. Primarily we are using OAuth based APIs to connect with these services. One of the user interaction problems we are facing is that ou...
I am talking about normal PC applications, memory should be sufficient. They declare global or member variables. In each function/method, they use the same global/member variables. At the beginning of each method, the variables are re-initialized so the old value is never used. Why do they keep the variables but no cha...
I am developing a 2d game where the world is made up of tiles. I have an overworld and a "current world": the current world represent the current tiles on screen at any given time, currently this is in a 2d array (14x10 elements). the overworld is the entire world, currently 28x20 elements, which means there are four ...
I am using Codeigniter framework for PHP on Windows platform. My problem is I am trying to track progress of a controller method running in background. The controller extracts data from the database(MySQL) then does some processing and then stores the results again in the database. The complete aforesaid process can be...
Having a minimum a maximum number of ranges a value between minimum and maximum I'm trying to come up with a method, or two, which would calculate which range the provided value belongs to. For min=1, max = 10, number of ranges=5 the ranges would be [1,2],[3,4],[5,6],[7,8],[9-10] The other method would behave like...
Several concepts related to REST conflict in my head when I try implementing it. I have a REST-ful back-end API system that holds the business logic, and a web application that provides the UI. From various resources about REST (particularly, REST in Practice: Hypermedia and Systems Architecture) I know that I should n...
Is there some syntax (other than a series of if statements) that allows for the use of a switch statement in Java to check if an object is an instanceof a class? I.e., something like this: switch (object) { case instanceof SecondObject: break; case instanceof ThirdObject: break; } Sidenote: ...
We use SVN and PhpStorm at work. Recently our team has grown a bit so there are several people working on the same project at a time, sometimes on the same file. We've run into the problem where people don't update before comitting and overwrite the changes that were made by someone else. This is a hassle. I don't know...
I'm pretty new in our develepors team. I need some strong arguments and/or "pitfall" examples, so my boss will finally understand the advantages of Unobtrusive JavaScript, so that he, and the rest of the team, stops doing things like this: <input type="button" class="bow-chicka-wow-wow" onclick="send_some_ajax(...
From https://stackoverflow.com/questions/4544588/difference-between-iphone-simulator-and-android-emulator The difference between emulators and simulators is that emulators mimic the software and hardware environments found on actual devices. Simulators, on the other hand, only mimic the software environment; they other...
I want to know if it is possible to write to a log/text file dynamically generated HTML in asp.net tags in an .aspx page using HTTP modules. By dynamically generated HTML, I mean the html content that asp.net generates in response to statements between the tags <% %> or <%# %> or <%$ %>. So when asp.net renders a page,...
I am developing an application where I am taking dynamic gestures as input and then mapping them to keyboard controls. By dynamic gesture, I mean for example hand moving from left to right or hand moving right to left. I have four gestures: hand moving bottom to top, top to bottom, left to right and right to left. I am...
Where is the best place to validate input parameters of function: in caller or in function itself? As I would like to improve my coding style, I try to find the best practices or some rules for this issue. When and what is better. In my previous projects, we used to check and treat every input parameter inside the func...
I am an advocate of commenting on source code and documenting software products. It is my personal experience and observation that working on source code that is rigorously commented has helped me in different ways when I have had to grow software or maintain it. However there's another camp that says commenting is ult...
With regular git and GitHub, I can do a code review by simply creating a pull request of the feature branch I'm working on to the master branch. How would I do code reviews with git-flow? With a workflow step like git flow feature finish (which merges the feature branch into the develop branch), I'm confused as to wher...
I've been focusing on multimedia applications and I've noticed that most applications don't use Java in the back end. Instead, I see solutions with PHP/ROR/Python and Flash/Silverlight without any trace of Java in the application stack. What part of Java is either limiting or constrained - or perceived as limiting or c...
I am working with multiple websites (freelancer) and a good amount of them I write using C# MVC4. I created a very good boilerplace project that I plan to use on every next starting mvc4 application I build, however the namespace is named Website. I also do a lot of copy-paste from one project to another and then I alw...