methods

Should C# methods that *can* be static be static?

Should C# methods that can be static be static? We were discussing this today and I'm kind of on the fence. Imagine you have a long method that you refactor a few lines out of. The new method probably takes a few local variables from the parent method and returns a value. This means it could be static. The question is: should it be sta...

Static methods in Python?

Is it possible to have static methods in Python so I can call them without initializing a class, like: ClassName.StaticMethod ( ) ...

Call external (i.e. interface) functions also internally?

I am wondering if it is good practice to call public functions also internally. By public functions I mean all methods/functions that you created explicitly to be called from other objects, modules, etc. For example methods that you would typically put in a Java interface definition. By calling internally, I mean in the same module, cl...

Passing an Array as Arguments, not an Array, in PHP

I seem to remember that in PHP there is a way to pass an array as a list of arguments for a function, dereferencing the array into the standard func($arg1, $arg2) manner. But now I'm lost on how to do it. I recall the manner of passing by reference, how to "glob" incoming parameters ... but not how to de-list the array into a list of a...

return key word in a void method in java?

Hi all. Looking a path finding tutorial here (http://www.cokeandcode.com/pathfinding) which i was linked to from SO :) good work people. Working in integrating the code into my game, and i noticed a "return;" line inside a void method. class is PathTest on website, line 130. I know im a novice at java, but can anyone tell me why its th...

Quick way to insert interface methods to a class in Visual Studio 2005

I know that in Eclipse, if your class implements an interface or extends an abstract class, there is a quick way to add the method definitions to your class. Can this be done with VS2005? How? ...

override java final methods via reflection or other means?

This question arise while trying to write test cases. Foo is a class within the framework library which I dont have source access to. public class Foo{ public final Object getX(){ ... } } my applications will public class Bar extends Foo{ public int process(){ Object value = getX(); ... } } The unit test case is ...

Unable to find documentation for a line in JavaScript

The code which I am analysing var id = $(this).parents('div.answer').attr('id').split('_')[1]; I have searched unsuccessfully documentation for the method parents in Google by Javascript "parents(" and by Java "parents(" How can you find the documentation for the following methods in JavaScript? parents() attr() split() ...

Asp.Net LinkButton Onclick = method( container.dataitem ), need help with syntax

I have a linkbutton that I want to call a method in the code behind. The method takes a parameter of which I need to stick in a container.dataitem. I know the container.dataitem syntax is correct because I use it in other controls. What I don't know is how to user it a parameter for a method. Upon clicking on the button, the method shoul...

Is there a way to require that an argument provided to a method is not null?

Is there a better way to require that an argument is not null in a method? I keep checking if any of the arguments that my method requires are null, as show below. But I'm wondering if there is a better way. public void MyMethod(string a, int b) { if(a==null){throw new ArgumentNullException("a");} if(b==null){throw new ArgumentNul...

Any good reason for Ruby to have == AND eql? ? (similarly with to_a and to_ary)

I know eql? is used by Hashes to see if an object matches a key*, and you do def ==(rb) if you want to support the == operator, but there must be a good reason that Hashes don't use == instead. Why is that? When are you going to have definitions for == and eql? that are not equivalent (e.g. one is an alias to the other) ? Similarly, ...

How to Convert "~/default.aspx" to "http://www.website.com/default.aspx" C#?

I know ASP.NET does this automatically, but for some reason I can't seem to find the method. Help anyone? Just as the title says. If I do a Response.Redirect("~/Default.aspx"), it works, but I don't want to redirect the site. I just want the full URL. Can anyone help me out? ...

C#: Returning 'this' for method nesting?

I have a class that I have to call one or two methods a lot of times after each other. The methods currently return void. I was thinking, would it be better to have it return this, so that the methods could be nested? or is that considerd very very very bad? or if bad, would it be better if it returned a new object of the same type? Or w...

How to hide __methods__ in python?

Hi, I just wondered, how to hide special __.*__ methods in python*? Especially I am using an interactive python interpreter with tab-completion, and I would like to display only the methods my modules expose ... thanks, / myyn / *(at least from the user, who uses a python shell) it looks like this now: h[2] >>> Q. Q.ALL( ...

Call a function from an object : object.function()

How can I call a function from an object in javascript, like for example in jquery you call myDiv.html() to get the html of that div. So what I want is this to work : function bar(){ return this.html(); } alert($('#foo').bar()); this is a simplified example, so please don't say : just do $('#foo').html() :) ...

Static vs. instance method for shared use

Here's what I am trying to determine... I have a utility class to append lines to a textfile. This must be used by a number of other classes, like a common logging file. In my first implementation, I had all the classes that wanted to use it make a referenceless instance, e.g. new Logger(logline,logname); The constructor creates a Pr...

C#, Writing longer method or shorter method?

I am getting two contradicting views on this. Some source says there should be less little methods to reduce method calls, but some other source says writing shorter method is good for letting the JIT to do the optimization. So, which side is correct? ...

Java Question, how to get the value of a method from an unknown object

I have lots of object defined in the system, perhaps 1000 objects, and some of them have this method: public Date getDate(); Is there anyway I can do something like this: Object o = getFromSomeWhere.....; Method m = o.getMethod("getDate"); Date date = (Date) m.getValue(); ...

How to display content that differs across controllers and methods in application layout?

I'm trying to display a javascript feedback widget in my default application.rhtml in a rails app. It will only appear on a subset of pages, distributed across different controllers. Trying to figure out the best way to do this. One thought was to do something like this: <%= render :partial => "layouts/feedback_tab" if @show_feedb...

How to pass control to a method

I want to create a method that changes enabled property. How do I pass the contorl name and property to a method. If the following were my original method: public void ChangeProperties() { btnAcesScore.Enabled = true; } I want to be able to change the "btnAcesScore" each time I call this method. How do I pass this to the metho...