The tag has no wiki summary.

learn more… | top users | synonyms

112
votes
13answers
24k views

Is it OK to split long functions and methods into smaller ones even though they won't be called by anything else? [duplicate]

Lately I've been trying to split long methods into several short ones. For example: I have a process_url() function which splits URLs into components and then assigns them to some objects via their ...
54
votes
18answers
4k views

Are long methods always bad?

So looking around earlier I noticed some comments about long methods being bad practice. I am not sure I always agree that long methods are bad (and would like opinions from others). For example I ...
45
votes
6answers
3k views

Refactoring into lots of methods - is this considered clean or not? [duplicate]

So, I watched as my colleague complained a bit about a project he has inherited from someone who is, shall we say, not very experienced as a programmer (intern left to his own devices on a project). ...
30
votes
9answers
3k views

How to name a method that both performs a task and returns a boolean as a status?

If there is a method bool DoStuff() { try { // doing stuff... return true; } catch (SomeSpecificException ex) { return false; } } should it rather be called ...
28
votes
5answers
7k 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 ...
27
votes
4answers
1k views

How do programming languages define functions?

How do programming languages define and save functions/methods? I am creating an interpreted programming language in Ruby, and I am trying to figure out how to implement function declaration. My ...
26
votes
8answers
5k views

Why have private static methods?

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 ...
18
votes
8answers
952 views

How and why to decide between naming methods with “get” and “find” prefixes

I always have trouble figuring out if I should name a certain method starting with getSomething versus findSomething. The problem resides in creating helpers for poorly designed APIs. This usually ...
15
votes
10answers
14k views

What is the opposite of initialize (or init)? [closed]

The term will be used as a method name. The method is called when a part of the user interface is hidden (or removed), and it is used to reset values to default and dispose objects that will not be ...
10
votes
6answers
1k views

Designing database related methods, which is better to return: true/false or row affected?

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

Design: Object method vs separate class's method which takes Object as parameter?

For example, is it better to do: Pdf pdf = new Pdf(); pdf.Print(); or: Pdf pdf = new Pdf(); PdfPrinter printer = new PdfPrinter(); printer.Print(pdf); Another example: Country m = new ...
10
votes
4answers
439 views

Where does “method” as a special term in OOP originate?

"Method" is a special term in Object-Oriented Programming. Does anyone know when the word began to be used in this particular sense, and in connection with what programming language or other branch of ...
9
votes
11answers
3k 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 ...
9
votes
1answer
2k 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. ...
9
votes
2answers
740 views

Refactoring several huge C++ classes / methods. How to start? [duplicate]

Possible Duplicate: I’ve inherited 200K lines of spaghetti code — what now? I'm dealing with legacy code. It contains some BIG classes (line count 8000+) and some BIG methods (line count ...
8
votes
1answer
412 views

Refactoring a 1500 LOC method that only builds the graphical UI [closed]

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

Prefer class members or passing arguments between internal methods?

Suppose within the private portion of a class there is a value which is utilized by multiple private methods. Do people prefer having this defined as a member variable for the class or passing it as ...
8
votes
1answer
409 views

Math library methods in Google's Go Programming Language

I have been programming in google Golang and have been enjoying it due to its brevity but I find it surprising that almost all its Math standard library methods are for the floating point type. Is ...
7
votes
4answers
368 views

How to prevent duplicate data access methods that retrieve similar data?

In almost every project I work on with a team, the same problem seems to creep in. Someone writes UI code that needs data and writes a data access method: AssetDto GetAssetById(int assetId) A week ...
6
votes
4answers
449 views

Which popular object-oriented languages support readonly methods?

I thought that many object-oriented languages have a reserved keyword for methods which do not modify the state of an object. These methods often have names that start with get. AFAIK a "getter" is ...
6
votes
6answers
341 views

Fields vs method arguments [closed]

I just started writing some new class and it occurred to me that I was adding a lot of method arguments that are not strictly needed. This is following a habit to avoid having state in classes that is ...
6
votes
5answers
3k views

Differences between messages and methods?

In Objective C you have the concept of sending messages to other objects, and, well this is very similar to method calling in languages like C# and Java. But what exactly are the subtle ...
5
votes
3answers
363 views

Should a method's parameter list contain objects or object identifiers?

Our teams is having the following discussion: Let's say we have the following two methods: public Response Withdraw(int clubId, int terminalId,int cardId, string invoice, decimal amount); public ...
5
votes
4answers
631 views

Method flags as arguments or as member variables?

I think the title "Method flags as arguments or as member variables?" may be suboptimal, but as I'm missing any better terminology atm., here goes: I'm currently trying to get my head around the ...
5
votes
6answers
803 views

Should I have a separate method for Update(), Insert(), etc., or have a generic Query() that would be able to handle all of these? [closed]

I'm currently trying to write a class library for a connection to a database. Looking over it, there are several different types of queries: Select From, Update, Insert, etc. My question is, what ...
5
votes
5answers
299 views

Is it good or bad form to name a function after the workaround it fixes?

Lets say you have to write some code to fix a bug that on first glance by another engineer would seem weird or unnecessary. Would it be good or bad form to put the code in a method named for example ...
5
votes
3answers
912 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 ...
5
votes
4answers
927 views

What is a good pattern for combined caching and reinitialization?

I have a situation where I have three requirements: Lazy initialization - don't create the collection until asked for it Caching - keep the collection in memory on the object Reinitialization - be ...
4
votes
2answers
418 views

Should I expose a “computed” value as a property or a method?

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 ...
4
votes
5answers
221 views

Group method parameter or individual parameter?

I would like to ask on method parameters design consideration. I am usually deciding between using individual variables as parameters versus grouping them to a class or dictionary as one parameter. ...
4
votes
3answers
1k 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? ...
4
votes
6answers
833 views

Is it bad practice to resolve null arguments to default static variables?

First, let me show you an example (written in ActionScript 3.0): class GameObject { public static function MakeFromName( pName:String, pAtlas:TextureAtlas ...
4
votes
4answers
322 views

Why is the following naming guideline different between OO and non-OO languages?

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 ...
4
votes
5answers
415 views

How does the concept of a class change when passing data to the constructor instead of method parameters?

Let's say we're making a parser. One implementation could be: public sealed class Parser1 { public string Parse(string text) { ... } } Or we could pass the text to the ...
4
votes
3answers
397 views

Renaming long named method in C# [closed]

I'm working on a project where exist one method with title string ValidateNewPasswordExpireCurrentPasswordAndCreateNewPassword(...) I'm sure the method name must be changed. But can't found good ...
4
votes
5answers
291 views

Sending Whole Data Object As Argument Or Just Required Fields?

Let's say I have a class that just stores data: ClassData Field1 Field2 Field3 Now let's say I have a function that uses Field1 and Field2: public void DoStuff(string field1, string ...
4
votes
2answers
190 views

Does the single responsibility principal promote flexibility?

Does the single responsibility principal promote flexibility? If not what are the other methods to make your classes more flexible? By flexibility I mean, a class is able to function correctly at any ...
4
votes
2answers
1k views

Naming methods that do the same thing but return different types

Let's assume that I'm extending a graphical file chooser class (JFileChooser). This class has methods which display the file chooser dialog and return a status signature in the form of an int: ...
4
votes
2answers
526 views

Should I put utility methods inside a class?

I have been working on a library which contains a large set of functions. For the sake of simplicity, I am going to use just one set as an example. I am not sure which is the better way, in terms of ...
4
votes
3answers
312 views

Python: How to decide which class' methods should provide behavior (functionality) affecting multiple classes

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

Best Method of function parameter validation

I've been dabbling with the idea of creating my own CMS for the experience and because it would be fun to run my website off my own code base. One of the decisions I keep coming back to is how best ...
4
votes
3answers
136 views

Using “prevent execution of method” flags

First of all I want to point out my concern with some pseudocode (I think you'll understand better) Assume you have a global debug flag, or class variable named "debug", class a : var debug = ...
4
votes
1answer
3k views

What's the difference between static and dynamic binding? [closed]

We are learning about methods in class, and I am having trouble especially with the concept of static vs. dynamic. Wikipedia says this: Methods can be bound to a class at compile time (static ...
3
votes
3answers
628 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 ...
3
votes
4answers
362 views

Using ref instead of out. Would that be considered a bug?

Given that out and ref parameters have slight different connotations would writing code like below be considered a bug (even though it doesn't cause an issue at present), or just a lack of ...
3
votes
4answers
234 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 ...
3
votes
4answers
822 views

Use null object as argument to method

Consider the following piece of code class Foo { public: //... bool valueFirstGet(int& value) const { if(this==nullptr) {return 0;} ...
3
votes
2answers
519 views

Do we ethically have the right to use the MAC Address for verification purposes?

I am writing a program, or starting at the very beginning of it, and I am thinking of purchase verification systems as a final step. I will be catering to Macs, PCs, and possibly Linux if all is said ...
3
votes
7answers
898 views

Pass in single settings object vs multiple setter methods?

Working with C++. Suppose I have a class BoxFilter. The class is used to filter boxes which have properties such as height, width, depth, weight, etc. The filter might have something like MaxWidth ...
3
votes
3answers
313 views

Making some methods mostly contain method calls, while others doing “the lowest level” work [duplicate]

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