methods

Should I always make my methods static where possible?

I have often pondered this one... its probably an idiot question but here goes. Say I have this class: public class SomeClass { public int AProperty { get; set; } public void SomeMethod() { DoStuff(AProperty); } } Is there any advantage to doing this: public class SomeClass { public int AProperty { get; ...

New to Java, help transforming this method into class. Over reliance on the Main Method

Let me start by saying, I am new to Java programming. I have coded something out that performs in the manner that I want it to. However, it is not very well written. Here is my code: import java.lang.Math; public class Advisor_Score { public static void main(String[] args){ double p1_1[] = {101,1,1,1.5,.5}; do...

Calling a property or method using an attribute name

Let's say I have a class that looks like this: public class CallByAttribute { [CodeName("Foo")] public string MyProperty { get; set; } [CodeName("Bar")] public string MyMethod(int someParameter) { return myDictionary[someParameter]; } } How would I call these two properties or methods, using CodeName ...

I'm making an Android IME. How do I add a "Settings" list item in the "Language & Keyboard" settings screen?

... like "Swype settings" in this picture. Been searching for hours on how to do this. Going to go insane. Help appreciated. ...

jQuery's AJAX call to a javascript class method

Hi there, I'm a newbee about jQuery's workflow and I would like to setup a javascript class that uses an internal method to make an AJAX request. When the request returns with success, the jQuery AJAX callback should invoke a method owned by the class itself. That's the code: function IXClock() { this.m_intervalID = 0; this.sta...

Convert several Java methods to run as non-blocking threads?

Is it possible to convert a number of methods (defined in an interface and implemented in a class) to run as non-blocking threads? Certainly, i can wrap each single method in the run() method of a thread class. But perhaps there exists a more sophisticated way to warp several different methods in one step, i.e. by a single thread class...

What's the reason for not being able to use more than one params parameter in a method definition?

Something like: public static void Estimate ( params string [ ] names, params int[] numbers ) { } where you could use it like: Estimate ( "Eric", "Simpson", "Jon", 1, 2, 3, 4, 5 ) ...

How do I debug this 'no method' error in ruby on rails?

I get the following error: Delayed::Job SomeMailJob# (NoMethodError) "undefined method `subject' for #<YAML::Object:0x2b0a191f4c78>" This comes from the following code which references the SombMailJob above: class SomeMailJob < Struct.new(:contact, :contact_email) def perform OutboundMailer.deliver_campaign_email(contact,co...

Easy way of overriding default methods in custom Python classes?

I have a class called Cell: class Cell: def __init__(self, value, color, size): self._value = value self._color = color self._size = size # and other methods... Cell._value will store a string, integer, etc. (whatever I am using that object for). I want all default methods that would normally use the ...

Good way to define a method

What is the best / good way to implement method calls. For eg: From the below which is generally considered as best practice. If both are bad, then what is considered as best practice. Option 1 : private void BtnPostUpdate_Click(object sender, EventArgs e) { getValue(); } private void getValue() { ...

Is it possible to break/return method execution from another method?

I have something like this: void MethodToBreak() { // do something if(something) { MethodThatBreaks(); return; } // do something } void MethodThatBreaks() { // do something } So, I was wondering: is it possible to break execution from: MethodThatBreaks()? Then, I would have: if(something) Met...

When should private methods in PHP work on class variables, and when should such methods be used as functions?

Hi, I'm wondering when private/protected methods should work on the class it's variables (like $this->_results) and when such methods should be used as if they were functions (like $this->_method($results)). Examples below: Work on class properties <?php class TestA { protected $_results; public function getResults() { ...

Using extension methods with runtime assemblies

Is there any way to use extension methods on a class that has been dynamically created using Relection.Emit? For example: class somewhere { somewhere() { // define the type here using ReflectionEmit, etc. Type tableType = CreateTableType(...table parameters...); var table = Activator.CreateInstan...

Python : how to prevent a class variable that is a function to be understood as a method ?

Hi all ! I am currently implementing a django app, for this I try to use a syntax that is consistent with Django's... So here is what I am trying : class Blablabla(Model): #this contains Blablabla's options class Meta: sort_key = lambda e: e sort_key is a key function (for sorting purposes), but of course, it is und...

Trimexcess on List(Of t) in .net

After filling a list with the the needed strings, if the list won't be further appended, should trimexcess be called? ...

What is a good name for an instance method that adds a linked-list node after the target?

I'm creating a doubly-linked list in Objective-C. I would like my node class to include an instance method that allows me to add another node after the target node, like so: // start <-> nodeA <-> nodeB <-> nodeC <-> end Node * newNode = [Node node]; [NodeB thisMethodNeedsAGoodName:newNode]; // start <-> nodeA <-> nodeB <-> newNode <-...

rails check for existing instance attribute

Hi guys I'm working on a social networking site (basically a copy of facebook to be honest...) and I reused big parts of insoshi. But the feed of insoshi is not accurate enough for my likings. As in it doesnt support more specialized messages. You will see what I mean in the following code: item = activity.item relationship = relation...

Call Dialog Methods form a static Class in C#

I have to catch an event from a parent dialog that uses a method from a static class to update an array. From this dialog I call a child dialog that shows the array in a list. I know with a variable if the current dialog is the child or the parent dialog, but from the method in the static class how can I call the method inside the chil...

Why am I getting a NoMethodError for an attribute that exists in my model?

This is the error I get: ContactPostalcardsController#skip (NoMethodError) "undefined method `status=' for #<ContactPostalcard:0x2b21433d64b0>" This is the code calling it and trying to assign a value to the status attribute for ContactPostalcard (the Model): def skip @contact_postalcard = ContactPostalcard.new(params[:contact...

Should method/class comments be consistently applied or on a need basis only?

For consistency, I've always applied comments (in the form of a JavaDoc) to all methods and classes, even if they are simple getters and setters methods or very small wrapper classes. But I'm also striving to write self-documenting code which often makes comments superfluous; i.e. write comments only where needed (and before doing that, ...