instruction
stringlengths
34
19.9k
I have a single page application where everything in the UI is javascript driven so any operation requiring data or updating of data is done via Ajax requests. The way things are setup right now is that my Ajax called are made to one ajax.php file which takes care of routing them to the proper service method. This work...
I have something like this: public byte[] EncodeMyObject(MyObject obj) I've been unit testing like this: byte[] expectedResults = new byte[3]{ 0x01, 0x02, 0xFF }; Assert.IsEqual(expectedResults, EncodeMyObject(myObject)); EDIT: The two ways I've seen proposed are: 1) Using hardcoded expected values, like the above ex...
This can apply to many error handling scenarios, but I'm curious about how to do it in a login scenario. Given this Spring controller method: @RequestMapping(value = "/account/login", method = RequestMethod.POST) public String login(@RequestParam("username") String aUsername, @RequestParam("password") String aP...
I'm writing a simple chess-related code with intention to write it clearly (performance doesn't matter at all). And this method I have doesn't look clean to me at all: public static Piece GetClosestPiece(Square squareFrom, Direction direction) { //TODO: rework this mess switch (direction) {...
I thought of asking on SO, but it seems this is more of a "concept" type question than a "problem" type question. If it needs to be moved, please do so. Anyway, I'm having a tough time finding straight info on this. I'm using Unity.Mvc3 to setup dependency injection for controllers and other components the controllers ...
Friend asked me to develop a software application for him. I did and he paid me. There was no written contract. I live in UK and he resides in Canada. My question is: who is the owner of the software now? Can my friend make and sell copies without my permission? Can I do the same? I'm asking this because another person...
I played a bit with WebSockets and started to implement a tiny chat. Last time I did something like this was when there was no such thing as threads and computers had single core. I started to think how to implement it with todays programming patterns but I didn't come to any final conclusion. How you implement chat's ...
How can one become better at debugging in general? I do not mean specific tools or tactics that apply to a certain programming language or stack, but simply how to make your mind better at it, hopefully something beyond "just more exercise". I am fairly good at "blank sheet" type programming problems: I can easily code...
I remember that in our first programming class with Java, while explaining data types, the following occurred (kinda): Professor: So, what data type would you choose if your program needs to store the user's gender? Someone: How about a boolean? You know, true for male and false for female. Professor: Sure, that m...
We have a system whereby the database connection is get once using a common method, and being pass throughout the relevant class to be used. There are doubts that passing the database connection as a parameter to different classes would cause problem, so i'm checking here to see whether this is actually viable, and are...
There isn't any cool LINQ sugar for creating unions. The Enumerable.Union() method is usually called like this: var bigList = list1.Union(list2); The alternative is to call Enumerable.Union() which can be more readable: var bigList = Enumerable.Union(list1, list2); However neither of these methods are very stylish (m...
I'm a student and I work as an undergrad in an IT department. They are very effective programmers, but as far as documenting what they do and tracking what time is spent on specific tasks - not so much. I was put in charge of setting up project management software. So far, I've created a satisfactory solution with Tra...
I have recently been looking at some testscripts which looks a bit like ... try { receiveSomething(); // something was received even though it shouldn't failTest(); } catch (TimeoutException e) { // nothing should be received succedTest(); } The problem I have with these types of tests is They are not deter...
I have a bulk emailing service within the system which allows for a template to be used. When the mail is sent the template is parsed or run through a parser to replace tags with actual information. i.e "[Foo] has logged in" is parsed to "Bar has logged in" Is it better to have 1 service for sending and parsing emails ...
The main difference between themes/skins and CSS are the HTML & Server Side Controls (SSC) only. We use skin files to format & cosmetics SSC which are not in HTML like <asp:Label>, <asp:TextBox> & </asp:RadioButtonList> etc... But what if we use the rendered HTML SSC in CSS instead skin files to handle <asp:Label> & <a...
I have been reading DDD Quickly and wondered about how to avoid naming clashes with technical terms and domain terms. For example, if I commonly used the repository pattern (with classes such as AddressRepository), but a customer also has something called a repository in their domain. How would I best avoid confusing t...
I've just read two statements that seem to be very different: Des Weiteren ist mangelnde Kommunikation zwischen Programmierern und Nutzern eine nicht zu vernachlässigende Quelle von unzureichenden Produkten. Translated: A lack of communication between programmers and users is a source of poor [software] products. Sou...
I was always under the assumption that trial softwares write a registry value of the installation date and then the software makes a comparison of the current date of the system with the remaining days + installation date to verify whether the trial period is still valid or not. If this assumption is to be true, windin...
I was assigned to fix some issues in a PHP project. Later on, I was asked to implement some new features, which I did. The project neither uses any framework nor does it use OOP. It lacks a proper structure, except for the use of folders (no sub-folders) to organize files. There was no documentation created by the or...
I think my book (Programming Languages: Principles and Paradigms) is wrong. a is a vector, assume a C-like language: b = 0; a[f(3)] = a[f(3)] + 1; int f(int n) { if(b == 0) { b = 1; return 1; } else return 2; } It has the effect of assigning the value of a[1] + 1 to a[2] whenever the e...
Basically we now have 2 developers for an iOS project, 2 developers for an Android project and 1 designer doing designs for both projects. Right now, the way we exchange designs and images is through mail...so not very advanced or efficient. We're switching to Dropbox, but I feel like we could go a step further and som...
TODO indicates "task to be completed", FIXME to be fixed etc. Is there a code tag to indicate "need improvement" on code comments?
So, I work in .Net. I make open source projects in .Net. One of my biggest problems with it isn't necessariyl with .Net, but with the community and frameworks around it. It seems everywhere that magical naming schemes and strings is treated as the best way to do everything. Bold statement, but look at it: ASP.Net MVC:...
I'm wondering what is better in terms of good OOP desing, clean code, flexibility and avoiding code smells in the future. Image situation, where you have a lot of very similar objects you need to represent as classes. These classes are without any specific functionality, just data classes and are different just by name...
When thinking about testability and modular code, I recently thought about whether I should split out the synchronization part of a class from the actual behavior part. By example: The app "needs" this: class Mogrifier { // Mogrifier accesses are thread safe private: unsigned int m_state; mutex m_sync; public: Mo...
I currently have the following models and am designing search functionality that searches within these 3 models: Locations Users User_friends Should I create a search controller or should I put the action in one of the existing locations, users, or user_friends controllers? If so should it be pluralized - searches_con...
We manage a range of client sites built in Wordpress and Joomla and these require regular updates to the core CMS and extensions. We keep these sites in subversion and place updates in subversion. We try to use a single revision for this. We face some difficulties in making this process efficient, over time we would li...
Under which application development scenarios C# dynamics and ExpandoObject can be used or when to consider using c# dynamics and ExpandoObject
I would like to develop a bit of functionality for a web site that involves a bit of 3D - the user can move around objects, rotate them and texture them. So far I've looked into: WebGL (in particular three.js) and it looks great, but it's not supported in IE nor IOS. IOS supports the <canvas> tag, but only 2d. It loo...
if(true/false){ //if condition is true }else { // if condition is false } Everyone knows about the structure of if-else. But what is if actually? Is it a class method, static method or keyword? I'm little confused about this.
I have a client that asked me to develop his Windows Application and use MS Access instead of SQL database. I did and now he asked me that he deployed the Application through several of his offices. Now he wished to have a "main Server" with all information from the "client applications" for Reporting purposes and also...
On my filesystem (Windows 7) I have some text files (These are SQL script files, if that matters). When opened with Notepad++, in the "Encoding" menu some of them are reported to have an encoding of "UCS-2 Little Endian" and some of "UTF-8 without BOM". What is the difference here? They all seem to be perfectly valid s...
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...