instruction
stringlengths
34
19.9k
Now that I've gotten into a dependency injection groove, I find main methods for different applications all look basically the same. This is similar to stuff you might find on the Guice documentation, but I'll put an example here: public class MyApp { public static void main(String... args) { Injector inj =...
I need to update a software framework once it has been deployed. The framework we are creating is made up of .NET 4.0 libraries (in Visual Studio). This common set of code libraries will be available for 2 .NET Windows services, a standalone .NET application, and a .NET MVC 4 website. (The services will run on a singl...
Does an in-code enumeration provide a stronger domain model than a static database table? As an example, say I have an Marble entity, with a Color attribute. The color attribute has a finite set of possible values—say red, green, blue. Say the database team recommends having a static S_ValidColors table, to the effect ...
I found this question at codility.com, but I don't understand the question. Can you help me figure out what do they want? I am more interested in the theory than a code. A non-empty zero-indexed array A consisting of N integers is given. A prefix_suffix_set is a pair of indices (P, S) such that 0 ≤ P, S < N and such th...
In C and C++, the main method holds the filename in the first position of the array at argv[0]. In Java, however, the filename is not included in the args string array. Is there a practical reason for this? I understand that this makes iterating through command line arguments 0-based instead of 1-based, but is there a ...
We have a closed-source commercial C++ application. Some of our logged error messages are in plain English like "ERROR: could not read file 'foo'". While others use a macro to print filename/line information like ""SplineReticulator.cpp(423): out of bounds". This is not an assert or a crash, the application recovers fi...
There are lots of projects released under more than one license. One example is Mozilla's tri-license, which states that the Software is released under the MPL, but the user can also choose GPL or LGPL instead of MPL (I think this is because the MPL license is incompatible with the GPL license). However, I came across ...
I've been working on some MSTest automated test infrastructure, that is testing a tool that merges data sets into SQL Server database tables. The basic structure of the test is to: Define the incoming dataset using anonymous types Apply the data using the reconcile tool Read records from the output tables Compare res...
I am building a software and trying to learn the typical steps for software life cycle, I am not sure if what I did is correct or enough so I would like to ask for the typical steps you follow during your life cycle in terms of actual steps taken for example requirement gathering is a not the step i mean, but gathering...
Given a class that implements an interface, but does not need all of the methods implemented, what is the best practice for unit testing this class with respect to code coverage? - or is it considered a sign for a code smell? To make the problem more concrete, consider a Java class (the question is not limited to Java ...
I am using state pattern on 28 states in my application. The states are for membership cards that has 7 major states, there are 4 boolean attributes for the membership card that actually affects the its behavior so I have decided to embed them with states, that's how it multiplied to 28 states. The problem now is with ...
Procedural code gets information then makes decisions. Object-oriented code tells objects to do things. — Alec Sharp So, when a view wants to display some information that is suppose to be derived from properties of a model it is displaying, should the calculation be part of the model or the view? Ideally the view ...
I am about to start User story sessions in my team. It's quite new for them and I am also wrestling with certain things. For the current project we have some well worked out wireframes. I read a lot about the way of writing user stories. What the template should be like and about different aids like Invest The plan is ...
I don't understand why a static method can't use non-static data. Can anybody explain what the problems are and why we can't do it?
I'm trying to figure out why going to 64 bit processors is such a big deal in an iPhone. I understand that there will be twice as many registers so the processor can work with twice as much data which should increase performance. However I don't see many phones going to more than 4GB of memory any time soon. It seems ...
The R&D team I'm in has decided to adopt a coding standard. We have only recently formed, and have too little code and common coding time of our own to base our standards/conventions document on what has developed organically in our team, and on good examples from our own code etc. Now, every one of us has some experie...
I have been working on a library which contains a large set of functions. For the sake of simplicity, I am going to use just one set as an example. I am not sure which is the better way, in terms of ease of use and performance, whether I should put those methods provided as individual methods, prepended with the functi...
I have been playing with Scrum methodology since year and half. I am using VersionOne as scrum tool. I have tried to follow most of the scrum principles. Sometimes, I feel like there is an issue with transparency of the stories. As of now, the whole team can get an access to all stories defined for the project. This cr...
I've had interviews with 5 separate people over the past two weeks and three of those five have all asked me this question: Explain what happens between hitting "Google.com" and the page coming up on the screen. Basically, how the Internet works. I figure after three times that I better be prepared if I ever get thi...
When discussing APIs between systems (on the business level) there are often two different point of views in our team: some people prefer a more - lets say - generic abstract approach, other a straight forward "concrete" approach. Example: the design of a simple "person search" API. the concrete version would be searc...
My team is writing a compiler for a domain-specific language (DSL) which will be integrated into an IDE. Right now, we are focused on the analysis phase of the compiler. We are not using any existing parser-generators (such as ANTLR) because we need real-time performance and highly detailed error/warning/message inform...
I was just wondering if there is some better way how to handle system "static" configuration data. Let say you have a system which offers several operation which are in code translated to operation code but you need to keep other related information to that operation like description, priority etc. Nasty way I have see...
I am working on a project that has two interface (web and desktop), they are not performing the same tasks but they use the same BLL and DAL, the web part using 100% of the BLL and DAL, while the desktop only needs to know about 20% of the BLL and DAL. Do you think it is a good idea to let the desktop use the same BLL ...
I'm about to create a new open-source project and I'm not sure about the licensing method I should choose. Here is what I know: The project will be built on the basis of an already existing open source. I will fork from the original project and will build a community around a new project that has a code base from the ...
Let's say I have a namespace my and this namespace contains a class foo. What should I prefer nesting typedefs into my class or hold it in my namespace? namespace my { class foo { // some stuff // nested one typedef bar my_foo_bar; }; // or namespaced one typedef bar my_foo_bar; } Looking at the std-libs ...
Intrigued by Flow Based Programming a la J Paul Morrison. I wonder if one can implement FBP in Excel/VBA. I searched quite a bit for a Basic-Lang FBP implementation to no avail. I've looked at some FBP implementation details in Python but I'm not grokking it. VBA is what I'm most familiar with, but I'm suspicious that...
I am constructing a program that does several things. Listens to a port. Every second a string is received When new data is received, it has to be logged. No errors or skipped entries are allowed When data is received, a plot on the screen has to be updated. This is an expensive computation. Missing some updates is n...
Problem: I'm asked to prepare a document where all our DB tables are listed and I'm supposed to list all Controllers that uses these DB tables for read and another list for Controllers that do write operations. Ex: +------------------------------------------+------------+ | DB table ...
First, there are many similar questions here, but I found none with direct answers about this specific scenario. If you find a duplicate, please be kind enough to link to the specific answer(s). Also, to avoid question being too broad, consider this specific scenario only. Assume a proprietary Linux application, which ...
I just started writing some new class and it occurred to me that I was adding a lot of method arguments that are not strictly needed. This is following a habit to avoid having state in classes that is specific to some method call, rather than being general configuration or dependencies of the class. Doing so means that...
CPython implementation detail: In CPython, due to the Global Interpreter Lock, only one thread can execute Python code at once (even though certain performance-oriented libraries might overcome this limitation). If you want your application to make better use of the computational resources of multi-core machin...
I feel uncomfortable when using query string parameters as: http://xyz.com/default.aspx?carId=1129&country=uk&uniqueId=98745DVF4563VVf1259 I would rather use something that should not make sense to anyone who is trying to make some sense from the URL: ?a=1129&b=uk&c=98745DVF4563VVf1259 (after all this query sting info ...
How can I check if an Android application running on a not rooted device is "secure" without knowing its source? I would look for: Plain text in Web-Requests (wireshark and emulator) SQL-injection (in EditTexts...) Doing stuff, that isn't always expected (i.e. fast clicking to check for race conditions) Question: Wh...
Is there some sort of standard regarding HTTP API responses? After reading this discourse thread I started to wonder. We are developing our public HTTP JSON API at my work, and we do not return anything when it's not strictly needed (for example a PUT to /resource/{id} only returns 200 when OK or the corresponding 4XX...
I am trying to learn how to do events in C#, and according to the MSDN Events tutorial, Events are declared using delegates. If you have not yet studied the Delegates Tutorial, you should do so before continuing so now I'm trying to understand Delegates first, and failing horribly. What are they for? What problem ar...
I've been reading about law of Demeter and I would like to know how to solve this traversing model properties problem that I see a lot on Objective-C. I know that there is a similar question but in this case I'm not calling a method from the last property that do some calculations, instead, I'm just setting values (Ok,...
I haven't found much on this, but what I did find doesn't explain it well enough (at least for me). What makes the application I make portable? Or what defines a portable application? Is there a specific difference that makes an app portable or not? I always thought if I just made an executable file and some images...
I have built this CMS that has the option to add entries to the database. Each entry that is created has about 5 to 10 new images showing the product for sale. Each image is about 150Kb in size. I already know that images should always be stored in Git however my problem is that the sales team users that add new entri...
We have employees with competencies: Pete Welder Carpenter Melissa Carpenter Assume they both work 40 hours/week, and have not yet been assigned work. We need to report the availability of these competencies, expressed in hours. As far as I can see now, we can report this in two ways: Method A. ...
The this keyword is primarily used in three situations. The first and most common is in setter methods to disambiguate variable references. The second is when there is a need to pass the current class instance as an argument to a method of another object. The third is as a way to call alternate constructors from wit...
I came across the concept of web development bootcamps, these 9-10 week intensive crash courses claim to teach beginners web development and help them get 80k starting salary jobs. Many of you might have heard of these. Is what the bootcamps promise feasible? Is it possible for web technologies like Ruby on Rails, HTML...
I have a class that represents a file in specific binary format on disk (the parent in the title) and another class that represents an object inside that file (child). When the object changes, it sometimes needs to relocate to a new position in the file and the file class has to be notified about this new position. To ...
I recently stumbled upon Microsoft's framework for code contracts. I read a bit of documentation and found myself constantly asking: "Why would I ever want to do this, as it does not and often cannot perform a static analysis." Now, I have a kind of defensive programming style already, with guarding exceptions like thi...
I use yii framework that implements Active Record pattern as ORM base. It has CActiveRecord class that is a table wrapper class with attributes reflecting table columns. So each object of this class represents a database row. Wiki says about Active Record pattern: Active record is an approach to accessing data in a da...
.NET defines the InvalidOperationException as The exception that is thrown when a method call is invalid for the object's current state. In an optimal software design, would it ever make sense to throw this exception? I would argue that the 'optimal' API prevents any misuse, including, never allowing a method to be...
I am writing some software that (for once - usually I open source stuff on sourceforge/github/etc.) I plan on selling. To each source file, I want to attach a proprietary software license that doesn't allow anyone to use, modify, derive, etc. the software (and source code) without my express permission. I have been loo...
I have been asked to automate the operation of a Windows (WinForms) application, performing some fairly complicated statistical analysis along the way. My first thought was the usual suspects: .NET, C# and White or AutoItX. Then it occured to me that I could try an alternative stack: SBCL, CFFI, and AutoItX. That way,...
What do you think until what point should a programmer refactor the code? Basically having def method do_something end Pieces of code would be handy, but they increase spaghetti code until the point where you have to remember the path of more than 8-10 methods. So wouldn't be easier to have no more than 3 methods ...
In computer science, what is the abstract common name of types and values (I mean an abstract "something" that can be a type or a value) ? To be more specific: If we have template <typename X> or template <int X> what is the abstract name of X?
Suppose a piece of software is distributed under some permissive license, e.g. BSD. Now, I modify this software and want to distribute my derivative work. My questions: Who is the owner of the derivative? Is it the original author, the new author or there is joint ownership? Is a copyright notice (say under the origin...
This is a followup question to this other question. Background Working from the MSDN Delegates Tutorial (C#), I see the following: Note that once a delegate is created, the method it is associated with never changes — delegate objects are immutable. And then, in the code sample, I see this (Spread out a little throu...
I played with 8-bit machines (C64), I used 16-bit machines (Win 3.1), I enjoyed flat 32-bit address space (Linux). Every time as a user (which was also means being a developer for fun or profit) I felt the need for more bits and welcomed the next wider bit architecture. Accessing to bigger memory space got easier, grap...
I started a discussion on StackOverflow earlier this week about one of my work project and how to lead it correctly. But it seems that this stack is a more appropriate place to ask those sort of questions, so here is my last question about my project: How do you value your work? / How do you rate it in a financial way?...
I read a lot about auto-incremental id (guid, interlocked.increment, ObjectIdGenerator...) but don't find nothing for my situation. In my domain model user ask to have an automatic progressive numeric Id for each Activity they create. Since it's a user request I want to put it in my domain model, but the mode I usually...
So we present a straightforward coding exercise to new candidates with some well defined requirements. Occasionally we receive solutions which don't really solve the problem at hand, but are over-engineered to solve a perceived problem - often outside the bounds of the exercise. Now my question is, is this a warning si...
I have a typical MVC based website, and I'd like to give some registered users the abillity to extract data from the database (in a variety of formats). The workflow is very simple: User logs in, User clicks export, A file is generated, User downloads the file. I'm trying to figure out a way to secure the last step a...
Scenario A clustered environment running N identical application nodes interacting with a single relational database. Problem Is it possible to upgrade the nodes to a new application version, which requires a new database schema and maintain data integrity in the database without any downtime in the application and wit...
I am working on a warehouse management system (WMS) that needs to support having stock in multiple locations. Could be in a different building, could be stored in n* places in a building (quick example would be stock, overflow, or fast moving slots all containing a qty of the same item). Where I am, they have always us...
I'm in the design stages of a program that based upon input received, would select a particular category, and action within that category. The category, the action within in, and the value(s) related to that action are all immutable values, along with the relationship between category and action. Normally I'd just assi...
THE QUESTION: There is an event where there are N contestants. There are three tasks in the event: A,B,C (say). Each participant takes part in the events in the listed order: i.e a contestant must first complete A and B before beginning C. However, in event A only one person can participate at a time. Any number of peo...
For example, say I want to fetch a User and all of his phone numbers and email addresses. The phone numbers and emails are stored in separate tables, One user to many phones/emails. I can do this quite easily: SELECT * FROM users user LEFT JOIN emails email ON email.user_id=user.id LEFT JOIN phones phone ON ph...
Several years ago, Microsoft announced that Ruby and Python were coming to .net. The projects were called IronRuby and IronPython, respectively. Microsoft said that the projects would be built on top of the .net DLR. WIKIpedia indicates that for all intents and purposes, these projects have been abandoned by Microsof...
Recently my team has programmed a custom developer console in a video game which can easily be hidden or displayed, because it's more comfortable and less of a hassle. The Console class contains a log(string) function which should be easily accessible from anywhere outside of it, without having to reference it everywhe...
I have had some experience in documenting the design for project developed in OOP languages. I made classes and used class diagrams to showcase the overall design structure of the implementation when I used OOP languages. Problem : I am about to begin a project in C language. How am I supposed to go about writing the d...
This is related to "Extends is evil" vs. OCP? but separate because the idea of "implement the interface" doesn't exist in Python. I'm writing a class to pull some data off a webpage. It's going to need to hold on to a cookie for authentication, so I'm going to use a requests.Session object in some form. I'm never sure ...
There are some guidelines out there (eg scala guidelines) and I'm wondering if it's okay to do some tidying up when committing other changes or if the commits should be more focused and to the point? Eg - remove unused, reorder per style guide. It might make it harder to read the pull request - but it will improve the ...
I've reached a point in my career where I want to consider myself less "an {x} engineer" where {x} is a specific programming language, and I want to be more of a language-agnostic software engineer. The obvious next step is to start learning as many languages as possible to build experience, but there's only so many ho...
I'm thinking of working with some other people on a c++ or java project. Usually for small projects, we collaborate mostly through emailing source code files back and forth, but on a larger scale, it becomes too easy for things to go wrong. I read up on version control systems such as git and it seems to fit my needs ...
There is a point in time where you make design choices and debate them with management. In my case I have to debate my positions and design choices with senior management but it is frustrating that management only strives for performance while I think stability is a must while performance can be achieved later. E.g. W...
I'm creating a program (in C++) that will password protects its user's database (.dat) file. I'm confused on where to store the password? In the user's database file or somewhere else. I'm new to this concept. I don't know where a program should store the hashed password. I've been thinking for this from a long time. I...
I'm working with a fairly complex web application. It's split up into the following layers: Presentation - HTML Service layer - A REST and SOAP API communicating with the business layer Business layer - Contains the business logic. Data access - Provides access to the storage (SQL etc) The business layers contains cl...
Assume that I'm a front-end developer (HTML, CSS) And some one who got their website built using ASP.NET came to me and asked for a new design and I don't know about ASP.NET. Then, how can I change the design of their website without affecting their code? Do I have to learn a little bit of server side languages to be a...
Say I have a method that inserts a record into the database. I don't need to know the newly-inserted ID or anything else. I have two options: public void Insert() public string Insert() In the first: if an insert is successful, the calling code will continue. If it fails, an exception with the details will be returne...
I have developed an application where you should be able to browse products catalog(READ ONLY) even network access is down no wifi or 3g/lte etc. Clients(windows,ios,android etc) consume the rest api. So far There is a REST api that grabs parts like categories with products and other api call to get preferences etc. T...
I have an API that returns a JSON formatted array of users within a given pair of lat/ long bounds. I'm using this data to plot a number of markers on a map, based on the location of each user. I also want to render a HTML list on each client request so that I can show the list of plotted users alongside the map. What ...
I am new to Branching and Merging but I have been tasked with making future development on an application possible while still allowing bug fixes to production. Usually I am the only developer on the application unless I am on leave. I have watched a Pluralsight video on Branching and done some forum/stack reading. I w...
I'm designing a function that given a UTC timestamp will convert it to the local time. The question I have, should the current times DST settings be applied to the conversion, or the timestamps DST settings? If going with the former, current DST setting applied to timestamp - it would mean 4pm that was recorded with DS...
We maintain a web application for a client who demands that new features be added at a breakneck pace. We've done our best to keep up with their demands, and as a result the code base has grown exponentially. There are now so many modules, subsystems, controllers, class libraries, unit tests, APIs, etc. that it's start...
My module has no dependency on its own but for running tests you need to install jasmine-node module. Should I include that module as a dependency?
It says in the book (APress Ganesh / Sharma) about Java 7: You create a method named fill() in the Utilities class with this declaration: public static <T> void fill(List<T> list, T val) You declare the generic type parameter T in this method. After the qualifiers public and static, you put <T> and then followed...
Question For those of you working with html/javascript/css "thick clients", specifically those that work against some client-independent server API, how do you manage your deployment environment configuration? Do you manage the configuration at build time with per-environment release builds (e.g. QA, STAGE, etc) or do ...
There are two types of color mixing: Additive and Subtractive. http://en.wikipedia.org/wiki/Color_mixing Is is possible that color mixing model be done in XOR?
I have been considering the following situation as part of documenting and interface (A) and an implementation (B) of that interface. The interface A contains methods which involve the following two arguments: A percentage, passed as an integer. A name, passed as a string. The valid values for the percentage are the ...
Probably few of you are interviewing wannabe programmers. I'm 28, never worked as a programmer, but spent few months learning C and solving problems. I loved it so much that I do it every day just because I can, now and started studying CS at local university. Now I'd like to try make living from it and am trying some...
I always appreciated the Java language. It is known as a very secure platform and many banks use it in their web applications. I wanted to build a project for my school and I discussed the options with some developers. However, one of them said we should ignore Java ecause of vulnerabilities appreared recently in it. ...
I'm designing an instant messaging server as a personal exercise to improve my understanding and application of multi-threading and design patterns in Java. I'm still designing, there's no code yet. My goal is to have a server that should make effective use of a multi-CPU box. I'd like the server to be distributable ac...
The web platform is hip these days. But the web platform consists of many parts that are conceptually separable, developed at different times and paces, and (most important to me) could be useful on their own. Basically the web platform is "a browser", but the browser lumps together several things: HTML/CSS renderer...
This is a question I've to-and-fro'd with for a while, and searched for and found nothing on: what're the accepted practices surrounding duplicating domain models in Javascript for a web application, when using a framework like Backbone or Knockout? Given a web application of a non-trivial size with a set of domain mod...
I have been thinking of a couple of possible extensions to the C language which I'd like to know the opinion of others about.1 This one is about multi-dimensional arrays. Imagine the following situation in C: void matrix_mul(double **res, double **a, double **b, size_t n, size_t m, size_t r); You cannot pass a double ...
I'm currently planning the database structure of a used car's advertisements site. Each advert contains information about a vehicle, and a vehicle can be advertised multiple times over its lifespan (granted, quite unlikely). I'm unsure which approach to take - a single table, or two separate relational tables, each has...
I know about Simple Factory Idiom, Factory Method and Abstract Factory Design patterns. But I have two situations that I'm not sure how to call (PHP code example) : class User { public static function LoadUserById($id) { $objUser = new User(); //load details from DB return $objUser; } } class UserFacto...
When creating a table, there is an option for us to set the numeric primary key as autoincrement where its value increases whenever a new data in inserted. This primary number can be used for setting the relationship of a table where it is assigned as a foreign key to that table. So my question is it a good practice f...
Is it good idea to require to commit only working code? This commit doesn't need to leave the repository in a working state as: ... we are in early design stages, the code is not yet stable. ... you are the sole developer on the project. You know why things aren't working. Furthermore, you are not stopping anyone's...
So I have this problem: in order to structure my code hierarchically, for every new tiny thing, I create a separate sub-folder, file, class ... and in it one 10-line function. It is an anti-pattern. Lately I have been trying to err on the opposite side. That is, when I need something new, instead of dreaming up grand h...
Recently I came across a moderately large python codebase with lots of MyClassAbstractFactory, MyClassManager, MyClassProxy, MyClassAdapter etc. classes. While on the one hand those names pointed me to research and learn the corresponding patterns, they were not very descriptive of what the class does. Also, they seem ...
I need to make a "SELECT * FROM" Sql from PHP, that now returns about 10.000 records, that I insert in an Array and re-utilize in a page to show results in a table. I need to have all that elements also in a hidden input fields, to connect via API to a SMS service to send SMS <input type="hidden" id="destinatariSMS" na...
I have been reading the Wikipedia article on double check locking and one thing that's not clear from it (at least to me) is what the pattern achieves. What is the reason for making the two checks below? Why not have triple checked locking? Wouldn't that be even better? if (mySingleton == null) { // 1st check ...
Planning my architecture for an MVVM application I come to this: MyApp.UI View MyApp.BusinessLayer ViewModel MyApp.DataAccessLayer RepositoryImplEF MyApp.DomainLayer DomainObject RepositoryInterface MyApp.Common Logging Security Utility (contains some reflection method used by many levels) CustomException My...
For my simple MUD client I'm using Apache Telnet (no, not ssh). A mud client is a strange beast: Generally, a MUD client is a very basic telnet client that lacks VT100 terminal emulation and the capability to perform telnet negotiations. ... Standard features seen in most MUD clients include ANSI color su...
This question focuses on user documentation, not on code documentation. I just finished my software project, and the people I work for are expecting me to write user documentation, describing everything the software does. All the documentation they had until now (about the rest of the software they use) is full of scre...