instruction
stringlengths
34
19.9k
I need to write a map of string data to an XML document. The XML document has a specific format. An entry key determines where in the XML document the value will be written to. See below for an example (pseudo-code where appropriate); map = {"document_id": "123"; "document_type": "type_A"} Produces an XML file like th...
There has been a story in the news about a man whose Paypal account was accidentally credited with $92,233,720,368,547,800. Where does this number come from? What sort of programming bug is likely to give rise to this number?
Very often, when using the command line or just programming, you want to express some kind of combination that you end up using a for - which is often verbose. for (int i = 0; i<10; ++i) std::cout << "img_" << i << std::endl; for f in *; do echo "$f"; done I always wondered if there is some kind of language made ...
Suppose you have the following: +--------+ +------+ | Animal | | Food | +-+------+ +----+-+ ^ ^ | | | | +------+ +-------+ | Deer | | Grass | +------+ +-------+ Deer inherits fro...
Fowler talks about a number of design patterns available for the data access layer e.g. Table Data Gateway, Row Data Gateway, Active Record and Data Mapper. In the book it suggests using Data Mapper with Transaction Script and Active Record with Domain Model. This doesn't seem to be logical to me as Transaction Script...
I was trying to find examples for using DDD factories and I came across the shipping application from Eric Evans' book. However when I checked the BookingService the code to create a Cargo had this comment at line 37: 34 public TrackingId bookNewCargo(final UnLocode originUnLocode, 35 ...
I'm currently a beginning developer (3 years). I have been mainly doing Web Development for as long as I have been developing. This is my comfort zone when it comes to programming. I like both JavaScript and PHP because they are easy to use; however, I would really like to further my knowledge when it comes to programm...
In a general sense, for medium/big projects, what's the best way to handle javascript/ajax code? Is it better, to have a script file where to put each script or, to add the script directly into the html file between tags? I know it doesn't make any difference in terms of result, but i would like to understand what's ...
There are a lot of variants of the CSV "standard" (or lack thereof). I've never personally see any that use an escape character (like \) instead of surrounding each field with double quotes. Instead of foo,bar,"foo,bar" it would be foo,bar,foo\,bar. This would be handy for situations where a file needs to manually ins...
I would like to extend an application using LuaJit FFI. Having seen http://luajit.org/ext_ffi_tutorial.html this is surprisingly easy when comparing this to the Lua C API. So far so good. However I do not plainly want to wrap C functions but provide a higher level API to users writing scripts for the application. Espec...
Background We have several webapps running on Tomcat 7.0.x (on Linux). For historical reasons, we have populated the "Common" lib (i.e. $CATALINA_HOME/lib) with many application jars. These jars include Spring, Jackson, and our own persistence-layer jars. As we deploy new persistence-layer jars, we are embroiled in a c...
There are some very experienced folks on Stack Overflow who always talk about the C standard. People seem to not like non-portable solutions, even if they work for me. Ok, I understand that the standard needs to be followed, but doesn't it put shackles on programmer's creativity? What are the concrete benefits that co...
We are having a disconnect between development and business needs. Business is asking me to produce an accurate list of deliverables for a fixed date and development being difficult to predict is pushing back saying that can only produce a list 80 or 90% accurate. So my question is, how do we solve this problem? How t...
I'm thinking about a design issue which affects my project's data base. Supposing there are three diferent tables: CLIENT ORDER PACKING_SLIP Each order has its client and different packing slips. So there are some foreign keys which are compulsory, there would be clientId for the ORDER and orderId for the PACKING...
When developing web apps you often build your app on top of some frameworks like Twitter's bootstrap. These frameworks come with less/sass/stylus, javascript, images and sometimes webfonts. I'm wondering how to embed these frameworks in my app. Most of my apps are build using some grunt tasks that compile my coffeescr...
I am a Java developer who is starting to pick up more and more C++/C (yes I know they're different, bear with me). One thing that struck me as odd was the different naming conventions used by these languages. In Java, is is very common to see something like this: int someVariable = someFunction(someParameterToPass); ...
I have been reviewing C# code that has a lot of generics (and generics with generics...) and its taking me longer to grok the code. I know the gang of four patterns, and I know some of the fowler enterprise patterns (learning them as I go). Are there any techniques you could suggest when tackling understanding systems...
When I'm coding small projects, I often use System.out.println to print valuable info. It's simple, easy and gets me info. The only drawback I found is that there is no simple way to disable parts of this output for finished application, except for commenting them out, which dirties my code. So, I d like to know, is th...
I know I should not expect a lawyer's notice here, but programmers advices would suit me well enough. I want to publish a program which is derivated from a GPL-licensed program. I understand from the GPL legal notice that the whole work is to be licensed under GPL as well. Now, I'd rather publish my work under a more ...
After working Scrum(ish) in a previous workplace, I am trying to implement it in my new place of work for a brand new project (I am no scrum expert). We have some pre-requisites to code before we can begin working on the stories (which are being groomed in the mean time). Things like database design, api design, etc. W...
As a freelancer, I come across many projects. Its almost impossible to store a backup of all of the projects on my laptop. What are some better options to store them?
Here is a simple code for a randomized skip-list: Coin_Side flip() { if ( random() % 2 == 0 ) return HEADS; else return TAILS; } Note: random() returns an integer that uses a modulus of the form M = 2^B. Then, what is the expected performance of the skip list algorithm? So we have: (ax mod M) m...
I started to create a php application I'd like to make open source in the near future. However I do not know, if it's needed to follow any kind of code/documentation convention, to make it more usable and acceptable when released. Is there any model, to follow, to develop a good open source application? Do you think it...
I am specifically interested in SQL Server, but the same question applies in general. When creating a new application, the way I see it, there are two options: Create a table called "Users" and store the user name, password, etc. Set up one database user called "application" (and possibly more users for various comp...
For the GUI of a program, I want it to list several items, all of which are, from a programming side, just subclasses. They can add one of these items to a list. I don't want to hard-code which subclasses there are. What would be the best way to allow the GUI to know about the subclasses, only having the base class to ...
I am a single developer working on a large system. I was recently informed that there may be an opportunity to recruit another developer or maybe two. I have incorporated source control into my approach using Subverison and Tortoise SVN. I was talking to another developer who I used to work with recently and he remin...
I need to come up with a data structure to keep information about English verb forms. In most cases a verb can be in one of 4 forms: base, present participle, past participle and past simple, for example: take taking taken took It's seemingly easy to define 4 types for each form and be over with it. However there ar...
I'm working on a website that will allow users to log in using OAuth credentials from the likes of Twitter, Google, etc. To do this, I have to register with these various providers and get a super-secret API key that I have to protect with pledges against various body parts. If my key gets ganked, the part gets yanke...
I have a TriggerCaller and a TriggerAction class. The Caller "calls" the do() method on the action, which is set with the TriggerCallers setAction() method. The rest of the program should deal with the Trigger class, which contains the caller and the action. I have two options: 1) Give the Trigger class the methods set...
I study multicore pipelining and the diagrams are not UML sequence diagrams for instance Why not remake this diagram like an UML sequence diagram, would not that be more clear so that we can see both how time progresses as well as the data paths since I do not think it is clear distinction between data path and time?...
I have a HTTP class that has a Get, and Post, method. It's a simple class I created to encapsulate Post and Get requests so I don't have to repeat the get/post code throughout the application. In C#: class HTTP { private CookieContainer cookieJar; private String userAgent = "..."; public HTTP() { ...
I am looking at configuration management and the idea of form, fit and function change can determine whether a change is minor or major. I wondered how this definition could be applied when doing software development. Is there a good guideline on whether a change to software is classed as a major or a minor change?
I saw lots of questions and explanations regarding empty catch clauses but I was never actually sure what "empty" means. Is a catch clause like this empty? It clearly isn't empty for the eye because there is one line of code. But the catch is not really handled. Instead the error is just logged. try { // do some wo...
From the official documentation... Modifier Class Package Subclass World public Y Y Y Y protected Y Y Y N no modifier Y Y N N private Y N N N The thing is, I can't remember having a use case where I needed ...
The following IMHO valid java program doesn't compile because the Oracle 1.7 javac compiler thinks there's a possible loss of precision in lines 5 and 6. If you uncomment line 3 and comment out line 4, it compiles fine. Would someone explain why the compiler believes there is a loss of precision on the assignment to ei...
I have a huge project that is using YACC and I would need to fix a bug in it. I might ask someone else who wrote that to fix it but I'm interested in how compilers work. Does it make sense to learn YACC nowadays? It was told me that it's old and obsolete. I would love to understand how compilers/llvm and other stuff li...
PhpServer will handle gSoap requests and http requests from clients. PushServer will push notifications to clients and act a file server. There are many server machines. Every PhpServer will communicate with a specific PushServer when needed. Every PhpServer needs to register itself to a PushServer letting the PushSe...
A co-worker and I recently had a discussion about Java versions and the JVM. I use Java 7 but we use Java 6 for our client (while he says that some are still on 5). My immediate thought was, why can't we target those VMs too? The Java VM is somewhat different than a real machine in that it has a bunch of runtime featur...
I'm new to using async calls in ajax. My problem is that I have two server "tasks": one that just checks if session is set (fast), and another that sets the session (slower). I want to check if the session is set and if not, set it. And I want to try X number of times (I'm unsure if I really need to but that, but that ...
The problem of Electronic Data Interchange over networks is well known and understood. Today, the most common formats for data interchange are things like XML and JSON. There are various pros and cons of using one format over the other, and certain formats lend themselves better to certain data-sets. I've been progra...
ASN.1 is a data format used on HTTPS certificates, and various other critical pieces of infrastructure. I need to analyze some potentially hostile ASN.1 data, and want to ensure my code is safe from any programmer error. I think the best way to do this is to use a managed language that does not use unsafe code. Are th...
The words invert or control are not used at all to define Inversion of Control in the definitions that I've seen. Definitions Wikipedia inversion of control (IoC) is a programming technique, expressed here in terms of object-oriented programming, in which object coupling is bound at run time by an assembler object...
I have found several functions in python 2.7.2 to be very useful and I recreated them in C++ for my own uses. How do I properly give python credit for them? Do I even have to? I never actually looked at their source codes. I just wrote functions that output the same values as the python versions of the function.
I have a question to somebody who is expert about "GNU General Public License version 2.0" license. I am making program and my code is using another program ("HoboCopy") inside which have this one license. I downloaded just a .exe of this one program and I am wondering if its ok with license if my boss will sell progra...
I'm building a search engine using Lucene.NET / Solr.NET, and I'm wondering should search hits be returned as a dictionary or strongly typed object. public class SearchResult { public string SearchTerm { get; set; } public List<Dictionary<string, object>> SearchHits { get; set; } ... } // where search hit ...
This question was brought up during a Standards discussion, which should revolve around SOLID Principles for Object Oriented Development. In your experiences, have you seen benefits or drawbacks in either code readability or performance based on whether variables are passed ByRef vs Module-Level Variable? Obviously: I...
I have been assigned to develop an integration to one of my employer's applications to an external system developed by our client. Our client's specification for the integration that has some blatant flaws related to security. The flaws would allow an unauthorized user access to the system to view restricted data. I ha...
I'm assigned to a project where the goal is to update an existing software. This software was developed in a totally ad hoc manner, which means that any documentation generated is outdated, confused and just plain useless. I do not want to retroactivelly produce all the missing artifacts, since this would just be a was...
In simple words, is it true that an average size of an encoded video frame would be FrameSize = BitRate/FrameRate? Because BitRate shows how much data we are transferring per time unit, and FrameRate shows how many frames does this time unit contain.
Firstly let me clarify that I know C and am learning Python. So my OOPS is kind of bad. I was reading the official tutorial and found this Although scopes are determined statically, they are used dynamically. At any time during execution, there are at least three nested scopes whose namespaces are directly accessible:...
The advantage is it protects your DTO against future "enhancements" ?
I need to create a graphical editor for our data model that works in an HTML5 compliant browser. I am looking for a proper library/framework to build on. The model is stored as xml, but that should be largely irrelevant for the front-end technology. To be more concrete, I am looking to build a kind of diagram editor to...
After reading a few articles about Newable vs Injectable objects and how these concepts relate to DDD's services, entities and value objects, I was left with some doubts about using newables in my code especially in my unit tests. Main candidates for newables were Entities and Value objects meaning that instead of inje...
This is my situation: I have a class called CueList, which is basically a wrapper around ArrayList. I have another class called TimeTicker that alerts all the Tickable (interface) in its list that a certain amount of time has passed. Since I need to tick all of the items in CueList, but I don't want to violate DRY by k...
I have a set of questions that bothering me, hopefully someone will be able to answer them here: What should be an optimal team (in terms of roles) to write a big enterprise nice-quality framework? What big frameworks could act as a good references in terms of documentation, architecture, quality of implementation et...
In chapter 24 of Code Complete the author says, in reference to encapsulate downcasting when returning from a method, "If a routine returns an object, it normally should return the most specific type of object it knows about. This is particurlarly applicable to routines that return iterators, collections, elements of c...
I am a web developer and at the moment am finding it hard to cope with long un-documented code written by previous developers in an organisation I work for. With the deadline gun always pointed at my forehead, it's doing my head in. I use aptana studio's search feature for some quick wins but it is becoming overwhelmin...
The C# community has so ubiquitously used the "I" prefix to denote an interface that even the most inexperienced programmers know to use it. Why is it then that we do not prefix enums, abstract classes or structs (possibly with "E", "A" and "S" respectively)? For example, if we did mark all abstract classes with an "A"...
I'm planning to write an e-commerce app using PHP & MySQL with lots & lots of custom rules. Say for example, I want to have a rule like "Give Customer X, a 10% a discount for Product Y if he bundles it with Product Z" I've heard about Business rules engine(in Java and others). I intend to implement a flexible business...
PHP supports the list() language construct which, in short, allows you to return multiple values from a function and then attach them to different variable, eg: function myBigReturn(){ return array("foo", "bar"); } list($fooer, $barer) = myBigReturn(); echo $fooer; // echoes "foo" echo $barer; // echoes "bar" I ha...
Function A() calls B() calls C(), which encounters an error. Which function writes to the log and which function reports to the user? My first inclination is that all functions should write to the log, and that the inner-most UI-facing function should be responsible for outputting the error to the user. However, the fi...
I recently was assigned to a task, but it says only a couple of words, like, do it as it made there, with no actual spec attached. What is the best thing to do in that circumstances?
Teams in our company deal with Product Owners who are in such a position that they cannot spend as much time with us, as we would like, to do proper Backlog Grooming. Thus in order to alleviate some of the time constraints we have begun implementing the art of getting stories "Ready for Sprint" or in other words gettin...
While practicing TDD, I came across this specification: A user should be created with its password hashed, be persisted and an activation token should be returned. Should my first unit test, (aiming to begin to test this scenario) should encompass the whole needs? : shouldPersistTheNewlyCreatedUserWithAHasedPasswordAnd...
I recently read this question that features, the arrow anti-pattern. I have something similar in code I'm trying to refactor except that it branches. It looks a little something like this: if(fooSuccess==true&&barSuccess!=true){ if(mooSuccess==true){ ..... }else if (mooSuccess!=true){ .......
I'm involved in a project for a redesign of an existing site. The Designer Team delivered us -the Engineering Team- four separate HTML/CSS prototypes of how the site should look: On a Desktop Browser. On a Table Device, a similar but simplified design of the Desktop View A High-Tech Smartphone, the design is mobile-ap...
I'm currently working on a code base that has many classes that implement a Start method. This seems like two-phase construction to me, which I had always considered a bad practice. I can't tell the difference between this and a constructor. When is it appropriate to use a start method instead of normal object constr...
The company I'm working on has a RUP-like software development process, with very heavy documentation. Right now we're doing a Multi-Channel web site -it's intended to be seen in Desktop, Tablets and Smartphones- and every version of the site has a particular flow of events and content. I don't see in RUP an artifact w...
Specifically, I am working on a tool that integrates a DVCS and build system, but I image the challenge I am facing would arise for anyone developing a "meta" tool (compiler, VCS, build system, test runner, etc.) that they wish to develop through "dogfooding". My question is: in a scrum-style release process using the ...
Despite being very stakeholders friendly, ATDD aimed to provide a "stop" line when a feature has just been done. This avoids wasting time to add non-focused (and sometimes useless) code. That's why some teams start by establishing a walking skeleton of the application, and directly specifying with an acceptance test th...
I'm trying to decide on what format I should save data in, and hopefully this question will help me come to a decision. The program I'm writing uses 'databases' in which word=meaning (not a dictionary, that was just an example). I don't really want people to be able to manually edit these 'databases' without my program...
It's current to see the terms callback, trigger and handler in some API documentations. It is just synonymous or each term correspond to a specific concept? I used to think that this terms are just synonymous, but I must be wrong ... Thanks !
I'm not coming from web-development at all, but am looking to build a web application. So far, I've looked into all the server-side stuff (for example, I think my stack will be Linux + node.js + ExpressJS + MongoDB), and have learnt a lot! At this point, I'm comfortable setting up an HTTP server, routing requests, usi...
I understand that in the earlier days of computing, shorter method names like printf made sense, because storage was limited. But why do modern languages like Python and Go still use the less readable names from the C APIs? Why don't they switch to a more readable form like print_format, the same goes for other names. ...
It always happen to me that if I leave the stuff for 1-2 months I forget the stuff. 5 months back I had symfony project and I did that. At that time I was very much confident that I can do any project in symfony2. Then we got one Python project in django and I worked full time on that for few months. But now when I had...
I have a customer who has a client app and when they log in to their client app, they will see a link to my website. When they click on the link, it should log in them in automatically to the website without asking for the credentials. Is this only possible if the username/password are the same between the client app...
I'm new to Android and while going through a tutorial on saving Activity state to a Bundle, I noticed that instead of accepting the more generic List interface, Bundle's put methods are expecting ArrayLists. Example: Bundle.putCharSequenceArrayList(key, value) Bundle.putIntegerArrayList(key, value) Bundle.putParcelable...
I'm aware that most modern languages use reserved words to prevent things like keywords from being used as identifiers. Reserved words aside, let's assume a language that allows keywords to be used as identifiers. (For example, in Ruby a keyword can be used as a method name). During compilation, how would you deal with...
could you please help me understand this ternary operator public static <E> void replace(List<E> list, E val, E newVal) { for (ListIterator<E> it = list.listIterator(); it.hasNext(); ) if (val == null ? it.next() == null : val.equals(it.next())) it.set(newVal); } i thought the part after ? is j...
Consider the following code: a.py import os def print_rand(): print os.urandom() And another module: b.py from a import * In this code, I end up with an os variable getting imported from a. I could prevent this with a small change: a.py import os as _os def print_rand(): print _os.urandom() Since from a im...
There are some design guidelines about testable code in “The Art of Unit Testing”. The first one is “Make methods virtual by default”. I’m curious to know your idea about non-virtual-by-default behavior in C#. I’ve read about Hejlsberg opinions but I think one the most important reasons could be that it may lead us to ...
I just started a new job, I have to create a web app for them and host it on their intranet on an Windows 2003 R2 server with SQL server 2008. As said in the question, I'll work on a MCV3 with Razor syntax application. I know that it won't work easily or even not work at all. On a recent server you have to install some...
I'm trying to adhere to PEP 8, with a 78 character limit on the length of my lines. I have the following statement: startTime = time.strptime(request.GET.get('st', (dt.datetime.now() - dt.timedelta(days=1)).strftime("%d/%b/%Y:%H:%M:%S")), "%d/%b/%Y:%H:%M:%S") How should I format it so that it adheres to PEP8 (where sh...
I'm investigating the legal issues of using LGPL native libraries in a closed source Android software. As for now, my research on the subject shows that using LGPL libraries in closed source software is doable, and that the requirements are not specially high. On a regular application (for example a C closed source app...
Normally TCP/IP Sequence and Acknowledge numbers are 32 bit. However, I need a way to shorten them to be 24 bit (it's an experiment in deep inspection firewalls). Question: Is it possible to shorten the bit resolution of the Seq/Ack numbers in windows without the knowledge of the application? (which in this case is IIS...
I'm learning about REST and had the chance to build a basic REST API. After doing so, most of the material I read was internalized and I now have a better understanding of it. However, I do not see any real difference yet as to the tangible benefits of using REST over the old way I was doing things, which was simple...
if I had a boolean (property) shouldAutoLogin is it better to name the getter getShouldAutoLogin or just shouldAutoLogin so that it reads more like English? ex : if(shouldAutoLogin){ ... } or if(getShouldAutoLogin){ ... }
I work in a fairly large and old solution that has many entry points for different kinds of clients, with web sites for public access, web sites for internal access, some web sites and web services for partner companies access, etc. All those applications use different (Microsoft-based) technologies, such as Classic AS...
I think this question should apply to most programs that load settings from a file. My question is from a programming point of view, and it is really how to deal with the loading of settings from a file in terms of different classes and accessibility. For instance: If a program had a simple settings.ini file, should i...
Recently I have started using a new(to me) paradigm for web services. I use the controller to accept JSON strings sent over POST, process it and return JSON strings. GET, PUT, DELETE and other methods throw HTTP 405. This pattern is proving to be very efficient from the point of view of asynchronous web frameworks (ver...
Say I have a class like this: public class MyObject { public List<string> MyCollection { get; set; } } And a method like this: public void DoSomething(MyObject object) { if(object.MyCollection == null) { // MyCollection must not be null // Should I... // a) object.MyCollect...
We are basically using Waterfall life cycle methodology. Requirement Analysis: I get a use case created by some one else. Design (talking only about Low level design): I get some little feeling about how would I design it, may be either instantly/ or after some time. Coding+Unit Testing: In case of unit Testing I am no...
I'm currently setting up a MongoDB database for a web-app. I'm running node.js and using Mongoose to help manage mapping, validation ect. I'm wondering if it's a good idea to really decouple MongoDB from my code, just on the off-chance we want to switch to something like CouchDB a little later. Specifically, I'd make ...
For my job we have a nice RESTful webservice we've built out that we use to drive a couple websites we have. Basically the webservice lets you create and work with support tickets, and the website is responsible for the front end. Any webservice requests use an auth header which we use to validate the user and their ...
What does "(say)" mean in this Java method? Since Mapper and Reducer are separate classes, the type parameters have different scopes, and the actual type argument of KEYIN (say) in the Mapper may be different from the type of the type parameter of the same name (KEYIN) in the Reducer. For instance, in the maximum tem...
I have the following field in Flex: [Bindable] public var zIndex:uint; And I was trying to create the methods to process the calls in Java and I ran into a problem. 1. public int getZIndex(); // Does not work. 2. public int getzIndex(); // Works. I thought that the letter following the get/set was supposed to be capi...
I'm trying to test this wrapper to request that I made: // lib/http-client.js var app = require('app'), request = require('request'); exports.search = function(searchTerm, next) { var options = { url: 'https://api.datamarket.azure.com/Bing/Search/Web', qs: { 'Query': '\'' + searchTerm + '\'', ...
On my web page, if I wish to display dynamic dropdowns (e.g city names based on country selected), I can do it using AJAX. But I can also do it using a REST call. So which should I use? My problem is I really don't get the difference between REST and any other HTTP browser request.(a.k.a a form submit). I have looked a...
I'm making a facebook app and I'm trying to follow MVC properly. But I was wondering if I had a class that was a bunch of fql queries (getting data from facebook) should I have keep these in a controller or a model? According to Codeigniter's user guide "Models are PHP classes that are designed to work with information...
In my org, we use SVN for version control So for each build (done periodically), we merge the code to trunk from the development branch (all the developers checks in to this branch). So when we want a new branch say for a new release, we create from the trunk doing a svn copy. Now in the new branch we have the histor...