instruction
stringlengths
34
19.9k
Early in my programming career I was in love with pointer twiddling, lean code, doing everything with as little layers of abstraction as possible and so on. The code was very C like I would say, close to metal and clever. Time has passed, I have a lot more experience, and I'm noticing my attitude towards the code has c...
I'm very familiar with xUnit frameworks and I try to implement unit tests on every project I start. Somewhere along the way, I realize that I'm writing the same tests over and over again, and then I run into a really difficult to test method or a test involving remote resources, and then I give up for a while. I end up...
The other day I reviewed code someone on my team wrote. The solution wasn't fully functional and the design was way over complicated-- meaning stored unnecessary information, built unnecessary features, and basically the code had lots of unnecessary complexity like gold plating and it tried to solve problems that do no...
I have a very big file delimited by some sequence of characters '*L*I*N*E'. The file will be of the order of 250G. And each line comes around 600bytes to 1000 bytes. I will be performing the following operations on the file, Read the file line by line and for each line, I will be giving it to a parser which will do som...
I'm bootstrapping my own project, it has a registration/login area (via devise with RoR, properly hashed and salted of course). As I'm using subdomains and I need to access them with iframes (it's justified, really!) I'd need one of those expensive certificates that cover subdomains. As I'm doing this out of my own tim...
I created a sessionful web service using WCF, and in particular I used the NetTcpBinding binding. In addition to methods to initiate and terminate a session, other methods allow the client to send to one or more tasks to be performed (the results are returned via callback, so the service is duplex), but they also allow...
Recently I was talking with a colleague who mentioned that his company was working on adding the MVC design pattern as a PHP extension. He explained that they wrote C code for adding Controllers, Models and Views to the language constructs to increase performance. Now I know that MVC is an architectural design pattern ...
I have a class created in some namespace, like SomeNameSpace.SubNameSpace.StaticClassName Here is a code snippet from other code file where I want to use this class many more times, so I created a property in the code file like this //Just to provide an Alias for long name "SomeNameSpace.SubNameSpace.StaticClassName.Pr...
For definitions and examples of "state", see: http://en.wikipedia.org/wiki/Program_state , http://en.wikipedia.org/wiki/Finite_state_machine , http://en.wikipedia.org/wiki/State_diagram A diagram showing a very easy example, notice how the current state changes how the turnstile operates when the same input (inserting ...
This morning I found a note on my desk with some tips from a higher up developer who had been looking over some HTML/CSS I had put together. One of his suggestions was for me to "stay away from context-based class and ID names like 'left' or 'right.' Never use colors as names. Stick to semantic names based on the conte...
I'm a Rails developer and I prefer Mercurial over Git. However, I know that the Rails community is very pro-Git. So my question is it possible that my choice of version control system would turn back some developers?
I'm writing a Genetic Program that I need some advice on for crossover operations. The GP is attempting to find the best solution for a matrix that has hard row constraints and softer column constraints. For a given solution in the population, the rows contain a random combination of object type ids from a fixed set. T...
I have many classes in my application responsible for behaviour- views, controllers, models, network- often the state of one class or system depends on another and I'm finding that classes that are primarily responsible for the behaviour for one system inevitably become dependees or dependers of other systems or classe...
It occurs to me that there's not a heck of a lot of difference between $>python module.py And: $>javac module.java $>java module.class The former compiles to an intermediate language (python bytecode) and executes the program. The latter breaks the steps up, first compiling to the intermediate language (jvm bytecode) ...
From Less is Exponentially More If C++ and Java are about type hierarchies and the taxonomy of types, Go is about composition.
I found a question (code cowboy on the team), but it was more related to "Ninja Coder" then the problem that I have. I have a team member who is a pure living example of "Cowboy Coder". I do understand that one can't change people, but is a way to make him stop behaving like a "Cowboy Coder"? He refuses to listen to ...
I have always found it more logic to validate input instead of filtering it. How to appropriately filter data depends on the situation, so IMO it should be done in output or when saving to a database. But I see that some frameworks provide automatic XSS filters for incoming POST and GET data. What is the logic behind t...
Is it possible to write an open source project that uses generated code from CodeSynthesis XSD (C++/Tree) and then link it to a third-party library that is licensed under the GPL version 3? Some background information: CodeSynthesis XSD is licensed under the GPL version 2 but with an extra FLOSS exception (http://www.c...
So I read up on the ordering of your includes, and this guy suggested you include your local header first so as to make sure it doesn't have prerequisites. Ok, I get that. I'm on board. The whole compartmentalization thing is good. But I've got this file, file.c which includes it's file.h, which declares functions to ...
In the PEAR standards there is no reference to HTML, if its allowed or not. http://pear.php.net/manual/en/standards.sample.php But I see some people use HTML tags like <kbd> and stuff.. So is HTML allowed? Will it break some doc parsers?
We're working on a large product which has been in production for about 5 years. The codebase is.. erm.. working. Not really well but it is working. New features are thrown into production and tested with a small QA. Bugs are fixed, etc. But no one, except me, is writing unit-tests. No one uses the power of "tracking" ...
I'm making an iPad app that will display a few choices and based on your choice will display a series of questions with each question triggering a different set of questions. I was wondering if there was a name for this or any open-source library that someone has made for this kind of app. If not, would it be best to h...
I'm not trained programmer, so be gentle with my ignorance. I'm trying to search changelog files for where an open source project dropped a feature I need. I was just wondering if there may be a good set of terms to describe this. Bugzilla has detailed bug reporting forms. Are design changes also logged using rigorous...
I realize the above question probably raises a few 'what??'s, but let me try to explain : I'm trying to wrap my head on a couple of related concepts, basically the Saga-pattern ( http://www.rgoarchitects.com/Files/SOAPatterns/Saga.pdf) in combination with Event-sourcing (A DDD-concept: http://en.wikipedia.org/wiki/Doma...
I'm implementing a machine learning structure to try and predict fraud on financial systems like banks, etc... This means that there is a lot of different data that can be used to train the model eg. card number, card holder name, amount, country, etc... I'm having trouble deciding which structure is the best for this ...
In my company, I'm the only developer, but we plan on expanding the team by hiring a second programmer. I know there are a lot of implications to that (especially around source control). I've Googled a lot, but haven't found a good tutorial/article on how to grow the team from one to many developers. Do you have any r...
Initially I started learning OOP and later started grasping concepts of Design Patterns. I wonder whether it is the Design Pattern which is the SuperSet of OOP or it is the OOP itself.
TL;DR Writing good, useful tests is hard, and has a high cost in C++. Can you experienced developers share your rationale on what and when to test? Long story I used to do test-driven development, my whole team in fact, but it didn't work well for us. We have many tests, but they never seem to cover the cases where we ...
we have some API which will be called either by client A, B, C or D Current code doSomething(String client){ if (client.equals("A")){ ... } else if (client.equals("B")){ ... } Proposed refactoring 1 separate into multiple methods and have each client call the dedicated method such as doSomethingForClientA() doSometh...
I am successfully able to scale all my old applications which were not using documented Design Patterns. Whatever pattern it is I don't know. To a large extent, I only felt a need to use simple OOP concepts. The Design Patterns concept is complex and hard to understand. When implemented, how to determine whether the i...
In many languages, the substring function works like this: substring(startIndex, endIndex) returns the substring from startIndex until endIndex-1 (if you view startIndex and endIndex as 0-based) / from startIndex+1 to endIndex (1-based) This is confusing. I understand that the two parameters can be interpreted as "star...
I know that default arguments are created at the function initialisation time and not every time the function is called. See the following code: def ook (item, lst=[]): lst.append(item) print 'ook', lst def eek (item, lst=None): if lst is None: lst = [] lst.append(item) print 'eek', lst max = 3 f...
I've been working with the XMLHttpRequest object in JavaScript recently, and I couldn't help but notice that the casing of this name makes no sense. Why is 'XML' all in caps while 'Http' is not? They're both acronyms! Surely it'd make more sense for the name to be one of the following: XmlHttpRequest (PascalCase, be...
I am currently writing a grammar for a programming language (PowerBuilder) and I am also collecting documentation about parsing and compilers creation. Now I would like to add in my grammar (that looks roughly like Visual Basic) the possibility to handle embedded SQL statements that are supported inline by the languag...
At first, hopefully following terms project and product won't be confused. Traditionally, we used to have a code base, which usually was a main project. For our products, we created one project for each product, and these projects surly depended on main project (code base). When product was released, we created relea...
I'm studying YAML as a replacement for XML, but I'm experiencing difficulties when dealing with elements containing free-flowing text with embedded elements. For instance, the following XML document: <text> This is an example text, spanning multiple lines, and it has embedded elements like <a p="value">thi...
I have seen this article: CSS3 Loading elements at HTML5 and CSS3 Tutorials pages. How did someone made this calculations? what angle, how much space, how much rotation to give? If I do it with hand, starting number one, I fear it takes too long as a process to complete. Is there some tool, or some trick that do this ...
I want to know what is considered better way of returning when I have if statement. Example 1: public bool MyFunction() { // Get some string for this example string myString = GetString(); if (myString == null) { return false; } else { myString = "Name " + myString; // Do somethi...
As I'm trying to get better at designing good software I'm wondering if there are out there good (as in well written) open source software with lot of code documentation that aims to explain details about why this or that design choice was made in the context of that specific problem set. I'm interested in OOP and I do...
When I started learning programming with the .NET framework, I started by using WinForms as a UI technology. It uses “classic” menus just like this office 2000: A few years later Office 2007 was released, the ribbon was born: And even some years later Office 2010 was released, which also added new features like the s...
I'm learning Clojure to see if it's something I can leverage at my current job, and more importantly, how I can convince my bosses that Clojure has a 'killer feature' over java that makes it worth the investment1. The feature that I'm guessing most clojure evangelists would tout is state management and concurrency. The...
From time to time I've encountered scenarios where several complex conditions need to be met prior to triggering an event. Furthermore, most listeners also run additional checks to determine the course of action. This got me thinking whether a better solution would be to think in terms of smaller events and let them tr...
In c++, the * operator can be overloaded, such as with an iterator, but the arrow (->) (.*) operator does not work with classes that overload the * operator. I imagine that the preprocessor could easily replace all instances of -> with (*left).right, and that would make iterators nicer to implement. is there a practica...
I am writing a utility that runs on RHEL5 command line. I need my command line options to be simple but powerful. I looked at the various UNIX utilities to get an idea of how simple command line utilities have to be. Do you guys suggest any documents/links that talk about command line etiquette? I am modelling my util...
Its very interesting for me which advantages gives "global root class" approach for framework. In simple words what reasons resulted the .NET framework was designed to have one root object class with general functionality suitable for all classes. Nowadays we are designing new framework for internal use (the framework...
I was going through this heavily discussed and highly voted question on SO and stumbled across one comment that got 5 upvotes. So I assume this was a great comment.But it got my head spinning at the same time. Can any one explain this comment? The comment says: You can't compare big-O values directly without thinking ...
I want to split poker pot to chips. Example: Pot = $17.500. I have the endless piles of chips. I have the following types of chips: ChipsTypes = [$1, $5, $10, $25, $100, $500, $1.000, $5.000, $10.000, and so on]. Index starts from 0. I want to get an array that says which chips I have to take to divide the pot and in w...
I am currently adding some functionality to a popular open source project. It written in C and in Every file GPL license text is embedded. The functionality I am adding is not supported by the project. So you can say its some sort of extending. My code gets compiled when the main project is compiled. My code is inside...
I'm designing a tiered .NET application, and I want to use the Code First approach. I'm new to this, so I'm struggling to envision how it ought to be designed. Would the following be a reasonable approach? What problems or limitations might I run into? Write DTO classes for my domain. These will be used for data t...
Is the ISC license suitable as a MIT or Simplified BSD license replacement? What are the pros and cons of ISC compared to MIT or BSD?
My company is exploring the move from Perforce to a DVCS and we currently use lots of Perforce proxies because the software development teams are spread over Germany, China, USA and Mexico and sometimes bandwidth from one place to another is not that great. Speaking with IT, we started looking for a way to keep things ...
I recently encountered a situation in our codebase where a different team created a 'god class' containing around 800 methods, split across 135 files as a partial class. I asked the other team about this. While my gut reaction was to nuke it from orbit, they insist that it's a good design, a common practice, and that ...
My service has a large ongoing number of user events, and we would like to do things like "count occurrence of event type T since date D." We are trying to make two basic decisions: What to store? Storing every event vs. only storing aggregates (Event log style) log every event and count them later, vs. (Time-series...
My team is currently locked into using a tool we dislike that takes the form of a Eclipse plugin and a .jar; the plugin gives us a button to quickly run a single file's code (via invoking the main .jar and passing to it the current file). We want to move to C#.net. Is there any way to get Visual Studio to replicate th...
In PHP you can have a function take an infinite number of arguments like /** * Do abc... * * @since 1.0 * @param mixed $arg1 Arg description * @return string Results */ function abc($arg1 = null){ $args = func_get_args(); // do smth with $args } How should I illustrate thi...
I am creating a software package that will be useful to programmers, engineers and scientists. List price will be in the region of $1,000 -- way beyond the budget of most open-source developers, hobbyists and enthusiasts. So I am considering two things, the first generous, the second maybe a little greedy: Offering ...
I'm a python programmer who sees a lot of C++ code but doesn't know the language and there seems to be two ways to initalize a class. I was hoping that someone can tell me the difference. class Point { int x, y; public: int get_x(); int get_y(); Point(int, int); } // ok we are goin...
Is it normal and still proper (in agile/SCRUM-based software development) for a product owner to be in charge of more than one product?
I'm basically trying to wrap my head around the concept of CQRS and related concepts. Although CQRS doesn't necessarily incorporate Messaging and Event Sourcing it seems to be a good combination (as can be seen with a lot of examples / blogposts combining these concepts ) Given a use-case for a state change for somethi...
Part of the FSF's instructions for placing a program under the GPL is including the following "copying permission statement" at the top of your file, under the copyright notice: This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the ...
This blogpost was posted on Hacker News with several upvotes. Coming from C++, most of these examples seem to go against what I've been taught. Such as example #2: Bad: def check_for_overheating(system_monitor) if system_monitor.temperature > 100 system_monitor.sound_alarms end end versus good: system_monitor....
currently, we have a closed source project on hand. However, we would like to have a communication channel together with our end users. We would like to have our end users to know, what features we are currently working on, and what features they are going to get in next release. We would like to know users' thought, ...
I'd like to find a way to write an API that can be accessed from any other programming language via language bindings (or some other framework). Is it possible to do this? If so, which programming language would be the most suitable for writing a "cross-language" API? My goal is to create a single set of functions that...
My team has been developing a web business application for more than a year. It started quite small, but now it is growing bigger and bigger. I think it's time for refactoring. Looking at the code, I see the below situation: IUserService addUser deleteUser updateUser addMember deleteMember updateMember registerMember ...
I am lucky in the sense that I have been given the opportunity to be a 'Technical Troubleshooter' for our offshore development team. While I am confident and capable of dealing with most issues, I have come across something that I am not. Based on initial discussions with various team members both on and offshore, a re...
I can't figure out what would be an appropriate data structure for my problem. I need to write a script that will count some events. Input is a list of events (thousands of them). Each event is an object with following attributes: class Event company city office department You can look at it like this: „Each e...
I often read/overhear that good commit messages should be written in present tense or to use imperative mood when describing the change eg. Fix xyz instead of Fixed xyz. What are the advantages of doing so? Are there differences between the various VCS (I mostly read these about git but that maybe because I mainly work...
I'm in the process of coding a game and almost done with the game mechanics to the point where it's pretty playable. I later discovered an open source version of the kind of game I'm making with the same mechanics, whereas I coded mine from scratch. However, in the interest of optimizing later on, I may want to adapt a...
I was doing my ER diagram for a rails application I'm about to begin with and there I have an entity called Class News so I'd have a model ClassNew but I don't know if I will have problems in the future with the New part or what would be the right way to do this o how should I call the model? since the right thing woul...
You can indicate that XXX is method name by writing XXX(). But in Objective-C, you can not write XXX() for XXX method. If you write XXX, you can't tell if XXX is method name or other type of identifier. How can you indicate that XXX is method name of Objective-C class? EDIT Method call of Objective-C is different from ...
I would have this asked on StackOverflow if it had code, but it's more on the idea/concept so I asked here. I am working on the UI of our inventory system when I found out that when registering a user in the system, the username and password of the user is optional. I asked our supervisor why is this so. He said that i...
Ok, I have used the word python in the question, but it well could be language agnostic in that: If a language X has a well optimised compiler targeting assembly and an OS is written in that language, then will it compete favorably with C in benchmarks? This comes from two conceptions I have (could be wrong): Langua...
If we have a large development team, say 100, and we would like to keep our encryption key hidden from developers who are not directly involved in the encryption module/algorithm, what are some best practices to keep this key as secret as possible while still allowing for development and debugging?
Consider a logging system - used absolutely everywhere in your codebase. (note - logging is just an example, don't take it too literally and point me at your favourite logging system). public interface ILogger { void LogMessage(string message); } // Just used for testing, do nothing public class NullLogger : ILogg...
I am tasked with building a piece of software that interfaces with a MySQL database, in order to allow the user to pick songs to play and que using a touch screen, and then they are shown simultaneously on a second monitor as videos. Questions: To allow both displays to work, would it be best to write two pieces of...
I'm working on some project where I have to make a database to store data which is currently kept in Excel files, so I have to do some changes before writing the data into the database. I'm going to read those files using Java and write them from Java into the database. Should I use Hibernate for that job? Or how else...
I'm trying to find a way to write an application with lock-free IPC on Linux, in C, with multi-core processors. Let's assume I have process 1 and process 2 that write to a FIFO or shared memory. Then process 3 and process 4 will read from that shared memory or FIFO. Is this possible with a lock-free algorithm? Your gui...
I've only worked at once place since graduating my CS degree. This is a pretty basic architecture question but i don't know any better since i've only worked at one place. Where i work we maintain a large number of code tables. For example say you have a Sales/Order system and you have an Order Status. We would maintai...
So this is the first time I am trying to work with an Open Source Project. I created a Code Plex Account browsed for a project that I thought I might become a part of. I sent a request to join the project.The project head accepted my request. I have already downloaded the source code of the project. Can some one just s...
I am exposing a few REST methods on a server for an mobile app. I would like to avoid that users can sniff how HTTP methods are built (from the mobile app) and then send them again to the server. Example : The mobile app send a request The user uses a proxy and can check what's going on on the network The user see...
Clojure does not perform tail call optimization on its own: when you have a tail recursive function and you want to have it optimized, you have to use the special form recur. Similarly, if you have two mutually recursive functions, you can optimize them only by using trampoline. The Scala compiler is able to perform TC...
I've been making small improvements to a public ASP.NET site that I have and have ran it through Google's online Page Speed several times. I have a specific problem, but something that really threw me off was that even if I didn't make any changes and just kept running it time after time (5 minutes intervals) I'd keep ...
The following is from the preface of Jon Resig's new book : Secrets of JavaScript Ninjas The portions of this book that cover features that are relatively un-changing, such as code evaluation, with statements, and timers are continually being used in interesting ways. There are now a number of active programming lang...
I'm making an indexOfReverse utility function in my C++ program, and I have caught a bit of a snag. Implementing the offset and maxOffset in my indexOf was very intuitive to me.. These start from the beginning of the string (+offset), and go forth to the end of the string (or maxOffset if given). While implementing off...
So In my app (iOS), you have to register in order to use the service (a food service). But in order to change details about your account (username, password, and email), you have to reenter your password. Except for if the user logged out, this is the only time you need your password to use the app. So I was wonderi...
Many a times I have to deal with code files which are quite long - about 5 screen pages at the minimum. Almost always there is something towards the top/bottom that I need to refer when I'm at the bottom/top (respectively). It's a mammoth overhead to constantly scroll back-n-forth between the file parts. It's a cognit...
When you download and install asp.net MVC, does it just add code to the .net framework class library? Or does it also modify the installed Visual Studio editions? Another question: If it is just adding code to the .net framework class library, why can it not be installed on top of .net 2.0?
I have lots of ideas for products to be built. The problem is that I have less than a year of professional work experience and I am afraid of getting judged negatively in the future based on what I produce now. I have no clue if my code is any good. I am not familiar with any of the coding patterns. All I know is to bu...
Is it better to use multiple html pages and link them together with href or just change content on the same page using JavaScript? I am thinking of how to layout a page and I don't have a lot of content. It would probably be about three of for pages if I just used all html. If I toggled and swapped bits of html around ...
I started learning arrays in C++ and came over a little side note in the book talking about 2D arrays in breif. I tested it out and i was amazed that it could give the programmer the ability to store data or information and lay it out infront of him in a spread sheet format. In a normal array to access elements i would...
I was asked this question in an interview. I'm somehow supposed to "read" a file into my C program as input without using a file pointer (including "f" functions, e.g. fgets, fscanf etc.). I'm also not allowed to redirect it using the terminal, i.e. no system or exec calls. The program will not get the file during runt...
On my way to learn Lisp I have discovered the all powerful and feared so called Macros, then after spending a hard time trying to understand them and their usefulness I said to myself, I FINALLY GOT IT. I couldn't be more wrong, I was thinking that the only purpose of Macros was to define new control structures and tha...
I've always used git before, but I want to contribute to python so now I have to learn mercurial and I find it very frustrating. So, I've made a couple of small patches and I wanted to track them as commits in my local mercurial repository. Apparently there are 4 ways to handle branching in mercurial. 1 and 4 looked co...
I am looking at some C/C++ code that appears to have functions that are defined, but never used. This is a pretty tedious process to trace through the code and verify. I've done some surveys and there are a number of tools that can do this type of analysis. Can anyone share any experiences or tips on which tools and te...
I'm working on an application which will run on multiple Amazon EC2 instances. I wish to incorporate auto update feature for my application. The updater should update all the Ec2 instances. Also, there is a central server which governs the creation/termination of EC2 instances as per load. The central server creates a ...
Well, I am reading Programing Windows with MFC, and I came across Unicode and ASCII code characters. I understood the point of using Unicode over ASCII, but what I do not get is how and why is it important to use 8bit/16bit/32bit character? What good does it do to the system? How does the processing of the operating s...
We already have a fully operational web service which caters requests from multiple paltform devices. Each device sends only one request at a time and immediately after a response for the request the device sends an applicative ACK, this ack message is like a regular request message, and it's all via http. During a pe...
My development on Android is based on scientific programs and while I'm building these most of the code is in one or two long classes. When I come to deploy these programs I try to decouple everything and use classes and objects like I would on a Java desktop application. However reading guide Designing for Performanc...
I am using Java. How does an event source like a (button in a GUI) knows which method to call in an interface? For example, I am listening to Mouse Events and have implemented a Mouse Listener interface in my class then how would the event source know whether it should call mousePressed(), mouseReleased() or some other...
I currently developing some M2M-transformations with the Atlas Transformation Language (ATL). During studying the language constructs and properties I have often read, that ATL is a prototype for QVT, but was not used for QVT. This leads me to the question, if ATL is a deprecated language. Personally, I claim that ATL ...