Skip to main content

Questions tagged [methods]

A method is a procedure that is associated with a particular object. The purpose of the method is to guide the behavior of the object, and the tag should be used when this is the case.

Filter by
Sorted by
Tagged with
5 votes
3 answers
529 views

Every class of a model in my application has a create method. The framework gives me the default implementation of create which is “create in the DB”. Sometimes I need to perform some extra actions ...
Vadim Pushtaev's user avatar
-2 votes
4 answers
497 views

Rewrite of the Question: Is there a technical reason why we are not using static methods instead of instance methods. Technical reasons are for example: Performance or added type-safety. I reason ...
Baudin999's user avatar
1 vote
2 answers
2k views

It's a discussion about follow very strictly the SRP (Single Responsability Principle) vs. be more flexible when you write simple codes, like setting or getting properties values, even out of a direct ...
David Rodrigues's user avatar
1 vote
3 answers
340 views

I have a group of methods that is going to be very large. I need to be able to call methods systematically from a large group, in two different ways. The methods create a new item object with ...
krill 's user avatar
  • 21
6 votes
4 answers
3k views

According to this question and just about every style guide I've ever read, large methods are bad. However, suppose I have a method that does the following: Receive a JSON String from some service and ...
Teofrostus's user avatar
3 votes
1 answer
2k views

Let's say I have a class that needs some helper methods to do its work. The number of helper methods starts to grow and the size of the class also starts to grow a lot. How should I handle this ...
Kevin Amorim's user avatar
6 votes
2 answers
7k views

Assuming I have this class (Java code only for the sake of example): class Person { private String name; public void setName(String name) { this.name = name; } } When I write ...
Martin Andersson's user avatar
4 votes
2 answers
11k views

The book I am reading on Java states something confusing and unacceptable. Learning About Ambiguity When you overload methods, you risk creating an ambiguous situation - one which the compiler ...
With A SpiRIT's user avatar
0 votes
3 answers
229 views

I'm doing a compiler, and I'm using the System.out.println(); to print assembly; And the code get bigger, and more complicate to understand. I want to know whats is the difference of efficiency ...
Elias Pinheiro's user avatar
0 votes
1 answer
879 views

I have the following code: def __init__(self, vocable_file_path, xsd_file_path, word_list_file_path): self.vocable_file_path = vocable_file_path self.xsd_file_path = xsd_file_path self....
Zelphir Kaltstahl's user avatar
4 votes
3 answers
2k views

Whenever I'm writing code, I always stub out my methods like this (not necessarily using generics): public T MyMethod() { T result = default(T); // or null return result; } This always puts ...
Will Custode's user avatar
13 votes
2 answers
3k views

Looking through the Java Collections Framework, I've noticed quite a few of the interfaces have the comment (optional operation). These methods allow implementing classes to through an ...
MirroredFate's user avatar
2 votes
2 answers
3k views

I ran into these lines of code in the QPYTHON Android app. They are part of a sample that uses the Bottle module to create a simple Web server that seems to work fine. app = Bottle() app.route('/', ...
giantpredatorymollusk's user avatar
1 vote
2 answers
252 views

Lets say i am writing a web app that accesses user accounts in a database. If the account exist use that data. But if the account doesn't exist create a new one. Should this be done with two or one ...
mattNit's user avatar
  • 65
2 votes
1 answer
100 views

I've been noticing that modern frameworks tend to have this kind of code style: expect(6 - 4).toBe(2) this can be rephrased as: assert(6-4, 2) Yet the former is much more readable. I would like to ...
Jonny's user avatar
  • 131
3 votes
3 answers
1k views

I'm going to build some public PHP packages, Following standards is a priority for me. PHP lets users call methods even if they don't pass required parameters to it. My question. Should I check ...
Milad Rahimi's user avatar
21 votes
3 answers
5k views

Java SE 8 comes with a new mechanism for dates, introducing LocalDate, LocalTime and LocalDateTime classes to represent instants of time. To manipulate such instants, a set of methods are given: ...
Luigi Cortese's user avatar
12 votes
2 answers
4k views

Are there any objective arguments for or against using objects vs unique ID as method/function parameters? (and members of other objects?). Specially in the context of statically typed languages (C#/...
0fnt's user avatar
  • 426
1 vote
1 answer
80 views

I am debating the pros and cons of a couple of utility classes I have. The classes have a couple of properties which are set prior to calling the class methods. However, I was wondering if there are ...
physics90's user avatar
  • 119
3 votes
3 answers
2k views

In other words, is there a Python design related reason for it to be so? Functions like map, filter, reduce etc. are just plain functions. Is it just a poor design choice (if it is a good one, ...
Ivan's user avatar
  • 141
27 votes
6 answers
2k views

When I split big methods (or procedures, or functions — this question is not specific to OOP, but since I work in OOP languages 99% of the time, it's the terminology that I'm most comfortable with) ...
Max Yankov's user avatar
4 votes
3 answers
15k views

I'm a beginner in learning programming. I ask about using the string array in main method as a parameter. Why not writing the Main() method without the string array? What is the point of having this ...
Makeed's user avatar
  • 49
2 votes
2 answers
1k views

Suppose I have a series of methods across different classes that all use the same five core variables defined in my main method. I could chain these five variables as method arguments from one method ...
user3834916's user avatar
5 votes
2 answers
4k views

When using depending injection, you generally pass everything around as an interface (perhaps with the exception of primitives and strings). That allows you to easily chance the behavior, without ...
David says Reinstate Monica's user avatar
0 votes
1 answer
750 views

I've got a class: AuthenticationService findLoggedInUser() Checks session if User is logged in. If not, check client persistent user login cookie and log in. loginUser($email, $pw, $remember = false)...
Kid Diamond's user avatar
0 votes
1 answer
607 views

Is the following method considered to be doing one thing only? I'm wondering about that since it takes an optional argument. public function findErrors($name = null) { if ($name) { ...
Kid Diamond's user avatar
11 votes
4 answers
28k views

I have a class that has three methods A(), B() and C(). Those methods modify the own instance. While the methods have to return an instance when the instance is a separate copy (just as Clone()), I ...
Martin Braun's user avatar
3 votes
4 answers
2k views

I have a class SuperClass with two subclasses SubClassA and SubClassB. I have a method in a different class which takes a SuperClass parameter. The method should do different things depending on the ...
Aviv Cohn's user avatar
  • 21.6k
4 votes
6 answers
2k views

First, let me show you an example (written in ActionScript 3.0): class GameObject { public static function MakeFromName( pName:String, pAtlas:TextureAtlas ...
chamberlainpi's user avatar
10 votes
6 answers
1k views

I have some methods that perform some data changing in a database (insert, update, and delete). The ORM I'm using return row-affected int values for those type of method. What should I return for "my ...
Hoang Tran's user avatar
36 votes
9 answers
13k views

If there is a method bool DoStuff() { try { // doing stuff... return true; } catch (SomeSpecificException ex) { return false; } } should it rather be called ...
Limbo Exile's user avatar
8 votes
1 answer
529 views

I'm currently scratching my head over how to refactor a method that basically only builds the UI. The method is more than 1500 lines of code (LOC) long - and counting. It has grown, there was no plan ...
Kawu's user avatar
  • 207
3 votes
1 answer
368 views

I just came across this article, and in particular, this answer. Essentially they're talking about returning self from instance methods to allow for method chaining. That being said, one of the ...
Panzercrisis's user avatar
  • 3,223
1 vote
2 answers
2k views

I will give a simple example to help you understand my question. Suppose we have a rectangle and a Utility class with a method that creates a buffer arround a shape. The .createBuffer method has ...
jorgeb's user avatar
  • 11
-3 votes
3 answers
162 views

My question will be about how do you think it would be fit to name some methods in a fluent interface. Let me try to demonstrate the problem. Consider this relation tree: A person can have dogs and ...
Balázs Édes's user avatar
114 votes
9 answers
187k views

I just wanted to clear up a question I have. What is the point of having a private static method as opposed to a normal method with private visibility? I would have thought an advantage to having a ...
Rehan Naqvi's user avatar
  • 1,259
20 votes
2 answers
4k views

I have a C# class that represents a content type in a web content management system. We have a field that allows a web content editor to enter an HTML template for how the object is displayed. It ...
Charles Wesley's user avatar
1 vote
1 answer
3k views

Is there a general rule of thumb, when we should pass a value as as class variable and when as a method argument? Or is it just a choice of the developer? For example -- are there any reasons, why ...
trejder's user avatar
  • 2,416
12 votes
4 answers
5k views

I'm writing a linear algebra library (long story short, it's a school assignment) that involves matrices, vectors, etc. In the process of creating this library, I'm going to be creating functions ...
apnorton's user avatar
  • 389
1 vote
1 answer
3k views

I have a class that will have a number of external methods that will all call the same smaller set of internal methods. So something like: obj.method_one(a, c) and obj.method_two(a, c) where obj....
tonyl7126's user avatar
  • 297
1 vote
1 answer
165 views

When looking through Java documentation or answers for Stack Overflow / programming forum questions, I often see people referring to methods like String#format, Object#clone etc, rather than String....
Andreas Holley's user avatar
3 votes
4 answers
5k views

Consider the following piece of code class Foo { public: //... bool valueFirstGet(int& value) const { if(this==nullptr) {return 0;} ...
user877329's user avatar
6 votes
3 answers
3k views

I have a question about object oriented design that is not specific to Python but since my code is in Python, I tagged it as such. How do I decide which of my classes should be responsible for ...
Arne's user avatar
  • 163
8 votes
4 answers
32k views

I've heard that methods are more Object-Oriented than functions. I was wondering if someone could show me an example of a function and a method and explain the differences between methods and ...
Andrew's user avatar
  • 207
3 votes
4 answers
512 views

I am working with a non-OO language and I'm trying to name my routines consistently. I came acrross the following guideline from Steve McConnell's Code Complete: To name a procedure, use a strong ...
rick's user avatar
  • 2,005
9 votes
1 answer
13k views

I want to know what is exactly a method header and what is a method signature and is this the same among programming languages or just in C#? So, is it correct to say the following is a method ...
user109547's user avatar
-1 votes
2 answers
3k views

In the application I am currently working on, there are generally 3 types of HTTP calls: pure GETs pure POSTs (updating the model with new data) "GET" POSTs (posting down an object to get some data ...
antonpug's user avatar
  • 571
1 vote
2 answers
928 views

I'm new to objective C, I'm following "Objective C 5th Edition Stephen Kochan and I don't have anyone to ask my doubts to. I'm confused with this question: Q. Is it necessary to use "-" or "+" before ...
babu rao's user avatar
3 votes
3 answers
391 views

So I thought about this, and I don't know if it's included or not in any methodology. I think the advantages of this coding style is that, at the lowest level, the code is extremely testable, and ...
vlad-ardelean's user avatar
4 votes
6 answers
2k views

I have never seen the use of "are" for boolean methods, but the use of "is" is very common. When I want to use "are" is usually because I am passing multiple variables, or a list of objects. I ...
TruthOf42's user avatar
  • 772