All Questions

Filter by
Sorted by
Tagged with
8
votes
2answers
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 ...
6
votes
3answers
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 ...
4
votes
2answers
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 ...
5
votes
4answers
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 ...
3
votes
2answers
466 views

Open database and hande errors

How to make this code better? ...
6
votes
2answers
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 ...
2
votes
2answers
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: ...
5
votes
1answer
1k views

Return Dictionary object having key/value pair of keywords and URLs

Can you please help me split this method to reuse the repeating code? Any advice/comments on the code are welcome. ...
3
votes
1answer
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 ...
4
votes
1answer
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 ...
5
votes
1answer
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 ...
4
votes
2answers
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 ...
15
votes
1answer
7k views

What is better for Lazy-Loading Navigation Properties of detached Self-Tracking Entities through a WCF service?

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 ...
5
votes
1answer
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, ...
3
votes
2answers
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 ...
3
votes
2answers
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 ...
22
votes
5answers
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 ...
5
votes
1answer
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-...
8
votes
3answers
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 ...
5
votes
2answers
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.: ...
6
votes
4answers
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 ...
7
votes
1answer
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: ...
7
votes
1answer
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." ...
4
votes
2answers
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 ...
4
votes
5answers
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: <...
4
votes
1answer
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 ...
11
votes
3answers
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 ...
14
votes
0answers
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 ...
6
votes
3answers
1k views

PHP Table generation

I have been using the following function (in the kohana html class in a table) to generate tables. ...
10
votes
4answers
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. ...
7
votes
1answer
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 ...
3
votes
4answers
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 ...
14
votes
10answers
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 ...
4
votes
1answer
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 ...
7
votes
4answers
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 ...
6
votes
3answers
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 ...
5
votes
1answer
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 ...
8
votes
1answer
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 ...
8
votes
1answer
1k views

Idiomatic haskell database connectivity

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-...
2
votes
1answer
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 ...
7
votes
2answers
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 ...
4
votes
3answers
812 views

Making a job completed, rolling back on error

I have the following construction in the program: ...
2
votes
2answers
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 ...
2
votes
0answers
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 ...
4
votes
1answer
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: ...
11
votes
7answers
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 ...
10
votes
3answers
1k views

FTP Download Helper Method

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 ...
1
vote
1answer
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: ...
7
votes
2answers
32k views

Is there a better way to search directories for a file or files?

Edit: The purpose of this method is to search a specific directory for a given file type, ex. (*.txt, *.pdb, *.exe") then move the file(s) to a given destination directory and delete the original ...
3
votes
2answers
622 views

PHP and Custom Functions

I am new to the world of coding as well as XHTML and PHP. As a way to gain more experience as well as to put theory into practice including a way to challenge myself, I put together the following code ...

15 30 50 per page