What is the difference between subroutine and function




















But now I am a die-hard fan of MS Excel. I learn new ways of doing things with Excel and share them here. Stay tuned! We provide tips, how to guide and also provide Excel solutions to your business problems. I earn a small commission if you buy any products using my affiliate links to Amazon.

Contact Privacy Policy. Kawser Sep 9, 1. Table of Contents hide. On casual inspection, they appear to be the same. In truth, however, they are different. A subroutine is a piece of code that performs a set of actions or calculations, or a combination of the two. It can form a "building block" within a program and may sometimes need to be repeated. PerlMonks parthenogenetically spawned by Tim Vroom.

PerlMonks is a proud member of the The Perl Foundation. Perl Monk, Perl Meditation. Difference between subroutine and functions by madtoperl Friar. Need Help?? Comment on Difference between subroutine and functions Replies are listed 'Best First'. Wikipedia is a good friend. The name method is commonly used in connection with object-oriented programming, specifically for subroutines that are part of objects. No value is associated with the name of a subroutine,while the name of a function subprogram must have a value, numerical or logical.

A subroutine may be invoked only by a special calling statement-the call statement. The name of a function subprogram may be used in the same way as library functions,,i. Since a function subprogram computes atleast one value, it must contain a return statement. The way I always explain it: CODE objects are declared as subroutines, but used either as functions or methods.

Nor can you write a function or method, except as a subroutine. Please apply a little thought about what you are doing. Yet, I maintain that the terminology for that language draws a distinction. One that could arguably be a convention of the language. Generally speaking though, I don't think there's a definitive difference.

In a purely mathematical sense however, a function takes arguments and returns a value. Obviously we can write a function, procedure, method, whatever that does neither of those ie. However in some languages VB you can not have a Function that doesn't return a value, but it can have no arguments. A subroutine cannot return a value and may or may not have arguments.

Object oriented practices complicate this more. But most commonly member functions are called methods, a word that has no mathematical ties though maybe scientific with a different definition. NerdFury, I encourage you to post this as your own answer. It would seem by your comment that you have provided an alternate definition.

Although I still maintain that the difference between these two terms boils down to specific language conventions, I agree with what you have said. Show 2 more comments. Thats my definition of them ;-. Andreas Andreas 7 7 bronze badges. Explain void function then? A void function doesn't return a value. Your definition is a function returns a value. Weak sauce. From Wikipedia: ' This is quite fundamental. Show 4 more comments. A function is a realization of the Subroutine concept in the programming language.

Amit Amit 79 1 1 silver badge 1 1 bronze badge. Andro Selva NKay NKay 41 1 1 bronze badge. One of the differences could be from the origin where the terminology comes from.

Azeem Akhter Azeem Akhter 7 7 silver badges 18 18 bronze badges. Teivaz 4, 4 4 gold badges 27 27 silver badges 66 66 bronze badges. Based on Wikipedia subroutine definition: In computer programming, a subroutine is a sequence of program instructions that perform a specific task, packaged as a unit.

Sometimes in OOP the function that belongs to the class is called a method. Vlad Bezden Vlad Bezden Yes, they are different, similar to what you mentioned. Summary: Subroutines work only based on side-effects, in the view of the programming language you are programming with. Details: The subroutine originally is simply a repeatable snippet of code which you can call in between other code.

Subroutines are concrete objects. Functions are abstract objects. ChrisoLosoph ChrisoLosoph 87 6 6 bronze badges. The essential is isolation of names to the function unless declared global in the function. Harry Binswanger Harry Binswanger 9 9 silver badges 11 11 bronze badges. Columns 1. Got it from another internet post. It works fine. Daredevil Daredevil 7 1 1 bronze badge.

Ti Kanon Ti Kanon 27 3 3 bronze badges. Your answer might be correct, but that info is already given in all the other answers to this question.



0コメント

  • 1000 / 1000