The tag has no usage guidance.

learn more… | top users | synonyms

39
votes
5answers
20k views

What is the difference between a function and a lambda?

I'm a little bit confused about 'function' and 'lambda'. I've seen some examples showing that the scheme keyword lambda works very similarly to the JavaScript keyword function, but I really don't ...
0
votes
2answers
43 views

Trouble handling constraints for the input of a method

I'm looking for advice on how to handle constraints on the input of a method. I have a method that only works if the input argument(s) fulfill certain constraints. If the method is called on input ...
0
votes
2answers
49 views

Object Oriented Python methods and their parameters

Let's say I have a class MyClass ... which has a data member x class MyClass1 : def __init__(self) : self.x = 1 Also a method which does something with x Should I pass self.x as a ...
0
votes
0answers
25 views

Exposing 'utility' functions with AngularJS

I have an single-page Angular application which contains several controllers, directives and services. The fact here is that there are some controllers that hold two type of methods: "Scope" methods,...
-1
votes
0answers
64 views

Good examples of using “private” visibility in PHP [duplicate]

This is a pretty basic question, but I think a lot of people would benefit from the answer. When I'm coding in PHP I find myself almost never using "private" visibility on anything, I almost ...
0
votes
0answers
42 views

Export a method vs using a boolean property in a class?

I am writing a base class with common code for several Web sites. Two of these sites have mobile support. Should I create (constant) boolean object property mobile_support and write if(site->...
-2
votes
2answers
94 views

Java Ellipses Signature for Multiple Parmeters

Firstly, I am studying function with new type of signature and body, and in this code, I want to know, what type of object is values? It doesn't appear to be an array of strings based on my ...
14
votes
11answers
2k views

What is better IllegalStateException or silent method execution? [closed]

Let's say I have a MediaPlayer class which has play() and stop() methods. What is the best strategy to use when implementing the stop method in case when the play method has not been called before. I ...
4
votes
4answers
14k views

What's the difference between a function and a method?

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 ...
5
votes
6answers
282 views

Rule of thumb for deciding which class a method belongs to

For example, imagine a website which stores results about a certain sport or game, which has a typical "season" structure, such that there's both a Player and a Season class. To retrieve a player's ...
1
vote
1answer
105 views

Should “magic” getter functions be used for dynamically calculated values or just existing properties?

For example, if I had a Customer class and wanted to get all orders by them. Would it be better to do: class Customer{ public function getOrders(){ return results from db query } } .....
1
vote
2answers
72 views

Benefit of not overloading `AbstractCollection.add()` and having `AbstractCollection.addAll()`?

example: public class Something { private Set<String> names = new HashSet(); public void add(String n) { names.add(n); } public void add(Set<String> set) { names.addAll(set); ...
19
votes
5answers
4k views

Is it okay for a class to use its own public method?

Background I currently have a situation where I have an object that is both transmitted and received by a device. This message has several constructs, as follows: public void ReverseData() public ...
2
votes
1answer
103 views

printing in methods vs printing in the main/driver class

I'm fairly new to programming and am currently creating a blackjack game in Java. I've progressed quite well, although could use some pointers with regards to the best way to implement a method. At ...
2
votes
3answers
75 views

Calculating a score and a breakdown of the score in different places - should I use the same methods?

I am creating a plugin that uses a metric to determine a score on one page and allows the user to click through to see a more detailed breakdown of the score on a separate page. The trouble is: I can'...
14
votes
12answers
10k views

What is the reason for using lowercase for the first word in a local variable (eg, employeeCount, firstName)

I take a good deal of criticism from other programmers due to my use of full proper casing for all my variables. For example, your typical programmer will use employeeCount for a variable name, but I ...
5
votes
3answers
449 views

“Smart create” method naming

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 ...
-2
votes
4answers
179 views

Why do we add instance methods to classes? [closed]

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 ...
1
vote
3answers
257 views

Java need to call many methods systematically

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 ...
1
vote
2answers
149 views

When decoupling methods is not a good idea?

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 ...
6
votes
3answers
3k views

Should a method do one thing and be good at it? [duplicate]

"Extract Till You Drop" is someting I've read in Uncle Bob's blog, meaning that a method should do one thing alone be good at it. What is that one thing? When should you stop extracting methods? ...
6
votes
4answers
211 views

What is the best way to split up large methods where each subtask depends on previous tasks?

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 ...
10
votes
4answers
2k views

Member functions vs. Non-member functions for math operators

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 ...
2
votes
1answer
189 views

Helper methods of a particular class [closed]

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 ...
1
vote
2answers
172 views

Use a hash character or a dot when referring to methods and fields in software documentation? [closed]

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 ...
3
votes
1answer
54 views

Modern frameworks method conventions

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 ...
1
vote
2answers
664 views

Ambiguity in method overloading

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 ...
0
votes
3answers
163 views

Difference of efficiency [duplicate]

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 ...
2
votes
2answers
429 views

when using dependency injection, should I always pass an interface

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 ...
1
vote
2answers
907 views

Is it necessary to use “-” or “+” before every property or method declaration in Interface and why?

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 ...
0
votes
1answer
107 views

Should I put the parameters in constructor or in method? (Python 3)

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....
3
votes
3answers
6k views

UML representation of type being passed as a parameter

I want to draw a UML diagram of my program. Class Barney has a method Yabadaba(Doo d) which takes a parameter of type Doo. How do I represent that class Doo is used in class Barney in my UML diagram?
4
votes
3answers
205 views

Returning a Flag Indicating Success [closed]

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 ...
12
votes
2answers
572 views

UnsupportedOperationException in java collections framework interfaces

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 ...
1
vote
1answer
200 views

Function name in parentheses after fuction call in Python

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('/', ...
1
vote
2answers
96 views

One method to search and create if not found, or two methods

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 ...
2
votes
4answers
365 views

Should I check parameter before using it in methods? [duplicate]

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 ...
21
votes
3answers
3k views

Are “plus” and “minus” appropriate method names?

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: ...
5
votes
2answers
325 views

Identifier vs domain object as a method parameter

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#/...
1
vote
1answer
62 views

Down Sides to Using Properties as Opposed to Method Variables [closed]

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 ...
0
votes
3answers
374 views

Why python function programming functions are not collection methods? [duplicate]

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, ...
26
votes
5answers
2k views

Method extraction vs underlying assumptions

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) ...
1
vote
0answers
68 views

what is the best method to return db query and additional information from other methods

I am new to MVC and trying to continue to learn base on best practices. I am trying to return data from multiple sources -- one source being a mysql db query and another source from another method ...
15
votes
1answer
4k views

Is there a difference between arguments and parameters?

It might be like this: Parameter means from the callers POV and arguments mean inside the procedure, or other way round. Or is there no difference? Update In Swedish we say "anropsparametrar" i.e. ...
2
votes
3answers
6k views

Why using string[] args in all main methods?

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 ...
2
votes
2answers
435 views

Passing by value multiple times vs. Creating a public class variable

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 ...
0
votes
1answer
152 views

How to split a Service class in two but still use them like one?

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 = ...
0
votes
1answer
343 views

Does this function do one thing only?

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) { ...
2
votes
4answers
1k views

When should a method of a class return the same instance after modifying itself?

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 ...
3
votes
4answers
319 views

Is there a way to avoid type-checking in this scenario?

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 ...