instruction
stringlengths
34
19.9k
In the book The Pragmatic Programmer, the writers mention the "programming by coincidence" concept. It explains what it is, why it is caused, what are the dangers you may encounter and it compares with a landmine field in a war. Do you ever watch old black-and-white war movies? The weary soldier advances cautiously ou...
I have been messing with code in The Unix Archive and have found that most of the code references a (non existent) license, however, this is in the root of the mirrors and apparently covers all of the code (typed from a PDF, so excuse the typos): (source pdf is here The following copyright notice applies to the source...
From what I understand, HTML is a mark-up language, so is the content of XAML, XIB and whatever Android uses and other native UI development frameworks. JavaScript is a programming language used along with it to handle client side scripting which will include things like event handling, client side validations and any...
I am referring to the state pattern as described in this link. In the example class diagram, a context has numerous states. However, it does not show how does a state communicates with a context (perhaps an input in a state has impact on a setting in the context). The two examples on the page shows either passing the ...
So I've been reading about namespace on w3schools and I understand they are to uniquely identify an element. But what is the point of having namespaces if you have to have prefixes along side them. Are you always required to have prefixes with namespaces? If not are you always required to have namespaces with prefixes?...
I'm designing an OO graph library and at the moment I'm trying to figure out the design for a GraphEdge class. I've added setters and getters for it's nodes, direction and weight. This seemes perfectly reasonable. Then I've started working on the Graph class and I've come to the need of knowing if the particular edge i...
I'm learning NodeJS and just wanted to clarify something. In several introductory tutorials and books so far, very early on they've described Node's "non-blocking" architecture - or rather that it's possible (and recommended, the entire point) to code in a non-blocking manner. So for example, this example was given in...
I have a method which constructs dependencies using Unity. Currently, all of the calls do pretty much the same thing: Registers 2 repository object and 2 'App Part' objects. My issue is, there's a lot of them and the method has become massive. I've generalised the calls but here's an example: container.RegisterType<IRe...
I am reading a Binary file, it has several blocks, each block has different names/data. Some of this data is string value, date, datetime, time but most of them are integer value. Previously I code a struct for each Block and create public member to hold each property of that block, and then I make a Wrapper class this...
I recently had a phone interview with a company. After that phone interview, I was told to complete a short programming assignment (a small program; shouldn't take more than three hours). I'm only directly instructed to complete the assignment and turn in the code. I was given complete freedom to use any language I wis...
I am learning design patterns. I read this article. Point no. 3 is not clear to me. The writer said that strategy lets you change the guts of an object. But this is a violation of the open-close principle. Am I wrong? If I am wrong, then help me to understand what writer wanted to describe. Strategy is like Template M...
I'm fan of onion architecture but looking for some relaxing solutions in some areas. First of all I was thinking about communicating directly from UI (from controller in mvc) to data on the read side. As everyone can see UI should not be referenced to any assembly except Core. When I want to display list of countries ...
Been poking around the web because I was curious as to why they called it that but haven't found anything yet. Anyone know? (I checked the FAQ and it wasn't clear if questions on history/origins were OK to put here or not, but I figured it wouldn't be good on StackOverflow, feel free to start closing it if it is out of...
I take a good deal of criticism from other programmers due to my use of full proper casing for all my variables. For example, your typical programmer will use employeeCount for a variable name, but I use EmployeeCount. I use full proper casing for everything, be it a void method, return method, variable, property, or...
I came across a question that (eventually) landed me wondering about array arithmetic. I'm thinking specifically in Ruby, but I think the concepts are language independent. So, addition and subtraction are defined, in Ruby, as such: [1,6,8,3,6] + [5,6,7] == [1,6,8,3,6,5,6,7] # All the elements of the first, then all th...
Are there any benefits to removing unused using statements in a VS project (such as can be done using Resharper), or will VS automatically take care of that when building/deploying?
a) To my knowledge Domain Objects should for the most part be oblivious to technical aspects of a design. Since I view class inheritance as being a technical solution, wouldn't introducing a Layer Supertype pattern into our domain corrupt it? b) If you disagree, please elaborate why Thanks
VS Web sites/projects come loaded with several .js files, most of which I don't use (e.g., I use a CDN for newer versions of jQuery and jQuery-UI). I know it's safe to remove these unneeded .js files from my projects, but is there any benefit from doing so? Are they deployed to the web server if left alone?
1. According to Fowler's definition this pattern is implemented by having all classes in a layer inherit from a superclass. But after some googling it appears all of the following are considered as implementations of a Layer Supertype pattern: a - all classes in a layer inheriting from the same superclass b - having o...
I have been doing web-based Javascript (vanilla JS, jQuery, Backbone, etc.) for a few years now, and recently I've been doing some work with Node.js. It took me a while to get the hang of "non-blocking" programming, but I've now gotten used to using callbacks for IO operations and whatnot. I understand that Javascript ...
I want to add a project which in this case is created in Netbeans but this question is general for most IDE's. It's simply, what should I include in my repository. For example Netbeans creates a nbproject folder, eclipse creates a .settings folder etc. should I include these in my repository, what are the advantages/di...
How can I refactor this code? class Node { public Node Parent { get; set; } } class AVLNode { public AVLNode Parent { get; set; } } I tried to use inheritance, but then I have to use type casting: class AVLNode : Node { } class Program { void Main() { AVLNode a = new AVLNode(); AVLNode b = a....
I have a very large c++ project and I'm trying to decrease build times. I've been religious about forward declaring and only including files which are used. However I have many preprocessor defines which are setup in the project files (ie not in cpp or header files) so that I can keep them all in a central location for...
Is there a more general concept or name for what WPF calls "dependency properties"? I imagine this is not a WPF-ism and in fact other libraries or frameworks have employed a similar approach? If so, what are these other instances and what are the similarities and differences compared to Microsoft's dependency propertie...
I would like to sell the compiled binary of my android application in the Google Play Store when it reaches production. Which license can I use to prevent people from downloading my source code from the open-source page and selling an exact copy of my work on the play store? I want the code to be free and open for ge...
After embracing the whole SOA thing, I've found that I'm gradually drowning in a sea of web.config and app.config files. As an example, one system has 2 services that it interacts with. Each service has 3 config files - one for dev, one for staging and one for production. That's 6 config files. Then each application (...
Folks, this seems like it should be straightforward, but I'm drawing a blank here. As a simplified example, consider an abstract class called Number with an abstract method add(). I want to create two concrete subclasses, Integer and Float, with method signatures Integer.add(Integer other) and Float.add(Float other). ...
I've been practicing behaviour driven development (BDD). I understand that you have to write tests that test the behaviour of the code, and this will allow the design of your code to evolve and take shape. When doing BDD and I find I need to refactor my code into a better design, and that refactor happens to involve e...
I am wondering what is the purpose of Chrome using multiple processes for each tabs? I asked this to C++ chat room and one responded it is a product of laziness. I personally believe this is an example of "Distributed processing" like in Erlang programming language. What exactly is it?
I'm working on a website and was hit with the thought of "do I need to give credit for the languages I'm using to build my website with?" I wasn't able to find any sort of licenses for HTML, CSS, or JavaScript and I'm a bit confused on the wording of PHP's license. My question is: Do I need to specify somewhere on my w...
I'm trying to find a way to design backend that will be handling customized web forms creation on the fly. Once created those forms will be injected to part of the existing web pages. I've created dynamic forms successfully but I'm unable to figure out how I can integrate these newly created forms or custom fields into...
Despite many years in IT, I still struggle with OO design. One particular problem I seem to keep ending up with is large classes, often containing many hundreds of lines of code. The OO world talks a lot about SRP, and I could argue that these large classes I end up with are each handling a single responsibility. The c...
I am building an web site which will allow users to aggregate the information stored in their online profiles ("data feeds") in one place. I am wondering - what is the accepted (from a secureness point of view) way to store user name / password information in a my database? Normally I would derive a salted-hash value...
Question 1 What's the computational complexity of the Groovy unique() method? Question 2 How could I have figured it out by myself? The unique() method is defined in the class DefaultGroovyMethods. The source code can be found here: org.codehaus.groovy.runtime.DefaultGroovyMethods. Can you point me to the piece of code...
I have a custom View Controller that is a subclass of UIViewController that requires a data object to be set up properly. Without this object, showing the VC doesn't make any sense. So I created a custom initialiser that requires this object to be passed as an parameter/argument. There is also no "default" data object,...
I have searched and could not find any information about it. What is the best approach to storing revisions? I have a website where the user can write a document which can be fairly long (200-300 lines). How do you determine when to make a revision? Is it not a scalable solution to make a new one whenever the save, be...
I'm wondering how responsive design plays along with the Separations of Concern principle, in respect of how we're allowing a single implementation behave for multiple presentation devices (mobile, tablet, browser sizes etc.). Is it breaking the principle? If I make changes to a web page that I know is behaving respons...
Is there a methodology to debug websites without a browser? Normally I use a web browser to view a results page. The slow debugging process confuses me a little. To correct an error I need to switch to a code window (which takes some time). Then I correct the error and return to a browser window, press F5, and wait for...
the other day I was discussing with a colleague and he came out saying that using user's session in a web application is just wrong. I replied that it could be wrong depending by the information you are storing, otherwise why should a web session service even being provided by Microsoft (we were talking about ASP.NET)....
I'm struggling to find pragmatic real-world advice on function naming conventions for a medium sized C library project. My library project is separated into a few modules and submodules with their own headers, and loosely follows an OO style (all functions take a certain struct as first argument, no globals etc). It's ...
During team formation, we have a conflict where 2 developers both really want the same coveted window seat with a lush view of a creek & the woods. What sort of game / activity can we place them in that will: Decide who gets the seat Provide a random (not skill based) chance of winning Allow both team members to part...
Given a corner x of an undirected Graph G I would like to ask for the connected component of x, but my first try does not work as desired. Here it is: edge( a,b ). edge( b,a ). edge( b,c ). edge( c,b ). edge( c,d ). edge( d,c ). connected( X,X ). connected( X,Y ) :- edge(X,Y). connected( X,Y ) :- \+ edge(X,Y), edge(...
Now I know people could consider this question duplicate or asked many times, in which case I would appreciate a link to relevant questions with answer to my question. I have been recently in disagreement with some folks about code coverage. I have a group of people who want our team to drop looking at code coverage al...
There seems to be an aversion to writing even the most basic documentation. Our project READMEs are relatively bare. There aren't even updated lists of dependencies in the docs. Is there something I'm unaware of in the industry that makes programmers dislike writing documentation? I can type out paragraphs of docs if n...
What is the difference between Microsoft.Web.Helpers and System.Web.Helpers? Did one take the place of the other (same thing, different version/name), or are they separate things. If so, how do they differ? What is the raison d'etre of each, and are there scenarios where you might use both of them?
My company is an online retailer, and we use an homebrew ecommerce platform. In the last year or so, we've partnered with a accounting software vendor, as our homebrew solution was unable to produce reports as needed, or otherwise satisfy the requests of banks and investors. We're off to a rocky start with the softwar...
We all know “The quick brown fox jumps over the lazy dog” used as benchmark for printing and fonts. I wonder if there is a similar “Lazy Dog” for Programming Languages. There are so many different programming languages, with all kinds of features and syntaxs, similar or different. The problem is: the user will be confu...
I am releasing an application at no cost, but I am not granting users the right to modify or redistribute the code. How should I call this? I initially used the term "free license", but on second thoughts I find this confusing because free can have several meanings, and in people's mind it is often associated with ope...
I'm going to make an application that will be given data to put in a database. The data will for the most part be the same, but the way it is formatted will vary a lot (could be in anything from text files to .xls to .doc). I'm not a very experienced developer, but I can see some potential issues and I want to minimize...
Looking through the server vs local code on a humongous legacy project, I see this in Settings.settings: <?xml version='1.0' encoding='utf-8'?> <SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)"> <Profiles> <Profile Name="(Default)" /> </Profiles> <Set...
The finally block for a try-catch structure is well known, and gives a really easy and elegant way to deal with some must-be-done code. Therefore, I can see no reason why It shouldn't be good for methods too. For instance, lets say I'm writing some very complicated logic in a method, and I expect to end up with a bunch...
I am creating a widget for rotating topics. The functionality is as follows: Each topic is displayed one by one on the homepage and has a duration of 30 seconds. A countdown timer is displayed on the page. When it reaches zero the current topic gets marked as "shown" and the next topic is displayed. Users can choose t...
I would to find an efficient structure (speed and volume) to store nodes and their neighbourhood. My input is build out of stings in the following format ./X/Y.log where X ∈ [0,359] and Y ∈ [0,169] and each pair of (X,Y) defined the coordinate of a cell on a grid of the size [170x360]. I would like to find which cell...
So after many many many years of building sites from scratch (and doing a lot of the lifting myself) I've dipped my toes into two projects that have been around for a few years that I've been avoiding: Bootstrap and Jekyll. The design was a very customised job that required me to dig into the LESS so I've got the Boots...
I've created a gateway which receives a POST from cUrl on one system which is a well-formed XML string. After processing the gateway sends back a response XML. All the fields in the XML are required and while the system sending the data constructs the XML itself I'm running some validation to make sure that every value...
Suppose I have a table "Progress" with two columns. One column is ID which is identity. Another column is Progress_Label ID Progress_Label 1 Submitted 2 Approved by user 3 Rejected by leadership 4 Cancelled 5 Completed What is the best programming practice, should I go by ID or by label? In m...
When I first taught myself how to make websites (html/css) I used exact pixel width and height for all div elements. I've also practiced making websites with nothing but percentage width and height. I can use either technique fairly easily, but I wanted to know is there a standard technique or structure to building the...
I come from an embedded world where we use C/C++ for programming, and use an IDE to generate a binary file, which is then programmed into a Hardware Board, which can then be tested. With this background, what is a better workflow for automated builds than the current workflow of -build(using IDE)->Flash into the hardwa...
We know some signature/checksum methods for text, like md5,sha. Now, I want to compute a checksum for a matrix, to represent the exact matrix. Say, two matrixes with different sizes, or with different values, have different checksum. And slightly different matrixes(same size) result in slightly different checksum. So, ...
Say I have an array of runners with which I need to find the tallest runner, the fastest runner, and the lightest runner. It seems like the most readable solution would be: runners = getRunners(); tallestRunner = getTallestRunner(runners); fastestRunner = getFastestRunner(runners); lightestRunner = getLightestRunner(ru...
I was going through an article here In the section named Aggregate Method ,the author says Then summing over the entire sequence, all the 1's sum to O(n), and all the di also sum to O(n). That is, and then gives this Σ1≤i≤n ci ≤ n + Σ0≤j≤m 2j−1 I can understand how summing 1's to get n , But I am not very clear ...
My question is about how to create a definition for an object that is handled by different web services. A brief description of my current scenario and why I think it's a problem: A PHP web application provides AJAX endpoints for populating various parts of my web app. The endpoint provides access to User and Project e...
Sometimes, the syntax of a language seems weird, I often think, why would someone make something like that, but definitely there is a reason and a history behind every aspect of a programming language. Apart from being fascinating, It helps me remember the syntax and also the purpose that language solves. Does knowing ...
I am going to make an online judge platform. I have looked for some online judge platforms on the Internet for reference (I mean the platforms which have the source code available, and can be hosted my others, not something like Codeforces). Most of them have a web interface written in PHP (or something else). When use...
From my understanding of REST, the implicit assumption is that all operations are CRUD operations. Sometimes, you are not doing CRUD operations and are doing some more complex logic. In this case, is not SOAP more suitable? Or is it the case that all operations no matter how complex are a series of CRUD operations so t...
Due to data protection, I cannot discuss fine details of the work itself so apologies PROBLEM CASE Sometimes my software projects require merging/integration with third party (customer or other suppliers) software. these software are often in linkable executables or object code (requires that my source code is retarget...
I work on embedded systems, so frequently, I am required to implement protocols. When I do this I like to make nice clean layers. However, this become difficult where the fields used by different layers are shared. I like to think of the layers as offering a number of services following the spirit of OSI model: Frami...
Looking at node.js, and avoiding nesting callbacks. I found Async.js, can someone show me how can I rewrite this code using the async.waterfall method? // db is a mongodb instance db.open(function(err, client){ client.createCollection("docs", function(err, col) { client.collection("docs", function(err, col...
I am getting some data from Gov tracker (http://www.govtrack.us/developers/api) and creating a Windows 8 Store application.. I started out trying to use the HttpClient to get the JSON and then use Json2Charp.com to convert it to classes... But then I had no idea what to do with this giant class and the line var co...
I have a desktop application that has the ability to automatically update itself on the next restart (without the user's consent - but this is another issue altogether). Assuming that the user would never notice anything related to application updating (such as a progress bar, or pop-up requiring restart), and that our...
Web applications usually have a database. The code and the database work hand in hand together. Therefore Frameworks like Ruby on Rails and Django create migration files Sure there are also servers written in Self or Smalltalk or other image-based systems that face the same problem: Code is not written on the server bu...
When reading articles on ISP, there seem to be two contradicting definitions of ISP: According to first definition ( see 1, 2, 3), ISP states that classes implementing the interface shouldn't be forced to implement functionalities which they don't need. Thus, fat interface IFat interface IFat { void A(); void...
EDIT: As pointed out by Steve Evers and pdr, I am not correctly implementing the Memento pattern, my design is actually State pattern. Menu Program I built a console-based menu program with multiple levels that selects a particular test to run. Each level more precisely describes the operation. At any level you can ty...
I have a file (or rather, a list of about 100 files) in my website's repository that is still requiring the use of register_globals and other nastiness (like custom error reporting, etc) because the code is so bad, throws notices, and is 100% procedural with few subroutines. We want to move to PHP 5.4 (and eventually 5...
This is referring to a discussion in an answer and the comments of this question: What's with the aversion to documentation in the industry?. The answer claimed that "code can't lie" and thus should be the go-to location instead of documentation. Several comments pointed out that "code can lie". There is truth on bo...
I've stumbled upon this problem when tried to run our application in bad network conditions; it spawns hundreds of threads (which exist long time before termination), and with time the application crashes. However, other developers answered this is "not a bug" and "as designed". I have a strong gut feeling that spawnin...
In general, how do I decide whether to use make a class a super class, or to make it a private data member of another class? For example, given two classes, how does one decide whether to do this: public class Sprite { private BaseImage image; ... or this: public class Sprite extends BaseImage { ... Funct...
In a nutshell, should we design death into our programs, processes, and threads at a low level, for the good of the overall system? Failures happen. Processes die. We plan for disaster and occasionally recover from it. But we rarely design and implement unpredictable program death. We hope that our services' uptimes ar...
So, I've been evaluating Entity Framework and NHibernate (I'm not looking for an EF vs. NH battle here, though!). One thing that I see come up very often is that NHibernate is recommended for "legacy"/brownfield database projects, and lighter-weight ORMs (Dapper, etc) are sometimes recommended for newer dbs. I will be ...
In git if I change a character in a line the entire line is considered changed. I don't know much but stackexchange seem to track changes in a word-by-word basis in the edit history. Is there an option to make git like that, or is there anything else that does this?
What does "branching is free" mean in Git? I hear this a lot whenever Git is mentioned in comparison to other version control systems. I haven't had the opportunity (?) to deal with others (SVN, etc.), so how is branching "expensive" in others?
I see the http parser written by Igor Sysoev for nginx does not use regular expressions https://github.com/joyent/http-parser What could be the main reason for such design decision? I guess I could write few regular expressions to parse HTTP req & res this would be a lot less complex than Igor's version of the parser. ...
I have been asked to make a mobile app for a friends website. The website is a Multi level marketing site that sells products and franchises. A client logs in in to the website and can view his or her dashboard ( user can view team members, business volume, commissions, invoices, etc.) The app is supposed to bring the ...
My OOP JavaScript question is at the very bottom if you want to skip my introduction. In an answer to the question Accessing variables from other functions without using global variables, there's a comment about OOP that says: If there's a chance that you will reuse this code, then I would probably make the effor...
Consider the following regex (no unicode): Example:\x04\x05\x41 Suppose you search this regex case-insensitively. Would you expect it to search the final \x41 in case-sensitive manner? People whom I ask actually expect such behavior. And such expectations are wrong. Perldoc says: Note that a character expressed as on...
As programmers I feel that our goal is to provide good abstractions on the given domain model and business logic. But where should this abstraction stop? How to make the trade-off between abstraction and all it's benefits (flexibility, ease of changing etc.) and ease of understanding the code and all it's benefits. I b...
(Let me edit this question to try to better get across what I am asking.) I don't understand what a license is and how I may "use" it. From the little that I do understand, there are two situations: One writes a program/source code and puts a license on it. The license says how other people may (are allowed) to use th...
Non-Turing complete languages offer a great advantage over Turing-complete languages as they are much more analyzable and, thus, offer much broader optimization possibilities. Yet they are barely used and Turing-completeness is actually sold as a good feature. Are there any mainstream non-Turing-complete languages avai...
Except the garbage collector, what are some other features in Java that make it unsuitable for real time programming? On the net, whenever Java vs C++ is discussed with regards to real time programming, it is always the garbage collector that is mentioned. Is there anything else?
I am developing an iPhone app, which I am integrating with PayPal. I did it successfully using PayPal library. I am testing it on sandbox mode. When I transfer money from one account to the other account, it displays a message "send to server for verification". Is there a real need to store this PayPal transaction id a...
I have an Email class that has a Send method that optionally takes an SmtpClient and sends an email asynchronously using SendAsync. If no SmtpClient is supplied to this method, it instantiates a default SmtpClient and uses that to send the email. Inside the Send function, I provide a SendCompleted callback which dispos...
Researching archiving systems like archive.org, found out main issue of such is the dynamic content. Initial analysis shows that content 'dynamicity' can be assigned to one of the following levels: Static html content - plain old web page which is represented only by html markup with auxiliary css-referred resources (...
I am in the process of filing in the gaps in my knowledge so that I can become a better developer. I am an ASP.NET developer and I sometimes need to do pure back-end stuff too. I ahve compiled a list of things I deem as necessary to know. Please feel free to fill in any gaps: WebForms MVC jQuery HTML5 WPF WCF The Repo...
I have come across a book that claims that alterations and augmentations to GPL works can be kept close-source as long as these are not redistributed into the wild. Therefore, customizations of websites deriving from GPL packages need not be released under the GPL and developers can earn profit on them by offering thei...
I am creating a flowchart for a program with multiple sequential steps. Every step should be performed if the previous step is succesful. I use a c-based programming language so the lay-out would be something like this: METHOD 1: if(step_one_succeeded()) { if(step_two_succeeded()) { if(step_three_succee...
I am trying to achieve zero downtime deployments so I can deploy less during off hours and more during "slower" hours - or anytime, in theory. My current setup, somewhat simplified: Web Server A (.NET App) Web Server B (.NET App) Database Server (SQL Server) My current deployment process: "Stop" the sites on both We...
Backstory I inherited a bunch of code that I'd like to refactor. It is a UI application written in javascript. Current state: We have main application which consist of several UI components. And each component has entry fields, textboxes, menus, etc), like "ticket", "customer information", etc. Based on input, where t...
Quick question concerning shared code/logic in back and front ends of a web application. I have a web application (Rails + heavy JS) that parses metadata from HTML pages fetched via a user supplied URL (think Pinterest or Instapaper). Currently this processing takes place exclusively on the client-side. The code that f...
I have come to a point, in building a services oriented architecture (on top of Thrift), that I need to expose events and allow listeners. My initial thought was, "create an EventService" to handle publishing and subscribing to events. That EventService can use whatever implementation it desires to actually distribute ...
At a recent job interview, I couldn't answer a question about SOLID -- beyond providing the basic meaning of the various principles. It really bugs me. I have done a couple of days worth of digging around and have yet to come up with a satisfactory summary. The interview question was: If you were to look at a .Net pr...