instruction
stringlengths
34
19.9k
Ruby normally makes things easy. However, it doesn't allow implicitely converting a number to a string: 2.0.0p247 :010 > "a"+1 TypeError: no implicit conversion of Fixnum into String Why is this when nearly every other language allows it, including Perl, PHP, Java and VBA?
I'm comparing 2 different approaches of J2EE application architecture: Divide independent parts as modules of one big web app. Divide independent parts as different web apps running on same server. Between these approaches I prefer the second one because it allows me to make changes without redeploying the whole appl...
I'm developing a push-notifications system for my ASP.NET MVC app. The idea is to use Redis for queueing, ServiceStack for queue processing and SignalR for push-notifications to implement a system that's able to distribute different types of notifications. I've put together a quick prototype where I have a ServiceStack...
When I set a variable to an object in VBA / VBScript, I always need to prefix the statement with "Set" such as: Set Dict = CreateObject("Scripting.Dictionary") If I set a variable to a primitive or array value, I have to omit the "Set" such as: Num = 123 This is different from languages such as JavaScript, PHP, Python ...
So, for the first big project that I'm getting paid for, I decided I'd do things right. To that end, I've created several projects in my Solution. Some of these projects are generic and handle common elements that can be used in any project (stuff like logging and such), but that's not where the focus of my question is...
I wasn't sure how to formulate the title, but there's something that's made little sense to me in OOP I understand the idea of encapsulation, which is to create a layer of protection, and abstraction, so that there's no direct access to a given variable. However, there are cases where encapsulation doesn't make any sen...
I'm facing a very real problem and, sadly, I cannot find the answer on my own: I'm hitting my limit as a programmer because my hardware knowledge is not sufficiently advanced at all. It's an issue I'm encountering during the development of the system (I need to find safe parameters value which depends on the answer to ...
I'm using an offline application's javascript API and I'd like to know if I can use deferred objects to handle the callbacks. The API calls do not use HTTP, the calls are to and from the applications local database. The only way I've been able to display information is by using 'setTimeout' on subsequent calls, which I...
We have a database that stores the process/history of particular machines. What I mean by that is that we have "started", "updating", "shutdown", and so on for all the computers in the company. The requirement is to have the history available in the right order. Simple enough. My approach was to have a simple database ...
I understand that for normal websites you'd want to share scripts and css and therefore liking to them means that each page shares them from the cache. But this question is not about "normal multipage websites", it's about WebApps. Pages where only one page is ever served. Examples include gmail, new google maps, faceb...
Here's a programming/language problem I'd like to hear your thoughts on. We have developed conventions that most programmers (should) follow that aren't a part of the languages syntax but serve to make code more readable. These are of course always a matter of debate but there's at least some core concepts that most pr...
I'm currently working on a project that the client wants to deliver to different countries. The application is a website. We started out using resource files to change the text the user sees when visiting pages based on their locations. But this isn't enough. In the English version of the site we have a page that state...
I am attempting to learn more about C and it's descendants(C++ mainly). I have decided that I would like to create a "file system" of sorts. Not a particularly advanced one mind you but something to play with. I have no intentions of making it mountable, securable or even recoverable. At the moment I am stuck in con...
I am constructing a UML 2.0 activity diagram. The activity is to evaluate data from a usability study of a prototype. It can optionally end with just getting the user satisfaction results. But if the company wants to choose which features to implement in the final version, which ones to change and which ones to leave o...
I have a series of hardware devices that I'm connecting to create paths through. I have some sanity checking to make sure if potential paths are valid and will do what is intended, but to do it properly I need to know what device is the source of the path, and other information from that soruce. Once everything is set...
These days it's possible to hash a file client-side, send the hash to the server, and have the server check whether or not that file is already uploaded. If it is, we can skip the file upload and make it appear to upload almost instantly to the user. This can also save have oodles of bandwidth for a large site. This ha...
I am currently writing an application that isn't huge but will be used through-out my company of 200+ people and external customers about projects we are working on (not software projects), but there are a fair amount of business rules, along with the implied ones that go with creating, verifying, and maintaining user ...
I understand and enjoy the benefits of the Garbage Collection in Java. However I don't understand why there is no way in Java to explicitly (and quickly) destroy an object. Surely this could be useful in some cases, I assume performance-critical software. It's true that in Java the GC will delete an object with no exis...
I think voice recognition is cool, and I might start studying it soon, but one big question that I've always wondered about is "How do the programmers separate the noise from the voice?" I mean, if you've watched "Her", you'll notice the main character uses voice commands commonly in quiet places, but today, voice reco...
I am interested in finding out who introduced code indentation, as well as when and where it was introduced. It seems so critical to code comprehension, but it was not universal. Most Fortran and Basic code was (is?) unindented, and the same goes for Cobol. I am pretty sure I have even seen old Lisp code written as con...
Just to get this out of the way, I have seen this, and it is not what I'm looking for. So, let's say you are programming a Rubik's Cube. (I know, very unoriginal, but bored programmers have to do something..) This Rubik's Cube is defined by an array of six 2-D arrays (one for each face,) and these 2-D arrays' sizes var...
In my team we have a multiple projects, some short term and some long term. The team is required to deliver these projects on different dates and the effort to deliver these is run in parallel with the team working on stories for more than one project during each sprint. When trying to compute our burndown we aren't su...
Context: I am making a learning project in XNA. What I would like to be able to do is allow the game to be moddable by allowing the users to place arbitrary values into a JSON data file which is read into the game. The thing is that I want to avoid hardcoding if possible and have it automagically work for whatever the ...
I have recently joined a startup as CTO/co-founder. The startup and I have been thinking about moving the existing codebase (which is in PHP5.5, laravel framework) to node.js . Main reason for this being that at the stage we are in right now, I'll need to hire talented, but inexperienced developers and train them to wo...
Context I have Specification class with several properties including: StartDate, EndDate, DaysToComplete, DateToComplete. A specification contains a list of required courses (i.e. a company requires employees to take training... perhaps a technical, diversity, or an ethics class). Based on a specification, courses will...
We're currently upgrading some components of our application to new technologies such as C# using WPF and MVVM. Since we try to avoid past mistakes that have been made in our now legacy applications, a question came up in our team how we should ship external resources that are likely to change, such as icons or images....
So I have my application consisting of a number of modules in a module hierarchy. Furthermore let's also assume each module is a class and we have a tree of classes where the classes at the top are using the classes below, to make it more simple. A class A1 at the very bottom may depend on some input parameters. class ...
I have a 3-layered app structured as follows. Presentation Layer (ASP.NET MVC project) Business Logic Layer (Services for controllers in PL) Data Access Layer (Repositories) Each Controller in PL interacts with its service in BLL, which in turn has access to Repositories in DAL. Is it a good practice to do a "global"...
I learned at school as well as I read everywhere else that a good development methodology needs conception and design before coding properly. That is not a new information even for a beginner programmer. However, I wonder if this a good advice because since I started developing in several programming languages I never ...
While studying the features of XML, I got to know that XML is software and hardware independent. Can anyone explain me why it is meant like that?
I'm a programmer and I'm looking to play around with translating one language to another. Say C# to Lua. I'm curious as to how translating languages like that works? I would think there is some kind of standard methodology that I could perhaps look into for this or is it pretty raw?
"Code review" (aka "peer review") seems like a really great idea, so my team started practicing it. For a little while it worked well, but then a co-worker merged a branch in, and asked for a review of the code. When I went to review her code, the Github diff page was about 420k pixels in height. Given that my screen...
I code in Python and I'm starting to use the Mock library. Although I've read through all of the documentation, something that I'm finding hard to understand is 'What makes a good mock'. For example, say I've got a function that makes a HTTP request: def fetch_url(url, method=urlfetch.GET, data=''): """Send a HTTP ...
My team has all agreed that writing a company development blog is a good idea. There are a lot of documented benefits to blogging, both for the individuals and the company. However, while everyone agrees that a blog is a good idea in theory, no one seems to want to actually sit down and write an entry. Between having a...
(Building on this question) If you have a static code analyser such as Checkstyle, is it possible to to relate any of the stuff that it checks for to actual robustness? Some of the things that Checkstyle checks for are e.g.: Class design: Visibility of class members, enforcing public only static final members, no pub...
Lately I started studying about different interesting concepts that exist in languages other than Java. Since the only language I've ever programmed with is Java, a lot of these concepts are very new to me. So this question may be very naive :) . I learned recently about first class functions and function pointers. Why...
I have been away from computers for about 3 years and starting to get back into programming. Lots has changed in resources and help sites available on the web especially the evolving StackExchange community. I come from the IRC #javascript, #html, #php days with php.net and a bit of google search finds here and there. ...
Coming from Java, I've never used a language with dynamic typing. I'm very used to the static-typing way of thinking. My question is, how much does the use of dynamic typing as opposed to static typing influence the overall design of programs written using languages with that kind of typing? Does the kind of typing (st...
I will immediately confess that I do very little multithreading, so questions of style and organization in this domain a little fresh to me. I've written a data structure (in Python, if that matters) which implements a special kind of a queue. I'd like to use this queue to pass messages between threads. Currently, the ...
Let's say we're writing a simple JSON parser and we've fully covered the code with unit tests: it can parse primitives "0", "123", "-456", '""', '"asd"', true, false it can parse arrays "[]", "[1, 2, 3]" it can parse nested arrays "[[]]" it can parse objects "{}", '{ "a": 1, "b": 2 }' it can parse nested objects '{ "a...
Why the c# allows project not to be strongly signed when they are build? They may be signed by some automatic name file if programmer do not choose his(hers) own sign file. Where is the advantage of not signed .dll file? What the strong names are? I am working on project which uses C# .dll files in Microsoft Dynamics A...
Sometimes while I'm editing something I see some useless code added by other developers, probably due to habit. Editing this code will not make any difference, so is it appropriate? In my specific case I'm talking about Java private fields like this: private int aSimpleInt = 0; private boolean myBool = false; private M...
I'm designing an object dependency graph of my program and one ambiguity between design variants appears from time to time. Imagine two objects having a reference to each other. Obviously, at least one reference should be assigned after object's initialization (for example, through a subscription method) and another on...
I have dataset that is contain 150 data that is actually divided into 3 group. Each group has it’s own label. I do clustering process with K-means algorithm to group the data. I need to assign the label of each group that is created by K-means process. So I could compare the result of K-means with the data training. An...
Setup Many years ago I took to a style of unit testing that I have come to like a lot. In short, it uses a base class to separate out the Arrangement, Action and Assertion of the test into separate method calls. You do this by defining method calls in [Setup]/[TestInitialize] that will be called before each test run. ...
I check Open Source Compliance for commercial code. I have recently found a few examples where the commercial source is matched against quite a few OSS projects. The matches are very similar, but not exact, say about 30 lines of code with about 4 methods, a few variables names differ, some extra lines in the commercia...
Recently, I started reading the book Specification by Example, which relates to automated functional testing and BDD (from what I've understood till now). I've tried using Concordion (.Net), and seems very interesting. I've been having issues with keeping any form of useful documentation for any designed system, and t...
I have a resource that can be represented in one of two ways: Big Serial Number, or Small Serial Number Is it closer adherence to REST principles to: A: have a query string specify the type (https://acme.org/api/widget/aaa-111-aaa?type=big vs https://acme.org/api/widget/aaa?type=small), or B: have query strings spec...
I write many a PowerShell script for the organization I currently work for. Most recently I have been co-writing a tool that, in the end, will have a lot of functionality (beyond a single purpose), will be configurable, and will have both a CLI and GUI, all in PowerShell. So when does a script stop being a script and w...
I have a project that requires a client app to communicate with a server. I was wondering if there is a way for the client app to detect available servers and "know" by some method or another which server is the one it needs. The client is built with .net and c#, the server is a simple SQL database.They are on the same...
It seems to be a very common thing to have to tell whether some list or set contains at least one object matching a given condition, yet my prior searching and reading have never found a satisfactory best practice or design pattern to speak of. In the situations I am thinking of, merely using "contains" is not suffici...
I primarily work with .Net WPF MVVM applications. I've used several frameworks, MVVM Light, Prism, etc, and I've been able to break the implementation of CRUD MVVM into three scenarios. Scenario 1: A web service returns a paged collection of small objects with no navigation properties, I whirl through these wrapping t...
I'm working on a project that, when all boiled down, is essentially a raffle. The twist is that due to the way we've set the ticket value, a user may be casting 10,000+ tickets. Essentially, a user can chose to cast a certain number of tickets for any given raffle. At the end of a period of time, a winning ticket is ch...
I was just reading this slightly older post on choosing a good source control system when I started thinking about how different projects use source control. Where I work we've essentially moved completely to Git and things have been mostly good. I have wondered about high security projects such as military software pr...
As our team is growing I've noticed that different developers put their class methods in different orders. For instance: var Foo = Backbone.Model.extend({ someVar: {}, initialize: function() {...}, fetch: function() {...}, handleFetchRepsonse: function() {...}, getFoo: function() {...}, ren...
All my projects share the same base library that I have build up over quite some time. It contains utilities and static helper classes to assist them where .NET doesn't exactly offer what I want. Originally all the helpers were written mainly to serve an internal purpose and it has to stay that way, but sometimes they ...
Please consider the following implementation of the Decorator design pattern: WordBank objects store strings and return them to the client through the method getWords(). The decorator class, WordSorter, is a subclass of WordBank (as in the Decorator pattern). However it's implementation of getWords() sorts some of the...
Almost everywhere you can read that you should use EL instead of scriptles in JSP. And I agree that you should not use any JAVA code in JSP except for calling getter methods on model objects. This is quite obvious for me and I don't need any clarification here. But there is this one thing that I really cannot understan...
Lets say you've got a list l = [0, 2..] and you want to get the nth number when n is pretty large, say n=123456789. So you call l !! 123456789. On my machine, this results in out of memory. So why aren't Haskell capable of realizing that the number at index n is 2n, and making a call such as l !! 1230981237 trivial?...
I'm new to NoSQL and have been playing around with a personal project on the MEAN stack (Mongo ExpressJs AngularJs NodeJs). I'm building a document editor of sorts that manages nodes of data. Each document is actually a tree. I have a CRUD api for documents, to create new trees and a CRUD api for nodes in a given docu...
I'm developing a desktop application with a GUI. To do so, I'm using the MVC design pattern for the GUI part. For now the application consists of a single window (view) with one controller interacting with the backend (model). The interaction is becoming more complex day by day with the controller getting more and mor...
I'm currently scratching my head over how to refactor a method that basically only builds the UI. The method is more than 1500 lines of code (LOC) long - and counting. It has grown, there was no plan how to approach this. You might find this familiar. Anyway, it's basically just one large method that goes a little some...
I'm really struggling to find a concrete, easy to grasp, explanation of Atomicity. My understanding thus far is that to ensure an operation is atomic you wrap the critical code in a locker. But that's about as much as I actually understand. Definitions such as the one below make no sense to me at all. An operation dur...
I'm a hobbyist programmer, so no professional experience. People here often talk about doing maintenance of software at work. The author of this question talks about doing 90% maintenance and 10% development at his job. My question is: what is 'software maintenance' anyway? Is it mainly about fixing bugs? If so, does t...
When you want to have continuous delivery any data schemas that you have must support multiple versions of your application at the same time (as you may have multiple version deployed when new versions are rolling out) In my specific case I have entities stored in Azure table storage. When I am making changes to my ent...
A few months ago I started a project, which will have two parts – business client overview panel (AngularJS SPA) and public front-end (dynamic HTML with progressive enchancements via XHR). I'd really like to stop and throw away dynamic HTML and switch to AngularJS + API + static HTML combo (like in "panel") to avoid du...
I am implementing a binary search tree in java. Inside the BST class I have a protected class Node (in case I want to extend to an AVL tree). The code is below. I had a problem, both conceptually and aesthetically, implementing empty nodes as null pointers. So instead I opted for the null object pattern and created an ...
I was wondering why the default select tag of HTML, for example: <select name="company_name"> <option value=""></option> <option value="1">Company 1</option> <option value="2">Company 2</option> <option value="3">Company 3</option> <option value="4">Company 4</option> <option value="5">Company 5...
The problem: Given the coordinates of N people on a regular 2-dimensional plane and N target points-of-interest (POI) on the same plane, determine the set of pairs of people and POIs that minimize the sum of straight-line distances between the locations in each pair. No two people can go to the same POI, and all POIs ...
Let's say you have a string $action run-time, that specifies which type of $object needs to be created: $dbobject, $memcacheobject, $fileobject, $xmlobject, etc. Assume also, that creation of an object is non-trivial and a $factory is required. Obviously, different object types depend on different things, one on PDO, a...
There are many questions about the performance of commands or scripts on the U+L SE asset. As time is of the essence, this is often evaluated using the bash time reserved word or the external time command and a subset of the target data, under average or no load. Yet there are scenarios which are either about a large n...
I have a use case where I need to create say two javascript objects & use their properties in one another. eg - var Object1 = { settings: { property1: 'someValue', property2: 'someValue' } } var Object2 = { foreignProperty: Object1.settings.property1; } I wanted to know if its alright to use a reference ...
I have an open-source project, which I would like to commercially license to various types of businesses. xGPL licenses do not work for me since they don't allow any conditional addenda. What I'm seeking to achieve is: require commercial licensing for businesses allow use and changes under some OSS license for individ...
Please consider a StringBank class. This class holds a list of Strings and can return them to the client. It's code (irrelevant stuff omitted): abstract class StringBank{ List<String> strings; public List<String> getStrings(){ for(String string : strings){ if(!stringValid(string)){ ...
There are a lot frameworks on the market who wrap actual websites into mobileapps. I found myself thinking about the question - why is it needed to create mobileapps if it's possible to just having mobile version of the site?
We have a project that is reaching a deadline for the final production release. It's a fixed price project and up till now we've managed to work in 2 week iterations, doing regular releases to our "inner test environment" where BAs and people acting as POs from the client's side had a chance to have a look, give feedba...
There are several ways to reach the same end point in JS, for example: (function (foo, bar) { return {run: function () {return foo(bar);}}; } (foo, bar)); (function (foo, bar) { return (function(foo, bar) { return {run: function () { return foo(bar); }}} (foo, bar)) } (foo, bar)) (function (foo, bar) { var Fizz...
I am working on large project solo as a hobby, and I made a mistake in the very beginning: I jumped right into programming without giving a second though to design. Now I am nearly 6 months in and things are starting to fall apart: I cant get anything done, the code is very inconsistant, and the whole thing is a mess. ...
I have seen in a couple of projects that developers prefer to keep essential user info in one table (email/login, password hash, screen name) and rest of the non essential user profile in another (creation date, country, etc). By non-essential I mean that this data is needed only occasionally. Obvious benefit is that i...
The below Javadoc is an snippet of HashMap documentation. Why authors would emphasize on putting a lock on the object that encapsulate a HashMap? Lock on the actual HashMap Object makes for sense. Note that this implementation is not synchronized. If multiple threads access a hash map concurrently, and at least one o...
I need to implement SSO for four different domains, say abc.com pqr.com sql.com xyz.com Now, I have already login system for two of my applications using Membership. But now requirement is changed, challenge is to make Single Sign On. Me: Can we have subdomains? client: no !!! Me: Can we have single database and sep...
I have got a legacy Java project with a lot of code. The code uses MVC pattern and is well structured and well written. It also has a lot of unit tests and it is still actively maintained (bug fixing, minor features adding). Therefore I want to preserve the original structure and code style as much as possible. I aim ...
Up until now I don't know the KEY differences between these three. When someone asks me about this, I only tell them that C# is a programming language, HTML and XML are Markup Languages, and JavaScript and VBScript are scripting languages. But what are the key differences that distinguish them from one another?
I am trying to improve the backup situation for my application. I have a Django application and MySQL database. I read an article suggesting backing up the database in Git. On the one hand I like it, as it will keep a copy of the data and the code in sync. But Git is designed for code, not for data. As such it will b...
I want to write a shell script to connect to the remote server and execute a command (any linux command). I am using linux and want to prepare a shell script which can login to the virtual directory server and execute a given command. I.e. if I want to execute the imqcmd command, how can I do this?
I have to replicate a manual generation of a large number of excel files. I started to manually track the relations between cells ( files, formulas, etc). I also had a talk with the person which generates those files. For now I have a general understanding about how the excel files are generated, but "devil is in the d...
So I know that business logic should be placed in the model. But using an ORM it is not as clear where I should place code that handles multiple objects. E.g. let's say we have a Customer model which has a type of either sporty or posh and we wanted to customer.add_bonus() to every posh customer. Where would we do this...
This question is quite general and not related to a specific language, but more to coding best practices. Recently, I've been developing a feature for my app that is requested in many cases with slightly different behaviours. This function send emails , but to different receivers, or with different texts according to t...
If I have a class with only only public method. When I use this class, is it good to use unnamed object to invoke its method? normal: TaxFileParser tax_parser(tax_file_name); auto content = tax_parser.get_content(); or unnamed object version: auto content = TaxFileParser(tax_file_name).get_content(); Because I've tol...
The difference between Composition and Aggregation in UML (and sometimes in programming too) is that with Composition, the lifetime of the objects composing the composite (e.g. an engine and a steering wheel in a car) is dependent on the composite object. While with Aggregation, the lifetime of the objects making up th...
I'm making a command line tool that allows end users to query a statically-schemed database; however, I want users to be able to specify boolean matchers in their query (effectively things like "get rows where (field1=abcd && field2=efgh) || field3=1234"). I did Googling a solution, but I couldn't find anything suitabl...
I have the following extension method: public static IEnumerable<T> Apply<T>( [NotNull] this IEnumerable<T> source, [NotNull] Action<T> action) where T : class { source.CheckArgumentNull("source"); action.CheckArgumentNull("action"); return source.ApplyIterator(ac...
In Java 6 Class<? extends ArrayList<?>> a = ArrayList.class; gives and error, but Class<? extends ArrayList<?>> b = (Class<? extends ArrayList<?>>)ArrayList.class; gives a warning. Why is (a) an error? What is it, that Java needs to do in the assignment, if not the cast shown in (b)? And why isn't ArrayList compatib...
Our client has a MS SQL database that has 1 million customer invoice records in it. Using the database, our client wants its customers to be able to log into a frontend web site and then be able to view, modify and download their company’s invoices. Given the size of the database and the large number of customers who m...
By recently I mean some weeks ago. I am trying to continue a project I left 2 weeks ago and I need time to understand some functions I wrote (not copied from somewhere) and it takes me time. Normally I don't need to because my functions, methods etc. are black boxes but when I need to change something it's really hard....
I am dealing with the following problem and i was looking to write a Pseudo-code for developing an algorithm that can be generic for such a problem. Here is what i have come up with thus far. STEP 1 In this step i try to get the robot where it maybe placed to the top left corner. Turn Left -> If no window or Wall det...
I am looking for hints/ideas for the best (most effective) way on how to scroll multi-line items as well as emphasizing of the "current item" and "selected items" such as: 1 FOO ITEM 1 Foo sub-item 2 Foo sub-item 3 Foo sub-item 2 BAR ITEM 1 Bar sub-item 3 BAZ ITEM 1 Baz sub-item 2 Baz sub-item 4 RAB ITEM...
Please consider this class: class ClassA{ private Thing[] things; // stores data // stuff omitted public Thing[] getThings(){ return things; } } This class exposes the array it uses to store data, to any client code interested. I did this in an app I'm working on. I had a ChordProgression c...
Coming from C++ originally and seeing lots of Java programmers doing the same we brought namespaces to JavaScript. See Google's closure library as an example where they have a main namespace, goog and under that many more namespaces like goog.async, goog.graphics But now, having learned the AMD style of requiring modul...
I'm (very slowly) making a website, and I'm creating a search engine for the database, which is essential to organize the dependencies during data entry. Anyway, what I would like is to type a few keywords into a box, have a menu pop up with various search results, and have the box fill with the ID number of the select...