instruction
stringlengths
34
19.9k
int *itPins = pins; for(int i = 0; i < count; i++) { ConfigureGpifPinAsGpioOutput(itPins); itPins++; } I have the impression that doing two things in one line is bad practice. This is why I am advancing the iterator outside of the only statement, using it. However, I feel blindly following a rule. Is this cod...
I was looking at some of my past codes, and I viewed one of my admin boards I've made. I had it setup so that the admin has to define/enter 2 passwords for his account. Is this really double-safe or was I deluded? It seems that it's reaaally hard to force-match username and 2 passwords from the client side. I've got it...
I have a sorted list of blocks L that I want to put in 4 containers C, the containers have a size limit S. I want to have similar containers height, by similar I mean the size variance should be as small as possible. eg: S = 4 L = [1, 1, 3, 1, 2, 1, 2] should result in: C = [[1, 1], [3], [1, 2], [1, 2]] note: it is a...
The Problem I came up with this select-box variant in answer to a question on UX.SE: https://ux.stackexchange.com/a/48951/16187 However, working out how to implement it has been driving me mad ever since I wrote that post. What I've tried Initially I figured it would be easy enough to do. The strategy I would have tak...
Kanban does assume a more-or-less linear flow. Most of the time this models software development quiet well: we crate a user story, we code it, we test it, and we deploy it. However, some internal stages are iterative in nature and thus not so obvious. Take this (simplistic) board: || Planning || Development ||...
If I have a photo album where each Photo can be commented on, Should the Comments be Entities or Value Object in these cases: Comments can be added only anonymously (i.e. Comments have no relation to anything except the photo). Comments can be added by registered users (i.e. there will be a relation between the Commen...
In the higher order function fold/reduce what is the name, if any, of the functional argument? I am working on a monadic tabular processing library where rows are folded to produce simple analyses (like finding the minimum, maximum, average of a column). I am therefore looking for a sound name for the argument of the ...
Which of the following options take less processing time/is less expensive in a graph traversal algorithm for a (indoor)navigation system? a) To produce all possible paths between start and destination points (nodes on the graph) then applying a filtering mechanism to match the navigation user's capabilities and prefer...
I am litle curious about what sorting algorithm is using OrderBy (linq to objects). quicksort? heapsort? introspective sort ? As i see in MSDN documentation List.Sort is using introspective sort: see: http://msdn.microsoft.com/en-us/library/b0zbh7b6.aspx Maybe OrderBy use the same? If we go to order by documetation i ...
I was reading the Bootstrap Getting Started docs, and I came across "Pre-Compiled Source" as a feature. Upon downloading the package, I just found .js, .css, and some image files. What is there to be "pre-compiled"? Doesn't it all compile in the browser upon page load? I'm guessing this means that it was compiled and t...
When we look at the the overlap between the Ruby Community - we see the following overlaps: Think Relevance (now Cognitect) has switched from Ruby to Clojure Jay Fields has switched from Ruby to Clojure David Chelimsky - author of RSpec - has left the Ruby RSpec project to join Cognitect Is there some linguistic simi...
What if, instead of looking at the C++ specification, you analyze the behavior (by inspecting the source code and testing with sample inputs) of existing C++ compilers and use your knowledge of C++ to create a new compiler? Is it a good way to implement programming languages? What are the possible disadvantages of this...
Programming languages are not just language. Each one tends to have: Its own IDEs, Its own package managers, Its own set of libraries, Its own build tools, Its own data formats. If you are writing Java syntax, you will be using Maven packages; if you are writing Haskell syntax, you will be using Cabal packages. What'...
I use a pattern that I call "ensure" extensively in my repository layer. In short, it does the following when I call an Ensure(...) method: It uses the arguments in the method to attempt to populate an entity of a specified type (ultimately from the database), If it finds one then it returns it; f it does not, it sav...
In the past, I've had alot of success just using a .NET Dictionary, with a TKey consisting of the X,Y coordinates merged together. However its read performance, despite being amortized constant time, is a bottleneck in a design of mine. My application needs to perform alot of reads, and would benefit greatly if the per...
I've been reading some into it, but I am time pressed, so I would require a simple solution now and I promise to read up on it later. I come from a winforms c# background, and have lately been working with WPF. As the user interface I'm implementing is not that input intensive, I've gotten by with using INotifyProperty...
I need to process all log messages from Postfix (/var/log/mail/mail.log), and print a summary/statistics (how many emails were sent/received and from/to which email addresses) The situation is made more complicated by the fact, that Postfix has multi-line log entries (in contrast, Apache for example, has single line en...
I would like to release a software library written in a class-based, object-oriented programming language (Java) on a web-based source code hosting service, that allows forks of the project to be merged into the main project (GitHub via pull requests). I have researched on the web and given a lot of thought on how to ...
I've been using Javascript for quite a while, but I've always ignored the common naming conventions that I see online (camelCase). I know it all depends on the developer's preference, but why camel case for Javascript? I'm originally a PHP programmer and I kind of have my own naming convention and I use it everywhere I...
I'm currently working on a project that requires a complicated model structure and I'm struggling with picking the right architecture. First of all, there are several interdependent models. Change in one model can trigger changes in several other models. For example, user inputs a query, first model checks the database...
I have read in several places this following rule concerning Aggregates: Entities in one aggregate can hold references to any other Aggregate Root, but never to an Entity or Value Object inside the other Aggregate. What can go wrong if an Entity was holding a direct reference to an entity in another Aggregate root?...
Should I use <?php if(!$user->is_logged_in()){ echo '<p id="login">Click <a href="login">here</a> to log in</p>'; } ?> or <?php if(!$user->is_logged_in()){ ?> <p id="login">Click <a href="login">here</a> to login.</p> <?php } ?> ? Why? The first one will not have the HTML tags coloured so ...
I'm trying to create a queue processing script that's purpose is to find particular files and apply actions based on specific parameters, with the result being to call a PHP script that serves to process a list of message files that we generated and passed to it. One of the things I need to specify in a config file th...
In code quarterly interview with Rich Hickey, Michael Fogus hints that Clojure borrows a lot from Haskell: Fogus: As someone who only knows Haskell enough to read the papers, Clojure appears to be influenced by it substantially. From the names and operation of core functions—take, drop, iterate, repeat, etc.—to its pr...
Last week, a few colleauges and I were participating in career fairs at three major universities (two here in the US and one in England), where we were trying (without much success) to recruit for several compiler positions, ranging from internship, to entry-level, to more senior, for our team. To our surprise, 80% of ...
Currently I am working on C++ project, which can be classified as "legacy" project. A lot of poor written code was committed because of lack of experience and under the pressure of deadlines. When I try to fix bugs I eventually make the new one. Recently I got some more free time and I want to make this project better...
Given the following relational model: I need to implement a typed search for hotels, which should be able to query on name, city, country, category, hoteltype, roomprice, customtype, room custom type and roomtype or any combination of these criteria. At the moment I'm doing this though Entity Framework, dynamically co...
First of all, I'd like to say this is a hardware-level question, which is very closely related to the "in" and "out" command in x86 assembly. I have searched for quite some time, but I still haven't found how they send the addresses and the data. Does the 8086 first send the address, then the data? If so, how does the ...
I have been reading about the (un)convenience of having null instead of (for example) Maybe. After reading this article, I am convinced that it would be much better to use Maybe (or something similar). However, I am surprised to see that all the "well-known" imperative or object oriented programming languages still use...
I'm having a hard time with this concept. What is Stroustrup getting at here? What is special about a class whose "representation is part of its definition"? What does a "concrete type" contrast with? (I assume it contrasts with "abstract type", but since, AFAIK, you can't even bring an instance of an abstract type i...
Over the last few months, I stumbled a few times over the following technique / pattern. However, I can't seem to find a specific name, nor am I a 100% sure about all its advantages and disadvantages. The pattern goes as follows: Within a Java interface, a set of common methods is defined as usual. However, using an in...
I am writing a paper on the tension between OOP and Generic programming created by Stepanov. He widely criticizes OOP and says it is "technically flawed" when compared to Generic Programming. Now I know we have plenty of programming languages that support OOP exclusivley and have no Generic support including Google GO...
Certain datastructures, like Python's Dictionary, are unordered/random read/written. As programming in python is iterative (and programming in general is?), how do these unordered datastructures work? I understand that Python's Dictionary is in essence a hashtable. But I figured that the datastructure gets stored in t...
We are required to make a package diagram for our senior project. Since our project uses MVC patter design, we created an MVC class diagram, now, our problem is in creating the package diagrams from our class diagram. Is it possible to have packages with MVC at the same time? so it would be something like this: Package...
If my domain has several Bounded Contexts, but only ONE team will work on all contexts, should I develop an Ubiquitous language for each context? or should I have only one and force to into all contexts? The bounded context definition from Evan's book states: A BOUNDED CONTEXT delimits the applicability of a particu...
I should log some events in a program but as far as I know it would be better to keep the logging code outside the program because it is not about the real functionality of the program. So may you tell me if I should keep it completely out of code and only use Observers and Listeners to log the events? Or I can add a l...
We currently have a SOAP based web service which is being used by various teams as the primary data source. We eventually want to transition to REST based services. We are reluctant to do this now as the clients would have to do changes. What can we do to make this transition smooth?
I have built a restful json api for an online store using Laravel. I now wish to create an AngularJS app to run the front-end web application. Product prices for my store need to update every second, so Angular needs to get the product json from the server once per second to update the html. I wish to somehow do someth...
I'm working on a Meteor app which lets users create events and assign them crew members. I've played around with MongoDB before and made some experiences along the way, where for instance my first attempt went overboard with embedded objects and quickly became sluggish and hard to maintain. Several people therefore sug...
I found, that some very famous app (I'm not disclosing name intentionally) has a "problem", when writing meta-data of a file and the file turns out to be read-only. Program doesn't handle that too gracefully. It does not check, whether a file is read only upon opening meta data dialog box. Thus, it allows the user to f...
I write CLI-executable Python 3 scripts regularly to do data compilation and some maintenance tasks, and try to adhere to PEP 8 and the Google Python Style Guide when doing so. Google's guide says to avoid using global variables, while PEP 8 offers naming conventions but doesn't really encourage or discourage use of th...
I recently started using namespaces in PHP. When I first saw them, I thought that their syntax was ugly and I'd never use them. However, I created an autoloader (spl_autoload_register) that makes it so that I never have to write an include/require statement again. I like namespaces, but is there any objective benefit o...
Stroustrup says that you should use structs unless you can specify an invariant for the data structure. I have to represent a physical object which holds things such as position, velocity, mass and inertia (and so on). I also want to render the object, for which I will need setup in the constructor and unloading stuff ...
The problem is the following. There's a set of simple entities E, each one having a set of tags T attached. Each entity might have an arbitrary number of tags. Total number of entities is near 100 million, and the total number of tags is about 5000. So the initial data is something like this: E1 - T1, T2, T3, ... Tn...
I haven't been able to find the appropriate terminology to search for content on the web related to what I'm asking, so I'm hoping someone on here can at least point me in the right direction. I'm a fairly senior JavaScript developer, but I have a secret -- I don't like event-driven programming (aside from user-trigger...
I'm trying to re-write a backend interface doohickey for a calendar, a todo list and another sort of calendar and found that they all were programmed to have subtly different formats for patterns of dates that could be used to configure certain properties in them. I have three screens that have different ways of essent...
I have a clustering problem which I can't seem to solve, although if I treat it as a labeled classification problem, I can solve it with satisfactory precision. Is there an elegant way to make the leap from being able to solve the classification problem, to being able to solve the clustering one? The details: I have a ...
I know nothing about gui programming. I try to learn. I have simple question... For example, I have small program. I have class that extends JFrame with main Window (MyWindowClass) and my "logic" class (MyClass) that do something (for example calculate something and I want to display it in window). Should I implement t...
I want to really opensource a project that did start as a personal hobby, but I'm an ignorant of licensing details. This project, provides some libraries for a given $language, and some wrapper command line utilities for those libraries. Those libraries, across many things, do generate more code in the same language, c...
Sometimes I read in observer-pattern descriptions, to make the constructor of a observer base class protected so the class will be abstract. but by making the constructor public (if even one is neccessary), I could use the observer as an instance and not only as base-class. Is there any disadvantage of doing so i'm not...
To make this question answerable, let's assume that the cost of ambiguity in the mind of a programmer is much more expensive then a few extra keystrokes. Given that, why would I allow my teammates to get away with not annotating their function parameters? Take the following code as an example of what could be a far mor...
I'm trying to create a website where the user enters a few numbers, these numbers are fed into some equations, and the output of these equations is emailed to the user. I'm using Python 2.7 for everything. I'm using a cheap Amazon instance (m1.small, Ubuntu 12.04) to host the frontend, but I only want to launch a backe...
ASP.NET WebForms seemed really great until that moment of realization the abstraction you'd welcomed was producing HTML that was worlds away from what you needed. Wrestling with that framework to generate HTML that matched a designers or used external libraries became a big nightmare for me and one I'd rather not have ...
I'm writing a Java class, part of an opensource game development framework under the Apache 2.0 license. There is another framework, under the same license, that happens to also have a Java class that addresses the same subject as mine. I recently checked it out, and my implementation is extremely similar to that. Heck...
I have a function that linearly "remaps" a value from a given interval to an other interval? The function remaps a value from a given interval [oldMin, oldMax] to another interval [newMin, newMax] using this formula: newVal = newMin + (newMax - newMin) * (oldVal - oldMin) / (oldMax - oldMin) If it helps identify what ...
My friend and I are building a mobile game and ran into the following design problem: We will have many different types of units all with different stats and abilities. However, all unit types should have a few commonalities (for example, they would all have a totalhealth attribute). We were trying to decide what the ...
The main issue I have here is are the 720P, 480P, 240P... classes for defining video quality or do they unambiguously define the resolution of the video? For example, the wikipedia article about 240P refers to a family of resolutions.
I was taking this course - CMU 18-447, Computer Architecture at Carnegie Mellon to brush my knowledge and concepts. They say that most of the machine level details and implementations are taken care of at the Instruction Set Architecture(ISA) level and is abstracted at that level. Some Intel processors even have hardwa...
Large codebases are more difficult to maintain when they are written in dynamic languages. At least that's what Yevgeniy Brikman, lead developer bringing the Play Framework to LinkedIn says in a video presentation recorded at JaxConf 2013 (minute 44). Why does he say this? What are the reasons?
When writing an API in Java, returning an immutable collection of some sort, I've got the option of returning Collection (or List, Map, etc) from the method, or guava's ImmutableCollection (or ImmutableList, ImmutableMap, etc): private final ImmutableMap<> _immutableMap = ... public Collection<T> getValues() { ret...
I currently have 4 projects under development. All of them related to the same product (hardware) but different after all (desktop, android and web environments). That product, the hardware, is constantly changing, improving and thus all related software so there is no real "ending". How should I manage time? Should ...
I'm relatively new to TDD and have been thinking a lot about how to manage the perpetually growing pool of tests that comes with it. One of my biggest concerns is about false positives. In my experience, it's not uncommon at all for a feature to undergo fairly massive changes over time. To implement a change we would ...
Is it better to have either a Deterministic test suite, that results in the same tests succeeding Non-deterministic test suite, which potentially possibly covers more cases ? Example: You write a test suite to test controller functionality in an MVC application. The controller requires application data from a databas...
We have a database with tables that use an inheritance hierarchy. An entity in the derived table will have an ID that matches an entity in the base table and so on through the hierarchy. We have repository classes for the derived types/tables so that you can get specific instances by ID. The problem we have at the mom...
A class loads properties from a file and uses those as it performs its duties. For testing purposes I want to be able to modify said properties directly without having to use a test properties file. I did the implementation, but it seems filled with smells -- I'm wrestling with keeping this thing small (avoiding fram...
I'm interested in build a prototype that needs this sort of thing: Point A (xa, ya) with a radius of 500 meters. Point B (xb, yb) with a radius of 700 meters. Point C (xc, yc) with a radius of 1200 meters. Point D (xd, yd) with a radius of 200 meters. Person 123 is in some certain point. Question: which points 123 is...
Are there any examples of inheritance in languages where classes call their subclasses' methods rather than their super classes' methods? It should not behave like traditional inheritance like the following. Parent.method = function () { // Do things } Child.method = function () { // Do things super.method(...
I am working on an application which have multiple layers. Data access layer to retrieve and save data from data source, business logic to manipulate data, user interface to show the data on screen. I also doing unit testing of the business logic layer. The only requirement is to test the flow of business layer logic. ...
I am building a program which would have WCF support. I am using the MVC pattern. For each controller there is a WCF service class. e.g. I have CTRL.CTRLBooking, WCF.IWCFBooking and WCF.WCFBooking. For each controller (total of 10) there is a WCF class and an endpoint. Is this a good approach or should I keep all the m...
I have been trying to design a library to do some simple geometric computations in an Euclidean space regardless of its dimension. While it is easy to represent points, vectors, hyperspheres and hyperplanes in a generic fashion, I am still unable to find a generic way to represent a (infinite) line, even though lines s...
I have always wondered about this, especially in C/Java style languages. For example, consider the first 3 lines of this C# code: lock (serviceLock) using (var client = new ServiceClient()) try { // Do something client.DoSomething(); } catch (System.ServiceModel.FaultException ex) { // Handle error add...
This question is asked many times, and I always prefer code-first as I like to keep the logic in code. But now I have a challenge to load screen under 5 seconds and very little time to do things. I have large set of records, and I'm possibly going to retrieve them asynchronously. There are a few doubts in my mind. D...
Our teamlead said that many files much worse than a single, despite of we are working on a big project. He argued that our customers could more easily send logs to us if there will be just a single file. To understand our log-file he wants to develope our own log-analyzer which will analyze a single log-file separating...
Our team is developing an application using WPF with MVVM. We want to make ViewModels reusable. With this intention we want to abstract the transition logic between Views (ViewModels, we use ViewModel-first approach with Caliburn.Micro) so the other application can override it. For instance, we have App1 and App2. Firs...
I am fairly new to using patterns and although I understand some of them to a point I find it difficult to work out which one(s) to use in a particular situation. I am trying to wrap up an existing db schema into a number of objects and am not sure if I should simply be using inheritance or a mixture some patterns I ...
Let's start with the problem: There is a large dictionary X that contains {key, value} pairs, i.e.: X = [{100, 10}, {101, 0}, {103, 0}, {106, 2}, {110, 1}] Every t seconds, X has to be updated with values from sub dictionary U and 0 set to each value for a key that is not present in new updated U, but was in the previ...
The Java team has done a ton of great work removing barriers to functional programming in Java 8. In particular, the changes to the java.util Collections do a great job of chaining transformations into very fast streamed operations. Considering how good a job they have done adding first class functions and functional...
I'm integration testing a system, by using only the public APIs. I have a test that looks something like this: def testAllTheThings(): email = create_random_email() password = create_random_password() ok = account_signup(email, password) assert ok url = wait_for_confirmation_email() assert url ok = accou...
I intuitively think that an application should be exactly the same in DEV, QA, and PROD environments. However, I have been asked to add a feature to an application that will only be available in DEV environment. I have a server and database for each environment - dev, test, and production. I want to know if there woul...
For example, if I wanted to generate some HTML based on some input. Which is the preferred way out of: <?php function generate_html($type, $input){ switch($type){ case 'paragraph': //Generate and return the HTML code for a paragraph break; case 'ul': //Generate a...
I have a 3 layered application. Presentation Layer (PL): ASP.NET MVC app Business Logic Layer (BLL) project Data Access Layer (DAL) project I need to add a Web Reference to a service for a payment gateway. Where does it go? PL or BLL? P.S. Before using the Web service I need to retrieve some data from database and ...
I want to present a list of products to the user. This list is paginated and can be sorted by the user by product ID or product name in ascending or descending order. I am using an MVC setting, where I would like to query the database in the model. How would I write functions that query the database? I can think of sev...
I have a piece of code that composes method name to call from a string parameter. I don't feel it's a good thing to do but I'm not sure what can go wrong with this. Here is a simplified snippet of that code: switchToFilter = function(filter){ var filterMethod = 'switchTo' + filter; myObject[filterMethod](); }
Java has the following syntax for different bases: int x1 = 0b0101; //binary int x2 = 06; //octal int x3 = 0xff; //hexadecimal Is there any reasoning on why it is 0 instead of something like 0o like what they do for binary and hexadecimal? Is there any documentation on why they went this route?
I was reading a thread and saw this post, which says that Javascript is faster than Jquery because it uses native code. But why is the use of native code faster? Is this always the case? What impediments does Jquery have in performance?
So I have a program whose purpose is to take text files and parse them into a binary format that an embedded system understands. However, the text format I've inherited that I need to parse is sufficiently complex enough that after refactoring the main parse routine I'm left with a class with more than 50 methods that...
I need to analyze data uploaded from vehicle GPS devices to detect travel patterns and then attempt to learn about the normal travel patterns for that vehicle so that predictions can be made about maintenance, refueling etc. Some vehicles are domestic (exhibiting normal home->work->home travel patterns) and some are co...
Let's say I wanted to start an open source project that I hope/expect to have many people submit patches and whatnot. Is it viable to take a strict TDD approach? Can/should I expect/trust collaborators to write quality tests whenever they submit a patch? One thing I've been thinking about is writing test suites for ind...
In one of the projects (in C), I have the code that looks like this (the names are obfuscated specially for question to not give out details of the probject): typedef struct Module_s { /* These fields are parsed by f1() */ S1 *s11; S2 *s12; size_t n11; size_t n12; int i11; /* These fields a...
I am using Singleton pattern for my application, I have used ADO.NET Entity framework as my Data Access Layer, after login to my application, it's taking 3 to 5 minutes to load the dashboard. Is there a way to reduce the time? Or I have to look for some other methods instead of Entity framework?
I have been tasked with producing a plan for implementing a slight change to the work of our developers (there are eight of us working at this company). The change affects a small portion of our work, but introduces a new tool that the developers aren't familiar with, and a new "step". Very schematically the change lo...
I recently ran into an error, I guess caused by my lack of understanding of how HTTP works, where I was sending a JSON object to the server to be stored in session data, and then sent back to the client at a later time. When I was sending the data to the server all of my booleans were enclosed in quotes and so when th...
Is it perfectly legal to use GHC as base and build some commercial application over its top ? Are there such examples I can can interact with ?
I'm using FogBugz for Project Management, and I'm unsure how to structure my cases. I have different features which require implementing as part of this project. For example, if I have a new feature to include autocomplete on a search text box, this would have cases such as: Method for returning search terms Front-end...
Many naming conventions recommend that methods returning a boolean (also called predicate methods) should be named after a question. My question is: don't they really mean the methods should be named after an assertion? The difference may be subtle, but you end up with different names in some cases: question: is_pixel...
I have been tasked with writing a print driver. I have no experience with this and have been researching it for a few days. The goal of this is to essentially write the data coming to the driver to a file and then do some additional processing of it. If I understand it correctly, I can start other processes to do mos...
At the moment, we're using sql server full text search, but it's too inflexible. The main thing we do is look up names of people from a database based on a search query. The searches need to be fast, and they need to be fuzzy. SQL Full Text Search doesn't really support fuzzy matching especially when combined with the ...
I'm working on a windows form to calculate UPC for item numbers. I successfully create one that will handle one item number/UPC at a time, now I want to expand and do it for multiple item numbers/UPCs. I have started and tried using a list, but I keep getting stuck. I created a helper class: public class Codes { pr...
I'm a Mac user, but I need to write a script on Windows, and I'm not sure how I should go about that. Here's the scenario: Someone adds photos to a USB drive. The drive is then inserted into a digital picture frame. In order for the photos to autoplay, a 'playlist.asb' file must be present on the drive. I want to creat...
I am working with a non-OO language and I'm trying to name my routines consistently. I came acrross the following guideline from Steve McConnell's Code Complete: To name a procedure, use a strong verb followed by an object McConnell gives the following good and bad examples: good, non-OO --> PrintDocument(doc) good,...