instruction
stringlengths
34
19.9k
I've recently read The Art of Unit Testing by Roy Osherove which I found very useful for helping me establish how to define a good unit test. One key aspect of the guidelines Roy puts forward are to make sure that one test only tests one thing, which is part of the following guidelines he puts forward: Make sure the t...
I am confused about use case levels. All I could understand was that use cases that are contained in another use case fall under the level which is below the level of the container use case. I have identified the following use cases for an e-commerce store and I would like to know if their levels are correctly determin...
So I took a job where the firm uses SVN (but will be moving to Git sometime in the future). The problem is that I don't know SVN. I've tried numerous Google queries and all I can ever find are SVN->Git tutorials, "Why is Git better than SVN" blogs, and a particular "cheat sheet" that gives (some) comparable commands......
What are my responsibilities, as a developer, if I stumble upon a zero day exploit in a widely used third party piece of software? Should the developer only tell the third party to limit the affect? What if the third party doesn't come clean to all its user base, who else should be alerted? What are the responsibilit...
I'm trying to write a program in c for Huffman coding, but i stack.In input i have: Sample input: 4 //here i scan how many letters i have A 00 // and for everyone i scan how they are coded in string down B 10 C 01 D 11 001010010101001011010101010110011000 //this is an unoptimal huffman code So first i ha...
When writing (parameterized) tests for stateless functions, how do I determine the most ideal set of values to test with? I'm writing a class with mathematical functions in C#, and I want to write unit tests for them. Today I want to write this function (really!): int Clamp(int value, int lowerBound, int upperBound) { ...
I'm about to implement my own very simple programming language, and an interpreter to execute code in that language. The language will be very basic. Example code: var x = 3 if x > 2 print x if x < 2 print "hello" The language wouldn't feature anything more complex than single-line if statements. This is because it's ...
I am about to deploy a new project that will have different components being deployed on different servers and in different web sites/technologies/etc. I was just wondering what would be the best way to communicate this with the business? I want to show that Service X will exist on server Y as a Windows Service and Se...
Our team has recently agreed on some very light coding standards, and that we need a means of enforcing them. We already have a mature Continuous Integration practice including frequent, small check-ins and pre-tested commits. We're considering two methods for implementing an enforcement mechanism: a pre-commit SVN hoo...
We have a large dataset that's current residing in many, many spreadsheets. I've been tasked with getting part of that data into our MySQL DB. When all is said and done, I will probably be inserting somewhere around 3 million rows. I intend to collect the inserts into batches of about a quarter-million or so (parsing t...
Consider the following: if(a == b or c) In most languages, this would need to be written as: if(a == b or a == c) which is slightly cumbersome and repeats information. I know my above sample syntax is slightly clunky, but I am sure there are better ways to convey the idea. Why don't more languages offer it? Is there...
I know that I can share files between Visual Studio projects using linked files and assemblies using project references. Is there a good approach for JavaScripts? I'd rather not use linked files since it doesn't allow projects to have their own version of the script.
Say your company develops software, and a client wants you to handle their development. It just so happens, that they have their own IT-team, but it is fully tied up, so they outsource to you. The project is in a quotation phase, and your client's Head of IT now asks for a requirement specification (SRS), an architectu...
I want to write a simple markup language with its rendering engine. First, I am not completely sure when I should try this... I am only 12... But I am competent in C++ having learned through the Web and books. I am also good with JavaScript, PHP and HTML. I am currently learning Ruby and Haskell for a change. I unde...
Suppose you had the following interface public interface IUserRepository { User GetByID(int userID); } How would you enforce implementers of this interface to throw an exception if a user is not found? I suspect it's not possible to do with code alone, so how would you enforce implementers to implement the intende...
We've been interviewing on and off for about two years, and I've run this by about 30 candidates. I wrote some 20 lines of code which perform a relatively basic operation, but has a bunch of errors in it. None of them are syntax errors. Errors range from bad memory management, incorrect data types, multithreading probl...
I've just finished reading The Art of Unit Testing, by Roy Osherove. It was an interesting book, but I'm having trouble with something he mentions near the end (section 11.2.2): Identifying "roles" in the application and abstracting them under interfaces is an important part of the design process. An abstract class...
Over the past couple weeks I have gotten a lot of help from StackOverflow users on a project, and rather than keep the finished product to myself I wanted to share it unencumbered by licenses, but don't want there to be so much legwork during installation that users shy away from trying it. I am about to post it to Gi...
Is it possible to implement generic routines in any language (C#, Java, etc). By generic routines I mean, in specific event Handlers. Lets say, I have 2 Buttons and 2 text boxes. One Button, when pressed, takes the first text box text and converts to Uppercase and second button prints the length of the string in the ot...
If I add the following in this order into a red-black tree: tree.Put(7) tree.Put(3) tree.Put(1) 7 3 / rotate(3) / \ 3 -----> 1 7 / 1 should I perform a right rotation after the insertion of 1 ? I am reading the algorithms bible but it the pseudoco...
We have a data service app working on object graphs. We place some complex graphs in a (memory) caching tier as a single data item, so as to avoid the length of time to retrieve every individual data item in disk storage in order to build the entire hierarchy. That means whenever any of the data items change, a re-cach...
Suppose I am using a very heavy applications(or you can say that it is a very bad code which keeps on allocating memory on heap and won't free it and also uses recursion) Now after some point of time both heap and stack will have no space to expand. Now In this situation heap and stack don't have any free space in betw...
For example I have this code: $route = 'product/category'; //variable overload $type = explode('/',$route); $type = $type[1]; My thinking behind this is that I actually don't need unique variable name for exploded variable, so why not to overwrite? Is this really bad concept? Or is there some more elegant way to wr...
Related to this question i want to know if there is a concise way to eleminate null values out of code in general or if there is not. E.g. imagine a class that represents a user with birthday as attribute which can be set but does not have to, which then means it's null. In scala and similar languages one could use the...
I've recently come across a Python library on GitHub. The library is great, but contains one glaring typo in a function name. Let's call it dummy_fuction() while it should be dummy_function(). This function is definitely "in the wild" and most likely used in embedded systems. The first thing that springs to mind is to ...
I just starting to use Core Data for my iOS app and I am thinking about how use Core Data for my needs. What are the features of my app: The user look for products proposed from a catalog. The user can add products into a basket. The user can customise each selected product. The user have to create an account to purch...
I have a RESTful call that can modify the state of an instance. My problem is that the JSON is different based on the type of action the user is taking, it could be a SetProperty action or a SetState action (among others). For example, a POST /api/sample/ _would send the following JSON { instanceId: 12312, ...
I'm sure designers of languages like Java or C# knew issues related to existence of null references (see Are null references really a bad thing?). Also implementing an option type isn't really much more complex than null references. Why did they decide to include it anyway? I'm sure lack of null references would encour...
I would like to have a function that will create a word (always the same word) for a given sequence number based on a given alphabet. word(0, [a,b,c]) = a word(1, [a,b,c]) = b word(2, [a,b,c]) = c word(3, [a,b,c]) = aa word(4, [a,b,c]) = ab word(5, [a,b,c]) = ac word(6, [a,b,c]) = ba word(7, [a,b,c]) = bb word(8, [a,b,...
When lexing, what would be the best way to tokenize operators? Would one just create a BinaryOperator token, or a separate token for every single binary operator? Examples: PlusOperator, MinusOperator, DivisionOperator ... I am tended towards having a universal one, but going from the documentations and project source...
Are there any design patterns or best practices around logging events for use in reporting and BI systems. For example in a system which manages orders from a website, it would be beneficial if a customer support worker could type in an order number and see that it the order was placed on a certain day, dispatched on ...
I don't consider myself a highly skilled javascript developer, but I thought I got one thing right for sure: don't create global variables unless you really have to. I've been learning angularjs lately and discovered one strange thing, almost everywhere in code samples for angular you can find constructions like the fo...
I am designing a web server that handles multiple things such as a user-to-user chat, a user-to-group chat, friends request, forum etc. The chats have to be real-time chats, the friends requests should be notified in real-time to the user, and the users should be instantly notified about the new topics on the forum. I ...
I'm designing a utility that will load data into a legacy SQL Server Database. I've been trying to mock up a simple WinForms utility with C# using the DataSource connectors (Tried a straight ORM Entity Framework approach first, but was having problems as the db follows few conventions). I am having particular difficult...
My coworker likes to see all of our unit tests pass (as would anyone) and he argues that some of the failing tests of a system he wrote are unnecessary "noise" since they all involve the validity of the data and a separate system in our stack is supposed to be responsible for validation. Personally, I think keeping the...
I'm working on some inherited code in C++ and am trying to use 2 classes with templates as I need 2-types of each class to operate on floating point or integer data (double v uint64_t to be exact). In the two classes that I'm trying to "templatize"(?), one inherits from the other. Data definitions needed for both ar...
Eric Lippert made a very interesting point in his discussion of why C# uses a null rather than a Maybe<T> type: Consistency of the type system is important; can we always know that a non-nullable reference is never under any circumstances observed to be invalid? What about in the constructor of an object with a non-nu...
I wonder why I rarely see any IDEs or other developers that use background colors for syntaxhighlighting. One of the first things when installing and configuring a new IDE is adjusting the colors so that for example comments have a decent light-grey background. This really helps me seeing where documentation is and whe...
In most, if not all implementations of regular expressions, the \w metacharacter matches all alphanumeric characters plus the underscore. Historically speaking, why was the underscore character included in this character class? And why not include dashes too?
The question title is not good, but I couldn't think of a way to word it better. I am used to develop using POCO classes in my projects, that is, domain objects contain absolutely no logic, only data. I am wondering which is the best approach when dealing with class relationships - to put a collection inside the class ...
I'm interested in building verifications into a REST service to help with service monitoring. For example, one could run assertions like http://example.com/posts/verify?min-posts=5&since=1-hour-ago which would respond with an error unless 5 new posts had been created in the past hour. Are there any existing services li...
I need to connect to a server and do manipulation with respect to HTTP GET and POST for my application and the server is generally used to handle multiple users with heavy load and many users might be sending multiple request at any moment. I have 3 questions here. The server is configured with ASP.NET I am using Java ...
I was thinking to make some jQuery functions that will use ajax to control mysql. The whole idea is to make separate files of PHP (e.g query.php, addRow.php, update.php and delete.php) provide data to them via the GET variables like query.php?sql=SELECT * FROM table and then control them with jQuery AJAX functions that...
Is it a lexer's job to undo any escaping done to a string literal? For example: "Me: \"Hello World!\"" Becomes: Me: "Hello World!" Should this conversion be done inside the lexer? I am guessing it should, because it'd allow for a more abstract and modular design. You could add ways to represent strings and you won't ...
I'm a C++/C# developer and recently I've started to learn Python. I think I understand the concept of duck typing right now except for one thing. When I'm coding in C++ or C# I sometimes create completely unrelated classes that have similar methods with similar signatures, for example: Create(), Open(), Close(), Proces...
The Problem Imagine you have a function in a public API that needs to return some kind of collection. Its type is something like foo :: a -> b where b is some kind of collection. As far as I can see, there a three major kinds of collections -- at least those are the ones used most often: Sequences (order matters, the...
I am trying to scrape websites for valuable text for example the title of an article, the author's name, and other distinguished text. I cannot always guarantee that this sort of text will have informative tags, and but this needs to be done as quickly as possible. As a possible short cut I think that I could just try ...
Since I learnt about MVC, I used it for every app I made (which is arguably not the best idea, but that's not the topic of this question). All of them small, 1000 LoC apps. I am using Java and Swing for the GUI. What usually happens is this: The view (the GUI class) reports to the controller about any GUI event (most c...
I have been self studying algorithms and data structures for some time now and currently enjoying it. Whenever I understand an algorithm, I usually try to code them from scratch for fun and I always will discover some logic I've never thought of before. I'm not so sure, but I always think that when I code algorithms, I...
My company runs 2 websites, a public facing website for clients, and an employee intranet. The intranet is used as a backend for employees to edit and maintain various parts of the public website. Both are written in PHP. The intranet is years older, and was designed using an inhouse framework. We have recently created...
The Single Responsibility Principle states that "a class should have one reason the change". In the MVC pattern, the Controller's job is to mediate between the View and the Model. It offers an interface for the View to report actions made by the user on the GUI (e.g. allowing the View to call controller.specificButtonP...
Is there a way to find errors caused by crafted input in php, such as naming POST-fields like variable[] instead of variable, causing PHP to implicitly convert it into an array, by using some form of automated testing?
I know that exception should be thrown in exceptional case (e.g. out of memory, programmer error). For these cases, I don't need to worry about performance throwing these exception. But what happen if use exception in normal code path? In my case, use it to stop user code supplied function. So for given code, is foo be...
I'm fairly new to unit testing. In school it's always been, "hey it works, onward!" But I've started to write professionally, and even at work that's been basically the mantra. However, I've started to see the validity of unit testing and TDD. I've come to a realization, that when I write maybe a 20 line piece of code,...
I wanted to know if there is a way to make your JavaScript private from client side?
Database designers building enterprise systems usually assign different sets of privileges to different users of DBMS. They can be as granular as needed. However, in my experience, web frameworks usually use a single connection to a DBMS, and the privileges are assigned and enforced at the framework level, through some...
Even if I don't like enforcing people to do things (and I believe that it may decline the productivity and cause anger), I really want to enforce good coding style. Is there a way to set up something like an integration server that measures the quality of code (for example it runs resharper or some other static checke...
I'm trying to choose a good name for a new open-source project. The problem is, there is already so much software in the world that Google search reveals one or more existing programs with every good name I can think of (and there have been several already). Obviously, names like "Linux" or "Windows" or "Java" or "Exce...
Consider an app that allows plugins to react to its program flow. I know 2 ways to achieve this: hooks and events 1. Hooks Use calls to empty functions inside the main program flow. These functions can be overriden by plugins. For example, Drupal CMS implements hooks which are available to modules and themes. Here's an...
Now I'm only a novice programmer, but what my friends that are studying programming tell me is that recursive code is a good thing, it leads to less code duplication and it looks more elegant. Now it may be so, but everytime I've tried my hand with recursive code I've always found it to be significantly slower than no...
I carefully followed the "always write quality code, unless you're writing a prototype" advice during my career as freelancer and software developer. I was convinced pretty early that avoiding to do code reviews, testing, QA or refactoring doesn't make the project faster, but only slower. Books like The Mythical Man Mo...
Using Python and sqlite3. This simple print loop takes a few seconds to execute. I don't know much about databases, so I'm guessing I'm not using these queries correctly. Surely sqlite should be faster? The entire db has 5k or so rows and just a few columns if that matters. con = lite.connect('gamelist.db') with con: ...
I was reading a proposal for value types in Java, and I came across this sentence: "Object identity serves only to support mutability, where an object’s state can be mutated but remains the same intrinsic object." From what I understand (albeit tentatively), object identity is the idea of your variable acting as a poin...
Most of the HTTP Servers I know send their application name and version in response http headers as default behaviour. (Nginx, IIS, Apache etc.) Of course we can change the default behaviour but I wonder why they send these information? Does it matter which HTTP Servers we use to the requesters? The only reason I can t...
Say you have a Car class. Properties that make sense for a Car class might be: var make; var model; var year; var turnOn; // a function But the turnOn function is very complicated and ends up needing a static variable and a couple sub functions: var isTurningOn; // too specific to be a class variable function turnOn()...
I'm working on a coarse API for performing higher level business functions. Under many conditions these functions may fail in a way that is expected (not exceptional), ie. the function may not be able to complete because of failing a validation condition of some kind. In many cases, what I want to do in these "failure...
I've seen at SOLID there is a principle Dependency inversion principle. Also I've seen that: High-level Classes should not depend on Low-level Classes but both of them should depend on abstractions. What exactly means High-Level Classes and Low-Level Classes?
In an MVC architecture pattern (for e.g., in iOS) there is a controller per view. In UML there is a concept of having Control object per use case to encapsulate an use case, which may span more than one view. Sometimes a same view can support multiple use case, in which case it would be nice to have multiple 'use case ...
After dealing with DDD for months now, I'm still confused about the general purposes of domain services, factories and aggregate roots in relation to each other, e.g. where they overlap in their responsibility. Example: I need to 1) create a complex domain entity in a saga (process manager) which is followed by 2) a ce...
From time to time we face difficult problems which are hard to reproduce. Creating a planning for solving such an issue is (nearly) undoable. What we do at the moment is break these up in analyses/reproduction and solving the problem. As long as know nothing we plan a number of hours to investigate and book off these h...
I am currently learning about memcached/redis, and I am trying to figure out how could I use this kind of technology at work. Now I understand that you should mostly cache data which is common to many user and which does not get modified every second. In our architecture, we have a very relational data model data model...
We have a university programming course and fellow students are asking some programming questions in our Facebook group. I'm a little hesitant to share all of my programs, especially if it's something cool for one of the assignments, since these are looked at by the TAs and they might notice if somebody has the same pr...
I'm going to include MongoDb(AGPLv3) in my product. My product is SaaS, I don't install this to client directly. My software is ASP.NET MVC website. But MongoDb's drivers for .Net is under Apache My questions are: 1) Should I license my software under AGPLv3 license if I use Mongo? I use them across drivers which writt...
There are businesses and people. People could be liked and businesses could be commented on: class Like class Comment class Person implements iLikeTarget class Business implements iCommentTarget Likes and comments are performed by a user(person) so they are authored: class Like implements iAuthored class Comment impl...
For the needs of a project, I would persist the datas contained in Core Data in several places depending on the state of the user. If the user is logged to my API -> Persist the datas on my API. If the is logged on iCloud -> Persist the datas on iCloud In all case -> Persist the datas on the device. Indeed, with ...
I need to implement a flexible Access Control system for a framework used by a couple of .NET applications. I have looked into Attribute-Based Access Control (ABAC) and XACML and this seems to provide the necessary flexibility to make decisions not only based on the user identity, but also on information about the requ...
I am doing my thesis on the subject of automated UI testing at a company that applies continuous integration to their projects. The company builds intranets in Microsoft SharePoint 2013 and my task is to create an automated test framework that can be used on any project as a smoke test, and that integrates with the con...
I'm building a medium-sized "single-page" JavaScript application using jQuery. If you include all possible functionality of the application, there are 134 click bindings. Since most of the content is dynamically loaded, I can't just do this: $(element).click(function() { ... }); Instead, I'm doing this: $(document).on(...
The main reason I use Shelve is to be able to quickly develop code without worrying about db table structure. Unfortunately changing a class name from, say, 'class1' to 'class2' gives "AttributeError: 'module' object has no attribute 'class2'" on the next run. What is the canonical way to rename a Shelved class? What o...
Often times users cannot comprehend the complexity of software. They think that because a problem is easy to describe then it is easy to solve. I want to equate the complexity of a "simple program" I have built with the complexity of a process with a tangible result. Is there a system that can take tangible process...
I want to save/serve multilingual data in my CMS application using Mongoose. Is this the correct way? name: { global: { type: String, default: '', trim: true, required: 'Please fill name', }, en_US: String, tr_TR: String, sv_SE: String }
I am not very good at estimating how long a piece of work will take to complete. I am guilty of putting my finger in the air and guessing. Usually things are later than expected, however sometimes they are earlier than expected. For example, a recent individual task was delivered in four months instead of five month...
I have 3 pages to my site. The 1st page allows you to select a bunch of options. Those options get sent to the 2nd page to be displayed with some data about those options. From here I can click on a link to get to page 3 on 1 of the options. On page 3 I can create a new/edit/delete all on the same page where reloads co...
I have a few HTTP resources, and i'm wondering if including the models of one in the other is acceptable or if there is a cleaner method. In this example, we have a ton of "news" resources, and users can subscribe via a resource called "subscription": ==>/news-items/{id}/ { "id": 987, "url": "http://example.com...
I don't know what scalar means exactly, but I'm trying to see if I'm thinking about it correctly. Does scalar relate to arbitrariness where the type of data could be any type, or a system is not able to know what the data is in advance.
I'm new to dependency injection and though I've really liked it so far, I'm not sure where bindings should go. I'm using Guice in Java, so some of what I say might be specific to just Guice. As I see it, there's two options: Accompanying the class(s) its needed for. Then, just write install(OtherClassModule.class) in w...
With the latest trends about C and C++ applications, and with latest I mean the latest years, I was expecting to see std::allocators to be used way more frequently than what it really is. Modern applications are usually multithreaded or with form of concurrency in them, and they manage a significant amount of memory, e...
I have some classes that represent, for the most part, data that's deserialized from XML. They also have some behavior in them, because I don't want to suffer from an anemic domain model. These domain objects don't have any XML specific code in them, but they do have properties that correspond exactly to the tags and a...
This is my first question so please indicate if my question is too vague and not understandable. My question is more related to High Level Design. We have a system (specifically an ATCA Chassis) configured in a Star Topology, having Master Node (MN) and other sub-ordinate nodes(SN). All nodes are connected via Ethernet...
I want to implement a system which store the profiles of employee and the resources that they have. There are many types of resources, such as the documents they produced, the techniques they have...etc. I store the properties of nodes and relationships on MongoDB, and only store the relationship on Neo4j. But I face a...
I've built a REST API and have been using Backbone models throughout a couple different applications to communicate to it. I would really like to build a single JS SDK that can be used in any application that contains that reusable code. I have started by creating an npm, bower, and component.json so that it can be eas...
I am programming a game engine as a hobby project, and I would like to separate physics and drawing into two separate threads. The position vectors of entities are subject to modifications by the physics thread, while the drawing thread only requires read access. In pseudocode: Physics thread: loop ... ...
This is more of a theoretical question. If jvm is implemented in go which itself is a garbage collected language, then does that jvm need a separate garbage collector to be implemented for its own operation?
Does comparison of floating point numbers takes (considerably) longer time than comparison of Integers in C? I just wrote a C program of heap sort to sort floating point numbers. I am on ubuntu 14.04 and I used time command to check the time taken by this program for sorting 50, 5000 and 50000 random numbers and then I...
I've been trying to learn more about generics, and I finally felt that I ran into a situation that it would be more useful to use it instead of only regular classes. Would the following be a practical use of generics? A spaceship has hardpoints that can equip only certain types of equipment. The equip function has code...
I am fairly new to OO design and have problems with the design of some software and looking for a pattern or a combination of patterns that could help me solving my problem. I have a type that has a collection of different geometric shapes (say lines, rectangles, and cubes). I actually even have composites of these sha...
Note: Even though this contains Python, it's not specifically about Python. It's more generally about expecting a certain behaviour from a language which is not necessarily the same across compilers/interpreters. So I came across this question: How do I convert a boolean to int in Python? Can I just do int(mybool)? ...
My workplace mostly uses C# for writing code. I'm trying to figure out a good way to indicate that a class with referentially transparent methods is intended to be referentially transparent (i.e., given the same set of arguments, you will always get the same return value) for future maintainers. I've considered just us...
I'm fairly new to MVC and I'm trying to get a better understanding of it. There is endless information about the theory and general responsibilities of each part of an MVC app, which I've read a good deal of, but I find myself constantly second guessing my implementation. I currently have my application setup where my ...
An app I'm working on is designed with MVC. The components often interacts with each other by passing int constants, which then have to be interpreted with if statements. I'm wondering if this is considered bad OO design. (Not specifically with MVC, but in general). For example: When the user clicks a specific button, ...