# All Questions

61,560 questions
Filter by
Sorted by
Tagged with
2k views

### Composition or Private Inheritance for Implementing Builder?

Over on StackOverflow, I was asked if I could come up with an example where private inheritance would be preferred to composition (in C++). The following is the situation I described, and I was ...
805 views

### Tetris clone in Java

I have a representation for each initial shape as an Enum with points and another for each rotated shape in the same Enum. Here ...
563 views

### JavaScript closure: code trivia to keep the event handler separate

Note: This was originally posted at SO, and as per the recommendation moving to this form. In my effort to learn JS on the backdrop of SVG development, I got lot of help from SO so far. The answer ...
3k views

### Is this architecture overly complex or following best practices?

I work as a C# developer at a company that doesn't use best practices at all. We're on .NET 3.5 but most code is written in a .NET 1.1 style (e.g. almost all the logic is in the code behind of the ...
466 views

### Open database and hande errors

How to make this code better? ...
853 views

### INI File Parser in Haskell

I'm learning Haskell at the moment, and have just written my first useful module - a parser fo INI files. I used Parsec. I'd like to know what can be improved here - or maybe I did some things ...
276 views

### Iterate comparison - How can I write this better?

I would like to write the following piece of code cleaner and more efficient, any comments will be greatly appreciated: ...
1k views

237 views

### Refactor a subroutine that divides date range into quarters.

The subroutine below, GetDetailsQuarterly, accepts two dates. Then it writes out each quarter that falls within the date range. It also gives the first and last day of the quarter. I really don't like ...
1k views

### C++ template meta sql

I wrote a wrapper around boost-mpl and transformed it to an sql engine. It is a compile time sql thing, not related to normal databases. I have not finished it completely. I have some problem with the ...
5k views

### Optimizing the reading of web.config

Here's the issue. When I build an asp.net application I create a singleton to read the values from the web.config file so that the values are only read once and gives a slight speed increase to the ...
262 views

### Preparing interpreter for error-handling

This is a follow-up to the question that I posted earlier regarding my interpreter. After a lot of help, I refactored my code and added more functionality to it. Now, it allows users to declare ...
7k views

I have a WCF client which passes Self-Tracking Entities to a WPF application built with MVVM. The application itself has a dynamic interface. Users can select which objects they want visible in their ...
1k views

### Haskell - Different log methods

I'm pretty new to Haskell and was playing around with some number manipulation in different bases when I had to write an integer logarithm function for my task. I don't mean discrete/modular logs, ...
285 views

### Best syntax for executing an action between each loop iteration.

The question of the cleanest way to write a loop that executes some action between each iteration has always interested me. In a sense, what is the best way in c/c++ to implement this fictional ...
1k views

### jQuery Delay slideDown using Queue

I have the task to create a function that adds some messages to the page and another to show them in last to first order with a jQuery slideDown() effect. jsFiddle ...
1k views

### Reading a collection of strings from the user

I was trying to write a program that will read a collection of strings from the user, and then end the moment it encounters a ".". So then I write a ...
5k views

### Is this a decent way of writing a start-stop-daemon script?

This is the first time I've written a start-stop-daemon script, so I would love some feedback. :) The goal is to have it start late, when the network and everything is ready. I also have 2 other start-...
2k views

### Generating very large prime numbers and their generator modulo N in php

I recently came up with the idea to attempt generating ungodly large prime numbers and their generators modulo N in php. I don't know much about number theory and just wanted to get some comments to ...
312 views

### shorthand methods

Is it good or bad practice (or, when is it appropriate) to use shorthand methods? Lets pretend we're using jQuery here, because it has a lot of them.: ...
12k views

### Polish notation interpreter/calculator

Just for the heck of it, I wrote a simple little interpreter that takes in inputs in the form of Polish Notation. The user will input something like + 5 6 And ...
4k views

### Becoming root from Python

In order to avoid the user having to explicitly prefix a script with sudo or su --command, I wrote the following: ...
701 views

### Merge sort and selection sort comparison taking too long

I have this python code that compares merge sort and selection sort, but it is taking "forever." ...
5k views

### Is this a reasonable Trie implementation?

http://en.wikipedia.org/wiki/Trie The basic idea is to support fast searches via prefix matching. In my implementation, I allow each node to store all of the words that match its given prefix, and ...
2k views

### single array or many single argument to call a constructor with params?

I am seeing it more and more. Which do you think works best and why? This: $config = array( 'param1'=>'abc' 'param2'=>'dfg' ); new Class($config); Or: <...
231 views

### Wrapper for dynamic behavior

I am writing a wrapper for dynamic behavior in C#. If I use GetMethod(), then an exception is thrown when there is more than one method (overloads). I figure it ...
2k views

### My own C++ Format function

I've never been satisfied with any of the possible sprintf()-like functions in C++: sprintf() is a C function and it's very ...
1k views

### PowerShell module for formatting objects using Razor

I managed to get something up and running, but I've no idea whether there are better ways to do this. I've spent all morning trying to figure out the best way to use parameters (allowing objects from ...
1k views

### PHP Table generation

I have been using the following function (in the kohana html class in a table) to generate tables. ...
2k views

### Change upper or lowercase vowels to [0,1,2,3,4] respectively and leave the rest the same

The objective was the following to be solved in Python: Given a string, def a function that returns another string with the vowels (upper or lowercase) replaced by 0,1,2,3,4 respectively. ...
500 views

### Find the Hardy–Ramanujan number using R5RS scheme

I remember once going to see [Srinivasa Ramanujan] when he was ill at Putney. I had ridden in taxi cab number 1729 and remarked that the number seemed to me rather a dull one, and that I hoped it was ...
1k views

### Days of life calculator for first-year mathematics students

I'm giving a lecture on basic programming to first-year mathematics students. The programming language is Java (defined by curriculum). Last week I gave the following task: Write a program, that ...
12k views

### Looping through a collection

In the situation where I am looping through a collection looking for an item, is it better practice to break before I return or ...
579 views

### User php class. Should I connect to DB in this class?

I have small Class which handles user's information. (name, surname, login, hash of password). Also this class can activate, register and login the user. This means I should connect to DB. Is it ...
658 views

### Managing part types and counts

Both functions look fairly similar to each other, but they are different in the type of string. I have 6 functions like this and all differ only in the "string cmd". Any ideas on how I can put it all ...
1k views

### Performance optimization for Linq To SQL

I have been working with C# for quite some time but relatively new to the concepts of lambdas and Linq. I was working with a Linq To SQL example and trying to write a generic solution for executing a ...
907 views

### CSV module in Ruby

I finished the Ruby chapter in Seven Languages in Seven Weeks. It tries to make you familiar with the core concepts of several languages rather quickly. Dutifully I did all exercises, but most likely ...
1k views

### Custom grep in Ruby

I finished the Ruby chapter in Seven Languages in Seven Weeks. It tries to make you familiar with the core concepts of several languages rather quickly. Dutifully I did all exercises, but most likely ...
1k views

In this post I asked about what would be idiomatic haskell database abstraction. I had been thinking for it a while, and the first answer was similar to what I had in mind, and I wrote a proof-of-...
541 views

### Simple octal reader macro in Common Lisp

As an exercise, I've implemented a simple reader macro in Common Lisp (using SBCL). It converts Octal (unsigned integers only) into numbers. Usage: * #z1234 668 ...
1k views

### Higher lower game in Ruby

I finished the Ruby chapter in Seven Languages in Seven Weeks. It tries to make you familiar with the core concepts of several languages rather quickly. Dutifully I did all exercises, but most likely ...
812 views

### Making a job completed, rolling back on error

I have the following construction in the program: ...
1k views

### PHP Output Block Defining and Best Practices

I've been rolling around several ideas or approaches in my head, and none seem any more useful or "right" than another. I'm sure this is extremely objective but I'm looking for a close-to-definitive ...
401 views

### Coercion with multiple arguments

From SICP: Exercise 2.82 Show how to generalize apply-generic to handle coercion in the general case of multiple arguments. One strategy is to attempt to coerce all the arguments to ...
682 views

### Parsing random phrases from a file

This essentially reads a specially-structured file from the scanner and then parses random phrases and prints them: ...
4k views

### Rock Papers Scissors in Python

I am a newbie to Python and have started object-oriented programming recently. I have implemented a "Rock Paper Scissors" application in OOP. I would like for you to evaluate my code, and tell me ...
1k views

I'm currently using an Open Source FTP library in all my projects as I've never managed to code a decent FTP Helper Library based on the C# 4.0 API. What do you think about this approach? I'm not ...
224 views

### Have I gone too far in factoring out repeated code in this example?

In a controller (PHP, CodeIgniter) I'm adding scripts & css to variables to be used in the view output. My initial coding looked like this: ...