methods

When to use method overloads VS "request" object

What is the best "rule of thumb" to determine when to use method overloads and when to use a separate "request" class? for example: MakePancakes(int size) MakePancakes(int size, bool addBlueBerries) MakePancakes(int size, bool addBlueBerries, ...) As opposed to: MakePancakes(PancakeOptions options) Is it best to stick to one way o...

Response.Redirect vs. Server.Transfer

Which is better, Response.Redirect or Server.Transfer in ASP.NET ? ...

Should I Use a Method with Parameters or a Function?

I've got a philosophical programming problem. Let's say I have a class named Employees. Employees has business members that get set from a dataTable. In order to fill this, I use a method that takes an instance of the employee class, loops through a dataTable, and sets the members of the instance passed into it. For instance: public...

Passing a method as a parameter in Ruby

I am trying to mess around a little bit with Ruby. Therefor I try to implement the algorithms (given in Python) from the book "Programming Collective Intelligence" Ruby. In chapter 8 the author passes a method a as parameter. This seems to work in Python but not in Ruby. I have here the method def gaussian(dist, sigma=10.0) foo end ...

How to call upon a gameOver method in a Java game when sprite "falls off" the screen?

I am developing a simple platform game in Java using BlueJ. Over the next few weeks I will be posting a few questions asking for help with this project as am not very proficient at programming. So I hope I don't become annoying and I would be very grateful if you can kindly help me. In my game I have a gameOver method which ends the ga...

How can I tell which class methods aren't being used?

Over time I tend to create methods that are no longer useful to me. I think I have moved all my code away from them but maybe not. Or, maybe the code references the old method and everything works fine until I hit that special thing that made me create a new method. Is there anyway besides just using find on each method, to see what i...

How do you build a web-based RSS reader that doesn't mess up reader statistics for blog authors?

My company is starting work on building a web-based RSS reader that users can sign up to and track feeds; a lot like Google Reader. My first thought was that once I have a feed URL for a certain blog or website, I'd only have to poll it once in order to grab the content and then insert entries into the database for anyone who subscribes...

Is a function an example of encapsulation?

By putting functionality into a function, does that alone constitute an example of encapsulation or do you need to use objects to have encapsulation? I'm trying to understand the concept of encapsulation. What I thought was if I go from something like this: n = n + 1 which is executed out in the wild as part of a big body of code and ...

Do well thought out method/function names create a DSL?

I was thinking, method names and their calls seem to create a DSL in your code, by wrapping up the generic stuff and naming it appropriately for what you're trying to achieve. You know, so it's easy to reason about what the following means if (a.isSubReportOf(b) || b.isSubReportOf(a)) { // do stuff } but the code in the methods m...

Do methods affect the size of my objects?

In .NET, do the number of methods or the size of the methods (i.e., amount of code) within an object affect the amount of memory the object uses when it is instantiated? EXAMPLE: Will an object with 3 int properties and 1 method take up more memory than an object with 3 int properties and 20 methods? If "yes", do static methods take u...

Java - static methods best practices

Let's say I have a class designed to be instantiated. I have several private "helper" methods inside the class that do not require access to any of the class members, and operate solely on their arguments, returning a result. public class Example { private Something member; public double compute() { double total = 0; ...

Optimize MySQL search process

Here is the scenario 1. I have a table called "items", inside the table has 2 columns, e. g. item_id and item_name. I store my data in this way: item_id | item_name Ss001 | Shirt1 Sb002 | Shirt2 Tb001 | TShirt1 Tm002 | TShirt2 ... etc, i store in this way: first letter is the code for clothes, i.e S for shirt, T for tshi...

C++ std::map of template-class values

Hi everyone, I'm attempting to declare a Row and a Column class, with the Row having a private std::map with values pointing to a templated Column. Something like this: template <typename T> class DataType { private: T type; }; template <typename T> class Field { private: T value; DataType<T> value; }; class Row { pri...

Javascript - check if method prototype has been changed?

What's the best method to check if the protoype of a method has been changed? ...

How do I intercept a method invocation with standard java features (no AspectJ etc)?

I want to intercept all method invocations to some class MyClass to be able to react on some setter-invocations. I tried to use dynamic proxies, but as far as I know, this only works for classes implementing some interface. But MyClass does not have such an interface. Is there any other way, besides implementing a wrapper class, that d...

Transactions in C#

Hi, In addition to this question: http://stackoverflow.com/questions/577080/preorder-tree-traversal-copy-folder I was wondering if it is possible to create a transaction that contains different calls to the database. ex: public bool CopyNode(int nodeId, int parentNode) { // Begin transaction. try { Method1(nodeId); Meth...

Different methods to use a class/struct - C++

struct Foo { void SayHello() { std::cout << "Hi, I am Foo"; } }; I have the above given struct. I have seen a usage like this in one of our code base. Foo foo; { foo.SayHello(); } IMO, It does same like Foo foo; foo.SayHello(); Or is there any advantage/difference for the first method? Any thoughts? ...

Javascript: better way to add dynamic methods?

I'm wondering if there's a better way to add dynamic methods to an existing object. Basically, I am trying to assemble new methods dynamically and then append them to an existing function. This demo code works. builder = function(fn, methods){ //method builder for(p in methods){ method = 'fn.' + p + '=' + methods[p]; eval(method...

How to search for all methods in a project that return implementation of Collection interface?

I've been reading Josh Bloch's 'Effective Java 2nd Edition'. Item 43 states 'Return empty arrays or collections, not nulls'. My question is how can I search for all methods in a project that return an implementation of java.util.Collection interface? IDE that is used is Eclipse, but any way of finding the right result is acceptable, e.g....

Method Overloading Cost In .Net

Is there a cost associated with overloading methods in .Net? So if I have 3 methods like: Calculate (int) Calculate (float) Calculate (double) and these methods are called at runtime "dynamically" based on what's passed to the Calculate method, what would be the cost of this overload resolution? Alternatively I could have a single C...